/// <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));
            }
        }
        internal void WriteObjectDefinition(ObjectProvider provider)
        {
            try
            {
                // Check to see if the company specific directory has been created yet or not, if not create it and copy all of the base configs into it
                // if it has, then we assume that the base configs are there since the copy always occurs after the directory creation
                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";

                var filePath = Path.Combine(this.GetConfigPath(false), configFileName);
                Common.ObjectDefinition objDef = new Common.ObjectDefinition();
                this.PublishPreConfigurationMessage(string.Format(CultureInfo.CurrentCulture, Resources.StartGeneratingProviderConfiguration, provider.Name));

                // Check to see if the object def is stored at the root, which means it is a base or version 1 definition
                if (File.Exists(filePath))
                {
                    provider.Name = Path.GetFileNameWithoutExtension(configFileName);
                    objDef = provider.ObjectDefinition;
                    this.FillObjectDef(objDef);
                }
                else
                {
                    // 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 = provider.Name };
                    FieldDefinition rootDef = new FieldDefinition() { DisplayName = provider.DisplayName, Name = provider.Name, TypeDefinition = typeDef, TypeName = provider.Name, AdditionalAttributes = new XmlAttribute[] { idAttrib } };
                    objDef.Types.Add(typeDef);
                    objDef.RootDefinition = rootDef;
                    this.FillObjectDef(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));
            }
        }