コード例 #1
0
        protected override void Execute(CodeActivityContext context)
        {
            if (context == null)
            {
                throw new InvalidPluginExecutionException("Context not found!");
            }
            ;

            var workflowContext = context.GetExtension <IWorkflowContext>();
            var serviceFactory  = context.GetExtension <IOrganizationServiceFactory>();
            var orgService      = serviceFactory.CreateOrganizationService(workflowContext.UserId);

            Guid recordId = Guid.Empty;

            if (Guid.TryParse(EntityId.Get <string>(context), out recordId))
            {
                DynamicsDAO             dynamicsDAO = new DynamicsDAO(orgService);
                List <AuditDetailModel> audits      = dynamicsDAO.RetrieveAuditHistory(EntityLogicalName.Get <string>(context), AttributeLogicalName.Get <string>(context), recordId);
                if (audits.Count > 0)
                {
                    if (audits.Where(w => w.Type == "optionsetvalue").ToList().Count > 0) //This is necessary because the audit log, capture all changes in attributes including 'clear'
                    {
                        OptionMetadataCollection optionMetadatas = dynamicsDAO.GetOptionsSetTextOnValue(EntityLogicalName.Get <string>(context), AttributeLogicalName.Get <string>(context));
                        audits.ReplaceOptionSetValuesByLabels(optionMetadatas);
                    }
                    else if (audits.Where(w => w.Type == "boolean").ToList().Count > 0)
                    {
                        BooleanOptionSetMetadata booleanOptionSetMetadata = dynamicsDAO.GetBooleanTextOnValue(EntityLogicalName.Get <string>(context), AttributeLogicalName.Get <string>(context));
                        audits.ReplaceBooleanValuesByLabels(booleanOptionSetMetadata);
                    }
                }
                ChangesCount.Set(context, audits.Count);
                History.Set(context, audits.ToJSON());
            }
        }
コード例 #2
0
ファイル: PAMetadataService.cs プロジェクト: rhw1111/DCEM
        public OptionMetadata[] GetOptionSet(string entityName, string fieldName)
        {
            OptionMetadata[]         optionMetadatas;
            IOrganizationService     orgService       = ContextContainer.GetValue <IOrganizationService>(ContextTypes.OrgService);
            RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest
            {
                EntityLogicalName     = entityName,
                LogicalName           = fieldName,
                RetrieveAsIfPublished = false
            };

            RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)orgService.Execute(attributeRequest);

            if (attributeResponse.AttributeMetadata.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Boolean)
            {
                BooleanAttributeMetadata boolenAttributeMetadata = (BooleanAttributeMetadata)attributeResponse.AttributeMetadata;
                BooleanOptionSetMetadata boolenOptionSetMetadata = boolenAttributeMetadata.OptionSet;

                OptionMetadata[] options = new OptionMetadata[2];
                options[0]      = boolenOptionSetMetadata.TrueOption;
                options[1]      = boolenOptionSetMetadata.FalseOption;
                optionMetadatas = options;
            }
            else
            {
                EnumAttributeMetadata picklistAttributeMetadata = (EnumAttributeMetadata)attributeResponse.AttributeMetadata;
                OptionSetMetadata     optionSetMetadata         = picklistAttributeMetadata.OptionSet;
                OptionMetadata[]      optionList = optionSetMetadata.Options.ToArray();
                optionMetadatas = optionList;
            }


            return(optionMetadatas);
        }
コード例 #3
0
        public static OptionsModel Parse(this BooleanOptionSetMetadata th, int?languageCode = null)
        {
            var options = new List <OptionModel>();

            var nullOption = new OptionModel();

            nullOption.DisplayName = "Null";
            nullOption.Hexadecimal = "#000000";
            nullOption.Value       = null;
            nullOption.Count       = 0;
            options.Add(nullOption);

            var trueOption = new OptionModel();

            trueOption.DisplayName = th.TrueOption.Label.GetLabel(languageCode);
            trueOption.Hexadecimal = th.TrueOption.Color;
            trueOption.Value       = th.TrueOption.Value.Value;
            trueOption.Count       = 0;
            options.Add(trueOption);

            var falseOption = new OptionModel();

            falseOption.DisplayName = th.FalseOption.Label.GetLabel(languageCode);
            falseOption.Hexadecimal = th.FalseOption.Color;
            falseOption.Value       = th.FalseOption.Value.Value;
            falseOption.Count       = 0;
            options.Add(falseOption);

            return(new OptionsModel()
            {
                Options = options.ToArray()
            });
        }
 public static AttributeMetadata CreateTwoOptions(BooleanOptionSetMetadata optionSet, bool? defaultValue = false, string formulaDefinition = null)
 {
     return new BooleanAttributeMetadata
     {
         DefaultValue = defaultValue,
         FormulaDefinition = formulaDefinition,
         OptionSet = optionSet
     };
 }
 public static AttributeMetadata CreateTwoOptions(BooleanOptionSetMetadata optionSet, bool?defaultValue = false, string formulaDefinition = null)
 {
     return(new BooleanAttributeMetadata
     {
         DefaultValue = defaultValue,
         FormulaDefinition = formulaDefinition,
         OptionSet = optionSet
     });
 }
コード例 #6
0
        private BooleanAttributeMetadata BuildCreateBooleanAttribute()
        {
            var optionSet = new BooleanOptionSetMetadata(
                new OptionMetadata(new Label("True", DefaultLanguageCode), 1),
                new OptionMetadata(new Label("False", DefaultLanguageCode), 0)
                );
            var boolAttribute = new BooleanAttributeMetadata(optionSet);

            // Set default value.
            if (this.CurrentColumnDefinition.Default != null)
            {
                ((IVisitableBuilder)this.CurrentColumnDefinition.Default).Accept(this);
                boolAttribute.DefaultValue = this.CurrentDefaultBooleanAttributeValue;
                this.CurrentDefaultBooleanAttributeValue = null;
            }
            return(boolAttribute);
        }
        private static IEnumerable <EnumItem> ToUniqueValues(BooleanOptionSetMetadata booleanOptionSetMetadata)
        {
            List <EnumItem> values = new List <EnumItem>();

            if (booleanOptionSetMetadata.FalseOption == null)
            {
                values.Add(new EnumItem(0, "No", "No"));
            }
            else
            {
                values.Add(new EnumItem(booleanOptionSetMetadata.FalseOption.Value.Value, booleanOptionSetMetadata.FalseOption.Label.UserLocalizedLabel.Label, booleanOptionSetMetadata.FalseOption.Label.UserLocalizedLabel.Label));
            }

            if (booleanOptionSetMetadata.TrueOption == null)
            {
                values.Add(new EnumItem(1, "Yes", "Yes"));
            }
            else
            {
                values.Add(new EnumItem(booleanOptionSetMetadata.TrueOption.Value.Value, booleanOptionSetMetadata.TrueOption.Label.UserLocalizedLabel.Label, booleanOptionSetMetadata.TrueOption.Label.UserLocalizedLabel.Label));
            }
            return(ToUniqueValues(values));
        }
コード例 #8
0
        private void UpdateGlobalOptionSet()
        {
            int? newValue = Value;
            bool isNew    = true;

            // Can be new or update
            OptionSetMetadataBase optionSet = _repository.GetOptionSet(OptionSet);

            if (optionSet is OptionSetMetadata)
            {
                OptionSetMetadata localOptionSet = optionSet as OptionSetMetadata;
                if (localOptionSet.Options.Any(o => o.Value.Value.Equals(Value.Value)))
                {
                    // Existing; Do update
                    isNew = false;
                }
            }
            else if (optionSet is BooleanOptionSetMetadata)
            {
                BooleanOptionSetMetadata localOptionSet = optionSet as BooleanOptionSetMetadata;
                if (localOptionSet.TrueOption.Value.Equals(Value.Value) || localOptionSet.FalseOption.Value.Equals(Value.Value))
                {
                    // Existing; Do update
                    isNew = false;
                }
            }

            if (isNew)
            {
                newValue = _repository.AddOptionSetValue(OptionSet, DisplayName, Value, Description);
            }
            else
            {
                _repository.UpdateOptionSetValue(OptionSet, Value.Value, DisplayName, Description);
            }
        }
コード例 #9
0
        /// <summary>
        /// </summary>
        /// <param name="serverConfig">Contains server connection information.</param>
        /// <param name="promptForDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        public void Run(IOrganizationService service, string solutionName)
        {
            try
            {
                //  string serverName = "https://workflow.crm.dynamics.com/Workflow_10312017";
                //  Uri organizationUri = new Uri(string.Format("{0}/XRMServices/2011/Organization.svc", serverName));
                //  Uri homeRealmUri = null;
                //  ClientCredentials credentials = new ClientCredentials();

                //  //use UserName object for CRM Online

                //credentials.UserName.UserName = "******";
                //credentials.UserName.Password = "******";

                //  use default for OnPrem...
                //credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;

                //IOrganizationService service = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);

                #region How to dump option set info
                RetrieveAllOptionSetsRequest retrieveAllOptionSetsRequest =
                    new RetrieveAllOptionSetsRequest();

                // Execute the request
                RetrieveAllOptionSetsResponse retrieveAllOptionSetsResponse =
                    (RetrieveAllOptionSetsResponse)service.Execute(
                        retrieveAllOptionSetsRequest);

                // Create an instance of StreamWriter to write text to a file.
                // The using statement also closes the StreamWriter.
                // To view this file, right click the file and choose open with Excel.
                // Excel will figure out the schema and display the information in columns.

                String filename = String.Concat("AllOptionSetValues.xml");
                using (StreamWriter sw = new StreamWriter(filename))
                {
                    // Create Xml Writer.
                    XmlTextWriter metadataWriter = new XmlTextWriter(sw);

                    // Start Xml File.
                    metadataWriter.WriteStartDocument();

                    // Metadata Xml Node.
                    metadataWriter.WriteStartElement("Metadata");

                    if (retrieveAllOptionSetsResponse.OptionSetMetadata.Count() > 0)
                    {
                        foreach (OptionSetMetadataBase optionSetMetadataBase in
                                 retrieveAllOptionSetsResponse.OptionSetMetadata)
                        {
                            if (optionSetMetadataBase.OptionSetType != null)
                            {
                                if ((OptionSetType)optionSetMetadataBase.OptionSetType == OptionSetType.Picklist)
                                {
                                    OptionSetMetadata optionSetMetadata = (OptionSetMetadata)optionSetMetadataBase;
                                    // Start OptionSet Node
                                    metadataWriter.WriteStartElement("OptionSet");
                                    metadataWriter.WriteAttributeString("OptionSetType", OptionSetType.Picklist.ToString());
                                    metadataWriter.WriteElementString("OptionSetDisplayName",
                                                                      (optionSetMetadata.DisplayName.LocalizedLabels.Count > 0) ? optionSetMetadata.DisplayName.LocalizedLabels[0].Label : String.Empty);

                                    // Writes the options
                                    metadataWriter.WriteStartElement("Options");

                                    foreach (OptionMetadata option in optionSetMetadata.Options)
                                    {
                                        metadataWriter.WriteStartElement("Option");
                                        metadataWriter.WriteElementString("OptionValue", option.Value.ToString());
                                        metadataWriter.WriteElementString("OptionDescription", option.Label.UserLocalizedLabel.Label.ToString());
                                        metadataWriter.WriteEndElement();
                                    }
                                    metadataWriter.WriteEndElement();

                                    // End OptionSet Node
                                    metadataWriter.WriteEndElement();
                                }
                                else if ((OptionSetType)optionSetMetadataBase.OptionSetType == OptionSetType.Boolean)
                                {
                                    BooleanOptionSetMetadata optionSetMetadata = (BooleanOptionSetMetadata)optionSetMetadataBase;
                                    // Start OptionSet Node
                                    metadataWriter.WriteStartElement("OptionSet");
                                    metadataWriter.WriteAttributeString("OptionSetType", OptionSetType.Boolean.ToString());
                                    if (optionSetMetadata.DisplayName.LocalizedLabels.Count != 0)
                                    {
                                        metadataWriter.WriteElementString("OptionSetDisplayName", optionSetMetadata.DisplayName.LocalizedLabels[0].Label);
                                    }
                                    else
                                    {
                                        metadataWriter.WriteElementString("OptionSetDisplayName", "UNDEFINED");
                                    }

                                    // Writes the TrueOption
                                    metadataWriter.WriteStartElement("TrueOption");
                                    metadataWriter.WriteElementString("OptionValue", optionSetMetadata.TrueOption.Value.ToString());
                                    metadataWriter.WriteElementString("OptionDescription", optionSetMetadata.TrueOption.Label.UserLocalizedLabel.Label.ToString());
                                    metadataWriter.WriteEndElement();
                                    // Writes the FalseOption
                                    metadataWriter.WriteStartElement("FalseOption");
                                    metadataWriter.WriteElementString("OptionValue", optionSetMetadata.FalseOption.Value.ToString());
                                    metadataWriter.WriteElementString("OptionDescription", optionSetMetadata.FalseOption.Label.UserLocalizedLabel.Label.ToString());
                                    metadataWriter.WriteEndElement();

                                    // End OptionSet Node
                                    metadataWriter.WriteEndElement();
                                }
                            }
                        }
                    }

                    // End Metadata Xml Node
                    metadataWriter.WriteEndElement();
                    metadataWriter.WriteEndDocument();

                    // Close xml writer.
                    metadataWriter.Close();
                }

                #endregion How to dump option set info
                Console.WriteLine("Done.");
                //DeleteRequiredRecords(promptForDelete);
            }
            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
コード例 #10
0
ファイル: XrmService.cs プロジェクト: josephmcmac/JosephM.Xrm
        public void CreateOrUpdateBooleanAttribute(string schemaName, string displayName, string description,
            bool isRequired, bool audit, bool searchable, string recordType)
        {
            var optionSet = new BooleanOptionSetMetadata();
            optionSet.FalseOption = new OptionMetadata(new Label("No", 1033), 0);
            optionSet.TrueOption = new OptionMetadata(new Label("Yes", 1033), 1);

            BooleanAttributeMetadata metadata;
            if (FieldExists(schemaName, recordType))
                metadata = (BooleanAttributeMetadata) GetFieldMetadata(schemaName, recordType);
            else
                metadata = new BooleanAttributeMetadata();

            SetCommon(metadata, schemaName, displayName, description, isRequired, audit, searchable);
            metadata.OptionSet = optionSet;

            CreateOrUpdateAttribute(schemaName, recordType, metadata);
        }
コード例 #11
0
 /// <summary>
 /// Replace Boolean (int) by labes (string)
 /// </summary>
 /// <param name="_this">List<AuditDetailModel></param>
 public static void ReplaceBooleanValuesByLabels(this List <AuditDetailModel> _this, BooleanOptionSetMetadata booleanOptionSetMetadata)
 {
     //All audits histories where the attribute has value
     foreach (var audit in _this.Where(w => !String.IsNullOrEmpty(w.Value)))
     {
         if (audit.Value == "1")
         {
             audit.Value = booleanOptionSetMetadata.TrueOption?.Label?.UserLocalizedLabel?.Label != null ? booleanOptionSetMetadata.TrueOption.Label.UserLocalizedLabel.Label : string.Empty;
         }
         else
         {
             audit.Value = booleanOptionSetMetadata.FalseOption?.Label?.UserLocalizedLabel?.Label != null ? booleanOptionSetMetadata.FalseOption.Label.UserLocalizedLabel.Label : string.Empty;
         }
     }
 }
コード例 #12
0
 public BooleanOptionSetMetadataInfo(BooleanOptionSetMetadata amd)
 {
     this.amd = amd;
 }
コード例 #13
0
        [STAThread] // Required to support the interactive login experience
        static void Main(string[] args)
        {
            CrmServiceClient service = null;

            try
            {
                service = SampleHelpers.Connect("Connect");
                if (service.IsReady)
                {
                    // Create any entity records that the demonstration code requires
                    SetUpSample(service);
                    #region Demonstrate

                    var retrieveAllOptionSetsRequest = new RetrieveAllOptionSetsRequest();

                    // Execute the request
                    var retrieveAllOptionSetsResponse = (RetrieveAllOptionSetsResponse)service.Execute(
                        retrieveAllOptionSetsRequest);

                    // Create an instance of StreamWriter to write text to a file.
                    // The using statement also closes the StreamWriter.
                    // To view this file, right click the file and choose open with Excel.
                    // Excel will figure out the schema and display the information in columns.

                    String filename = String.Concat("AllOptionSetValues.xml");
                    using (var sw = new StreamWriter(filename))
                    {
                        // Create Xml Writer.
                        var metadataWriter = new XmlTextWriter(sw);

                        // Start Xml File.
                        metadataWriter.WriteStartDocument();

                        // Metadata Xml Node.
                        metadataWriter.WriteStartElement("Metadata");

                        if (retrieveAllOptionSetsResponse.OptionSetMetadata.Count() > 0)
                        {
                            foreach (OptionSetMetadataBase optionSetMetadataBase in
                                     retrieveAllOptionSetsResponse.OptionSetMetadata)
                            {
                                if (optionSetMetadataBase.OptionSetType != null)
                                {
                                    if ((OptionSetType)optionSetMetadataBase.OptionSetType == OptionSetType.Picklist)
                                    {
                                        OptionSetMetadata optionSetMetadata = (OptionSetMetadata)optionSetMetadataBase;
                                        // Start OptionSet Node
                                        metadataWriter.WriteStartElement("OptionSet");
                                        metadataWriter.WriteAttributeString("OptionSetType", OptionSetType.Picklist.ToString());
                                        metadataWriter.WriteElementString("OptionSetDisplayName",
                                                                          (optionSetMetadata.DisplayName.LocalizedLabels.Count > 0) ? optionSetMetadata.DisplayName.LocalizedLabels[0].Label : String.Empty);

                                        // Writes the options
                                        metadataWriter.WriteStartElement("Options");

                                        foreach (OptionMetadata option in optionSetMetadata.Options)
                                        {
                                            metadataWriter.WriteStartElement("Option");
                                            metadataWriter.WriteElementString("OptionValue", option.Value.ToString());
                                            metadataWriter.WriteElementString("OptionDescription", option.Label.UserLocalizedLabel.Label.ToString());
                                            metadataWriter.WriteEndElement();
                                        }
                                        metadataWriter.WriteEndElement();

                                        // End OptionSet Node
                                        metadataWriter.WriteEndElement();
                                    }
                                    else if ((OptionSetType)optionSetMetadataBase.OptionSetType == OptionSetType.Boolean)
                                    {
                                        BooleanOptionSetMetadata optionSetMetadata = (BooleanOptionSetMetadata)optionSetMetadataBase;
                                        // Start OptionSet Node
                                        metadataWriter.WriteStartElement("OptionSet");
                                        metadataWriter.WriteAttributeString("OptionSetType", OptionSetType.Boolean.ToString());
                                        if (optionSetMetadata.DisplayName.LocalizedLabels.Count != 0)
                                        {
                                            metadataWriter.WriteElementString("OptionSetDisplayName", optionSetMetadata.DisplayName.LocalizedLabels[0].Label);
                                        }
                                        else
                                        {
                                            metadataWriter.WriteElementString("OptionSetDisplayName", "UNDEFINED");
                                        }

                                        // Writes the TrueOption
                                        metadataWriter.WriteStartElement("TrueOption");
                                        metadataWriter.WriteElementString("OptionValue", optionSetMetadata.TrueOption.Value.ToString());
                                        metadataWriter.WriteElementString("OptionDescription", optionSetMetadata.TrueOption.Label.UserLocalizedLabel.Label.ToString());
                                        metadataWriter.WriteEndElement();
                                        // Writes the FalseOption
                                        metadataWriter.WriteStartElement("FalseOption");
                                        metadataWriter.WriteElementString("OptionValue", optionSetMetadata.FalseOption.Value.ToString());
                                        metadataWriter.WriteElementString("OptionDescription", optionSetMetadata.FalseOption.Label.UserLocalizedLabel.Label.ToString());
                                        metadataWriter.WriteEndElement();

                                        // End OptionSet Node
                                        metadataWriter.WriteEndElement();
                                    }
                                }
                            }
                        }

                        // End Metadata Xml Node
                        metadataWriter.WriteEndElement();
                        metadataWriter.WriteEndDocument();

                        // Close xml writer.
                        metadataWriter.Close();
                    }

                    Console.WriteLine("Done.");
                    #endregion Demonstrate

                    #region Clean up
                    CleanUpSample(service);
                    #endregion Clean up
                }
                else
                {
                    const string UNABLE_TO_LOGIN_ERROR = "Unable to Login to Microsoft Dataverse";
                    if (service.LastCrmError.Equals(UNABLE_TO_LOGIN_ERROR))
                    {
                        Console.WriteLine("Check the connection string values in cds/App.config.");
                        throw new Exception(service.LastCrmError);
                    }
                    else
                    {
                        throw service.LastCrmException;
                    }
                }
            }
            catch (Exception ex)
            {
                SampleHelpers.HandleException(ex);
            }

            finally
            {
                if (service != null)
                {
                    service.Dispose();
                }

                Console.WriteLine("Press <Enter> to exit.");
                Console.ReadLine();
            }
        }
コード例 #14
0
 public BooleanOptionSetMetadataInfo(BooleanOptionSetMetadata amd)
 {
     this.amd = amd;
 }
        /// <summary>
        /// </summary>
        /// <param name="serverConfig">Contains server connection information.</param>
        /// <param name="promptForDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        public void Run(ServerConnection.Configuration serverConfig, bool promptForDelete)
        {
            try
            {
                // Connect to the Organization service.
                // The using statement assures that the service proxy will be properly disposed.
                using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    // This statement is required to enable early-bound type support.
                    _serviceProxy.EnableProxyTypes();

                    #region How to dump option set info


                    RetrieveAllOptionSetsRequest retrieveAllOptionSetsRequest =
                        new RetrieveAllOptionSetsRequest();

                    // Execute the request
                    RetrieveAllOptionSetsResponse retrieveAllOptionSetsResponse =
                        (RetrieveAllOptionSetsResponse)_serviceProxy.Execute(
                            retrieveAllOptionSetsRequest);

                    // Create an instance of StreamWriter to write text to a file.
                    // The using statement also closes the StreamWriter.
                    // To view this file, right click the file and choose open with Excel.
                    // Excel will figure out the schema and display the information in columns.

                    String filename = String.Concat("AllOptionSetValues.xml");
                    using (StreamWriter sw = new StreamWriter(filename))
                    {
                        // Create Xml Writer.
                        XmlTextWriter metadataWriter = new XmlTextWriter(sw);

                        // Start Xml File.
                        metadataWriter.WriteStartDocument();

                        // Metadata Xml Node.
                        metadataWriter.WriteStartElement("Metadata");

                        if (retrieveAllOptionSetsResponse.OptionSetMetadata.Count() > 0)
                        {
                            foreach (OptionSetMetadataBase optionSetMetadataBase in
                                     retrieveAllOptionSetsResponse.OptionSetMetadata)
                            {
                                if (optionSetMetadataBase.OptionSetType != null)
                                {
                                    if ((OptionSetType)optionSetMetadataBase.OptionSetType == OptionSetType.Picklist)
                                    {
                                        OptionSetMetadata optionSetMetadata = (OptionSetMetadata)optionSetMetadataBase;
                                        // Start OptionSet Node
                                        metadataWriter.WriteStartElement("OptionSet");
                                        metadataWriter.WriteAttributeString("OptionSetType", OptionSetType.Picklist.ToString());
                                        metadataWriter.WriteElementString("OptionSetDisplayName",
                                                                          (optionSetMetadata.DisplayName.LocalizedLabels.Count > 0)? optionSetMetadata.DisplayName.LocalizedLabels[0].Label : String.Empty);

                                        // Writes the options
                                        metadataWriter.WriteStartElement("Options");

                                        foreach (OptionMetadata option in optionSetMetadata.Options)
                                        {
                                            metadataWriter.WriteStartElement("Option");
                                            metadataWriter.WriteElementString("OptionValue", option.Value.ToString());
                                            metadataWriter.WriteElementString("OptionDescription", option.Label.UserLocalizedLabel.Label.ToString());
                                            metadataWriter.WriteEndElement();
                                        }
                                        metadataWriter.WriteEndElement();

                                        // End OptionSet Node
                                        metadataWriter.WriteEndElement();
                                    }
                                    else if ((OptionSetType)optionSetMetadataBase.OptionSetType == OptionSetType.Boolean)
                                    {
                                        BooleanOptionSetMetadata optionSetMetadata = (BooleanOptionSetMetadata)optionSetMetadataBase;
                                        // Start OptionSet Node
                                        metadataWriter.WriteStartElement("OptionSet");
                                        metadataWriter.WriteAttributeString("OptionSetType", OptionSetType.Boolean.ToString());
                                        if (optionSetMetadata.DisplayName.LocalizedLabels.Count != 0)
                                        {
                                            metadataWriter.WriteElementString("OptionSetDisplayName", optionSetMetadata.DisplayName.LocalizedLabels[0].Label);
                                        }
                                        else
                                        {
                                            metadataWriter.WriteElementString("OptionSetDisplayName", "UNDEFINED");
                                        }

                                        // Writes the TrueOption
                                        metadataWriter.WriteStartElement("TrueOption");
                                        metadataWriter.WriteElementString("OptionValue", optionSetMetadata.TrueOption.Value.ToString());
                                        metadataWriter.WriteElementString("OptionDescription", optionSetMetadata.TrueOption.Label.UserLocalizedLabel.Label.ToString());
                                        metadataWriter.WriteEndElement();
                                        // Writes the FalseOption
                                        metadataWriter.WriteStartElement("FalseOption");
                                        metadataWriter.WriteElementString("OptionValue", optionSetMetadata.FalseOption.Value.ToString());
                                        metadataWriter.WriteElementString("OptionDescription", optionSetMetadata.FalseOption.Label.UserLocalizedLabel.Label.ToString());
                                        metadataWriter.WriteEndElement();

                                        // End OptionSet Node
                                        metadataWriter.WriteEndElement();
                                    }
                                }
                            }
                        }

                        // End Metadata Xml Node
                        metadataWriter.WriteEndElement();
                        metadataWriter.WriteEndDocument();

                        // Close xml writer.
                        metadataWriter.Close();
                    }


                    #endregion How to dump option set info



                    Console.WriteLine("Done.");

                    //DeleteRequiredRecords(promptForDelete);
                }
            }

            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
コード例 #16
0
        /// <summary>
        /// Load Global Option Set
        /// </summary>
        private static void LoadGlobalOptionSet()
        {
            RetrieveAllOptionSetsRequest request   = new RetrieveAllOptionSetsRequest {
            };
            RetrieveAllOptionSetsResponse response = (RetrieveAllOptionSetsResponse)organizationService.Execute(request);
            var optionSetData = response.OptionSetMetadata;

            string content = string.Empty;

            foreach (var optionSet in optionSetData)
            {
                if (optionSet.IsGlobal.HasValue &&
                    !optionSet.IsGlobal.Value)
                {
                    continue;
                }

                string optionSetCode = GlobalOptionSetCodeTemplate;

                string label       = GetOptionSetLabel(optionSet);
                string displayName = label;
                string description = label;
                if (string.IsNullOrEmpty(description))
                {
                    description = displayName;
                }

                optionSetCode = optionSetCode.Replace("[@OptionSet.DisplayName]", displayName);
                optionSetCode = optionSetCode.Replace("[@OptionSet.Description]", TransformToSymmary(description));
                optionSetCode = optionSetCode.Replace("[@OptionSet.SchemaName]", optionSet.Name);
                optionSetCode = optionSetCode.Replace("[@OptionSet.OptionSetType.Value]", optionSet.OptionSetType.Value.ToString());
                optionSetCode = optionSetCode.Replace("[@OptionSet.LogicalName]", optionSet.Name);

                string optionSetEnums = string.Empty;

                if (optionSet.OptionSetType != null)
                {
                    if ((OptionSetType)optionSet.OptionSetType == OptionSetType.Picklist)
                    {
                        OptionSetMetadata optionSetMetadata = (OptionSetMetadata)optionSet;
                        int optionCount = 1;
                        foreach (OptionMetadata option in optionSetMetadata.Options)
                        {
                            var desc   = label;
                            var value  = option.Value.Value.ToString(CultureInfo.InvariantCulture);
                            var label2 = optionCount + "_" + ConvertNameAsVariable(desc);

                            string optionSetEnumCode = OptionSetEnumCodeTemplate;
                            optionSetEnumCode = optionSetEnumCode.Replace("[@Option.Description]", TransformToSymmary(desc));
                            optionSetEnumCode = optionSetEnumCode.Replace("[@Option.Label]", label2);
                            optionSetEnumCode = optionSetEnumCode.Replace("[@Option.Value]", value);
                            optionSetEnums   += optionSetEnumCode;
                            optionCount++;
                        }
                    }
                    else if ((OptionSetType)optionSet.OptionSetType == OptionSetType.Boolean)
                    {
                        BooleanOptionSetMetadata optionSetMetadata = (BooleanOptionSetMetadata)optionSet;

                        string optionSetEnumCode = OptionSetEnumCodeTemplate;
                        optionSetEnumCode = optionSetEnumCode.Replace("[@Option.Description]", optionSetMetadata.TrueOption.Label.UserLocalizedLabel.Label);
                        optionSetEnumCode = optionSetEnumCode.Replace("[@Option.Label]", "TrueOption");
                        optionSetEnumCode = optionSetEnumCode.Replace("[@Option.Value]", optionSetMetadata.TrueOption.Value.ToString());
                        optionSetEnums   += optionSetEnumCode;

                        optionSetEnumCode = OptionSetEnumCodeTemplate;
                        optionSetEnumCode = optionSetEnumCode.Replace("[@Option.Description]", optionSetMetadata.FalseOption.Label.UserLocalizedLabel.Label);
                        optionSetEnumCode = optionSetEnumCode.Replace("[@Option.Label]", "FalseOption");
                        optionSetEnumCode = optionSetEnumCode.Replace("[@Option.Value]", optionSetMetadata.FalseOption.Value.ToString());
                        optionSetEnums   += optionSetEnumCode;
                    }
                    optionSetCode = optionSetCode.Replace("[@OptionSet.Values]", optionSetEnums);
                }

                content += optionSetCode;
            }

            string classContent = GlobalOptionSetClassCodeTemplate;

            classContent = classContent.Replace("[@DefaultNamespace]", DefaultNamespace);
            classContent = classContent.Replace("[@OptionSetDefinition]", content);

            string fileName = Path.Combine(TargetPath, "GlobalOptionSet.generated.cs");

            File.WriteAllText(fileName, classContent);
        }
コード例 #17
0
        internal async Task <List <string> > GetDifference(BooleanOptionSetMetadata optionSet1, BooleanOptionSetMetadata optionSet2, string entityName, string attributeName)
        {
            List <string> strDifference = new List <string>();

            {
                FormatTextTableHandler table = new FormatTextTableHandler(true);

                table.CalculateLineLengths("LanguageCode", "Value");
                table.CalculateLineLengths("LanguageCode", "Organization", "Value");

                var isDifferentDisplayName = LabelComparer.GetDifference(optionSet1.DisplayName, optionSet2.DisplayName);
                var isDifferentDescription = LabelComparer.GetDifference(optionSet1.Description, optionSet2.Description);

                isDifferentDisplayName.LabelsOnlyIn1.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayName.LabelsOnlyIn2.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayName.LabelDifference.ForEach(i =>
                {
                    table.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    table.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                isDifferentDescription.LabelsOnlyIn1.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDescription.LabelsOnlyIn2.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDescription.LabelDifference.ForEach(i =>
                {
                    table.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    table.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                if (!isDifferentDisplayName.IsEmpty)
                {
                    if (isDifferentDisplayName.LabelsOnlyIn1.Count > 0)
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName1, isDifferentDisplayName.LabelsOnlyIn1.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayName.LabelsOnlyIn1.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayName.LabelsOnlyIn2.Count > 0)
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName2, isDifferentDisplayName.LabelsOnlyIn2.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayName.LabelsOnlyIn2.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayName.LabelDifference.Count > 0)
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("DisplayNames DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDisplayName.LabelDifference.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentDisplayName.LabelDifference.ForEach(i =>
                        {
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName1, i.Value1));
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName2, i.Value2));
                        });
                    }
                }

                if (!isDifferentDescription.IsEmpty)
                {
                    if (isDifferentDescription.LabelsOnlyIn1.Count > 0)
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("Descriptions ONLY in {0}: {1}", _connectionName1, isDifferentDescription.LabelsOnlyIn1.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDescription.LabelsOnlyIn1.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDescription.LabelsOnlyIn2.Count > 0)
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("Descriptions ONLY in {0}: {1}", _connectionName2, isDifferentDescription.LabelsOnlyIn2.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDescription.LabelsOnlyIn2.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDescription.LabelDifference.Count > 0)
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("Descriptions DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDescription.LabelDifference.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentDescription.LabelDifference.ForEach(i =>
                        {
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName1, i.Value1));
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName2, i.Value2));
                        });
                    }
                }
            }

            {
                var table = new FormatTextTableHandler(true);
                table.SetHeader("Property", _connectionName1, _connectionName2);

                table.AddLineIfNotEqual("IsCustomizable", optionSet1.IsCustomizable, optionSet2.IsCustomizable);
                table.AddLineIfNotEqual("IsCustomOptionSet", optionSet1.IsCustomOptionSet, optionSet2.IsCustomOptionSet);
                table.AddLineIfNotEqual("IsGlobal", optionSet1.IsGlobal, optionSet2.IsGlobal);
                //table.AddLineIfNotEqual("IsManaged", optionSet1.IsManaged, optionSet2.IsManaged);
                table.AddLineIfNotEqual("Name", optionSet1.Name, optionSet2.Name);

                if (table.Count > 0)
                {
                    strDifference.AddRange(table.GetFormatedLines(true));
                }
            }

            {
                Dictionary <string, List <string> > optionValueDifferent = new Dictionary <string, List <string> >(StringComparer.InvariantCultureIgnoreCase);

                {
                    List <string> optionDiff = await GetDifferenceOptionSetValue(optionSet1.FalseOption, optionSet2.FalseOption, entityName, attributeName);

                    if (optionDiff.Count > 0)
                    {
                        optionValueDifferent.Add("FalseOption", optionDiff);
                    }
                }

                {
                    List <string> optionDiff = await GetDifferenceOptionSetValue(optionSet1.TrueOption, optionSet2.TrueOption, entityName, attributeName);

                    if (optionDiff.Count > 0)
                    {
                        optionValueDifferent.Add("TrueOption", optionDiff);
                    }
                }

                if (optionValueDifferent.Count > 0)
                {
                    foreach (var item in optionValueDifferent.OrderBy(e => e.Key))
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("Different Value {0}", item.Key));

                        foreach (var value in item.Value)
                        {
                            strDifference.Add(_tabSpacer + value);
                        }
                    }
                }
            }

            return(strDifference);
        }