private string GetSolutionFilename(SolutionBlock block) { container.StartSection("GetSolutionFilename"); var file = block.File; if (string.IsNullOrWhiteSpace(file)) { file = block.Name; } var path = block.Path; if (string.IsNullOrWhiteSpace(path) && !string.IsNullOrWhiteSpace(definitionpath)) { path = definitionpath; } path += path.EndsWith("\\") ? "" : "\\"; string filename; if (block.Import.Type == SolutionTypes.Managed) { filename = path + file + "_managed.zip"; } else if (block.Import.Type == SolutionTypes.Unmanaged) { filename = path + file + ".zip"; } else { throw new ArgumentOutOfRangeException("Type", block.Import.Type, "Invalid Solution type"); } if (filename.Contains("%")) { var envvars = Environment.GetEnvironmentVariables(); foreach (DictionaryEntry de in envvars) { filename = filename.Replace("%" + de.Key.ToString() + "%", de.Value.ToString()); } } container.Log("Filename: {0}", filename); container.EndSection(); return(filename); }
private static string GetSolutionFilename(SolutionBlock solBlock, string definitionpath) { string file = solBlock.File; if (string.IsNullOrWhiteSpace(file)) { file = solBlock.Name; } string path = solBlock.Path; if (string.IsNullOrWhiteSpace(path) && !string.IsNullOrWhiteSpace(definitionpath)) { path = definitionpath; } path += path.EndsWith("\\") ? "" : "\\"; string filename; if (solBlock.Import.Type == SolutionTypes.Managed) { filename = path + file + "_managed.zip"; } else if (solBlock.Import.Type == SolutionTypes.Unmanaged) { filename = path + file + ".zip"; } else { throw new ArgumentOutOfRangeException("Type", solBlock.Import.Type, "Invalid Solution type"); } if (filename.Contains("%")) { IDictionary envvars = Environment.GetEnvironmentVariables(); foreach (DictionaryEntry de in envvars) { filename = filename.Replace("%" + de.Key.ToString() + "%", de.Value.ToString()); } } return(filename); }
private ItemImportResult ImportSolutionBlock(SolutionBlock block) { container.StartSection("ImportSolutionBlock"); var importResult = ItemImportResult.None; if (block.Import != null) { var name = block.Name; container.Log("Block: {0}", name); SendStatus(name, null); SendLine(container, "Importing solution: {0}", name); var filename = GetSolutionFilename(block); var version = ExtractVersionFromSolutionZip(filename); try { ValidatePreReqs(container, block.Import, version); var ImportCondition = CheckIfImportRequired(container, block.Import, name, version); if (ImportCondition != SolutionImportConditions.Skip) { if (DoImportSolution(block.Import, filename, version)) { if (ImportCondition == SolutionImportConditions.Create) { importResult = ItemImportResult.Created; } else { importResult = ItemImportResult.Updated; } } else { importResult = ItemImportResult.Failed; container.Log("Failed during import"); } var publish = block.Import.PublishAll; if (publish) { SendLine(container, "Publishing customizations"); container.Execute(new PublishAllXmlRequest()); } } else { importResult = ItemImportResult.Skipped; container.Log("Skipped due to import condition"); } } catch (Exception ex) { container.Log(ex); importResult = ItemImportResult.Failed; if (stoponerror) { throw; } } } container.EndSection(); return(importResult); }
private void ExportSolutionBlock(SolutionBlock block) { log.StartSection("ExportSolutionBlock"); var name = block.Name; log.Log("Block: {0}", name); var path = block.Path; var file = block.File; if (string.IsNullOrWhiteSpace(path) && !string.IsNullOrWhiteSpace(definitionpath)) { path = definitionpath; path += path.EndsWith("\\") ? "" : "\\"; } if (string.IsNullOrWhiteSpace(file)) { file = name; } if (block.Export != null) { var type = block.Export.Type; var setversion = block.Export.SetVersion; var publish = block.Export.PublishBeforeExport; var targetversion = block.Export.TargetVersion; var cdSolution = GetAndVerifySolutionForExport(name); var currentversion = new Version(cdSolution.Property("version", "1.0.0.0")); SendLine("Solution: {0} {1}", name, currentversion); if (!string.IsNullOrWhiteSpace(setversion)) { SetNewSolutionVersion(setversion, cdSolution, currentversion); } if (publish) { SendLine("Publishing customizations"); crmsvc.Execute(new PublishAllXmlRequest()); } var req = new ExportSolutionRequest() { SolutionName = name }; #if Crm8 if (!string.IsNullOrWhiteSpace(targetversion)) { req.TargetVersion = targetversion; } #endif if (block.Export.Settings != null) { req.ExportAutoNumberingSettings = block.Export.Settings.AutoNumbering; req.ExportCalendarSettings = block.Export.Settings.Calendar; req.ExportCustomizationSettings = block.Export.Settings.Customization; req.ExportEmailTrackingSettings = block.Export.Settings.EmailTracking; req.ExportGeneralSettings = block.Export.Settings.General; req.ExportMarketingSettings = block.Export.Settings.Marketing; req.ExportOutlookSynchronizationSettings = block.Export.Settings.OutlookSync; req.ExportRelationshipRoles = block.Export.Settings.RelationshipRoles; req.ExportIsvConfig = block.Export.Settings.IsvConfig; } if (type == SolutionTypes.Managed || type == SolutionTypes.Both) { var filename = path + file + "_managed.zip"; SendLine("Exporting solution to: {0}", filename); req.Managed = true; var exportSolutionResponse = (ExportSolutionResponse)crmsvc.Execute(req); var exportXml = exportSolutionResponse.ExportSolutionFile; File.WriteAllBytes(filename, exportXml); } if (type == SolutionTypes.Unmanaged || type == SolutionTypes.Both) { var filename = path + file + ".zip"; SendLine("Exporting solution to: {0}", filename); req.Managed = false; var exportSolutionResponse = (ExportSolutionResponse)crmsvc.Execute(req); var exportXml = exportSolutionResponse.ExportSolutionFile; File.WriteAllBytes(filename, exportXml); } } log.EndSection(); }