protected void PublishSolutions(CrmParameter crmParameter) { var solutionTool = new SolutionTool(crmParameter); var stopwatch = Stopwatch.StartNew(); WriteObject($"Publishing "); /* publish solution */ var publishTask = solutionTool.PublishAsync(); while (!publishTask.IsCompleted) { WriteVerbose("."); Thread.Sleep(3000); } var elapsed = $"{stopwatch.Elapsed.Minutes}min {stopwatch.Elapsed.Seconds}s"; WriteObject($"Done... [{elapsed}]{Environment.NewLine}"); }
protected override void ProcessRecord() { MessageQueue = new ConcurrentQueue <string>(); try { var crmParameter = new CrmParameter(ConnectionString) { ConnectionTimeOutMinutes = ConnectionTimeOutMinutes }; SolutionDir = SolutionDir + @"\"; crmParameter.ExecutionDirectory = SolutionDir; /* Connect to Dynamics */ WriteObject($"Connecting ({crmParameter.GetConnectionStringObfuscated()})"); SolutionTool solutionTool = null; var stopwatch = Stopwatch.StartNew(); var taskInstantiateSolution = Task.Run(() => solutionTool = new SolutionTool(crmParameter)); while (!taskInstantiateSolution.IsCompleted) { WriteVerbose("."); Thread.Sleep(2000); } solutionTool.MessageLogger += ReceiveMessage; var elapsed = $"{stopwatch.Elapsed.Minutes}min {stopwatch.Elapsed.Seconds}s"; WriteObject($"Done... [{elapsed}]{Environment.NewLine}"); /* Import Solutions */ var solutionNames = SolutionName.Split(';'); foreach (var sol in solutionNames) { stopwatch = Stopwatch.StartNew(); var fileName = SolutionDir + sol + (Managed ? "_managed" : "") + ".zip"; WriteObject($"Uploading '{sol.ToUpper()}' solution "); var solutionBinaryTask = solutionTool.ImportSolutionAsync(fileName); while (!solutionBinaryTask.IsCompleted) { WriteVerbose("."); Thread.Sleep(3000); /* check if any messages from the solution import thread * have been passed back */ while (true) { if (MessageQueue.Count == 0) { break; // exit while } var MessageFound = MessageQueue.TryDequeue(out string message); if (MessageFound) { WriteObject(message); } } } if (solutionBinaryTask.IsFaulted) { foreach (var innerException in solutionBinaryTask.Exception.InnerExceptions) { WriteObject($"ERROR - {innerException.Message}"); throw new Exception(); } } elapsed = $"{stopwatch.Elapsed.Minutes}min {stopwatch.Elapsed.Seconds}s"; WriteObject($"Done... [{elapsed}]{Environment.NewLine}"); stopwatch = Stopwatch.StartNew(); WriteObject($"Publishing "); /* publish solution */ var publishTask = solutionTool.PublishAsync(); while (!publishTask.IsCompleted) { WriteVerbose("."); Thread.Sleep(3000); } elapsed = $"{stopwatch.Elapsed.Minutes}min {stopwatch.Elapsed.Seconds}s"; WriteObject($"Done... [{elapsed}]{Environment.NewLine}"); } } catch (Exception ex) { var errorRecord = new ErrorRecord(new Exception($"Solution Import Failed: {ex.Message}", ex.InnerException), "", ErrorCategory.InvalidResult, null); ThrowTerminatingError(errorRecord); } }
protected override void ProcessRecord() { try { var crmParameter = new CrmParameter(ConnectionString) { ConnectionTimeOutMinutes = ConnectionTimeOutMinutes }; SolutionDir = SolutionDir + @"\"; crmParameter.ExecutionDirectory = SolutionDir; /* Connect to Dynamics */ WriteObject($"Connecting ({crmParameter.GetConnectionStringObfuscated()})"); SolutionTool solutionTool = null; solutionTool = new SolutionTool(crmParameter); var stopwatch = Stopwatch.StartNew(); var taskInstantiateSolution = Task.Run(() => solutionTool = new SolutionTool(crmParameter)); while (!taskInstantiateSolution.IsCompleted) { WriteVerbose("."); Thread.Sleep(2000); } if (taskInstantiateSolution.IsFaulted) { foreach (var innerException in taskInstantiateSolution.Exception.InnerExceptions) { WriteObject($"ERROR - {innerException.Message}"); } return; } var elapsed = $"{stopwatch.Elapsed.Minutes}min {stopwatch.Elapsed.Seconds}s"; WriteObject($"Done... [{elapsed}]{Environment.NewLine}"); /* Export Solutions */ if (!Directory.Exists(SolutionDir)) { Directory.CreateDirectory(SolutionDir); } var solutionNames = SolutionName.Split(';'); foreach (var sol in solutionNames) { stopwatch = Stopwatch.StartNew(); var fileName = SolutionDir + sol + (Managed ? "_managed" : "") + ".zip"; WriteObject($"Downloading '{sol.ToUpper()}' solution "); var solutionBinaryTask = solutionTool.ExportSolutionAsync(sol, Managed); while (!solutionBinaryTask.IsCompleted) { WriteVerbose("."); Thread.Sleep(3000); } if (solutionBinaryTask.IsFaulted) { foreach (var innerException in solutionBinaryTask.Exception.InnerExceptions) { WriteObject($"ERROR - {innerException.Message}"); } } else { WriteObject($"Saving file {fileName.ToUpper()} "); elapsed = $"{stopwatch.Elapsed.Minutes}min {stopwatch.Elapsed.Seconds}s"; File.WriteAllBytes(fileName, solutionBinaryTask.Result); WriteObject($"Done... [{elapsed}]{Environment.NewLine}"); if (crmParameter.ExtractSolutionContent) { var folderToUnzip = solutionTool.ExtractSolution(fileName, crmParameter.ExecutionDirectory, null); WriteObject($"Solution is extracted to {folderToUnzip}"); } } } } catch (Exception ex) { WriteObject(ex.Message); WriteObject(ex.StackTrace); if (ex.InnerException != null) { WriteObject(ex.InnerException.Message); WriteObject(ex.InnerException.StackTrace); } } }