bool doSave() { // Build a show config from the tree ShowConfig sc = new ShowConfig(); sc.eventGroups = new List <EventGroup>(); foreach (TreeNode tn in treeView1.Nodes) { sc.eventGroups.Add((EventGroup)tn.Tag); } // Validate all the properties if (!ValidateShowConfig(sc)) { return(false); } // Serialize to json DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ShowConfig)); MemoryStream ms = new MemoryStream(); ser.WriteObject(ms, sc); // Write to the file File.WriteAllBytes(_currentFilePath, ms.ToArray()); // Clear dirty flag _dirty = false; UpdateTitle(); return(true); }
internal static int Show(ShowConfig !config) { RouteEntry[] in ExHeap routes; RoutingContract.Imp routeConn = ((!)config.routingRef).Acquire(); if (routeConn == null) { Console.WriteLine("Could not initialize routing endpoint."); return(1); } routeConn.RecvReady(); routeConn.SendGetRoutingTable(); routeConn.RecvRoutingTable(out routes); if (routes == null) { throw new Exception("routes is null"); } for (int i = 0; i < routes.Length; i++) { Console.WriteLine("Network : " + ChannelUtils.NetworkToString(routes[i].network)); Console.WriteLine("Gateway : " + ChannelUtils.AddressToString(routes[i].gateway)); Console.WriteLine("Interface address : " + ChannelUtils.AddressToString(routes[i].ifaddr)); Console.WriteLine("Metric : " + routes[i].metric); Console.WriteLine(String.Format("Tag : {0:x8}\n", routes[i].tag)); } delete routes; delete routeConn; return(0); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "JSON Show Scripts|*.json|All Files|*.*"; dlg.CheckFileExists = true; if (dlg.ShowDialog() == DialogResult.OK) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ShowConfig)); FileStream fs = File.OpenRead(dlg.FileName); ShowConfig cfg = (ShowConfig)ser.ReadObject(fs); fs.Close(); treeView1.BeginUpdate(); treeView1.Nodes.Clear(); foreach (EventGroup eg in cfg.eventGroups) { TreeNode tn = treeView1.Nodes.Add(eg.name); tn.Tag = eg; eg.treeNode = tn; if (eg.stopCondition != null) { TreeNode stopCondition = tn.Nodes.Add("Stop Condition"); stopCondition.Tag = eg.stopCondition; } TreeNode eventsNode = tn.Nodes.Add("Events"); foreach (Event evt in eg.events) { TreeNode en = eventsNode.Nodes.Add(string.Format("{0}|{1}", evt.action, evt.arg1)); en.Tag = evt; } } treeView1.EndUpdate(); _currentFilePath = dlg.FileName; _dirty = false; UpdateTitle(); } }
bool ValidateShowConfig(ShowConfig sc) { HashSet <string> validStopConditions = new HashSet <string>(c_ValidStopConditions); HashSet <string> validActions = new HashSet <string>(c_ValidActions); HashSet <string> egNames = new HashSet <string>(); foreach (EventGroup eg in sc.eventGroups) { if (egNames.Contains(eg.name)) { MessageBox.Show("Script contains multiple Event Groups named: \n\t" + eg.name, "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } egNames.Add(eg.name); if (eg.stopCondition != null) { if (!validStopConditions.Contains(eg.stopCondition.type)) { string err = string.Format("Script contains invalid stop condition type: \n\t{0}\nEvent Group: {1}", eg.stopCondition.type, eg.name); MessageBox.Show(err, "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } foreach (Event evt in eg.events) { if (!validActions.Contains(evt.action)) { string err = string.Format("Script contains invalid action:\n\t{0}\nEvent Group: {1}", evt.action, eg.name); MessageBox.Show(err, "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } } return(true); }
void LoadJSON(string json) { _theShow = JsonUtility.FromJson <ShowConfig>(json); _lastSceneMarker = 0; Show_ExecuteStep(); }