Пример #1
0
        public static Instantiator.InstanceType DeserializeInstantiator(string filename)
        {
            // Declare an object variable of the type to be deserialized.
            Instantiator.InstanceType i = null;
            FileStream fs = null;

            try
            {
                Console.WriteLine("Reading with XmlReader");

                // Create an instance of the XmlSerializer specifying type and namespace.
                XmlSerializer serializer = new XmlSerializer(typeof(Instantiator.InstanceType));

                // A FileStream is needed to read the XML document.
                fs = new FileStream(filename, FileMode.Open);

                XmlReader reader = new XmlTextReader(fs);

                // Use the Deserialize method to restore the object's state.
                i = (Instantiator.InstanceType)serializer.Deserialize(reader);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }

            return(i);
        }
Пример #2
0
        public static string serializeInstantiator(Instantiator.InstanceType instance)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Instantiator.InstanceType));

            string filename = Path.GetTempFileName();

            FileStream fs = new FileStream(filename, FileMode.Open);

            XmlWriter writer = new XmlTextWriter(fs, null);

            serializer.Serialize(writer, instance);

            fs.Close();

            return(File.ReadAllText(filename));
        }
Пример #3
0
        /*	public static string serialize<T>(T instance)
         *      {
         *              XmlSerializer serializer = new XmlSerializer(typeof(T));
         *
         *              string filename = Path.GetTempFileName ();
         *
         *              FileStream fs = new FileStream(filename, FileMode.Open);
         *
         *              XmlWriter writer = new XmlTextWriter(fs, null);
         *
         *              serializer.Serialize(writer, instance);
         *
         *              fs.Close();
         *
         *              return File.ReadAllText(filename);
         *
         *      }
         */
        public static byte[] serializeInstantiator(string filename, Instantiator.InstanceType inst)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Instantiator.InstanceType));

            FileStream fs = new FileStream(filename, FileMode.Create);

            XmlWriter writer = new XmlTextWriter(fs, null);

            serializer.Serialize(writer, inst);

            BinaryReader br    = new BinaryReader(fs);
            int          count = (int)fs.Length;

            fs.Position = 0;

            byte[] data = br.ReadBytes(count);
            br.Close();
            fs.Close();

            return(data);
        }
Пример #4
0
        private string buildInstantiatorStringOfSystem(string component_ref, int facet_instance, Tuple <int, string>[] facet_address_list, int[] nodes)
        {
            IList <AbstractComponentFunctor> acf_list = BackEnd.acfdao.listByKind(Constants.KIND_APPLICATION_NAME);
            AbstractComponentFunctor         acf      = acf_list [0];

            Instantiator.InstanceType instantiator = new Instantiator.InstanceType();
            Instantiator.ComponentFunctorApplicationType contract = new Instantiator.ComponentFunctorApplicationType();
            contract.component_ref = component_ref;
            contract.argument      = new Instantiator.ContextArgumentType[0];

            instantiator.contextual_type         = contract;
            instantiator.facet_instanceSpecified = true;
            instantiator.facet_instance          = facet_instance;

            IList <Interface> units = BackEnd.idao.list(acf.Id_abstract);

            instantiator.unit_mapping = new Instantiator.UnitMappingType[units.Count];

            Console.WriteLine("buildInstantiatorStringOfSystem 0 " + units.Count);

            int iu = 0;

            foreach (Interface u in units)
            {
                instantiator.unit_mapping [iu] = new Instantiator.UnitMappingType();

                instantiator.unit_mapping [iu].unit_id    = u.Id_interface;
                instantiator.unit_mapping [iu].unit_index = 0;

                instantiator.unit_mapping [iu].facet_instanceSpecified = true;
                instantiator.unit_mapping [iu].facet_instance          = instantiator.unit_mapping [iu].facet = u.Facet;

                int number_of_nodes = nodes[instantiator.unit_mapping [iu].facet_instance];
                instantiator.unit_mapping [iu].node = new int[number_of_nodes];
                for (int n = 0; n < number_of_nodes; n++)
                {
                    instantiator.unit_mapping [iu].node [n] = n;
                }

                iu++;
            }

            Console.WriteLine("buildInstantiatorStringOfSystem 1");

            instantiator.facet_address = new Instantiator.FacetAddressType[facet_address_list.Length];
            for (int i = 0; i < facet_address_list.Length; i++)
            {
                instantiator.facet_address [i] = new Instantiator.FacetAddressType();
                instantiator.facet_address [i].facet_instanceSpecified = true;
                instantiator.facet_address [i].facet_instance          = instantiator.facet_address [i].facet = facet_address_list[i].Item1;
                instantiator.facet_address [i].facetSpecified          = true;
                instantiator.facet_address [i].facet = instantiator.facet_address [i].facet_instance;

                string platform_address = facet_address_list[i].Item2 != null ? facet_address_list[i].Item2 : "http://127.0.0.1:100";

                Uri uri = new Uri(platform_address);

                instantiator.facet_address [i].address       = uri.Host;
                instantiator.facet_address [i].portSpecified = true;
                instantiator.facet_address [i].port          = uri.Port;
            }

            Console.WriteLine("buildInstantiatorStringOfSystem 2");

            string instantiator_string = LoaderApp.serializeInstantiator(instantiator);

            return(instantiator_string);
        }