Exporting whole neo4j database in .NET using BoltGraphClient - c#

Can anyone tell me how to export an entire neo4j database (so including properties, relationships, paths) to e.g. JSON or CSV using c# and in particular by using the BoltGraphClient connection method. I can of course do it within neo4j simply by clicking the export button but I want to do it using .NET and then just stream the JSON to a local file.
I'm feeling a bit limited by the query methods found with BoltGraphClient, figured it would be easier just to manipulate a JSON file.
Thanks in advance!
I've tried adapting the answer given to this question (it's achieved using GraphDatabase.Driver, rather than BoltGraphClient).
Neo4J CYPHER in C# or Java: Return JSON output from “call db.schema.nodeTypeProperties()”?
But no joy.

If you don't want to convert the node and relationship-objects that come back from the bolt-client, you can construct the "Dict" also on the server.
You can probably just run these queries from the bolt client:
MATCH (n) RETURN {id:id(n), labels:labels(n), properties:properties(n)} as node
MATCH (r) RETURN {id:id(r), type:type(r), properties:properties(r), start:id(startNode(r)), end:id(endNode(r))} as rel
HTH

Related

Reading/writing PLC tags from PLC s7-1500

I was wondering if there is any way to read and write values from the PLC tags folder using a custom c# application?
I have tried using Snap7 which is great tool to use and actually got it working, but only reading and writing data blocks and not tags what I am willing to achieve. I haven't tried Libnodave just yet.
Would you please recommend me a way to achieve this and if there is other ways to do this.
Update #1
I partiely understand now how to read and write Merkers. But how about Inputs and outputs such as those?
Update #2
I have setup a watch table and got it working using Python Snap7, but wasn't able to do the same using C#.
Besides any tag value from a datablock, libnodave can get/set input, output and memory tags. Snap7 can also do that. I do not see any problem with that.
Its very easy to read and write using Libnodave. Download latest Libnodave.dll from official site and refer this sample. You will get an idea.

C# and Mantis API, get reproducability

I am currently working on a project where I will be using Mantisbt's API to integrate bugtracking features into my program, however I have hit a snag.
I used wsdl.exe to generate a c# client library.
I am trying to get the reproducibility, severity, and priority from mantis (preferably in an ObjectRef array) to display it to the end-user so that they may select it from a drop down list. I managed to get the categories using the following line:
this.connector.mc_project_get_categories(username,password,projectid);
However, there doesn't seem to be a similar line for the other fields I am looking for.
I think you're looking for mc_enum_reproducibilities . This is preferred to hard-coding your own values, since the MantisBT installation may be customized to have other reproducibilities.
Reproducibility, severity, priority and similar fields are enumerations in the Mantis PHP files and must be hard-coded in. The values and text are found in the core/constant_inc.php file.
From these definitions you can create your own ObjectRef to pass.

Getting Part Documents From Assembly Documents in SolidWorks API

Here is my scenario: I am reading in an Assembly file into Solidworks. From there, when the user is trying to edit a part, I want to get the information on which part file they want to edit.
Is there a way to get all the PartDoc information upon importing an AssemblyDoc file?
The closest I got to was getting the Body2 objects from the AssemblyDoc using
GetComponents() and GetBodies2() function described here. I had hoped that I could somehow grab the PartDocs from the bodies but I've found no way out.
Thank you in advance!
GetComponents return an array of IComponent2s.
For each component you can call GetModelDoc2 method to retrieve corresponding ModelDoc which can be either PartDoc, or AssemblyDoc.

How to create XSD file programmatically in C#?

I have a xml file (that i created in c# using XmlDocument) and now i have to create xsd file the corresponds to it also programmatically in C# ... how can I do this ??
can I use the same classes for creating xml files ? or are there any other (xsd related) classes I should use ??
If you just want to produce an XSD file from an XML file, then you can use Microsoft's XSD.EXE, which is included with Visual Studio.
To use it, open a Visual Studio Command Prompt. Then enter xsd file.xml to produce a schema for that XML file.
You can also use that tool to generate classes for your XML input, just pass in the /classes parameter.
While an XML Schema file is an XML file, it has certain things that could make it cumbersome to do it "by hand"; one could say why write XML using the DOM API instead of using C# classes generated by XSD.exe or XSD2Code.exe? Or to push it a bit... somewhat similar to someone saying C# statements eventually turn into IL assembly; why not write IL instead?
Another alternative is provided by the Schema Object Model API; in .NET, it is the System.Xml.Schema namespace.
Take a look at the code example found here on MSDN. It'll give you an idea for another approach. It provides a programmer friendly API to generate XSDs, instead of dealing with the actual XML.
XSD is just another XML-type file. whatever you are using to create your XML file will also be useful to create the XSD file; you just need to know what tags/attributes you want to put in the file...
Solution:
I originally posted a reply, but Stack Overflow rather I edit my response, so here is the edit. The original tool that I suggested goes the other way. I then did some research and someone recommended a tool called MyGenerations or something like that. That required an installation, downloaded template, and oodles of work, so way too complicated. I then did some more research and came across a rather nifty solution on CodePage, but that solution, which works, because I tested it, requires some modifications. The code is called XmlToXsd with the URL:
http://www.codeproject.com/Articles/133570/XmlToXsd-A-Better-Schema-Generator.
The Programs section has two bugs. First it saves the XSD to the executable's root. Do not worry, the exe merely calls a method located in one CS file. Simply include that CS file in your project and call with the line given, just you have to change the path to the same folder as the XML. Additionally, the author uses a targetnamespace of a junk URL. DevExpress throws a complaint on the nonexistent URL. Through some effort, I replaced the target URL with null. In the accompanying CS file I had to make a few changes. Others with more understanding than I can modify to his/her hearts extent. I merely help others by telling them what I did, so no static back.
Change 1: Before "target = XNamespace.Get(targetNamespace);" add an if-statement only loading if not null for the target namespace.
Change 2: I added another if-statement for the return. The null return, a copy of the original return modifies as follows:
2.1: Nuke the targetnamespace attribute item.
2.2: After the replace call, add another replace call of ".Replace("xmlns=\"null\"", null))".
2.3: Before the return, requires adding braces, set target = "null".
The resulting file now appears totally valid and created programatically.
Yes, one can use XSD.exe but manually, but I needed a programatic way of the conversation.
Original Post:
I had the same question, not necessarily programatically. The XSD utility does do the job. The problem is that Microsoft does not distribute xsd.exe with Visual Studio 2012 Professional. I searched my hard drive and found the utility with Microsoft's SDK, path on my disk "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64\xsd.exe".
I had to go to the folder where the XML file is and execute XSD utility from a command box (not in Visual Studio) and wound up with the XSD file.
One way to do this task programatically is to call XSD from code, but that would mean distributing XSD.
I found this one assembly, but never used it that might do the job. Check out: http://xsd2code.codeplex.com/
Try this:
string xmlFilePath = #"myxmlfile.xml";
string xsdOutputPath = #"myxmlfile.xsd";
DataSet ds = new DataSet();
System.IO.FileStream fsReadXml = new System.IO.FileStream(xmlFilePath, System.IO.FileMode.Open);
ds.ReadXml(fsReadXml);
ds.WriteXmlSchema(xsdOutputPath);
If from xDocument:
DataSet ds = new DataSet();
ds.ReadXml(YourXDocument.CreateReader());
ds.WriteXmlSchema(xsdOutputPath);

.CSV to SQL CE Table?

Is there any way to quickly import data from a .csv or tab delineated .txt into a SQL Compact Edition 3.5 Table?
I have a large amount of data that is impractical for manual input.
I know I can use the BULK INSERT function if I wanted to import into a Server Based SQL Database, but this method does not work in SQL CE.
I use visual studio 2010 and I have SQL Server Management Studio installed.
Any help will be appreciated!
You can use my VS Add-in, which generates INSERT statements based on a CSV file: http://sqlcetoolbox.codeplex.com
Maybe simpler is better. Nothing easier than your own code which can be expanded very easily. You could even have it build the table dynamically if you wanted but probably not necessary.
var stuff = from l in File.ReadLines(filename)
let x = l.Split(new [] {',', ' '}, StringSplitOptions.RemoveEmptyEntries)
.Skip(1)
.Select(s => int.Parse(s))
select new
{
Sum = x.Sum(),
Average = x.Average()
};
see: Read Csv using LINQ
If you have Microsoft Access, you can import .csv or delimited .txt data as a new table then upsize to SQL database. Also you can create a linked table and copy-paste the data (say from Microsoft Excel) and it tends to be efficient and reliable (throwing errors into a separate table that you can review).
There is no straight way of doing it, you will have to read each line in the file and insert one by one to SQLCE. There's some posts on it before, folks using C# program to read the file to a DataTable. If you know C# its fairly simple to setup and run.
Bulk insert from DataTable to SQLCE DataSource
http://ruudvanderlinden.com/2010/10/13/bulk-insert-into-sql-ce-in-c/
Oops just noticed that c# is one of the tags in your question :D
My tool of choice when dealing with csv is powershell since it has an import-csv command built in. It's fantastic glue for this kind of stuff.
Here's a link where the developer imports a csv and converts it to an insert script.
http://allen-mack.blogspot.com/2008/02/powershell-convert-csv-to-sql-insert.html
To run the script from the link (note: powershell gives you tab completion so you can use it to help with file paths while you are typing):
Create a file named something like Import-File.ps1 and copy the contents of the script from the link into it.
Start powershell
Type 'set-executionpolicy remotesigned' (note: this is loosening security of your system just a tad; but the default settings won't let you run any scripts)
Navigate to the directory with both your script and import file
Type '.\import-file.ps1 .\importfile.csv'
Hit enter; voila, you should have an insert sql script in the same directoy (i.e., 'importfile.sql' in our case)
Finally, since you can instantiate .net objects from within powershell, you could alter the script and do a number of things like insert data directly into a database.

Categories

Resources