Beispiel #1
0
        private static void ChooseNextAction(MessagePrompter mp, string extractPath, List <EntityMeta> selectedEntities)
        {
            mp.Prompt("");
            mp.Prompt("Please choose what to do with the gathered attributes. Type in just the number.");
            mp.Prompt("[{0}] Show the attributes that have different display names and labels", (int)ActionList.ShowNonMatchingLabels);
            mp.Prompt("[{0}] Show attributes of the selected entity", (int)ActionList.ShowAllAttributes);
            mp.Prompt("[{0}] Exit", 0);

            var exit = false;

            while (!exit)
            {
                var resp            = mp.Read();
                var resultsFilePath = "";

                switch (Convert.ToInt32(resp))
                {
                case (0):
                    exit = true;
                    break;

                case ((int)ActionList.ShowNonMatchingLabels):
                    resultsFilePath = extractPath + "\\NonMatchingLabels.out";
                    ShowAllAttributes(resultsFilePath, selectedEntities, (att) =>
                                      !String.IsNullOrEmpty(att.Label) &&
                                      !att.IsLabelMatchingDisplayName);
                    mp.Prompt("Results are stored in the '{0}' file.", resultsFilePath);
                    break;

                case ((int)ActionList.ShowAllAttributes):
                    resultsFilePath = extractPath + "\\AllAttributes.out";
                    ShowAllAttributes(resultsFilePath, selectedEntities, (att) =>
                                      !String.IsNullOrEmpty(att.Label) &&
                                      !att.IsLabelMatchingDisplayName);
                    mp.Prompt("Results are stored in the '{0}' file.", resultsFilePath);
                    break;

                default:
                    mp.Prompt("Please choose a number between {0} and {1}.", 1, 2);
                    break;
                }

                mp.Prompt("");
                mp.Prompt("Please choose the next action.");
            }
        }
        public CrmObject GetCrmConnection()
        {
            // Get the Url
            Mp.Prompt("Please enter the Url of the organization. E.g. 'http://www.contoso.com:5555/OrganizationName'\n");
            Url = Mp.Read();

            // Get the Domain
            Mp.Prompt("Please enter the Domain of the user.");
            Domain = Mp.Read();

            // Get the Username
            Mp.Prompt("Please enter the Username");
            Username = Mp.Read();

            // Get the Password
            Mp.Prompt("Please enter the Password");
            Password = Mp.ReadPassword();

            Mp.Prompt("\n\nChecking connection details...\n\n");
            // Check the credentials
            try
            {
                CrmConnection connection = CrmConnection.Parse(
                    "Url=" + Url + "; Domain=" + Domain + "; Username="******"; Password="******"The connection details supplied are not valid. Please enter the correct credentials");
                return(GetCrmConnection());
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            MessagePrompter mp = new MessagePrompter();

            // Get the connection to CRM
            var cv  = new CredentialsValidator(mp);
            var Crm = cv.GetCrmConnectionFromString(ConfigurationManager.ConnectionStrings["EverestOrg"].ConnectionString);

            // Enable debugging trace errors
            if (false)
            {
                Trace.Listeners.Add(new ConsoleTraceListener()
                {
                    Name = "debug"
                });
            }


            // Get the list of entities from CRM and their attributes
            var entityGetter = new EntityMetadataGetter(Crm);

            mp.Prompt("Getting the list of entities from CRM");

            #region Identify which entity to analyse
            var entityName = GetSelectedEntity(entityGetter
                                               .Entities
                                               .OrderBy(x => x.LogicalName)
                                               .Select(x => x.LocalizedName)
                                               .ToList());

            mp.Prompt("You have selected \"{0}\"", entityName);
            #endregion

            // Get the selected entity object
            var selectedEntities = new List <EntityMeta>();
            if (entityName == "ALL")
            {
                selectedEntities = entityGetter.Entities.ToList();
            }
            else
            {
                selectedEntities = entityGetter.Entities.Where(x => x.LocalizedName == entityName).ToList();
            }

            #region Export the Solution from CRM
            //mp.Prompt("Exporting the solution from CRM");

            //var solManager = new SolutionManager(
            //    Crm,
            //    selectedEntities.ToDictionary(x => x.EntityId, x => x.LogicalName.ToLower()));
            //byte[] exportXml = solManager.ExportSolution();

            //var exportPath = @"C:\temp\EntityAttributeComparerSolution.zip";
            //File.WriteAllBytes(exportPath, exportXml);

            //mp.Prompt("Solution exported to {0}.", exportPath);
            #endregion


            #region Extract the customizations.xml from the solution archive
            var zipPath     = @"C:\temp\EntityAttributeComparerSolution.zip";
            var extractPath = @"C:\temp\EntityAttributeComparerSolution";

            ExtractCustomizationsFile(zipPath, extractPath);
            #endregion


            #region Get the labels of the attributes
            //mp.Prompt("Parsing the customizations.xml to gather the attribute labels...");

            var customizationsPath = @"C:\temp\EntityAttributeComparerSolution\customizations.xml";
            var custXmlParser      = new CustomizationsXmlParser(customizationsPath, selectedEntities);
            custXmlParser.GetLabels();

            //mp.Prompt("Parsing complete.");
            #endregion


            ChooseNextAction(mp, extractPath, selectedEntities);
        }