Skip to content

Commit

Permalink
Merge pull request #3 from DigitalFlow/feature/XrmTooling
Browse files Browse the repository at this point in the history
Feature/xrm tooling
  • Loading branch information
DigitalFlow authored Feb 17, 2020
2 parents 7f73f40 + f48aa24 commit 28bcd35
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,38 @@
<HintPath>..\..\..\packages\Microsoft.IdentityModel.6.1.7600.16394\lib\net35\Microsoft.IdentityModel.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory">
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.22.302111727\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms">
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.22.302111727\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime">
<HintPath>..\..\..\packages\Microsoft.CrmSdk.XrmTooling.CoreAssembly.9.0.2.12\lib\net462\Microsoft.Rest.ClientRuntime.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Xrm.Sdk">
<HintPath>..\..\..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.12\lib\net462\Microsoft.Xrm.Sdk.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Xrm.Sdk.Deployment">
<HintPath>..\..\..\packages\Microsoft.CrmSdk.Deployment.9.0.2.9\lib\net462\Microsoft.Xrm.Sdk.Deployment.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Xrm.Sdk.Workflow">
<HintPath>..\..\..\packages\Microsoft.CrmSdk.Workflow.9.0.2.9\lib\net462\Microsoft.Xrm.Sdk.Workflow.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Xrm.Tooling.Connector">
<HintPath>..\..\..\packages\Microsoft.CrmSdk.XrmTooling.CoreAssembly.9.0.2.12\lib\net462\Microsoft.Xrm.Tooling.Connector.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Activities" />
<Reference Include="System.Activities.Presentation" />
<Reference Include="System.Core" />
<Reference Include="System.DirectoryServices" />
<Reference Include="System.DirectoryServices.AccountManagement" />
Expand All @@ -81,6 +105,9 @@
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Services" />
<Reference Include="System.Workflow.Activities" />
<Reference Include="System.Workflow.ComponentModel" />
<Reference Include="System.Workflow.Runtime" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
Expand Down
85 changes: 21 additions & 64 deletions src/app/Dynamics.CRM.SolutionExchanger/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ let OptionToString (opt : option<'T>)=
| Some value -> "Present"
| None -> "Missing"

let ExportAllSolutions password user (url:string option) (managed:bool option) (workingDir:string option) timeOut =
let ExportAllSolutions connectionString (managed:bool option) (workingDir:string option) timeOut =
let solutions = ExportAllSolutions (fun cred ->
{ cred with
Password = password
Username = user
Url = url.Value
ConnectionString = connectionString
TimeOut = timeOut
}) managed.Value

Expand All @@ -45,34 +43,10 @@ let ExportAllSolutions password user (url:string option) (managed:bool option) (
printf "Skipping solution %s, since it has no value.\n" uniqueName)
0

let ExportAllOrganizations password user (url:string option) (managed:bool option) (workingDir: string option) timeOut =
let solutions = ExportAllOrganizations (fun cred ->
{ cred with
Password = password
Username = user
Url = url.Value
TimeOut = timeOut
}) managed.Value

let dir = if workingDir.IsNone then @".\" else workingDir.Value

// Write all solutions into a directory called like the organization
solutions
|> Seq.iter(fun (friendlyName, solutions) ->
solutions
|> Seq.iter(fun (solution, uniqueName) ->
if solution.IsSome then
WriteSolutionToFile (uniqueName + ".zip") solution.Value (Path.Combine(dir, friendlyName))
else
printf "Skipping solution %s, since it has no value.\n" uniqueName))
0

let ExportSolution password user (url:string option) (sol:string option) (filename:string option) (managed:bool option) (workingDir: string option) timeOut =
let ExportSolution connectionString (sol:string option) (filename:string option) (managed:bool option) (workingDir: string option) timeOut =
let solution = ExportSolution (fun cred ->
{ cred with
Password = password
Username = user
Url = url.Value
ConnectionString = connectionString
TimeOut = timeOut
}) sol.Value managed.Value

Expand Down Expand Up @@ -112,91 +86,74 @@ let parseInt (input:string option) referenceName =

/// Used for exporting solution from CRM and saving it to file
let Export args =
let url = FindOption "/url:" args
let user = FindOption "/user:" args
let password = FindOption "/password:" args
let connectionString = FindOption "/connectionString:" args
let solution = FindOption "/solution:" args
let managedText = FindOption "/managed:" args
let workingDir = FindOption "/workingdir:" args
let filename = FindOption "/filename:" args
let allSolutionsText = FindOption "/allSolutions:" args
let allOrganizationsText = FindOption "/allOrganizations:" args
let timeOutText = FindOption "/timeout:" args

let allSolutions = parseBool allSolutionsText "allSolutions"
let managed = parseBool managedText "managed"
let allOrganizations = parseBool allOrganizationsText "allOrganizations"
let timeOut = parseInt timeOutText "timeout"

if url.IsNone || (solution.IsNone && (allSolutions.IsNone || not allSolutions.Value) && (allOrganizations.IsNone || not allOrganizations.Value)) || managed.IsNone then
printf "Values missing: Needed /url (%s), (/solution (%s) or /allSolutions:true or allOrganizations:true) and /managed (%s)\n" (OptionToString url) (OptionToString solution) (OptionToString managed)
if connectionString.IsNone || (solution.IsNone && (allSolutions.IsNone || not allSolutions.Value)) || managed.IsNone then
printf "Values missing: Needed /connectionString (%s), (/solution (%s) or /allSolutions:true or allOrganizations:true) and /managed (%s)\n" (OptionToString connectionString) (OptionToString solution) (OptionToString managed)
1
else
if allSolutions.IsSome && allSolutions.Value then
ExportAllSolutions password user url managed workingDir timeOut
else if allOrganizations.IsSome && allOrganizations.Value then
ExportAllOrganizations password user url managed workingDir timeOut
ExportAllSolutions connectionString.Value managed workingDir timeOut
else
ExportSolution password user url solution filename managed workingDir timeOut
ExportSolution connectionString.Value solution filename managed workingDir timeOut


/// Used for importing solution to CRM
let Import args =
let url = FindOption "/url:" args
let user = FindOption "/user:" args
let password = FindOption "/password:" args
let connectionString = FindOption "/connectionString:" args
let filename = FindOption "/filename:" args

let timeOutText = FindOption "/timeout:" args
let timeOut = parseInt timeOutText "timeout"

if url.IsNone || filename.IsNone then
printf "Values missing: Needed /url (%s) and /filename (%s)\n" (OptionToString url) (OptionToString filename)
if connectionString.IsNone || filename.IsNone then
printf "Values missing: Needed /connectionString (%s) and /filename (%s)\n" (OptionToString connectionString) (OptionToString filename)
1
else
ImportSolution (fun cred ->
{ cred with
Password = password
Username = user
Url = url.Value
ConnectionString = connectionString.Value
TimeOut = timeOut
}) filename.Value
0

/// Used for publishing all customizations in CRM
let Publish args =
let url = FindOption "/url:" args
let user = FindOption "/user:" args
let password = FindOption "/password:" args

let connectionString = FindOption "/connectionString:" args

let timeOutText = FindOption "/timeout:" args
let timeOut = parseInt timeOutText "timeout"


if url.IsNone then
printf "Values missing: Needed /url (%s)\n" (OptionToString url)
if connectionString.IsNone then
printf "Values missing: Needed /url (%s)\n" (OptionToString connectionString)
1
else
PublishAll (fun cred ->
{ cred with
Password = password
Username = user
Url = url.Value
ConnectionString = connectionString.Value
TimeOut = timeOut
})
0

[<EntryPoint>]
let main argv =
if argv.Length < 1 then
printf "%s%s%s%s%s%s%s%s%s%s%s"
"Usage SolutionExchanger.exe [Export | Import | Publish] [/user: | /password: | /url: | /solution: | /managed: | /filename: | /workingdir: | /allSolutions: | /allOrganizations:]\n"
"/user - Username for authenticating with CRM endpoint. If no user and password are given, fallback to default credentials\n"
"/password - Password for authenticating with CRM endpoint. If no user and password are given, fallback to default credentials\n"
"/url - Required. Url of CRM endpoint\n"
printf "%s%s%s%s%s%s%s%s"
"Usage SolutionExchanger.exe [Export | Import | Publish] [/connectionString: | /solution: | /managed: | /filename: | /workingdir: | /allSolutions: | /allOrganizations:]\n"
"/connectionString - Connection string for connecting to CRM. Always required.\n"
"/solution - Required if exporting. Unique name of solution to export. Can be replaced by allSolutions to get all unmanaged solutions in organization\n"
"/allSolutions - Pass like /allSolutions:true to Export all unmanaged solutions in organization\n"
"/allOrganizations - Pass like /allOrganizations:true to Export all unmanaged solutions in all organizations\n"
"/managed - Required if exporting. Pass 'true' for exporting managed, false for unmanaged\n"
"/filename - Required if importing. Pass full path to solution. If Exporting sets name of exported solution file\n"
"/workingdir - Sets working directory for writing exported solution to file\n"
Expand Down
Loading

0 comments on commit 28bcd35

Please sign in to comment.