Ejemplo n.º 1
0
        public string SerializeDeviceFile(RaspiDeviceFile File)
        {
            JsonSerializerSettings settings = new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            };

            return(JsonConvert.SerializeObject(File, Formatting.Indented, settings));
        }
Ejemplo n.º 2
0
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            SaveFileDialog sf = new SaveFileDialog();

            sf.Filter = "RaspiDevice Files (*.rd) | *.rd";

            if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var file = sf.OpenFile();

                RaspiDeviceFile rd = new RaspiDeviceFile
                {
                    Elements = elements.ToArray(),
                    Links    = linkedIOS.Values.Select(li => new RaspLink
                    {
                        InputDevice      = li.Input.Parent.Name,
                        InputName        = li.Input.InputName,
                        InputLinkOnLeft  = li.InputOnLeft,
                        OutputDevice     = li.Output.Parent.Name,
                        OutputName       = li.Output.OutputName,
                        OutputLinkOnLeft = li.OutputOnLeft
                    }).ToArray(),
                    Positions = designer1.Document.Elements
                                .Cast <Dalssoft.DiagramNet.BaseElement>()
                                .Where(ed => ed is RectangleGroup)
                                .Select(eds => new RaspPosition {
                        ElementName = ((eds as RectangleGroup).Tag as RaspiImporter.BaseElement).Name, X = eds.Location.X, Y = eds.Location.Y
                    })
                                .ToArray()
                };

                StreamWriter sw = new StreamWriter(file);
                sw.Write(importer.SerializeDeviceFile(rd));
                sw.Close();
            }
        }
Ejemplo n.º 3
0
        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();

            of.Filter = "RaspiDevice Files (*.rd) | *.rd";

            if (of.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                RaspiDeviceFile data = importer.DeserializeDeviceFile(File.ReadAllText(of.FileName));

                foreach (var v in designer1.Document.Elements.OfType <Dalssoft.DiagramNet.BaseElement>().ToArray())
                {
                    designer1.Document.DeleteElement(v);
                }

                linkedIOS.Clear();
                elements.Clear();

                Dictionary <string, Dalssoft.DiagramNet.BaseElement> groups = new Dictionary <string, Dalssoft.DiagramNet.BaseElement>();

                foreach (var item in data.Elements)
                {
                    var elem = importer.ElementsByType[item.InternalClassName];
                    var rect = GenericElement.GetGenericElement(elem);
                    elem      = rect.Tag as RaspiImporter.BaseElement;
                    elem.Name = item.Name;
                    groups.Add(elem.Name, rect);
                    elements.Add(rect.Tag as RaspiImporter.BaseElement);
                    designer1.Document.AddElement(rect);

                    var props = item.GetType().GetProperties();

                    foreach (var prop in props)
                    {
                        prop.SetValue(elem, prop.GetValue(item));
                    }
                }

                foreach (var pos in data.Positions)
                {
                    groups[pos.ElementName].Location = new Point(pos.X, pos.Y);
                }

                foreach (var link in data.Links)
                {
                    var inputElement  = groups[link.InputDevice] as RectangleGroup;
                    var outputElement = groups[link.OutputDevice] as RectangleGroup;

                    var input  = (inputElement.Tag as RaspiImporter.BaseElement).Inputs.Where(i => i.InputName == link.InputName).FirstOrDefault();
                    var output = (outputElement.Tag as RaspiImporter.BaseElement).Outputs.Where(o => o.OutputName == link.OutputName).FirstOrDefault();

                    var inputLinkNode  = (inputElement.Children[input.InputName] as NodeElement).Connectors[link.InputLinkOnLeft ?  1 : 0];
                    var outputLinkNode = (outputElement.Children[output.OutputName] as NodeElement).Connectors[link.OutputLinkOnLeft ? 1 : 0];

                    var lnk = designer1.Document.AddLink(inputLinkNode, outputLinkNode);

                    Guid g = Guid.NewGuid();

                    var lnkI = new BaseElementLink {
                        Input = input, Output = output
                    };

                    linkedIOS.Add(g.ToString(), lnkI);

                    lnk.Tag = lnkI;
                }
            }
        }