public void TestFromStringNoArgument() { GraphCommand command = GraphCommand.FromString("UndoOperation"); Assert.IsNotNull(command); Assert.AreEqual(GraphCommand.Name.UndoOperation, command.CommandName); }
public GraphModel(DocumentClient client, DocumentCollection collection) { this.client = client; this.collection = collection; this.graphConnection = new GraphConnection(client, collection); this.graphCommand = new GraphCommand(this.graphConnection); }
public ChildCommands(DiffCommand diff, SetupComCommand setupCom, CleanCommand cleanCom, SortCommand sort, GraphCommand graph, AnalyzeCommand analyze) { Diff = diff; SetupCom = setupCom; CleanCom = cleanCom; Sort = sort; Graph = graph; Analyze = analyze; }
public void TestToStringForUnsigned() { GraphCommand command = new GraphCommand(GraphCommand.Name.UndoOperation); command.AppendArgument("Math.Sin"); command.AppendArgument(12.34); command.AppendArgument((uint)5678); Assert.AreEqual("UndoOperation|s:Math.Sin|d:12.34|u:0x0000162e", command.ToString()); }
public void SetUp() { new ArbiterMSBuildLocator().RegisterDefaults(); var container = ContainerHelper.ConfigureContainer().WithRealFileSystem().Build(); _command = container.Resolve <GraphCommand>(); _console = container.Resolve <IConsole>(); }
public MainWindowButtons() { InitializeComponent(); LogInCommand = new LogInCommand(); GraphCommand = new GraphCommand(); ProfileCommand = new ProfileCommand(); EnterMealsCommand = new EnterMealsCommand(); //MainGrid.DataContext = new MainWindowVM(); }
public void TestToStringWithLineBreak() { GraphCommand command = new GraphCommand(GraphCommand.Name.EndNodeEdit); command.AppendArgument((uint)0x10000001); command.AppendArgument("a=3;\nb=4;"); command.AppendArgument(true); Assert.AreEqual("EndNodeEdit|u:0x10000001|s:a=3;\\nb=4;|b:True", command.ToString()); }
public void TestToStringWithArguments() { GraphCommand command = new GraphCommand(GraphCommand.Name.UndoOperation); command.AppendArgument(1234); command.AppendArgument(56.78); command.AppendArgument(true); command.AppendArgument("DesignScript Rocks!"); Assert.AreEqual("UndoOperation|i:1234|d:56.78|b:True|s:DesignScript Rocks!", command.ToString()); }
public void TestFromStringWithLineBreak() { GraphCommand command = GraphCommand.FromString("EndNodeEdit|u:0x10000001|s:a=3;\\nb=4;|b:True"); Assert.IsNotNull(command); Assert.AreEqual(GraphCommand.Name.EndNodeEdit, command.CommandName); Assert.AreEqual(0x10000001, command.GetArgument(0)); Assert.AreEqual("a=3;\nb=4;", command.GetArgument(1)); Assert.AreEqual(true, command.GetArgument(2)); }
public void TestToStringForEnum() { GraphCommand command = new GraphCommand(GraphCommand.Name.UndoOperation); command.AppendArgument(NodeType.Function); command.AppendArgument("Math.Sin"); command.AppendArgument(12.34); command.AppendArgument(56.78); Assert.AreEqual("UndoOperation|e:DesignScriptStudio.Graph.Core.NodeType,Function|s:Math.Sin|d:12.34|d:56.78", command.ToString()); }
public void TestFromStringForUnsigned() { GraphCommand command = GraphCommand.FromString("UndoOperation|s:Math.Sin|d:12.34|u:0x0000162e"); Assert.IsNotNull(command); Assert.AreEqual(GraphCommand.Name.UndoOperation, command.CommandName); Assert.AreEqual("Math.Sin", command.GetArgument(0)); Assert.AreEqual(12.34, command.GetArgument(1)); Assert.AreEqual(5678, command.GetArgument(2)); }
public void TestFromStringForEnum() { GraphCommand command = GraphCommand.FromString("CreateFunctionNode|e:DesignScriptStudio.Graph.Core.NodeType,Function|s:Math.Sin|d:12.34|d:56.78"); Assert.IsNotNull(command); Assert.AreEqual(GraphCommand.Name.CreateFunctionNode, command.CommandName); Assert.AreEqual(NodeType.Function, command.GetArgument(0)); Assert.AreEqual("Math.Sin", command.GetArgument(1)); Assert.AreEqual(12.34, command.GetArgument(2)); Assert.AreEqual(56.78, command.GetArgument(3)); }
public void TestFromStringWithEmptyArgs() { GraphCommand command = GraphCommand.FromString("UndoOperation|i:1234|d:56.78|b:True|s:"); Assert.IsNotNull(command); Assert.AreEqual(GraphCommand.Name.UndoOperation, command.CommandName); Assert.AreEqual(1234, command.GetArgument(0)); Assert.AreEqual(56.78, command.GetArgument(1)); Assert.AreEqual(true, command.GetArgument(2)); Assert.AreEqual(String.Empty, command.GetArgument(3)); }
public void TestFromStringWithArguments() { GraphCommand command = GraphCommand.FromString("UndoOperation|i:1234|d:56.78|b:True|s:DesignScript Rocks!"); Assert.IsNotNull(command); Assert.AreEqual(GraphCommand.Name.UndoOperation, command.CommandName); Assert.AreEqual(1234, command.GetArgument(0)); Assert.AreEqual(56.78, command.GetArgument(1)); Assert.AreEqual(true, command.GetArgument(2)); Assert.AreEqual("DesignScript Rocks!", command.GetArgument(3)); }
/// <summary> /// This uses undocumented and marked as INTERNAL ONLY functionality of CosmosDB Graph Library /// </summary> /// <param name="graphConnection"></param> /// <param name="outputformat">To be able to call NextAsPOCO outputformat must be set to GraphSON! </param> /// <returns></returns> public static GraphCommand Create(object graphConnection, OutputFormat outputformat = OutputFormat.GraphSON) { BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public; CultureInfo culture = null; // use InvariantCulture or other if you prefer object instantiatedType = Activator.CreateInstance(typeof(GraphCommand), flags, null, new object[] { graphConnection, null, null, default(CancellationToken) }, culture); GraphCommand cmd = (GraphCommand)instantiatedType; cmd.SetOutputFormat(outputformat); // GraphSON is necessary in order to be able to call "NextAsPOCO" return(cmd); }
/// <summary> /// Allows to set the internal OutputFormat of the GraphCommand thus allowing you to /// retrieve GRAPHJSON or GraphsonCompact (without references to Edges) as result from Traversals /// </summary> /// <param name="cmd"></param> /// <param name="format"></param> public static void SetOutputFormat(this GraphCommand cmd, OutputFormat format) { Type graphCommandType = typeof(GraphCommand); PropertyInfo outputFormatPropertyInfo = graphCommandType.GetProperty("OutputFormat", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); object originalValue = outputFormatPropertyInfo.GetValue(cmd); Type outputFormatType = originalValue.GetType(); string[] eNames = outputFormatType.GetEnumNames(); object desiredValue = Enum.Parse(outputFormatType, format.ToString()); outputFormatPropertyInfo.SetValue(cmd, desiredValue); }
public MainWindowVM() { Model = new MainModel(); MainWindowButtons = new MainWindowButtons(); initLogIn(); LogInCommand = new LogInCommand(); GraphCommand = new GraphCommand(); EnterMealsCommand = new EnterMealsCommand(); ProfileCommand = new ProfileCommand(); LogInCommand.ShowLogIn += LogInCommand_ShowlogIn; ProfileCommand.ShowProfile += ProfileCommand_ShowProfile; EnterMealsCommand.ShowEnterMeals += MealCommand_ShowEnterMeals; GraphCommand.ShowGraph += GraphCommand_ShowGraph; }
static int Main(string[] args) { if (args.Any(a => a == "--debug")) { args = args.Where(a => a != "--debug").ToArray(); Console.WriteLine($"Waiting for debugger to attach. Process ID: {System.Diagnostics.Process.GetCurrentProcess().Id}"); Console.WriteLine("Press ENTER to continue."); Console.ReadLine(); } var app = new CommandLineApplication(); app.Name = Name; app.FullName = "ILspect Command-Line Interface"; app.HelpOption("-h|-?|--help"); app.VersionOption("-v|--version", Program.Version); ListCommand.Register(app); GraphCommand.Register(app); DisassembleCommand.Register(app); SyntaxCommand.Register(app); CommandHelpers.RegisterHelpCommand(app); app.OnExecute(() => { app.ShowHelp(); return(0); }); try { return(app.Execute(args)); } catch (Exception ex) { CommandHelpers.Error(ex.Message); #if DEBUG CommandHelpers.Error(ex.ToString()); #endif return(-1); } }
public async Task TestDeliveryExperimental() { MemoryGraph partialGraph = new MemoryGraph(); #region EXPERIMENTAL DEMO /// ================================================================================================= /// IMPORTANT: The following code makes use of the internal GraphTraversal class, which should not /// be used according to the documentation of Microsofts Graph Library. Use at your own risk. /// ================================================================================================= var graphConnection = GraphConnectionFactory.Create(client, collection); GraphCommand cmd = GraphCommandFactory.Create(graphConnection); partialGraph.Drop(); GraphTraversal personTrav = cmd.g().V().HasLabel("Person"); { var persons = await personTrav.NextAsPOCO <IEndpointVertex>(partialGraph); foreach (Delivery.Person p in persons) { Console.WriteLine($"Vertex ==> Label:{p.Label} Name:{p.FirstName}"); } } #endregion }
private static async Task <bool> UploadEdge(Edge edge) { var sourceNodePrimaryKey = nodes[edge.SourceNode].NodeIdAttribute; var destNodePrimaryKey = nodes[edge.DestinationNode].NodeIdAttribute; var graphCommand = new GraphCommand(connection); // Get all existing edges so we can check if the edge already exist before inserting var getAllEdgeInternalInstruction = graphCommand.g().E().Values("EdgeId_Internal"); var allEdgesInternalIds = await getAllEdgeInternalInstruction.NextAsync(); // Get list of all files in the directory for this edge var files = Directory.GetFiles(edge.PathToData).ToList(); foreach (string filePath in files) { var lines = File.ReadAllLines(filePath).ToList(); foreach (var line in lines) { List <string> values = line.Split('\t').ToList(); Dictionary <string, string> keyval = new Dictionary <string, string>(); for (var i = 0; i < edge.Attributes.Count; i++) { keyval.Add(edge.Attributes[i], values[i]); } try { var insertEdgeInstruction = graphCommand.g().V().Has(sourceNodePrimaryKey, keyval[sourceNodePrimaryKey]).AddE(edge.SourceNode + edge.DestinationNode); var edgeInternalId = edge.Name; foreach (var item in keyval) { if (item.Key != sourceNodePrimaryKey && item.Key != destNodePrimaryKey) { insertEdgeInstruction = insertEdgeInstruction.Property(item.Key, item.Value); } if (edge.PrimaryAttributes.Contains(item.Key)) { edgeInternalId += item.Value; } } insertEdgeInstruction = insertEdgeInstruction.Property("EdgeId_Internal", edgeInternalId).To(graphCommand.g().V().Has(destNodePrimaryKey, keyval[destNodePrimaryKey])); if (!allEdgesInternalIds.Contains(edgeInternalId)) { var resultInsert = await insertEdgeInstruction.NextAsync(); if (resultInsert.Count == 0 || resultInsert[0] == "[]") { throw new Exception("Could not insert edge"); } Interlocked.Increment(ref counterUploaded); } else { Interlocked.Increment(ref counterExist); } Console.Write("\rUploaded " + counterUploaded + " edges and found " + counterExist + " existing edges"); } catch (Exception ex) { errors.Add(edge.Name + " (" + ex + ") : " + JsonConvert.SerializeObject(keyval) + "\n"); } } } return(true); }
private static async Task <bool> UploadNode(Node node) { var graphCommand = new GraphCommand(connection); // Get all existing edges so we can check if the edge already exist before inserting var getAllNodeInternalInstruction = graphCommand.g().V().Values("NodeId_Internal"); var allNodesInternalIds = await getAllNodeInternalInstruction.NextAsync(); // Get list of all files in the directory for this node var files = Directory.GetFiles(node.PathToData).ToList(); foreach (var filePath in files) { var lines = File.ReadAllLines(filePath).ToList(); foreach (var line in lines) { var values = line.Split('\t').ToList(); try { var insertNodeInstruction = graphCommand.g().AddV(node.Name); var nodeInternalId = node.Name; for (int i = 0; i < node.Attributes.Count; i++) { insertNodeInstruction = insertNodeInstruction.Property(node.Attributes[i], values[i]); if (node.PrimaryAttributes.Contains(node.Attributes[i])) { nodeInternalId += values[i]; } } insertNodeInstruction = insertNodeInstruction.Property("NodeId_Internal", nodeInternalId); if (!allNodesInternalIds.Contains(nodeInternalId)) { List <string> resultInsert = await insertNodeInstruction.NextAsync(); if (resultInsert.Count == 0 || resultInsert[0] == "[]") { throw new Exception("Could not insert node"); } Interlocked.Increment(ref counterUploaded); } else { Interlocked.Increment(ref counterExist); } Console.Write("\rUploaded " + counterUploaded + " nodes and found " + counterExist + " existing nodes"); } catch (Exception ex) { errors.Add(node.Name + " (" + ex + ") : " + JsonConvert.SerializeObject(values) + "\n"); } } } return(true); }
private static bool RunLikeGraphCommand(string postId, GraphCommand graphCmd) { if (string.IsNullOrEmpty(postId)) { return false; } string likeCommand = string.Format("{0}/likes", postId); var response = graphCmd(likeCommand); bool isSuccess; if (bool.TryParse(response.ToString(), out isSuccess)) { return isSuccess; } return false; }
public static bool SetFbLike(string fBPostId, short rating, FacebookClient fbapp) { GraphCommand likeCall = null; if (rating <= 0) { likeCall = new GraphCommand( (likeCommand) => fbapp.Delete(likeCommand, null) ); } else if (rating > 0) { likeCall = new GraphCommand( (likeCommand) => fbapp.Post(likeCommand, null) ); } return RunLikeGraphCommand(fBPostId, likeCall); }
public void TestToStringNoArgument() { GraphCommand command = new GraphCommand(GraphCommand.Name.UndoOperation); Assert.AreEqual("UndoOperation", command.ToString()); }
public async Task Execute(DocumentClient client, DocumentCollection collection) { MemoryGraph context = new MemoryGraph(); Person andreas = new Person() { FirstName = "Andreas", LastName = "Pollak" }; Person tina = new Person() { FirstName = "Tina", LastName = "Pollak" }; Place vienna = new Place() { name = "Vienna" }; Place venice = new Place() { name = "Venice" }; // Add EndPoints context.Add(andreas, tina, vienna, venice); DeliveryByCar andreasTotina = new DeliveryByCar(andreas, tina, 1); DeliveryByCar andreasToVienna = new DeliveryByCar(andreas, vienna, 1); DeliveryByCar andreasToVenice = new DeliveryByCar(andreas, venice, 5); DeliveryByTrain andreasToVeniceByTrain = new DeliveryByTrain(andreas, venice, 3, "TR0012"); DeliveryByTrain tinaToViennaByTrain = new DeliveryByTrain(tina, vienna, 2, "TR0042"); // Add Paths/Edges context.Add(andreasTotina, andreasToVienna, andreasToVenice, andreasToVeniceByTrain, tinaToViennaByTrain); await client.UpsertGraphDocumentsAsync(collection, context); MemoryGraph partialGraph = new MemoryGraph(); /// Try both queries in both directions first vertices then edges then edges and vertices var query = client.CreateGremlinQuery <Vertex>(collection, "g.V()"); foreach (var result in await query.ExecuteNextAsyncAsPOCO <IEndpointVertex>(partialGraph)) { Console.WriteLine(result.GetType().Name); } var edgeQuery = client.CreateGremlinQuery <Edge>(collection, "g.E()"); foreach (var result in await edgeQuery.ExecuteNextAsyncAsPOCO <IDeliveryEdge>(partialGraph)) { Console.WriteLine(result.GetType().Name); } #region EXPERIMENTAL DEMO /// ================================================================================================= /// IMPORTANT: The following code makes use of the internal GraphTraversal class, which should not /// be used according to the documentation of Microsofts Graph Library. Use at your own risk. /// ================================================================================================= var graphConnection = GraphConnectionFactory.Create(client, collection); GraphCommand cmd = GraphCommandFactory.Create(graphConnection); partialGraph.Drop(); GraphTraversal personTrav = cmd.g().V().HasLabel("Person"); { var persons = await personTrav.NextAsPOCO <IEndpointVertex>(partialGraph); foreach (Person p in persons) { Console.WriteLine($"Vertex ==> Label:{p.Label} Name:{p.FirstName}"); } } #endregion }