Beispiel #1
0
        protected bool RemoveComContractIfNotUsedByAnyService(Configuration config, string interfaceID)
        {
            ServiceModelSectionGroup sg          = ServiceModelSectionGroup.GetSectionGroup(config);
            ServiceElementCollection serviceColl = sg.Services.Services;
            Guid iidInterface = new Guid(interfaceID);

            // Find serviceElement
            foreach (ServiceElement el in serviceColl)
            {
                // Now, check if endpoint already exists..
                foreach (ServiceEndpointElement ee in el.Endpoints)
                {
                    try
                    {
                        if (!IsMetaDataEndpoint(ee))
                        {
                            Guid Iid = new Guid(ee.Contract);
                            if (iidInterface == Iid)
                            {
                                return(false);
                            }
                        }
                    }
                    catch (FormatException)
                    {
                    }
                }
            }
            ComContractElementCollection contractCollection = sg.ComContracts.ComContracts;

            foreach (ComContractElement element in contractCollection)
            {
                try
                {
                    Guid contract = new Guid(element.Contract);
                    if (contract == iidInterface)
                    {
                        contractCollection.Remove(element);
                        return(true);
                    }
                }
                catch (FormatException)
                {
                }
            }
            return(false);
        }
Beispiel #2
0
        protected bool RemoveComContractMethods(Configuration config, string interfaceID, IList <string> methods)
        {
            Guid iidInterface = new Guid(interfaceID);
            ServiceModelSectionGroup     sg = ServiceModelSectionGroup.GetSectionGroup(config);
            ComContractElementCollection contractCollection = sg.ComContracts.ComContracts;

            foreach (ComContractElement contractElement in contractCollection)
            {
                try
                {
                    Guid contract = new Guid(contractElement.Contract);
                    if (contract == iidInterface)
                    {
                        foreach (string methodName in methods)
                        {
                            foreach (ComMethodElement methodElement in contractElement.ExposedMethods)
                            {
                                if (methodElement.ExposedMethod == methodName)
                                {
                                    contractElement.ExposedMethods.Remove(methodElement);
                                    break;
                                }
                            }
                        }
                        if (contractElement.ExposedMethods.Count == 0)
                        {
                            sg.ComContracts.ComContracts.Remove(contractElement);
                            return(true);
                        }
                    }
                }
                catch (FormatException)
                {
                }
            }
            return(false);
        }
Beispiel #3
0
        protected bool AddComContractToConfig(Configuration config, string name, string contractType, IList <string> methods)
        {
            Guid contractIID = new Guid(contractType);
            ServiceModelSectionGroup     sg = ServiceModelSectionGroup.GetSectionGroup(config);
            ComContractElementCollection contractCollection = sg.ComContracts.ComContracts;

            foreach (ComContractElement comContract in contractCollection)
            {
                try
                {
                    Guid contractFound = new Guid(comContract.Contract);
                    if (contractIID == contractFound)
                    {
                        bool methodsAdded = false;
                        bool found        = false;
                        foreach (string methodName in methods)
                        {
                            found = false;
                            foreach (ComMethodElement methodElement in comContract.ExposedMethods)
                            {
                                if (methodElement.ExposedMethod == methodName)
                                {
                                    found = true;
                                }
                            }
                            if (!found)
                            {
                                comContract.ExposedMethods.Add(new ComMethodElement(methodName));
                                methodsAdded = true;
                            }
                        }

                        if (comContract.PersistableTypes.Count == 0 && Tool.Options.AllowReferences && methodsAdded)
                        {
                            comContract.PersistableTypes.EmitClear = true;
                        }

                        return(methodsAdded);
                    }
                }
                catch (FormatException)
                {
                }
            }
            // The contract does not exists
            // so we are going to add it
            ComContractElement newComContract = new ComContractElement(contractIID.ToString("B").ToUpperInvariant());

            newComContract.Name      = name;
            newComContract.Namespace = EndpointConfig.TempURI + contractIID.ToString().ToUpperInvariant();
            foreach (string methodName in methods)
            {
                newComContract.ExposedMethods.Add(new ComMethodElement(methodName));
            }

            if (newComContract.PersistableTypes.Count == 0 && Tool.Options.AllowReferences)
            {
                newComContract.PersistableTypes.EmitClear = true;
            }

            newComContract.RequiresSession = true;

            contractCollection.Add(newComContract);

            return(true);
        }