I searched the internet before coming here. I guess everyone's needs are different. I want a Windows GUI program that will get information from database and show it in grid and have a delete button next to each record. I also want it to have a link, for example if the id number of the record is clicked, it opens new browser and navigates to a page associated with it, and completes forms then submits by itself.
The question is: Since there are many modules out there, which one is the best for this?
(Perl Nubie)
Nobody can truly say what is BEST, but the option of the Tk module with a backend of, in your case, DBD::MySQL, is maybe the most "standard" for things like this in Perl. Examples for both can be found all around online.
Here are some for SQL with mySQL and DBD :
http://sql-info.de/mysql/examples/Perl-DBI-examples.html
Here is a good document of examples for perl TK:
http://www.ibm.com/developerworks/aix/library/au-perltkmodule/index.html
As far as opening a browser - a simple system command will do:
my #command = ('start', $url);
system(#command);
^That is for Windows. It looks like you have a decently large application you want to build - opening a browser is just a small part of it - you will want to execute the above when a button is pressed, no doubt.
The last part...submitting data to forms on the web, is a topic called "web crawling"... WWW::Mechanize is a library to look into - Google "perl web crawler" and you are bound to get more good examples.
I found this with a little searching - it looks to be of use to you:
http://www.stratos.me/2009/05/writing-a-simple-web-crawler-in-perl/
Give one (nasty) precondition, ca. 25 lines of HTML
<html>
<head>
<hta:application id="demo" scroll="No"></hta>
<title>Demo</title>
<script language = "PerlScript"
src = "demo.pl"
type = "text/perlscript"
></script>
</head>
<body onload="DoOnLoad()" onunload="DoOnUnLoad()">
<object classid = "clsid:67397AA3-7FB1-11D0-B148-00A0C922E820"
id = "id_oDC"
style = "position:relative;width:1px;height:1px"
></object>
<object classid = "clsid:CDE57A43-8B86-11D0-B3C6-00A0C90AEA82"
id = "id_oDG"
style = "position:relative;width:100%;height:95%"
></object>
</body>
</html>
and ca. 40 lines of Perl:
use strict;
use warnings;
use Win32::OLE qw( in );
use Win32::OLE::Const 'Microsoft ActiveX Data Objects';
use vars qw( $window );
my $oAdoDC;
my $oAdoDG;
sub DoOnLoad {
my $owda = $window->document->all;
$oAdoDC = $owda->id_oDC;
$oAdoDC->{ConnectionString} = 'DSN=SakilaGent';
$oAdoDG = $owda->id_oDG;
$oAdoDC->{CursorType} = adOpenKeyset;
$oAdoDG->Font->{Name} = "Arial";
$oAdoDG->Font->{Size} = "8";
$oAdoDG->HeadFont->{Name} = "Arial";
$oAdoDG->HeadFont->{Size} = "8";
$oAdoDC->{RecordSource} = "select * from customer";
$oAdoDG->{Caption} = $oAdoDC->{RecordSource};
$oAdoDC->Refresh();
$oAdoDG->{DataSource} = $oAdoDC;
}
sub DoOnUnLoad {
$oAdoDG->{ DataSource }->Close();
$oAdoDC->{ Recordset }->Close();
$oAdoDG = undef;
$oAdoDC = undef;
}
will give you a flexible 'display/edit every recordset from every database accessible by ADO' type of data grid:
at no costs. A person familiar with HTML (but not Tk or Wx) and ADO/Access/Excel (but not DBI) could build a nice Database GUI easily/effiently. The precondition (i.e. drawback) is: Even the deployment computers need to have the "Microsoft DataGrid Control 6.0 (OLEDB)" (there are a plain tabular, a hierarchical, and a flexible hierarchical grid control too; maybe more modern controls can be used also) installed in a development/design-time enabled mode.
I would suggest using:
Wx for the user interface (provides a more modern/native look than Tk; see also the main site wxWidgets)
DBD::SQLite for local database storage
WWW::Mechanize - submitting forms
Since you're using Windows, your best bet would be to install Strawberry Perl which includes SQLite and Mechanize. Installing Wx or Tk is an extra step, but you should be able to find tutorials on the web from others who have done so. You may also want to look at Padre, the Perl IDE which is a Perl editor / development environment (it also happens to use Wx).
I am developing image extraction application in .net using C# in VS2010.
i have created a path ,where the image will be extracted.But this path is specific to my system.
string image1 = "c:\\Users\\Raghu\\Desktop\\r.bmp";
I want a path which should be general i.e when the project will be deployed ,the output file should be extracted in Target Users desktop.
how create a folder on desktop and and all my extracted files goes in it.
Any ideas! please help me!!
Next code will return path to the desktop of current user:
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
So, in your case it would be
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string image1 = System.IO.Path.Combine(desktop, "r.bmp");
Environment.SpecialFolder (http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx) contains many definitions of system folder paths. Take a look which you need.
You would use the DesktopDirectory for Environment.SpecialFolder. Something like this:
public static string GetDesktopDirectory()
{
return Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
}
Then using the result of that method, you can use Path.Combine to append a file name to it.
var myFilePath = Path.Combine(GetDesktopDirectory(), "r.bmp");
Path.Combine is the general solution for this, as directly concating strings may result in double slashes, etc. This takes care of that for you.
A Windows Phone 7 app, it seems, has two places with version number - one in AssemblyInfo.cs (via AssemblyVersion/AssemblyFileVersion attributes), the other is WMAppManifest.xml. Those two seem uncorrelated - changing one does not affect the other. The Marketplace, it seems, uses the one from the manifest - can someone please confirm this?
The real question is - how do I retrieve the one from manifest programmatically to display on the About screen?
The WmAppManifest.xml number is in use. First two digits are relevant for Marketplace (it is checked when you do the update) next two are for your internal usage.
This is a regular XML file, open it as a XDocument and parse it. An example.
EDIT: the example is extraneous. For just the version, use:
string Version = XDocument.Load("WMAppManifest.xml")
.Root.Element("App").Attribute("Version").Value;
To get App Version from "WMappManifest.xml", this solution might be a bit more efficient than lukas solution:
For WP7:
var xmlReaderSettings = new XmlReaderSettings
{
XmlResolver = new XmlXapResolver()
};
using (var xmlReader = XmlReader.Create("WMAppManifest.xml", xmlReaderSettings))
{
xmlReader.ReadToDescendant("App");
return xmlReader.GetAttribute("Version");
}
For WP8:
using (var stream = new FileStream("WMAppManifest.xml", FileMode.Open, FileAccess.Read))
{
string appVersion = XElement.Load(stream).Element("App").Attribute("Version").Value;
}
In Visual Studio debug mode it's possible to hover over variables to show their value and then right-click to "Copy", "Copy Expression" or "Copy Value".
In case the variable is an object and not just a basic type, there's a + sign to expand and explore the object. It there a way to copy all that into the clipboard?
In the immediate window, type
?name_of_variable
This will print out everything, and you can manually copy that anywhere you want, or use the immediate window's logging features to automatically write it to a file.
UPDATE: I assume you were asking how to copy/paste the nested structure of the values so that you could either search it textually, or so that you can save it on the side and then later compare the object's state to it. If I'm right, you might want to check out the commercial extension to Visual Studio that I created, called OzCode, which lets you do these thing much more easily through the "Search" and "Compare" features.
UPDATE 2 To answer #ppumkin's question, our new EAP has a new Export feature allows users to Export the variable values to Json, XML, Excel, or C# code.
Full disclosure: I'm the co-creator of the tool I described here.
You can run below code in immediate window and it will export to an xml file the serialized XML representation of an object:
(new System.Xml.Serialization.XmlSerializer(obj.GetType())).Serialize(new System.IO.StreamWriter(#"c:\temp\text.xml"), obj)
Source: Visual Studio how to serialize object from debugger
Most popular answer from https://stackoverflow.com/a/23362097/2680660:
With any luck you have Json.Net in you appdomain already. In which
case pop this into your Immediate window:
Newtonsoft.Json.JsonConvert.SerializeObject(someVariable)
Edit: With .NET Core 3.0, the following works too:
System.Text.Json.JsonSerializer.Serialize(someVariable)
There is a extension called Object Exporter that does this conveniently.
http://www.omarelabd.net/exporting-objects-from-the-visual-studio-debugger/
Extension: https://visualstudiogallery.msdn.microsoft.com/c6a21c68-f815-4895-999f-cd0885d8774f
You can add a watch for that object, and in the watch window, expand and select everything you want to copy and then copy it.
By using attributes to decorate your classes and methods you can have a specific value from your object display during debugging with the DebuggerDisplay attribute e.g.
[DebuggerDisplay("Person - {Name} is {Age} years old")]
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
I always use:
string myJsonString = JsonConvert.SerializeObject(<some object>);
Then I copy the string value which unfortunately also copies the back slashes.
To remove the backlashes go here:
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_replace
Then within the <p id="demo">Visit Microsoft!</p> element replace the text with the text you copied.
then replace the var res = str.replace("Microsoft", "W3Schools"); line with
var res = str.replace(/\\/g, '')
Run these new changes but don't forget to click the "try it" button on the right.
Now you should have all the text of the object in json format that you can drop in a json formatter like http://jsonformatter.org or to create a POCO you can now use http://json2csharp.com/
ObjectDumper.NET
This is an awesome way!
You probably need this data for a unit test, so create a Sandbox.cs temporary test or you can create a Console App.
Make sure to get NuGet package, ObjectDumper.NET, not ObjectDumper.
Run this test (or console app)
View test output or text file to get the C# initializer code!
Code:
[TestClass]
public class Sandbox
{
[TestMethod]
public void GetInitializerCode()
{
var db = TestServices.GetDbContext();
var list = db.MyObjects.ToList();
var literal = ObjectDumper.Dump(list, new DumpOptions
{
DumpStyle = DumpStyle.CSharp,
IndentSize = 4
});
Console.WriteLine(literal); // Some test runners will truncate this, so use the file in that case.
File.WriteAllText(#"C:\temp\dump.txt", literal);
}
}
I used to use Object Exporter, but it is 5 years old and no longer supported in Visual Studio. It seems like Visual Studio Extensions come and go, but let's hope this NuGet package is here to stay! (Also it is actively maintained as of this writing.)
Google led me to this 8-year-old question and I ended up using ObjectDumper to achieve something very similar to copy-pasting debugger data. It was a breeze.
I know the question asked specifically about information from the debugger, but ObjectDumper gives information that is basically the same. I'm assuming those who google this question are like me and just need the data for debugging purposes and don't care whether it technically comes from the debugger or not.
I know I'm a bit late to the party, but I wrote a JSON implementation for serializing an object, if you prefer to have JSON output. Uses Newtonsoft.Json reference.
private static void WriteDebugJSON (dynamic obj, string filePath)
{
using (StreamWriter d = new StreamWriter(filePath))
{
d.Write(JsonConvert.SerializeObject(obj));
}
}
I've just right clicked on the variable and selected AddWatch, that's bring up watch window that consists of all the values. I selected all and paste it in a text a text editor, that's all.
Object Dumper is a free and open source extension for Visual Studio and Visual Studio Code.
"Dump as" commands are available via context menu in the Code and Immediate windows.
It's exporting objects to:
C# object initialization code,
JSON,
Visual Basic object initialization code,
XML,
YAML.
I believe that combined with the Diff tool it can be helpful.
I'm the author of this tool.
if you have a list and you want to find a specific variable:
In the immediate window, type
myList.Any(s => s.ID == 5062);
if this returns true
var myDebugVar = myList.FirstOrDefault(s => s.ID == 5062);
?myDebugVar
useful tips here, I'll add my preference for when i next end up here asking this question again in the future.
if you don't mind adding an extension that doesn't require output files or such there's the Hex Visualizer extension for visual studio, by mladen mihajlovic, he's done versions since 2015.
provides a nice display of the array via the usual magnifine glass view object from the local variables window.
https://marketplace.visualstudio.com/items?itemName=Mika76.HexVisualizer2019 is the 2019 version.
If you're in debug mode, you can copy any variable by writing copy() in the debug terminal.
This works with nested objects and also removes truncation and copies the complete value.
Tip: you can right click a variable, and click Copy as Expression and then paste that in the copy-function.
System.IO.File.WriteAllText("b.json", page.DebugInfo().ToJson())
Works great to avoid to deal with string debug format " for quote.
As #OmerRaviv says, you can go to Debug → Windows → Immediate where you can type:
myVariable
(as #bombek pointed out in the comments you don't need the question mark) although as some have found this limits to 100 lines.
I found a better way was to right click the variable → Add Watch, then press the + for anything I wanted to expand, then used #GeneWhitaker's solution, which is Ctrl+A, then copy Ctrl+C and paste into a text editor Ctrl+V.
I've got a visual studio addin written by developer who is no longer at the company and have no idea how to debug it. But I want to add a feature so it can recurse into solution folders.
Sounds simple but I'm not sure the api allows testing for this?
Well there's got to be a way because AnkhSVN and VisualSVN work fine with Solution Folders.
StackOverflow I'm reaching out for some help on this issue.
Thanks
Notes
-We are using solution folders to hide "Dependency Projects" which are basically a list of project references that we probably don't care about in the particular solution and want to hide by default.
public class Connect : IDTExtensibility2, IDTCommandTarget
{
public void GetProjectLocations(DTE2 dte)
{
UIHierarchy UIH = dte.ToolWindows.SolutionExplorer;
try
{
UIHierarchyItem UIHItemd = UIH.UIHierarchyItems.Item(1);
}
catch (Exception E)
{
Debug.Write(E);
}
UIHierarchyItem UIHItem = UIH.UIHierarchyItems.Item(1);//this looks suspect to me
// Iterate through first level nodes.
for (int i = 1; i <= UIHItem.UIHierarchyItems.Count; i++)
{
Project TempGeneralProjObj = dte.Solution.Item(i);
if (TempGeneralProjObj.Kind == PrjKind.prjKindCSharpProject)
{
}
}
}
}
So far from my tests it appears that solution folders will cast to type Project surprisingly and once that is done the Project.ProjectItems property will hold a list of Projects that may exists underneath that folder. So in short, this is one way to at least get information about how things are structured. The problem however is that each ProjectItem located underneath a solution folder appears to cast find to type ProjectItem but doesn't seem to be able to be cast to a Project.
This is how I'm currently detecting a solution folder in my loop.
if(project.Kind == "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}")
{
// TODO: Do your thing
}
This has also been frustrating me and I've also noticed a bug in how ActiveReports handles solution folders as well which is related to this same issue.
UPDATE!
Ok so I found the solution but I can't claim it 100% because I found most of it at Macaw's Blog.
So it appears that my original findings were right on however in order to get the actual project type for each ProjectItem under the solution item you need to look under the ProjectItem.SubProject property.
Now Macaw takes a recursive approach to walking the project structure which I think I would also normally recommend however in my case I wanted a single method implementation to simply log out an XML representation of the project for simple research purposes so I ended up using a Stack implementation. For reference you can find my code below which is successfully handling at least one level of solution folders full of projects only and no other specialty solution items.
XElement rootNode = new XElement("Solution");
rootNode.Add(new XAttribute("Name", _applicationObject.Solution.FullName));
Stack<Project> projectStack =
new Stack<Project>(_applicationObject.Solution.Projects.Cast<Project>());
while(projectStack.Count > 0)
{
var project = (Project)projectStack.Pop();
var solutionItemName = "Project";
if(project.Kind == "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}")
{
foreach(ProjectItem innerProject in project.ProjectItems)
{
if(innerProject.SubProject != null)
{
projectStack.Push(innerProject.SubProject);
}
}
solutionItemName = "Folder";
}
var projectNode = new XElement(
solutionItemName,
new XAttribute("Name", project.Name),
new XAttribute("Kind", project.Kind)
);
rootNode.Add(projectNode);
foreach(ProjectItem item in project.ProjectItems)
{
var itemNode = new XElement("Item", new XAttribute("Name", item.Name));
projectNode.Add(itemNode);
if(item.Properties == null)
{
continue;
}
foreach(Property property in item.Properties)
{
var propertyNode = new XElement(property.Name, property.Value);
itemNode.Add(propertyNode);
}
}
}
By the fact of this post and by apparent bugs in other Add-ins it is apparent that this isn't the most intuitive design but thats what we have to live with.
To debug a Visual Studio add-in, load the source code into a copy of visual studio that is not running the add-in. Then, configure the project to start a second copy of visual studio when you "run" the project, that second copy will then run with the first able to breakpoint and debug it.
Make sure you have a batch file (or equivalent) to clean up, so that you can always get back to running VS without the plugin.
Useful resources ...
How to debug a Visual Studio .NET 2005 Add-In
Walkthrough: Debugging an Add-in Project