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() { WriteObject("Transform File(s): " + string.Join("; ", TransformFiles)); WriteObject("Input Data Path: " + InputDataPath); var crmParameter = new CrmParameter(ConnectionString) { ExportDirectoryName = InputDataPath }; ExecuteImportData(crmParameter, crmParameter.GetSourceDataDirectory(), TransformFiles); if (PublishAllCustomizations) { /* some reference data needs the solution to be published for the changes to be applied * eg systemforms enitity */ PublishSolutions(crmParameter); } }
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}"); }
/// <summary> /// Creates a SqlParameter given a name, type, and direction /// </summary> internal static CrmParameter CreateParameter(string name, TypeUsage type, ParameterMode mode, object value) { // int? size; value = EnsureParameterValue(value); CrmParameter result = new CrmParameter(name, value); throw new NotImplementedException(); //// .Direction //result.Direction = MetadataHelpers.ParameterModeToParameterDirection(mode); //// .Size and .SqlDbType //// output parameters are handled differently (we need to ensure there is space for return //// values where the user has not given a specific Size/MaxLength) //bool isOutParam = mode != ParameterMode.In; //string udtTypeName; //result.DbType = GetSqlDbType(type, isOutParam, out size, out udtTypeName); //result.UdtTypeName = udtTypeName; //// Note that we overwrite 'facet' parameters where either the value is different or //// there is an output parameter. //if (size.HasValue && (isOutParam || result.Size != size.Value)) //{ // result.Size = size.Value; //} //// .IsNullable //bool isNullable = MetadataHelpers.IsNullable(type); //if (isOutParam || isNullable != result.IsNullable) //{ // result.IsNullable = isNullable; //} //return result; }
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); } } }