Exemplo n.º 1
0
        public override void Load(BinaryReader reader)
        {
            Global.Debugf("iodetail", "<componentlist>");
            string s;

            BinIO.string_read(reader, out s);
            if (s != "<componentlist>")
            {
                throw new Exception("Expected string: <componentlist>");
            }
            BinIO.string_read(reader, out s);
            int n;

            if (!int.TryParse(s, out n))
            {
                throw new Exception("Incorrect number format (count of component).");
            }
            data.Resize(n);
            for (int i = 0; i < n; i++)
            {
                data[i] = ComponentIO.load_component(reader);
                if (data[i] != null)
                {
                    Global.Debugf("iodetail", "   {0}", data[i].Name);
                }
            }
            BinIO.string_read(reader, out s);
            if (s != "</componentlist>")
            {
                throw new Exception("Expected string: </componentlist>");
            }
            Global.Debugf("iodetail", "</componentlist>");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Save network to file
        /// </summary>
        /// <param name="filepath">full file path</param>
        public override void Save(string filepath)
        {
            FileStream   stream = new FileStream(filepath, FileMode.Create, FileAccess.Write);
            BinaryWriter writer = new BinaryWriter(stream);

            try
            {
                ComponentIO.save_component(writer, this);
            }
            finally
            {
                writer.Close();
                stream.Close();
            }
        }
        private void ReadComponent(XmlNode aNode)
        {
            String      type = "";
            ComponentIO IO   = new ComponentIO();

            IO.myIOType          = eIOType.IN;
            IO.myIOComponentType = "";
            IO.myIOElementName   = "";
            IO.myIOAttribute     = new String[8];
            for (int i = 0; i < 8; i++)
            {
                IO.myIOAttribute[i] = "";
            }

            myXMLReader.ReadAttribute(aNode, "type", ref type);

            XmlNode IOnode = myXMLReader.FindFirstChildElement(aNode);

            if (IOnode != null)
            {
                if (IOnode.Name == "InputOutput")
                {
                    IO.myIOType = eIOType.INOUT;
                }
                else if (IOnode.Name == "Output")
                {
                    IO.myIOType = eIOType.OUT;
                }
                else
                {
                    IO.myIOType = eIOType.IN;
                }

                myXMLReader.ReadAttribute(IOnode, "type", ref IO.myIOComponentType);
                myXMLReader.ReadAttribute(IOnode, "elementName", ref IO.myIOElementName);
                myXMLReader.ReadAttribute(IOnode, "attribute0", ref IO.myIOAttribute[0]);
                myXMLReader.ReadAttribute(IOnode, "attribute1", ref IO.myIOAttribute[1]);
                myXMLReader.ReadAttribute(IOnode, "attribute2", ref IO.myIOAttribute[2]);
                myXMLReader.ReadAttribute(IOnode, "attribute3", ref IO.myIOAttribute[3]);
                myXMLReader.ReadAttribute(IOnode, "attribute4", ref IO.myIOAttribute[4]);
                myXMLReader.ReadAttribute(IOnode, "attribute5", ref IO.myIOAttribute[5]);
                myXMLReader.ReadAttribute(IOnode, "attribute6", ref IO.myIOAttribute[6]);
                myXMLReader.ReadAttribute(IOnode, "attribute7", ref IO.myIOAttribute[7]);
            }
            BuildComponent(type, IO);
        }
        private void BuildComponent(string aType, ComponentIO aIO)
        {
            BaseComponent newComponent = null;

            switch (aType)
            {
            case "DLLPreview":
                newComponent = new DLLPreviewComponent(new Point(0, 0), new Size(700, 530), "DLLPreview", myCurrentPanelName);
                break;

            case "Vector3":
                newComponent = new Vector3Component(new Point(0, 0), new Size(120, 13), aIO.myIOElementName, myCurrentPanelName);
                break;
            }
            if (newComponent != null)
            {
                myComponents.Add(newComponent);
            }
        }
Exemplo n.º 5
0
 public override void Save(BinaryWriter writer)
 {
     Global.Debugf("iodetail", "<componentlist>");
     // write start tag
     BinIO.string_write(writer, "<componentlist>");
     // write array length
     BinIO.string_write(writer, data.Length().ToString());
     // write components
     for (int i = 0; i < data.Length(); i++)
     {
         if (data[i] != null)
         {
             Global.Debugf("iodetail", "   {0}", data[i].Name);
         }
         ComponentIO.save_component(writer, data[i]);
     }
     // write end tag
     BinIO.string_write(writer, "</componentlist>");
     Global.Debugf("iodetail", "</componentlist>");
 }
Exemplo n.º 6
0
        public void LoadOldFormat(BinaryReader reader)
        {
            string magic = BinIO.magic_get(reader, "linerec".Length);

            CHECK_ARG(magic == "linerec" || magic == "linerc2", "magic=='linerec' || magic=='linerc2'");
            PLoad(reader);
            IComponent comp   = ComponentIO.load_component(reader);
            IModel     cmodel = comp as IModel;

            classifier.Object = cmodel;
            counts.Clear();
            if (magic == "linerec")
            {
                PSet("minsize_factor", 0.0);
            }
            else if (magic == "linerc2")
            {
                Narray <int> intcount = counts;
                BinIO.narray_read(reader, intcount);
            }
        }
Exemplo n.º 7
0
        public static Linerec LoadLinerec(string filename)
        {
            FileStream   stream = new FileStream(filename, FileMode.Open, FileAccess.Read);
            BinaryReader reader = new BinaryReader(stream);

            try
            {
                IComponent comp = ComponentIO.load_component(reader);
                // loaded component is Linerec
                Linerec linerec = comp as Linerec;
                if (linerec != null)
                {
                    return(linerec);
                }

                // else component is IModel
                IModel cmodel = comp as IModel;
                if (cmodel != null)
                {
                    linerec = new Linerec();
                    linerec.SetClassifier(cmodel);
                    return(linerec);
                }
            }
            finally
            {
                reader.Close();
                stream.Close();
            }

            // try load old format
            Linerec linerec_old = new Linerec();

            linerec_old.LoadOldFormat(filename);
            return(linerec_old);
        }
Exemplo n.º 8
0
 public override void Load(BinaryReader reader)
 {
     data.SetComponent(ComponentIO.load_component(reader));
 }
Exemplo n.º 9
0
 public override void Save(BinaryWriter writer)
 {
     ComponentIO.save_component(writer, data.GetComponent());
 }