Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import as upgrade #78

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Delegate.Daxif/API/Solution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ type Solution private () =
/// <param name="diffCallingInfo">[Experimental] When specified, a diff import will be performed. Assumes exportdiff has been used prior.</param>
/// <param name="publishAfterImport">Flag whether or not to publish all customizations after solution import. - defaults to: true</param>
/// <param name="reassignWorkflows">Flag whether to reassign workflows based on environment from which the solution was exported. - defaults to: false</param>
/// <param name="upgrade">Flag to import the solution as an upgrade rather than an update. - defaults to: false (update)</param>
/// <param name="timeOut">DataVerse Service Client timeout represented as a TimeSpan. - defaults to: 1 hour</param>
static member Import(env: Environment, pathToSolutionZip, ?activatePluginSteps, ?extended, ?logLevel, ?diffCallingInfo, ?publishAfterImport, ?reassignWorkflows, ?timeOut: System.TimeSpan) =
static member Import(env: Environment, pathToSolutionZip, ?activatePluginSteps, ?extended, ?logLevel, ?diffCallingInfo, ?publishAfterImport, ?reassignWorkflows, ?upgrade, ?timeOut: System.TimeSpan) =
let publishAfterImport = publishAfterImport ?| true
let reassignWorkflows = reassignWorkflows ?| false
let timeOut = timeOut ?| defaultServiceTimeOut

match diffCallingInfo with
| Some dci -> Main.importDiff pathToSolutionZip dci.SolutionName Domain.partialSolutionName env timeOut
| _ -> Main.importStandard env activatePluginSteps extended publishAfterImport reassignWorkflows pathToSolutionZip logLevel timeOut
| _ -> Main.importStandard env activatePluginSteps extended publishAfterImport reassignWorkflows pathToSolutionZip logLevel upgrade timeOut

/// <summary>Exports a solution package from a given environment</summary>
/// <param name="env">Environment the action should be performed against.</param>
Expand Down
43 changes: 33 additions & 10 deletions src/Delegate.Daxif/Modules/Solution/Import.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,34 @@ let createImportRequest zipFile jobId managed =
req.RequestId <- new Nullable<Guid>(Guid.NewGuid())
req

let createStageAndUpgradeAsyncRequest zipFile jobId managed =
let req = new StageAndUpgradeAsyncRequest()
req.CustomizationFile <- zipFile
req.ImportJobId <- jobId
req.ConvertToManaged <- managed
req.OverwriteUnmanagedCustomizations <- true
req.PublishWorkflows <- true
req.RequestId <- new Nullable<Guid>(Guid.NewGuid())
req

let executeImportSync (service: IOrganizationService) (req:ImportSolutionRequest) =
log.Debug @"Execution import request (RequestId: %A)" req.RequestId.Value
log.Debug @"Executing import request (RequestId: %A)" req.RequestId.Value
service.Execute(req) :?> Messages.ImportSolutionResponse |> ignore

let executeImportAsync (service: IOrganizationService) (req:ImportSolutionRequest) =
let areq = new Messages.ExecuteAsyncRequest()
areq.Request <- req
let asyncJobId =
service.Execute(areq) :?> Messages.ExecuteAsyncResponse
service.Execute(areq) :?> Messages.ExecuteAsyncResponse
|> fun r -> r.AsyncJobId
log.Debug @"Execution import request asyncrunously (AsyncJobId: %A, RequestId: %A)" asyncJobId req.RequestId.Value
log.Debug @"Executing import request asynchronously (AsyncJobId: %A, RequestId: %A)" asyncJobId req.RequestId.Value
asyncJobId

let executeUpgradeAsync (service: IOrganizationService) (req:StageAndUpgradeAsyncRequest) =
let asyncJobId =
service.Execute(req) :?> Messages.StageAndUpgradeAsyncResponse
|> fun r -> r.AsyncOperationId
log.Debug @"Executing stageAndUpgrade request asynchronously (AsyncJobId: %A, RequestId: %A)" asyncJobId req.RequestId.Value
asyncJobId

let getImportJobStatus service (jobInfo: ImportJobInfo) =
Expand Down Expand Up @@ -172,25 +189,31 @@ let publish service managed =
CrmDataHelper.publishAll service
log.WriteLine(LogLevel.Verbose, @"The solution was successfully published")

let execute service solution location managed =
let execute service solution location managed upgrade =
log.WriteLine(LogLevel.Info, @"Importing solution")
let zipFile = File.ReadAllBytes(location)
log.WriteLine(LogLevel.Verbose, @"Solution file loaded successfully")

let jobId = Guid.NewGuid()
let req = createImportRequest zipFile jobId managed
let req =
match upgrade with
| false -> createImportRequest zipFile jobId managed :> OrganizationRequest
| true -> createStageAndUpgradeAsyncRequest zipFile jobId managed :> OrganizationRequest

let startImport () =
async {
let asyncJobId =
match CrmDataInternal.Info.version service with
| (_, CrmReleases.CRM2011) ->
executeImportSync service req
log.WriteLine(LogLevel.Verbose,@"Import job Started")
executeImportSync service (req :?> ImportSolutionRequest)
log.WriteLine(LogLevel.Verbose, @"Import job started")
None
| (_, _) ->
let asyncJobId = executeImportAsync service req
log.WriteLine(LogLevel.Verbose,@"Asynchronous import job started")
let asyncJobId =
match upgrade with
| true -> executeUpgradeAsync service (req :?> StageAndUpgradeAsyncRequest)
| false -> executeImportAsync service (req :?> ImportSolutionRequest)
log.WriteLine(LogLevel.Verbose, @"Asynchronous import job started")
Some (asyncJobId)

log.WriteLine(LogLevel.Verbose, @"Import solution: " + solution + @" (0%)")
Expand Down
11 changes: 6 additions & 5 deletions src/Delegate.Daxif/Modules/Solution/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ let export (env: Environment) solution location managed async (timeOut: TimeSpan
| false -> Export.exportSync service solution location managed
| true -> Export.exportAsync service solution location managed

let import publishAfterImport (env: Environment) location (timeOut: TimeSpan) =
let import publishAfterImport (env: Environment) location upgrade (timeOut: TimeSpan) =
let solution, managed = CrmUtility.getSolutionInformationFromFile location
logVersion log
log.Info @"Import solution: %s" solution
Expand All @@ -124,7 +124,7 @@ let import publishAfterImport (env: Environment) location (timeOut: TimeSpan) =
log.Verbose @"Publish after Import: %O" publishAfterImport
env.logAuthentication log
let service = env.connect().GetService(timeOut)
Import.execute service solution location managed |> ignore
Import.execute service solution location managed upgrade |> ignore
if publishAfterImport then
Import.publish service managed

Expand Down Expand Up @@ -172,7 +172,7 @@ let exportWithExtendedSolution (env: Environment) solution location managed asyn
env.logAuthentication log
SolutionHelper.exportWithExtendedSolution env solution location managed async timeOut

let importWithExtendedSolution reassignWorkflows (env: Environment) location (timeOut: TimeSpan) =
let importWithExtendedSolution reassignWorkflows (env: Environment) location (upgrade:bool) (timeOut: TimeSpan) =
let solution, managed = CrmUtility.getSolutionInformationFromFile location
logVersion log
log.Info @"Import extended solution: %s" solution
Expand All @@ -183,14 +183,15 @@ let importWithExtendedSolution reassignWorkflows (env: Environment) location (ti
env.logAuthentication log
SolutionHelper.importWithExtendedSolution reassignWorkflows env solution location managed timeOut |> ignore

let importStandard (env: Environment) (activatePluginSteps: bool option) extended publishAfterImport reassignWorkflows pathToSolutionZip logLevel (timeOut: TimeSpan) =
let importStandard (env: Environment) (activatePluginSteps: bool option) extended publishAfterImport reassignWorkflows pathToSolutionZip logLevel upgrade (timeOut: TimeSpan) =
let logLevel = logLevel ?| LogLevel.Verbose
let extended = extended ?| false
let upgrade = upgrade ?| false

match extended with
| true -> importWithExtendedSolution reassignWorkflows
| false -> import publishAfterImport
|> fun f -> f env pathToSolutionZip timeOut
|> fun f -> f env pathToSolutionZip upgrade timeOut

match activatePluginSteps with
| Some true ->
Expand Down
2 changes: 1 addition & 1 deletion src/Delegate.Daxif/Modules/Solution/SolutionHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ let exportWithExtendedSolution (env: Environment) solution location managed asyn
let importWithExtendedSolution reassignWorkflows (env: Environment) solution location managed (timeOut: TimeSpan) =
let service = env.connect().GetService(timeOut)
Extend.preImport service solution location
Import.execute service solution location managed
Import.execute service solution location managed false
|> fun jobInfo -> jobInfo.result
|> function
| Some (AsyncJobHelper.JobResult.Success) ->
Expand Down