示例#1
0
        internal static void send(string service, string operation, List <string> param)
        {
            //convertir param en byte[][]
            int iStamp;

            if (emptyQueryNumbers.Count > 0)
            {
                iStamp = emptyQueryNumbers[0];
            }
            else
            {
                iStamp = queryNumber++;
            }
            string       stamp = iStamp.ToString();
            ServiceInfos ks    = null;

            foreach (ServiceInfos ks_ in knownServices)
            {
                if (ks_.Service == service)
                {
                    ks = new ServiceInfos(new Dictionary <string, List <Type> >()
                    {
                        { operation, ks_.Operation[operation] }
                    }, service);
                    break;
                }
            }
            queries.Add(iStamp, ks);
            mySelf.Send(service, operation, stamp, new byte[][] {});
        }
示例#2
0
        internal static void send(string service, string operation, List <string> param)
        {
            int          iStamp = queryNumber++;
            string       stamp  = iStamp.ToString();
            ServiceInfos ks     = null;

            foreach (ServiceInfos ks_ in knownServices)
            {
                if (ks_.Service == service)
                {
                    ks = new ServiceInfos(new Dictionary <string, List <Type> >()
                    {
                        { operation, ks_.Operation[operation] }
                    }, service);
                    break;
                }
            }
            queries.Add(iStamp, ks);
            string address = DataUtils.GetIPaddresses(System.Net.Dns.GetHostName())[0];

            if (!mySelf.Send(address, service, operation, stamp, param))
            {
                mySelf.Disconnect();
                MessageBox.Show("Le serveur sur lequel vous étiez connecté s'est arrêté.",
                                "Attention",
                                MessageBoxButtons.OK);
                if (request != null)
                {
                    if (request.Visible)
                    {
                        request.Close();
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Removes a mock service info from our collections.
        /// </summary>
        /// <param name="serviceInfo">Mock service info to remove</param>
        internal void RemoveService(ServiceInfo serviceInfo)
        {
            // If we delete a service : Unbind linked plugins and services.

            // Unbind generalized services
            foreach (ServiceInfo s in ServiceInfos.Where(si => si.Generalization == serviceInfo).ToList())
            {
                s.Generalization = null;
            }

            // Unbind implementations
            foreach (PluginInfo p in PluginInfos.Where(pi => pi.Service == serviceInfo).ToList())
            {
                p.Service = null;
            }

            // Delete all existing service references

            foreach (PluginInfo p in PluginInfos)
            {
                foreach (MockServiceReferenceInfo reference in p.InternalServiceReferences.Where(r => r.Reference == serviceInfo).ToList())
                {
                    p.InternalServiceReferences.Remove(reference);
                }
            }

            _labServiceInfos.Remove(serviceInfo);
            _serviceInfos.Remove(serviceInfo);
        }
示例#4
0
        private void BuildServiceInfos()
        {
            ServiceInfos.Clear();

            CloudFoundryApplicationOptions appOpts = new CloudFoundryApplicationOptions();
            var aopSection = _config.GetSection(CloudFoundryApplicationOptions.CONFIGURATION_PREFIX);

            aopSection.Bind(appOpts);

            ApplicationInstanceInfo appInfo = new ApplicationInstanceInfo(appOpts);
            var serviceSection = _config.GetSection(CloudFoundryServicesOptions.CONFIGURATION_PREFIX);
            CloudFoundryServicesOptions serviceOpts = new CloudFoundryServicesOptions();

            serviceSection.Bind(serviceOpts);

            foreach (KeyValuePair <string, Service[]> serviceopt in serviceOpts.Services)
            {
                foreach (Service s in serviceopt.Value)
                {
                    IServiceInfoFactory factory = FindFactory(s);
                    if (factory != null && factory.Create(s) is ServiceInfo info)
                    {
                        info.ApplicationInfo = appInfo;
                        ServiceInfos.Add(info);
                    }
                }
            }
        }
示例#5
0
        public void handleToolsEvents(object o, ClientToolsEvent e)
        {
            switch (e.Type)
            {
            case ClientToolsEvent.typeEvent.ERROR:
                string errorMessage = Utils.decodeString(e.Message[0]);
                MessageBox.Show("Le serveur sur lequel vous êtes connecté à renvoyé l'erreur suivante : " + errorMessage,
                                "Attention",
                                MessageBoxButtons.OK);
                break;

            case ClientToolsEvent.typeEvent.EXTINCTION:
                MessageBox.Show("Le serveur sur lequel vous étiez connecté a signalé une extinction!",
                                "Attention",
                                MessageBoxButtons.OK);
                if (request.Visible)
                {
                    disconnect();
                    request.Dispose();
                    request.Close();
                    request = null;
                }
                break;

            case ClientToolsEvent.typeEvent.MESSAGE:
                if (int.Parse(e.Stamp) == queryNumber - 1)
                {
                    setQueryNumberToHighest();
                }
                else
                {
                    emptyQueryNumbers.Add(int.Parse(e.Stamp));
                }

                ServiceInfos ks = queries[int.Parse(e.Stamp)];

                if (ks.Operation.Keys.First() != catalogue_name)
                {
                    Dictionary <string, List <Type> > operation = ks.Operation; //opération de la requête
                    List <Type> types = operation.Values.First();               //types pour la première et unique opération de cette structure
                    Type        type  = types[types.Count - 1];                 //on récupère le dernier type de la liste, correspondant à la valeur de retour de l'opération

                    object retour = Utils.decode(e.Message[0], type);

                    request.appendTextToLog(retour.ToString() + Environment.NewLine);
                }
                else
                {
                    //traiter le getinfos ici
                    mySelf.Disconnect();
                    mySelf = null;
                }
                break;
            }
        }
示例#6
0
        /// <summary>
        /// Set an existing plugin's dependency to an existing service.
        /// </summary>
        /// <param name="plugin">Plugin</param>
        /// <param name="service">Service the plugin depends on</param>
        /// <param name="runningRequirement">How the plugin depends on the service</param>
        internal void SetPluginDependency(PluginInfo plugin, ServiceInfo service, DependencyRequirement runningRequirement)
        {
            Debug.Assert(plugin != null);
            Debug.Assert(service != null);
            Debug.Assert(ServiceInfos.Contains(service));
            Debug.Assert(PluginInfos.Contains(plugin));

            MockServiceReferenceInfo reference = new MockServiceReferenceInfo(plugin, service, runningRequirement);

            plugin.InternalServiceReferences.Add(reference);
        }
示例#7
0
 public static bool Register(ServiceInfos serverInfos, string ip, int port, int id)
 {
     try
     {
         IPEndPoint ipEnd = new IPEndPoint(IPAddress.Parse(ip), port);
         subscribers.Add(new Tuple <Tuple <ServiceInfos, IPEndPoint>, int> (new Tuple <ServiceInfos, IPEndPoint>(serverInfos, ipEnd), id));
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#8
0
        /// <summary>
        /// Removes an existing plugin dependency.
        /// </summary>
        /// <param name="plugin">Plugin owner.</param>
        /// <param name="service">Service reference</param>
        internal void RemovePluginDependency(PluginInfo plugin, ServiceInfo service)
        {
            Debug.Assert(plugin != null);
            Debug.Assert(service != null);
            Debug.Assert(ServiceInfos.Contains(service));
            Debug.Assert(PluginInfos.Contains(plugin));

            MockServiceReferenceInfo reference = plugin.InternalServiceReferences.First(x => x.Reference == service);

            if (reference != null)
            {
                plugin.InternalServiceReferences.Remove(reference);
            }
        }
示例#9
0
        /// <summary>
        /// Creates a new named plugin, which implements an existing service.
        /// </summary>
        /// <param name="pluginName">Name of the new plugin</param>
        /// <param name="service">Implemented service</param>
        /// <returns>New plugin</returns>
        internal PluginInfo CreateNewPlugin(string pluginName, ServiceInfo service = null)
        {
            Debug.Assert(!String.IsNullOrWhiteSpace(pluginName));

            if (service != null)
            {
                Debug.Assert(ServiceInfos.Contains(service));
            }

            PluginInfo plugin = new PluginInfo(pluginName, AssemblyInfoHelper.ExecutingAssemblyInfo, service);

            CreateLabPlugin(plugin);
            _pluginInfos.Add(plugin);   // Throws on duplicate

            return(plugin);
        }
示例#10
0
        /// <summary>
        /// Creates a new named service, which specializes another service.
        /// </summary>
        /// <param name="serviceName">Name of the new service</param>
        /// <param name="generalization">Specialized service</param>
        /// <returns>New service</returns>
        /// <remarks>Cannot be used when engine is running.</remarks>
        internal ServiceInfo CreateNewService(string serviceName, ServiceInfo generalization = null)
        {
            Debug.Assert(serviceName != null);
            Debug.Assert(_serviceInfos.Any(x => x.ServiceFullName == serviceName) == false, "Service does not exist and can be added");

            if (generalization != null)
            {
                Debug.Assert(ServiceInfos.Contains(generalization));
            }

            ServiceInfo newService = new ServiceInfo(serviceName, AssemblyInfoHelper.ExecutingAssemblyInfo, generalization);

            CreateLabService(newService);
            _serviceInfos.Add(newService);   // Throws on duplicate


            return(newService);
        }
示例#11
0
 private void loadServerList(List <string> serviceNames,
                             List <List <string> > operationNames,
                             List <List <Type> > typeForOperations,
                             List <string> ipAdresses,
                             List <string> portValues)
 {
     for (int i = 0; i < serviceNames.Count; i++)
     {
         Dictionary <string, List <Type> > operations = new Dictionary <string, List <Type> >();
         foreach (string operationName in operationNames[i])
         {
             List <Type> typeForOperation = typeForOperations[i];
             operations.Add(operationName, typeForOperation);
         }
         ServiceInfos si = new ServiceInfos(operations, serviceNames[i]);
         knownServices.Add(si);
         dgv_infos.Rows.Add(new object[] { false, ipAdresses[i], portValues[i], serviceNames[i] });
     }
 }
示例#12
0
        public Echo()
        {
            InitializeComponent();
            config = new Configuration(new setCatalogueInfo(setCataloguePortAndAdress));
            Dictionary <string, List <Type> > param = new Dictionary <string, List <Type> >()
            {
                { "echo",
                  new List <Type>()
                  {
                      typeof(string),   //prend une chaîne en entrée
                      typeof(string)
                  } }                   //retourne une chaîne
            };

            myInfos           = new ServiceInfos(param, service);
            port_local        = port_local_default;
            port_catalogue    = port_catalogue_default;
            adresse_catalogue = adresse_catalogue_default;
        }
        private void BuildServiceInfos()
        {
            ServiceInfos.Clear();

            var appInfo     = new CloudFoundryApplicationOptions(_config);
            var serviceOpts = new CloudFoundryServicesOptions(_config);

            foreach (var serviceopt in serviceOpts.Services)
            {
                foreach (var s in serviceopt.Value)
                {
                    var factory = FindFactory(s);
                    if (factory != null && factory.Create(s) is ServiceInfo info)
                    {
                        info.ApplicationInfo = appInfo;
                        ServiceInfos.Add(info);
                    }
                }
            }
        }
        private void BuildServiceInfos()
        {
            var factory = FindFactory(new Service());

            ServiceInfos.Add(factory.Create(null));
        }
示例#15
0
        internal Requete(List <ServiceInfos> knownServices, string service)
        {
            /**
             * on construit dynamiquement les contrôles:
             * - un radio button par opération pour le service
             * - une textbox par paramètre pour l'opération sélectionnée
             */
            this.service = service;
            InitializeComponent();
            ServiceInfos ks = null;

            foreach (ServiceInfos ks_ in knownServices)
            {
                if (ks_.Service == service)
                {
                    ks = ks_;
                    break;
                }
            }
            int rbtnX = 0;
            int rbtnY = 0;
            int i     = 0;

            rbtns = new List <RadioButton>();
            txtbx = new List <List <TextBox> >();
            foreach (String s in ks.Operation.Keys)
            {
                rbtns.Add(new RadioButton());
                rbtns[i].Text     = s;
                rbtns[i].Name     = i.ToString();
                rbtns[i].Location = new Point(rbtnX, rbtnY);
                txtbx.Add(new List <TextBox>());
                panels.Add(new Panel());
                panels[i].Name   = "panel" + i;
                panels[i].Height = 1000;
                for (int param = 0; param < ks.Operation[s].Count - 1; param++)
                {
                    txtbx[i].Add(new TextBox());
                    txtbx[i][param].Width    = 200;
                    txtbx[i][param].Location = new Point(rbtnX, rbtnY + 30 * param + 30);
                    txtbx[i][param].Name     = i.ToString() + " _ " + param.ToString();
                    txtbx[i][param].Text     = "Enter a " + ks.Operation[s][param].ToString() + " here.";
                    panels[i].Controls.Add(txtbx[i][param]);
                }
                panels[i].Location = new Point(rbtnX + 100, rbtnY - 100 * i);
                if (i != 0)
                {
                    panels[i].Visible = false;
                }
                else
                {
                    rbtns[i].Checked = true;
                    operation        = rbtns[i].Text;
                }
                rbtns[i].Click += new System.EventHandler(dynamicRbtnSelect);
                this.Controls.Add(rbtns[i]);
                this.Controls.Add(panels[i]);
                i++;
                rbtnY += 100;
            }
        }
        public void LoadComponentData(IEnumerable <Assembly> assemblies)
        {
            if (_loadedData)
            {
                return;
            }

            // Iterate through all loaded assemblies searching for NQ components
            Dictionary <Assembly, ComponentInfo>  componentAssemblies     = new Dictionary <Assembly, ComponentInfo>();
            Dictionary <string, List <Assembly> > componentPartAssemblies = new Dictionary <string, List <Assembly> >();

            foreach (Assembly a in assemblies)
            {
                if (AttributeComponentInfo.IsComponent(a))
                {
                    // Create component info and save it
                    AttributeComponentInfo componentInfo = new AttributeComponentInfo(a);

                    if (!componentInfo.IsComponentPart)
                    {
                        // Add component definition to internal list
                        if (!_componentInfos.ContainsKey(componentInfo.Name))
                        {
                            _componentInfos.Add(componentInfo.Name, componentInfo);
                        }
                        else
                        {
                            // Component is already known
                            _logger.Write(LogType.Error, "Multiple definition of component " + componentInfo.Name + ".");
                            throw new ComponentDefinitionException(ErrorReason.ComponentMultiplyDefined, "Multiple definition of component " + componentInfo.Name + ".");
                        }
                    }
                    else
                    {
                        // Add assembly to temporary parts list
                        if (!componentPartAssemblies.ContainsKey(componentInfo.Name))
                        {
                            componentPartAssemblies.Add(componentInfo.Name, new List <Assembly>());
                        }
                        componentPartAssemblies[componentInfo.Name].Add(a);
                    }

                    // Save assembly and ComponentInfo reference in hashtable for later iteration
                    componentAssemblies.Add(a, componentInfo);
                }
            }

            // Convert part assembly lists to arrays
            foreach (KeyValuePair <string, List <Assembly> > partList in componentPartAssemblies)
            {
                ((ComponentInfo)ComponentInfos[partList.Key]).PartAssemblies = partList.Value;
            }

            // Now iterate through all well-defined NQ components and search for services inside
            foreach (KeyValuePair <Assembly, ComponentInfo> nqAssembly in componentAssemblies)
            {
                ComponentInfo compInfo = nqAssembly.Value;

                Type[] classes = nqAssembly.Key.GetTypes();
                if (classes != null)
                {
                    foreach (Type comptype in classes)
                    {
                        if (AttributeServiceInfo.IsValidServiceClass(comptype))
                        {
                            // Firstly create a NQServiceInfo, we'll get all other information from it later
                            AttributeServiceInfo serviceInfo = new AttributeServiceInfo(comptype, compInfo.Name);

                            if (!ServiceInfos.ContainsKey(serviceInfo.ServiceInterface))
                            {
                                ServiceInfos.Add(serviceInfo.ServiceInterface, serviceInfo);
                            }
                            else
                            {
                                throw new ServiceDefinitionException(ErrorReason.ServiceMultiplyDefined,
                                                                     "Service \"" + serviceInfo.ServiceInterface + "\" is multiply defined.");
                            }
                        }
                    }
                }
            }

            _loadedData = true;
        }
示例#17
0
 /// <summary>
 /// Get all Service Infos of type
 /// </summary>
 /// <param name="type">Service Info Type to retrieve</param>
 /// <returns>List of matching Service Infos</returns>
 public List <IServiceInfo> GetServiceInfos(Type type)
 {
     return(ServiceInfos.Where((info) => info.GetType() == type).ToList());
 }
示例#18
0
 /// <summary>
 /// Get a named Service Info
 /// </summary>
 /// <param name="name">Name of service info</param>
 /// <returns>Service info</returns>
 public IServiceInfo GetServiceInfo(string name)
 {
     return(ServiceInfos.FirstOrDefault((info) => info.Id.Equals(name)));
 }
示例#19
0
        public static List <string> IRegister(List <string> param)
        {
            Dictionary <string, List <Type> > dico = new Dictionary <string, List <Type> >();

            string title = param[1];

            List <string>       operationNames    = new List <string>();
            List <List <Type> > typeForOperations = new List <List <Type> >();

            string[] operations = title.Split('_');

            int noOperation = 0;

            foreach (string operation in operations)
            {
                string operationName = "";
                int    charAt        = 0;
                do
                {
                    operationName += operation[charAt++];
                }while (operation[charAt] != '(');
                charAt++;
                operationNames.Add(operationName);

                typeForOperations.Add(new List <Type>());
                do
                {
                    string typeParamIn = "";
                    do
                    {
                        typeParamIn += operation[charAt];
                        charAt++;
                        if (operation[charAt] == ')')
                        {
                            break;
                        }
                    }while (operation[charAt] != ',');

                    typeForOperations[noOperation].Add(DataUtils.GetType(typeParamIn));
                }while (operation[charAt] != ')');
                charAt++;
                //on est sur le type de retour
                string typeRetour = "";
                do
                {
                    typeRetour += operation[charAt++];
                }while (charAt < operation.Length);
                typeForOperations[noOperation].Add(DataUtils.GetType(typeRetour));
                noOperation++;
            }

            for (int i = 0; i < operationNames.Count; i++)
            {
                dico.Add(operationNames[i], typeForOperations[i]);
            }
            string       service = param[0];
            string       address = param[2];
            string       port    = param[3];
            ServiceInfos si      = new ServiceInfos(dico, service);

            Register(si, address, int.Parse(port), int.Parse(param[4]));
            return(null);
        }