private PayloadClass PayloadClass() { PayloadClass payload = new PayloadClass(); pos++; // '{' SkipWhiteSpacesAndComments(); // to ustawi na pierwszym tagu, a każdy kolejny będzie z automatu bo tagi skipują WS'y za sobą. while (currentChar != Syntax.CLASS_CLOSING) { int begin = pos; Tag newTag = Tag(); if (payload.Has(newTag.name)) { throw new KFFParseException("Found duplicated Tag '" + newTag.name + "' (" + TextFileData.Calculate(this.fileName, this.s, begin) + ")."); } payload.Set(newTag); } pos++; // '}' SkipWhiteSpacesAndComments(); return(payload); }
private string StringFromPayloadClass(PayloadClass t) { StringBuilder sb = new StringBuilder(); if (((int)classOpeningNL & 1) == 1) // before { sb.Append(Environment.NewLine); } sb.Append(Syntax.CLASS_OPENING); if (((int)classOpeningNL & 2) == 2) // after { sb.Append(Environment.NewLine); } if (tabInsideClass) { // insert tab at the front of the class, right before the first tag. sb.Append("\t"); } for (int i = 0; i < t.value.Count; i++) { string tag = StringFromAnyTag(t.value[i]); if (tabInsideClass) { // insert tab after every newline char (skips the front of the tag, as there's no newline char there). tag = tag.Replace(Environment.NewLine, Environment.NewLine + "\t"); } sb.Append(tag); } if (((int)classClosingNL & 1) == 1) // before { sb.Append(Environment.NewLine); } sb.Append(Syntax.CLASS_CLOSING); if (((int)classClosingNL & 2) == 2) // after { sb.Append(Environment.NewLine); } return(sb.ToString()); }
private void ActivitySurrogateSelector() { string myApp = "TestConsoleApp_YSONET"; sampleInputArgs = new InputArgs(myApp + " /foo bar", true, true, true, true, true, null); bool isErrOk = false; PayloadClass myPayloadClass = new PayloadClass(1, sampleInputArgs); List <object> ls = myPayloadClass.GadgetChains(); //* // Disable ActivitySurrogate type protections during generation ConfigurationManager.AppSettings.Set("microsoft:WorkflowComponentModel:DisableActivitySurrogateSelectorTypeCheck", "true"); //Serialize(myPayloadClass, "BinaryFormatter", sampleInputArgs); MemoryStream lsMs = new MemoryStream(); System.Runtime.Serialization.Formatters.Binary.BinaryFormatter fmt = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); fmt.SurrogateSelector = new MySurrogateSelector(); fmt.Serialize(lsMs, ls); //lsMs.Position = 0; //fmt.Deserialize(lsMs); byte[] bf_byte = lsMs.ToArray(); Console.WriteLine("Init size: " + bf_byte.Length); string json_string = AdvancedBinaryFormatterParser.StreamToJson(new MemoryStream(bf_byte), false, true, true); //MemoryStream msCanIt = AdvancedBinaryFormatterParser.JsonToStream(json_string); //msCanIt.Position = 0; //fmt.Deserialize(msCanIt); string result = BinaryFormatterMinifier.MinimiseJsonAndRun(json_string, sampleInputArgs, isErrOk, true); Console.WriteLine(result); MemoryStream ms = AdvancedBinaryFormatterParser.JsonToStream(result); Console.WriteLine("Final size: " + ms.Length); Console.ReadLine(); }
public void New() { Payload = new PayloadClass(); FileName = null; Dirty = false; }
public bool Load(string file) { var DeSerializer = new XmlSerializer(typeof(PayloadClass)); PayloadClass pc; using (var stream = File.OpenRead(FileName = file)) try { pc = (PayloadClass)DeSerializer.Deserialize(stream); } catch { pc = new PayloadClass(); } if (pc.Buttons.Count == 0 && pc.Priorities.Count != 0) { if (MessageBox.Show("The file you are trying to load doesn't contain any buttons, " + "but there are priority sets referencing them. Would you want me to try to " + "fill in buttons from the registry (from the old version of the button lists)?\n\n" + "This may not work and it might render the entire file unusable. Please " + "test it thoroughly before saving!", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { var log = ""; var root = Registry.LocalMachine.OpenSubKey("software") .OpenSubKey("ss").OpenSubKey("button tester"); var n = (int)root.GetValue(null); for (var i = 0; i < n; ++i) { var bt = new PayloadClass.ButtonType(); bt.Name = (string)root.GetValue("name_" + i); bt.PinID = (int)root.GetValue("pinid_" + i); pc.Buttons.Add(bt); log += bt.Name + " (" + bt.PinID + ")\n"; } MessageBox.Show("Buttons found and loaded: " + log, "Import log", MessageBoxButtons.OK, MessageBoxIcon.Information); Payload = pc; } catch { MessageBox.Show("Could not load the buttons from the registry.", "Import log", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else { if (pc.Version < ver && MessageBox.Show("The file you are trying to load is an from an older version " + "of this program. It will most likely not work or work wrong. Are you sure you want to load it?", "Old save file detected", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Payload = pc; } else if (pc.Version > ver && MessageBox.Show("The file you are trying to load is an from a newer (!) version " + "of this program. It will most likely not work or work wrong. Are you sure you want to load it?", "Newer save file detected", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Payload = pc; } else if (pc.Version == ver) { Payload = pc; } else { return(false); } } Payload.Version = ver; Dirty = false; return(true); }
public bool Load(string file) { XmlSerializer DeSerializer = new XmlSerializer(typeof(PayloadClass)); PayloadClass pc; using (FileStream stream = File.OpenRead(FileName = file)) pc = (PayloadClass)DeSerializer.Deserialize(stream); if (pc.Buttons.Count == 0 && pc.Priorities.Count != 0) { if (MessageBox.Show("The file you are trying to load doesn't contain any buttons, " + "but there are priority sets referencing them. Would you want me to try to " + "fill in buttons from the registry (from the old version of the button lists)?\n\n"+ "This may not work and it might render the entire file unusable. Please "+ "test it thoroughly before saving!", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { string log = ""; RegistryKey root = Registry.LocalMachine.OpenSubKey("software") .OpenSubKey("ss").OpenSubKey("button tester"); int n = (int)root.GetValue(null); for (int i = 0; i < n; ++i) { PayloadClass.ButtonType bt = new PayloadClass.ButtonType(); bt.Name = (string)root.GetValue("name_" + i); bt.PinID = (int)root.GetValue("pinid_" + i); pc.Buttons.Add(bt); log += bt.Name + " (" + bt.PinID + ")\n"; } MessageBox.Show("Buttons found and loaded: " + log, "Import log", MessageBoxButtons.OK, MessageBoxIcon.Information); Payload = pc; } catch { MessageBox.Show("Could not load the buttons from the registry.", "Import log", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else { if (pc.Version < ver && MessageBox.Show("The file you are trying to load is an from an older version " + "of this program. It will most likely not work or work wrong. Are you sure you want to load it?", "Old save file detected", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) Payload = pc; else if (pc.Version > ver && MessageBox.Show("The file you are trying to load is an from a newer (!) version " + "of this program. It will most likely not work or work wrong. Are you sure you want to load it?", "Newer save file detected", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) Payload = pc; else if (pc.Version == ver) Payload = pc; else return false; } Payload.Version = ver; Dirty = false; return true; }
/// <summary> /// Creates a new tag of type Class with the specified name and payload. /// </summary> /// <param name="name">The name of the new Tag.</param> /// <param name="payload">The payload of the new Tag.</param> public TagClass(string name, PayloadClass payload) : base(name) { this.payload = payload; this.payload.EmbedIn(this); }