/// <summary> /// Method checks dependency components present in target instance /// </summary> /// <param name="serviceProxy">service proxy</param> /// <param name="dependencyComponents">dependency components</param> /// <param name="solutionManager">solution manager</param> /// <param name="checkTarget">check target</param> /// <param name="sourceServiceProxy">source service proxy</param> /// <returns>returns boolean value</returns> private bool CheckDependency(OrganizationServiceProxy serviceProxy, EntityCollection dependencyComponents, SolutionManager solutionManager, bool checkTarget, OrganizationServiceProxy sourceServiceProxy) { foreach (Entity component in dependencyComponents.Entities) { try { solutionManager.GetComponentDetails(null, null, component, ((OptionSetValue)component.Attributes["requiredcomponenttype"]).Value, (Guid)component.Attributes["requiredcomponentobjectid"], "requiredcomponenttype", serviceProxy); } catch (Exception ex) { Console.WriteLine(ex.Message); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<tr>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<td style='width:100px;background-color:tomato;border: 1px solid #ccc'>"); Console.WriteLine("The below component was not present in Target"); solutionManager.GetComponentDetails(null, null, component, ((OptionSetValue)component.Attributes["dependentcomponenttype"]).Value, (Guid)component.Attributes["dependentcomponentobjectid"], "dependentcomponenttype", null); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</td>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<td style='width:100px;background-color:tomato;border: 1px solid #ccc'>"); solutionManager.GetComponentDetails(null, null, component, ((OptionSetValue)component.Attributes["requiredcomponenttype"]).Value, (Guid)component.Attributes["requiredcomponentobjectid"], "requiredcomponenttype", null); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</td>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</tr>"); checkTarget = true; } } return(checkTarget); }
/// <summary> /// Method gets deployment instance record /// </summary> /// <param name="serviceProxy">organization service proxy</param> /// <param name="solutionFile">solution file info</param> private void ImportSolutionToTargetInstance(OrganizationServiceProxy serviceProxy, SolutionFileInfo solutionFile) { Entity sourceControl = solutionFile.Solution; EntityCollection deploymentInstance = this.FetchDeplopymentInstance(serviceProxy, sourceControl.Id); var checkTarget = false; if (deploymentInstance.Entities.Count > 0) { foreach (Entity instance in deploymentInstance.Entities) { ClientCredentials clientCredentials = new ClientCredentials(); clientCredentials.UserName.UserName = instance.Attributes["syed_name"].ToString(); clientCredentials.UserName.Password = this.DecryptString(instance.Attributes["syed_password"].ToString()); ////Resetting password instance.Attributes["syed_password"] = "******"; serviceProxy.Update(instance); OrganizationServiceProxy targetserviceProxy = new OrganizationServiceProxy(new Uri(instance.Attributes["syed_instanceurl"].ToString()), null, clientCredentials, null); targetserviceProxy.EnableProxyTypes(); List <EntityCollection> componentDependency = this.GetDependentComponents(serviceProxy, new Guid(solutionFile.MasterSolutionId), solutionFile.SolutionUniqueName); SolutionManager sol = new SolutionManager(serviceProxy); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<br><br><table cellpadding='5' cellspacing='0' style='border: 1px solid #ccc;font-size: 9pt;font-family:Arial'><tr><th style='background-color: #B8DBFD;border: 1px solid #ccc'>Dependent Components in Source Instance</th><th style='background-color: #B8DBFD;border: 1px solid #ccc'>Required Components</th></tr>"); if (componentDependency.Count > 0) { foreach (var comDependency in componentDependency) { if (comDependency != null && comDependency.Entities != null && comDependency.Entities.Count > 0) { foreach (Entity dependency in comDependency.Entities) { Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<tr>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<td style='width:100px;background-color:#FFCC99;border: 1px solid #ccc'>"); sol.GetComponentDetails(null, null, dependency, ((OptionSetValue)dependency.Attributes["dependentcomponenttype"]).Value, (Guid)dependency.Attributes["dependentcomponentobjectid"], "dependentcomponenttype", null); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</td>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<td style='width:100px;background-color:#FFCC99;border: 1px solid #ccc'>"); sol.GetComponentDetails(null, null, dependency, ((OptionSetValue)dependency.Attributes["requiredcomponenttype"]).Value, (Guid)dependency.Attributes["requiredcomponentobjectid"], "requiredcomponenttype", null); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</td>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</tr>"); } } } } else { Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<tr>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<td style='width:100px;background-color:#FFCC99;border: 1px solid #ccc'>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("There is no missing dependent component to display"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</td>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<td style='width:100px;background-color:#FFCC99;border: 1px solid #ccc'>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("----"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</td>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</tr>"); } Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</table><br><br>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<table cellpadding='5' cellspacing='0' style='border: 1px solid #ccc;font-size: 9pt;font-family:Arial'><tr><th style='background-color: #B8DBFD;border: 1px solid #ccc'> Missing Dependent Components in Target Instance</th><th style='background-color: #B8DBFD;border: 1px solid #ccc'>Components Details</th></tr>"); if (componentDependency.Count > 0) { foreach (var comDependency in componentDependency) { checkTarget = this.CheckDependency(targetserviceProxy, comDependency, sol, checkTarget, serviceProxy); } } if (!checkTarget) { Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<tr>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<td style='width:100px;background-color:tomato;border: 1px solid #ccc'>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("All dependent components are present in target instance"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</td>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<td style='width:100px;background-color:tomato;border: 1px solid #ccc'>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("----"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</td>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</tr>"); Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</table><br><br>"); this.ImportSolution(targetserviceProxy, solutionFile, new Uri(instance.Attributes["syed_instanceurl"].ToString())); } else { Singleton.SolutionFileInfoInstance.WebJobsLog.AppendLine(" Target Instance missing Required components. <br> "); solutionFile.Solution[Constants.SourceControlQueueAttributeNameForStatus] = Constants.SourceControlQueueMissingComponents; solutionFile.Solution["syed_webjobs"] = Singleton.SolutionFileInfoInstance.WebJobs(); Singleton.SolutionFileInfoInstance.UploadFiletoDynamics(serviceProxy, solutionFile.Solution); solutionFile.Update(); } } } }