protected override void ProcessRecord() { var crmParameter = new CrmParameter(ConnectionString) { ConnectionTimeOutMinutes = ConnectionTimeOutMinutes }; WriteObject($"Connecting ({crmParameter.GetConnectionStringObfuscated()}){Environment.NewLine}"); var recordManager = new RecordManager(crmParameter); recordManager.Logger += ReceiveMessage; try { if (SetEnabled) { recordManager.SetStatus(TargetRecordsFetchXML, RecordManager.RecordStatus.Enable); } else { recordManager.SetStatus(TargetRecordsFetchXML, RecordManager.RecordStatus.Disable); } } catch (Exception ex) { WriteError(new ErrorRecord(ex, "Error setting record status", ErrorCategory.InvalidOperation, TargetRecordsFetchXML)); } }
protected override void ProcessRecord() { var crmParameter = new CrmParameter(ConnectionString) { ConnectionTimeOutMinutes = ConnectionTimeOutMinutes }; WriteObject($"Connecting ({crmParameter.GetConnectionStringObfuscated()}){Environment.NewLine}"); var plugin = new PluginManager(crmParameter); plugin.Logger += ReceiveMessage; try { if (setEnabled) { plugin.SetStatus(PluginStepNames, PluginManager.PluginStatus.Enable); } else { plugin.SetStatus(PluginStepNames, PluginManager.PluginStatus.Disable); } } catch (Exception ex) { WriteError(new ErrorRecord(ex, "Error setting pugin status", ErrorCategory.InvalidOperation, PluginStepNames)); } }
protected override void ProcessRecord() { WriteObject(""); WriteObject($"FetchXML File: {FetchXmlFile}"); WriteObject($"Output Data Path: {OutputDataPath}{Environment.NewLine}"); var crmParameter = new CrmParameter(ConnectionString) { ExportDirectoryName = OutputDataPath }; var attributesToExcludeArray = AttributesToExclude?.Split(';'); string dataDir = crmParameter.GetSourceDataDirectory(); FetchXmlFile = (string.IsNullOrWhiteSpace(FetchXmlFile) || FetchXmlFile == "NULL" ? @"Veritec.Dynamics.DataMigrate.FetchQuery.xml" : FetchXmlFile); WriteObject($"Connecting ({crmParameter.GetConnectionStringObfuscated()})"); var dataExport = new DataExport(crmParameter, FetchXmlFile); WriteObject($"Fetch queries loaded {Environment.NewLine}"); foreach (var fetchXml in dataExport.FetchXmlQueries) { WriteObject($"Executing Fetch Query: {fetchXml.Key}..."); var queryResultXml = dataExport.ExecuteFetchXmlQuery(fetchXml.Key, fetchXml.Value, attributesToExcludeArray); WriteObject($"Writing Results: {dataDir}{fetchXml.Key}.xml {Environment.NewLine}"); DataExport.SaveFetchXmlQueryResulttoDisk(dataDir, fetchXml.Key, queryResultXml.ToString()); } }
protected override void ProcessRecord() { var crmParameter = new CrmParameter(ConnectionString) { ConnectionTimeOutMinutes = ConnectionTimeOutMinutes }; WriteObject($"Connecting ({crmParameter.GetConnectionStringObfuscated()}){Environment.NewLine}"); var autoNumber = new AutoNumber(crmParameter); try { var recordCount = autoNumber.TargetEntityRowCount(EntityName, AttributeName); if (Force == true || recordCount == 0) { /* only do this if the user forces it or there are no records in the target */ autoNumber.SetSeed(EntityName, AttributeName, Value, Force); WriteObject($"Autonumber has been set to {Value}"); } else { WriteObject($"No action required to set the autonumber seed for {EntityName} because {recordCount} record(s) already exist."); } } catch (Exception ex) { WriteError(new ErrorRecord(ex, "Error setting autonumber", ErrorCategory.InvalidOperation, AttributeName)); } }
protected virtual void ExecuteImportData(CrmParameter crmParameter, string dataDir, string[] transformFileNames) { WriteObject($"Connecting ({crmParameter.GetConnectionStringObfuscated()})"); var dataImport = new DataImport(crmParameter, transformFileNames); dataImport.Logger += Feedback_Received; WriteObject("Reading FetchXML data from disk"); dataImport.ReadFetchXmlQueryResultsFromDiskAndImport(dataDir, null); }
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); } } }