private static SAFeSWL_Architecture DeserializeArchitecture_SAFeSWL(string filename)
        {
            // Declare an object variable of the type to be deserialized.
            SAFeSWL_Architecture i  = null;
            FileStream           fs = null;

            try
            {
                // Create an instance of the XmlSerializer specifying type and namespace.
                XmlSerializer serializer = new XmlSerializer(typeof(SAFeSWL_Architecture));

                // 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 = (SAFeSWL_Architecture)serializer.Deserialize(reader);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }

            return(i);
        }
        createSystem(SAFeSWL_Architecture arch_desc,
                     IDictionary <string, Instantiator.ComponentFunctorApplicationType> contracts,
                     IDictionary <string, Instantiator.UnitMappingType[]> unit_mapping,
                     ref IList <string> platforms)
        {
            string app_name = null;
            string application_component_name = null;
            string workflow_component_name    = null;;
            IList <Tuple <string, string, EnvironmentPortType, string> > bindings_application = null;
            IList <Tuple <string, string, EnvironmentPortType, string> > bindings_workflow    = null;
            IList <Tuple <string, Tuple <string, string, int>[]> >       bindings_system      = null;
            IList <Tuple <string, Tuple <string, string, int>[]> >       bindings_task        = null;

            LoaderSystem.readArchitecture(arch_desc,
                                          ref app_name,
                                          ref application_component_name,
                                          ref workflow_component_name,
                                          ref bindings_application,
                                          ref bindings_workflow,
                                          ref bindings_system,
                                          ref bindings_task,
                                          ref platforms);

            // Take the configuration files of components of the system.
            Tuple <Tuple <ComponentType, ComponentType>,
                   Tuple <ComponentType, ComponentType>,
                   Tuple <ComponentType, ComponentType> > system = null;              //LoaderSystem.createSystemComponent (app_name, application_component_name, workflow_component_name, contracts, unit_mapping, bindings_application, bindings_workflow, bindings_system, bindings_task, platforms);

            return(system);
        }
        public static SAFeSWL_Architecture readArchitecture(string arch_desc_xml)
        {
            string filename = System.IO.Path.GetTempFileName();

            File.WriteAllText(filename, arch_desc_xml);
            SAFeSWL_Architecture arch_desc = CoreServicesUtil.DeserializeArchitecture_SAFeSWL(filename);

            return(arch_desc);
        }
        public static void invokeDeploySystem(SAFeSWL_Architecture arch_desc,
                                              string arch_ref,
                                              object platform_address,
                                              ComponentType c_appplication_abstract,
                                              ComponentType c_application_concrete,
                                              ComponentType c_workflow_abstract,
                                              ComponentType c_workflow_concrete,
                                              ComponentType c_system_abstract,
                                              ComponentType c_system_concrete)
        {
            try
            {
                IPlatformServices platform_access = null;
                if (platform_address is string)
                {
                    // Deploy the components of the system.
                    ServiceUtils.PlatformServices.PlatformServices platform_access_ = new ServiceUtils.PlatformServices.PlatformServices((string)platform_address);
                    platform_access_.Timeout = int.MaxValue;
                    platform_access          = (IPlatformServices)platform_access_;
                }
                else if (platform_address is IPlatformServices)
                {
                    platform_access = (IPlatformServices)platform_address;
                }

                string application_abstract = LoaderApp.serialize <ComponentType>(c_appplication_abstract);
                string application_concrete = LoaderApp.serialize <ComponentType>(c_application_concrete);
                string workflow_abstract    = LoaderApp.serialize <ComponentType>(c_workflow_abstract);
                string workflow_concrete    = LoaderApp.serialize <ComponentType>(c_workflow_concrete);
                string system_abstract      = LoaderApp.serialize <ComponentType>(c_system_abstract);
                string system_concrete      = LoaderApp.serialize <ComponentType>(c_system_concrete);

                Console.Error.WriteLine(platform_access.deploy(application_abstract));
                Console.Error.WriteLine(platform_access.deploy(workflow_abstract));
                Console.Error.WriteLine(platform_access.deploy(system_abstract));

                Console.Error.WriteLine(platform_access.deploy(application_concrete));
                Console.Error.WriteLine(platform_access.deploy(workflow_concrete));
                Console.Error.WriteLine(platform_access.deploy(system_concrete));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.StackTrace);
                if (e.InnerException != null)
                {
                    Console.Error.WriteLine(e.InnerException.Message);
                    Console.Error.WriteLine(e.InnerException.StackTrace);
                }
            }

            //return 0;
        }
        public static bool checkIsPlatform(SAFeSWL_Architecture arch_desc, string arch_ref)
        {
            SAFeSWL_Component[] cs = arch_desc.solution;
            foreach (SAFeSWL_Component c in cs)
            {
                if (c.id_component.Equals(arch_ref) && c is SAFeSWL_Platform)
                {
                    return(true);
                }
            }

            return(false);
        }
        public static void invokeDeployPlatform(SAFeSWL_Architecture arch_desc,
                                                string arch_ref,
                                                object platform_address,
                                                ComponentType appplication_abstract,
                                                ComponentType application_concrete,
                                                ComponentType workflow_abstract,
                                                ComponentType workflow_concrete,
                                                ComponentType system_abstract,
                                                ComponentType system_concrete)
        {
            //	invokeDeployContracts (arch_desc, arch_ref, contracts, platform_address);


            invokeDeploySystem(arch_desc, arch_ref, platform_address, appplication_abstract, application_concrete, workflow_abstract, workflow_concrete, system_abstract, system_concrete);
        }
        public static void invokeDeployContracts(SAFeSWL_Architecture arch_desc,
                                                 string arch_ref,
                                                 IDictionary <string, Instantiator.ComponentFunctorApplicationType> contracts,
                                                 object platform_address)
        {
            br.ufc.pargo.hpe.backend.DGAC.database.Connector.openConnection();

            IPlatformServices platform_access = null;

            if (platform_address is string)
            {
                // Deploy the components of the system.
                ServiceUtils.PlatformServices.PlatformServices platform_access_ = new ServiceUtils.PlatformServices.PlatformServices((string)platform_address);
                platform_access_.Timeout = int.MaxValue;
                platform_access          = (IPlatformServices)platform_access_;
            }
            else if (platform_address is IPlatformServices)
            {
                platform_access = (IPlatformServices)platform_address;
            }

            IDictionary <string, int[]> cs = LoaderSystem.componentsInPlatform(arch_desc, arch_ref);

            foreach (string c in cs.Keys)
            {
                if (contracts.ContainsKey(c))
                {
                    AbstractComponentFunctorApplication acfaRef = BackEnd.loadACFAFromInstantiator(contracts[c]);

                    string[] config_dependencies = calculateDependenciesOf(acfaRef.Id_functor_app);

                    foreach (string cRef in config_dependencies)
                    {
                        string config_filename = Constants.PATH_TEMP_WORKER + cRef + ".hpe";
                        string config_contents = File.ReadAllText(config_filename);

                        platform_access.deploy(config_contents);
                    }
                }
            }
            br.ufc.pargo.hpe.backend.DGAC.database.Connector.closeConnection();
        }
        public int openWorkflowSession(string arch_desc_xml)
        {
            int workflow_handle = WorkflowHandle;

            workflow_contract.Add(workflow_handle, new Dictionary <string, Instantiator.ComponentFunctorApplicationType> ());
            workflow_resolution.Add(workflow_handle, new Dictionary <string, string[]> ());
            workflow_platform_address.Add(workflow_handle, new Dictionary <string, string> ());
            workflow_base_binding_port.Add(workflow_handle, new Dictionary <string, int> ());
            workflow_nodes.Add(workflow_handle, new Dictionary <string, int> ());
            delayed_contracts.Add(workflow_handle, new List <string> ());

            SAFeSWL_Architecture arch_desc = CoreServicesUtil.readArchitecture(arch_desc_xml);

            active_workflows.Add(workflow_handle, arch_desc);

            SAFeSWL_Component[] cs = arch_desc.solution;
            foreach (SAFeSWL_Component c in cs)
            {
                if (c.contract != null && c.contract.Item is Instantiator.ComponentFunctorApplicationType)
                {
                    registerContract(workflow_handle, c.id_component, (Instantiator.ComponentFunctorApplicationType)c.contract.Item);
                }
                else if (c.contract != null && c.contract.Item is string) /* TODO: read from URI */ } {