private int SortResourcesExecute(BizTalkResource root, int order)
        {
            order = root.Dependencies.Select(name => this.Resources.Find(r => r.FullName == name)).Where(dependency => dependency != null).Where(dependency => !dependency.IsProcessed).Aggregate(order, (current, dependency) => this.SortResourcesExecute(dependency, current));

            root.IsProcessed = true;
            root.Order       = order;
            return(++order);
        }
        private void AddAssembly(BizTalkResource resource)
        {
            if (!System.IO.File.Exists(resource.SourcePath))
            {
                throw new Exception(string.Format(CultureInfo.CurrentCulture, "The AssemblyPath was not found: {0}", resource.SourcePath));
            }

            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "GAC Assembly: {0} on: {1}", resource.DeploymentPath, this.MachineName));
            if (string.Compare(this.MachineName, Environment.MachineName, StringComparison.OrdinalIgnoreCase) == 0)
            {
                this.Install(resource.SourcePath, this.Force);
            }
            else
            {
                if (string.IsNullOrEmpty(resource.DeploymentPath))
                {
                    throw new Exception("DeploymentPath is required for remote deployment");
                }

                // the assembly needs to be copied to the remote server for gaccing.
                if (System.IO.File.Exists(resource.DeploymentPath))
                {
                    this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "Deleting old remote Assembly: {0}", resource.DeploymentPath));
                    System.IO.File.Delete(resource.DeploymentPath);
                }

                this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "Copying Assembly from: {0} to: {1}", resource.SourcePath, resource.DeploymentPath));
                System.IO.File.Copy(resource.SourcePath, resource.DeploymentPath);
                this.GetManagementScope(@"\root\cimv2");
                using (ManagementClass m = new ManagementClass(this.Scope, new ManagementPath("Win32_Process"), new ObjectGetOptions(null, System.TimeSpan.MaxValue, true)))
                {
                    ManagementBaseObject methodParameters = m.GetMethodParameters("Create");
                    methodParameters["CommandLine"] = @"gacutil.exe /i " + resource.DeploymentPath;
                    ManagementBaseObject outParams = m.InvokeMethod("Create", methodParameters, null);

                    if (outParams != null)
                    {
                        if (int.Parse(outParams["returnValue"].ToString(), CultureInfo.InvariantCulture) != 0)
                        {
                            this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Remote AddAssembly returned non-zero returnValue: {0}", outParams["returnValue"]));
                            return;
                        }

                        this.LogTaskMessage(MessageImportance.Low, "Process ReturnValue: " + outParams["returnValue"]);
                        this.LogTaskMessage(MessageImportance.Low, "Process ID: " + outParams["processId"]);
                    }
                    else
                    {
                        this.Log.LogError("Remote Create returned null");
                        return;
                    }
                }
            }
        }
        private int SortResourcesExecute(BizTalkResource root, int order)
        {
            order = root.Dependencies.Select(name => this.Resources.Find(r => r.FullName == name)).Where(dependency => dependency != null).Where(dependency => !dependency.IsProcessed).Aggregate(order, (current, dependency) => this.SortResourcesExecute(dependency, current));

            root.IsProcessed = true;
            root.Order = order;
            return ++order;
        }
        private void AddAssembly(BizTalkResource resource)
        {
            if (!System.IO.File.Exists(resource.SourcePath))
            {
                throw new Exception(string.Format(CultureInfo.CurrentCulture, "The AssemblyPath was not found: {0}", resource.SourcePath));
            }

            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "GAC Assembly: {0} on: {1}", resource.DeploymentPath, this.MachineName));
            if (string.Compare(this.MachineName, Environment.MachineName, StringComparison.OrdinalIgnoreCase) == 0)
            {
                this.Install(resource.SourcePath, this.Force);
            }
            else
            {
                if (string.IsNullOrEmpty(resource.DeploymentPath))
                {
                    throw new Exception("DeploymentPath is required for remote deployment");
                }

                // the assembly needs to be copied to the remote server for gaccing.
                if (System.IO.File.Exists(resource.DeploymentPath))
                {
                    this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "Deleting old remote Assembly: {0}", resource.DeploymentPath));
                    System.IO.File.Delete(resource.DeploymentPath);
                }

                this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "Copying Assembly from: {0} to: {1}", resource.SourcePath, resource.DeploymentPath));
                System.IO.File.Copy(resource.SourcePath, resource.DeploymentPath);
                this.GetManagementScope(@"\root\cimv2");
                using (ManagementClass m = new ManagementClass(this.Scope, new ManagementPath("Win32_Process"), new ObjectGetOptions(null, System.TimeSpan.MaxValue, true)))
                {
                    ManagementBaseObject methodParameters = m.GetMethodParameters("Create");
                    methodParameters["CommandLine"] = @"gacutil.exe /i " + resource.DeploymentPath;
                    ManagementBaseObject outParams = m.InvokeMethod("Create", methodParameters, null);

                    if (outParams != null)
                    {
                        if (int.Parse(outParams["returnValue"].ToString(), CultureInfo.InvariantCulture) != 0)
                        {
                            this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Remote AddAssembly returned non-zero returnValue: {0}", outParams["returnValue"]));
                            return;
                        }

                        this.LogTaskMessage(MessageImportance.Low, "Process ReturnValue: " + outParams["returnValue"]);
                        this.LogTaskMessage(MessageImportance.Low, "Process ID: " + outParams["processId"]);
                    }
                    else
                    {
                        this.Log.LogError("Remote Create returned null");
                    }
                }
            }
        }