private System.Collections.ObjectModel.Collection <ObjectProvider> GetObjectProviders()
        {
            this.providers = new System.Collections.ObjectModel.Collection <ObjectProvider>();
            ObjectDefinition objDef = null;

            // This will need to be modified to reflect utilizing a different directory
            foreach (string configFileName in Directory.GetFiles(this.GetConfigPath <DynamicCrmAdapterDestination>()))
            {
                using (var fs = File.OpenRead(configFileName))
                {
                    using (var xr = XmlReader.Create(fs))
                    {
                        var serializer = new XmlSerializer(typeof(ObjectDefinition));
                        objDef = (ObjectDefinition)serializer.Deserialize(xr);
                    }
                }

                if (!IsStaticObjectProvider(objDef))
                {
                    DynamicObjectProvider dynObject = new DynamicObjectProvider()
                    {
                        Adapter = this, Id = GetDynamicProviderId(objDef), DisplayName = objDef.RootDefinition.DisplayName, Name = CRM2011AdapterUtilities.GetObjectProviderName(objDef)
                    };
                    this.providers.Add(dynObject);
                }

                if (objDef.RootDefinition.Name.Equals("OptionList"))
                {
                    PicklistObjectProvider pickObject = new PicklistObjectProvider()
                    {
                        Adapter = this
                    };
                    this.providers.Add(pickObject);
                }
            }

            return(this.providers);
        }
        /// <summary>
        /// Write out a object definition for the picklist provider
        /// </summary>
        internal void WritePicklistObjectDefinition()
        {
            var provider = new PicklistObjectProvider();

            try
            {
                if (!Directory.Exists(this.GetConfigPath(true)))
                {
                    this.SetupCompanyConfig(ConfigurationOption.Install);
                }

                var providerObjectDefinition = this.LoadObjectDefinitionsFromConfigs().FirstOrDefault(str => str.RootDefinition.TypeName.ToUpperInvariant() == provider.Name.ToUpperInvariant());
                string configFileName = providerObjectDefinition == null ?
                    CultureInfo.CurrentCulture.TextInfo.ToTitleCase(provider.DisplayName.ConvertToValidFileName().Replace(" ", string.Empty)) + "ObjectProvider.config" :
                    providerObjectDefinition.RootDefinition.DisplayName.ConvertToValidFileName().Replace(" ", string.Empty) + "ObjectProvider.config";
                Common.ObjectDefinition objDef = new Common.ObjectDefinition();
                this.PublishPreConfigurationMessage(string.Format(CultureInfo.CurrentCulture, Resources.StartGeneratingProviderConfiguration, provider.Name));

                // This is a new configuration file and we need to add the id attribute to it so the framework knows what this object provider's id is
                XmlDocument doc = new XmlDocument();
                XmlAttribute idAttrib = doc.CreateAttribute(CRM2011AdapterUtilities.EntityMetadataId);
                idAttrib.Value = provider.Id.ToString();
                TypeDefinition typeDef = new ComplexType() { ClrType = typeof(System.Collections.Generic.Dictionary<string, object>), Name = "Microsoft.Dynamics.Integration.Adapters.Crm2011.OptionList" };
                FieldDefinition rootDef = new FieldDefinition() { DisplayName = "Option list", Name = "OptionList", TypeDefinition = typeDef, TypeName = "Microsoft.Dynamics.Integration.Adapters.Crm2011.OptionList" };
                objDef.Types.Add(typeDef);
                objDef.RootDefinition = rootDef;
                this.FillPicklistObjectDef(objDef);

                using (var fs = File.Create(Path.Combine(this.GetConfigPath(true), configFileName)))
                {
                    using (var xr = XmlWriter.Create(fs, new XmlWriterSettings() { Indent = true }))
                    {
                        var serializer = new XmlSerializer(typeof(ObjectDefinition));
                        serializer.Serialize(xr, objDef);
                    }
                }

                this.PublishPostConfigurationMessage(string.Format(CultureInfo.CurrentCulture, Resources.FinishedGeneratingProviderConfiguration, provider.Name));
            }
            catch (IOException e)
            {
                // Log any exceptions the occur and publish them to any listeners
                TraceLog.Error(string.Format(CultureInfo.InvariantCulture, Resources.ExceptionDump), e);
                this.PublishExceptionConfigurationMessage(string.Format(CultureInfo.CurrentCulture, Resources.ProviderConfigurationExceptionMessage, provider.Name));
            }
        }
        private System.Collections.ObjectModel.Collection<ObjectProvider> GetObjectProviders()
        {
            this.providers = new System.Collections.ObjectModel.Collection<ObjectProvider>();
            ObjectDefinition objDef = null;

            foreach (string configFileName in Directory.GetFiles(this.GetConfigPath<DynamicCrmAdapter>()))
            {
                using (var fs = File.OpenRead(configFileName))
                {
                    using (var xr = XmlReader.Create(fs))
                    {
                        var serializer = new XmlSerializer(typeof(ObjectDefinition));
                        objDef = (ObjectDefinition)serializer.Deserialize(xr);
                    }
                }

                if (!IsStaticObjectProvider(objDef))
                {
                    DynamicObjectProvider dynObject = new DynamicObjectProvider() { Adapter = this, Id = GetDynamicProviderId(objDef), DisplayName = objDef.RootDefinition.DisplayName, Name = CRM2011AdapterUtilities.GetObjectProviderName(objDef) };
                    this.providers.Add(dynObject);
                }

                if (objDef.RootDefinition.Name.Equals("OptionList"))
                {
                    PicklistObjectProvider pickObject = new PicklistObjectProvider() { Adapter = this };
                    this.providers.Add(pickObject);
                }
            }

            return this.providers;
        }