public MissingComponent[] GetMissingComponentsOnTarget(
            string solutionFilePath)
        {
            Logger.LogInformation("Retrieving Missing Components for  Solution: {0}", solutionFilePath);

            if (!File.Exists(solutionFilePath))
            {
                Logger.LogError("Solution File does not exist: {0}", solutionFilePath);
                throw new FileNotFoundException("Solution File does not exist", solutionFilePath);
            }

            SolutionXml solutionXml = new SolutionXml(Logger);

            XrmSolutionInfo info = solutionXml.GetSolutionInfoFromZip(solutionFilePath);

            if (info == null)
            {
                throw new Exception("Invalid Solution File");
            }
            else
            {
                Logger.LogInformation("Solution Unique Name: {0}, Version: {1}",
                                      info.UniqueName,
                                      info.Version);
            }

            byte[] solutionBytes = File.ReadAllBytes(solutionFilePath);

            var request = new RetrieveMissingComponentsRequest()
            {
                CustomizationFile = solutionBytes
            };

            RetrieveMissingComponentsResponse response = OrganizationService.Execute(request) as RetrieveMissingComponentsResponse;

            Logger.LogInformation("{0} Missing Components retrieved for Solution", response.MissingComponents.Length);

            return(response.MissingComponents);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Output missing components to CSV file in user designated location and to in App grid
        /// </summary>
        /// <param name="ExportedSolution"></param>
        /// <returns> String signifiying if missing components were found or not </returns>
        public string ShowMissingComponents(byte[] ExportedSolution)
        {
            const int GRIDWIDTH_DEFAULT = 1660;

            try
            {
                RetrieveMissingComponentsRequest GetMissingComponents_Request = new RetrieveMissingComponentsRequest
                {
                    CustomizationFile = ExportedSolution
                };

                RetrieveMissingComponentsResponse GetMissingComponents = (RetrieveMissingComponentsResponse)base.Service.Execute(GetMissingComponents_Request);

                if (GetMissingComponents.MissingComponents.Count() == 0)
                {
                    panel1.Visible = false;
                    return("No Missing Components");
                }

                // create data table to dispaly missing component information in app
                gridDataSet = new DataSet("gridDataSet");
                DataTable  tComp      = new DataTable("Components");
                DataColumn cDType     = new DataColumn("Dependent Component Type", typeof(string));
                DataColumn cDDisplay  = new DataColumn("Dependent Component Display Name", typeof(string));
                DataColumn cDSchema   = new DataColumn("Dependent Component Schema Name", typeof(string));
                DataColumn cRPDisplay = new DataColumn("Required Component Parent Name", typeof(string));
                DataColumn cRPSchema  = new DataColumn("Required Component Parent Schema Name", typeof(string));
                DataColumn cRType     = new DataColumn("Required Component Type", typeof(string));
                DataColumn cRDisplay  = new DataColumn("Required Component Display Name", typeof(string));
                DataColumn cRSchema   = new DataColumn("Required Component Schema Name", typeof(string));
                tComp.Columns.Add(cDType);
                tComp.Columns.Add(cDDisplay);
                tComp.Columns.Add(cDSchema);
                tComp.Columns.Add(cRPDisplay);
                tComp.Columns.Add(cRPSchema);
                tComp.Columns.Add(cRType);
                tComp.Columns.Add(cRDisplay);
                tComp.Columns.Add(cRSchema);
                gridDataSet.Tables.Add(tComp);

                // Create csv string builder
                var csv = new StringBuilder();

                // Set headers on file
                csv.AppendLine(string.Format("{0},{1},{2},{3},{4},{5},{6},{7}",
                                             "Dependent Component Type",
                                             "Dependent Component Display Name",
                                             "Dependent Component Schema Name",
                                             "Dependent Component ID",
                                             "Required Component Type",
                                             "Required Component Display Name",
                                             "Required Component Schema Name",
                                             "Required Component ID"
                                             ));

                // loop
                foreach (MissingComponent MissingComponent in GetMissingComponents.MissingComponents)
                {
                    // Add new row to table
                    DataRow newRow;
                    newRow = tComp.NewRow();
                    newRow["Dependent Component Type"]              = (TypeIcon_Dictionary.ContainsKey(MissingComponent.DependentComponent.Type) ? TypeIcon_Dictionary[MissingComponent.DependentComponent.Type] : "Type Code: " + MissingComponent.DependentComponent.Type.ToString());
                    newRow["Dependent Component Display Name"]      = MissingComponent.DependentComponent.DisplayName;
                    newRow["Dependent Component Schema Name"]       = MissingComponent.DependentComponent.SchemaName;
                    newRow["Required Component Parent Name"]        = MissingComponent.RequiredComponent.ParentDisplayName;
                    newRow["Required Component Parent Schema Name"] = MissingComponent.RequiredComponent.ParentSchemaName;
                    newRow["Required Component Type"]         = (TypeIcon_Dictionary.ContainsKey(MissingComponent.RequiredComponent.Type) ? TypeIcon_Dictionary[MissingComponent.RequiredComponent.Type] : "Type Code: " + MissingComponent.RequiredComponent.Type.ToString());
                    newRow["Required Component Display Name"] = MissingComponent.RequiredComponent.DisplayName;
                    newRow["Required Component Schema Name"]  = MissingComponent.RequiredComponent.SchemaName;
                    tComp.Rows.Add(newRow);

                    csv.AppendLine(string.Format("{0},{1},{2},{3},{4},{5},{6},{7}",
                                                 $"{(TypeIcon_Dictionary.ContainsKey(MissingComponent.DependentComponent.Type) ? TypeIcon_Dictionary[MissingComponent.DependentComponent.Type] : "Type Code: " + MissingComponent.DependentComponent.Type.ToString())}",
                                                 $"{MissingComponent.DependentComponent.DisplayName}",
                                                 $"{MissingComponent.DependentComponent.SchemaName}",
                                                 $"{MissingComponent.DependentComponent.Id}",
                                                 $"{(TypeIcon_Dictionary.ContainsKey(MissingComponent.RequiredComponent.Type) ? TypeIcon_Dictionary[MissingComponent.RequiredComponent.Type] : "Type Code: " + MissingComponent.RequiredComponent.Type.ToString())}",
                                                 $"{MissingComponent.RequiredComponent.DisplayName}",
                                                 $"{MissingComponent.RequiredComponent.SchemaName}",
                                                 $"{MissingComponent.RequiredComponent.Id}"
                                                 ));
                }

                // write csv file
                File.WriteAllText($@"{txt_OutputPath.Text}\dependencies.csv", csv.ToString());

                SolutionComponents_DataGrid.SetDataBinding(gridDataSet, "Components");

                if (panel1.Visible != true)
                {
                    this.Height = this.Height + panel1.Height;
                }

                int gridWidth = GRIDWIDTH_DEFAULT;

                // remove Dependent Component columns if unwanted
                if (checkBox1.Checked == false)
                {
                    tComp.Columns.Remove("Dependent Component Type");
                    tComp.Columns.Remove("Dependent Component Display Name");
                    tComp.Columns.Remove("Dependent Component Schema Name");
                    gridWidth -= 600;
                }

                // remove Dependent Component columns if unwanted
                if (checkBox2.Checked == false)
                {
                    tComp.Columns.Remove("Required Component Parent Name");
                    tComp.Columns.Remove("Required Component Parent Schema Name");
                    gridWidth -= 400;
                }
                SolutionComponents_DataGrid.Size = new Size(gridWidth, 500);

                panel1.Visible = true;

                return("Succeeded");
            }
            catch (Exception error)
            {
                return(error.ToString());
            }
        }