Skip to content
Open
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
6 changes: 4 additions & 2 deletions src/Delegate.Daxif/API/WebResource.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ type WebResource private () =
/// <param name="solutionName">The name of the solution to which to sync web resources</param>
/// <param name="logLevel">Log Level - Error, Warning, Info, Verbose or Debug - defaults to: 'Verbose'</param>
/// <param name="patchSolutionName">The name of the patch solution to which to sync web resources.</param>
static member Sync(env: Environment, webresourceRoot: string, solutionName: string, ?logLevel: LogLevel, ?patchSolutionName: string, ?publishAfterSync: bool) =
static member Sync(env: Environment, webresourceRoot: string, solutionName: string, ?logLevel: LogLevel, ?patchSolutionName: string, ?publishAfterSync: bool, ?validExtensions: string array) =
let proxyGen = env.connect(log).GetService
log.setLevelOption logLevel
Main.syncSolution proxyGen solutionName webresourceRoot patchSolutionName publishAfterSync

let extensions = validExtensions ?| System.Enum.GetNames(typeof<DG.Daxif.WebResourceType>)
Main.syncSolution proxyGen solutionName webresourceRoot patchSolutionName publishAfterSync extensions
6 changes: 5 additions & 1 deletion src/Delegate.Daxif/Common/CrmDataInternal.fs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ module CrmDataInternal =
q.Criteria <- f
CrmDataHelper.retrieveFirstMatch proxy q

let retrieveWebResources proxy solutionId =
let retrieveWebResources proxy solutionId (extensions: WebResourceType array option)=
let (solutionId : Guid) = solutionId
let ln = @"webresource"
let an = @"solutionid"
Expand All @@ -515,6 +515,10 @@ module CrmDataInternal =
let f = FilterExpression()
f.AddCondition
(ConditionExpression(nm, ConditionOperator.Equal, false))
if extensions.IsSome then
let validExtensions = extensions.Value |> Array.map (fun x -> (int)x)
f.AddCondition
(ConditionExpression("webresourcetype", ConditionOperator.In, validExtensions))
let q = QueryExpression(ln)
q.ColumnSet <- ColumnSet(true)
q.Criteria <- f
Expand Down
4 changes: 2 additions & 2 deletions src/Delegate.Daxif/Modules/Solution/Extend.fs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ let export service solution solutionPath =
)

let workflowsIdsAndOwners = workflows |> getWorkflowData service
let webResIds = getWebresources service solutionId |> getEntityIds
let webResIds = getWebresources service solutionId None |> getEntityIds

let delegateSolution =
{ states=states
Expand Down Expand Up @@ -356,7 +356,7 @@ let postImport service solutionName zipPath reassignWorkflows =
log.Verbose "Synching Web Resource and Workflows"

// Sync Webresources and workflows
let targetWebRes = getWebresources service solutionId |> getEntityIds
let targetWebRes = getWebresources service solutionId None |> getEntityIds
let targetWorkflows = getWorkflows service solutionId |> getEntityIds
let sourceWorkflows = extSol.keepWorkflows |> Seq.map (fun (id,name,_) -> id,name)

Expand Down
4 changes: 2 additions & 2 deletions src/Delegate.Daxif/Modules/WebResources/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open DG.Daxif.Common
open DG.Daxif.Common.Utility
open DG.Daxif.Common.InternalUtility

let syncSolution proxyGen solution webresourceRoot patchSolutionName publishAfterSync =
let syncSolution proxyGen solution webresourceRoot patchSolutionName publishAfterSync extensions =
let publishAfterSync = publishAfterSync ?| true
logVersion log
let patchInfo = match patchSolutionName with
Expand All @@ -16,5 +16,5 @@ let syncSolution proxyGen solution webresourceRoot patchSolutionName publishAfte
log.Info @"Sync solution webresources: %s%s" solution patchInfo
log.Verbose @"Solution: %s" solution
log.Verbose @"Path to webresources: %s" webresourceRoot
WebResourcesHelper.syncSolution proxyGen webresourceRoot solution patchSolutionName publishAfterSync
WebResourcesHelper.syncSolution proxyGen webresourceRoot solution patchSolutionName publishAfterSync extensions
log.Info "The solution webresources were synced successfully"
26 changes: 15 additions & 11 deletions src/Delegate.Daxif/Modules/WebResources/WebResourcesHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ type WebResourceAction =
let getMatchingEntitiesByName namesToKeep =
Seq.filter (fun (x: Entity) -> namesToKeep |> Set.contains (x.GetAttributeValue<string>("name")))

let getWebresourceTypeFromExtensions (ext: string) =
Enum.Parse(typeof<WebResourceType>, ext.ToUpper()) :?> WebResourceType

// Convert a local web resource file to an entity object.
let localResourceToWebResource path name =
let ext = Path.GetExtension(path).ToUpper().Replace(@".", String.Empty)
let webResourceType = Enum.Parse(typeof<WebResourceType>, ext.ToUpper()) :?> WebResourceType
let webResourceType = getWebresourceTypeFromExtensions ext

let wr = Entity("webresource")
wr.Attributes.Add("content", fileToBase64 path)
Expand All @@ -37,10 +40,10 @@ let localResourceToWebResource path name =

/// Get all local webresources by enumerating all folders at given location,
/// while looking for supported file types.
let getLocalResourcesHelper location crmRelease =
let getLocalResourcesHelper location (extensions: string array) crmRelease =
seq {
let exts =
Enum.GetNames(typeof<DG.Daxif.WebResourceType>)
extensions
|> Array.map (fun x -> @"." + x.ToLower())
|> Array.toList
|> List.filter (fun x -> (x <> ".svg" && x <> ".resx" ) || crmRelease >= CrmReleases.D365)
Expand Down Expand Up @@ -70,22 +73,23 @@ let getPrefixAndUniqueName location =
@"Incorrect root folder (must only contain 1 folder ex: 'publishPrefix_uniqueSolutionName'"

/// Filter out any files which are labeled with "_nosync"
let getLocalWRs location prefix crmRelease =
getLocalResourcesHelper location crmRelease
let getLocalWRs location prefix extensions crmRelease =
getLocalResourcesHelper location extensions crmRelease
|> Seq.filter (fun name -> not <| name.EndsWith("_nosync"))
|> Seq.map (fun path ->
let name = path.Substring(path.IndexOf(location) + location.Length).Replace(@"\", "/").Trim('/')
sprintf @"%s/%s" prefix name, path
)
|> Map.ofSeq

let getSyncActions proxy webresourceFolder solutionName patchSolutionName =
let getSyncActions proxy webresourceFolder solutionName patchSolutionName extensions =
let (solutionId, prefix) = CrmDataInternal.Entities.retrieveSolutionIdAndPrefix proxy solutionName
let wrBase = CrmDataInternal.Entities.retrieveWebResources proxy solutionId |> Seq.toList
let extensionAsWebresourceTyoe = extensions |> Array.map getWebresourceTypeFromExtensions
let wrBase = CrmDataInternal.Entities.retrieveWebResources proxy solutionId (Some extensionAsWebresourceTyoe) |> Seq.toList

let wrPatch = match patchSolutionName with
| Some s -> let (sIdPatch, _) = CrmDataInternal.Entities.retrieveSolutionIdAndPrefix proxy s
CrmDataInternal.Entities.retrieveWebResources proxy sIdPatch |> Seq.toList
CrmDataInternal.Entities.retrieveWebResources proxy sIdPatch (Some extensionAsWebresourceTyoe) |> Seq.toList
| None -> List.empty

let wrBaseOnly = wrBase |> Seq.filter (fun a -> not (wrPatch |> Seq.exists (fun b -> b.Id = a.Id)))
Expand All @@ -96,7 +100,7 @@ let getSyncActions proxy webresourceFolder solutionName patchSolutionName =
let localWrPathMap =
CrmDataInternal.Info.version proxy
|> snd
|> getLocalWRs webresourceFolder wrPrefix
|> getLocalWRs webresourceFolder wrPrefix extensions
let localWrs = localWrPathMap |> Seq.map (fun kv -> kv.Key) |> Set.ofSeq

let crmWRs =
Expand Down Expand Up @@ -152,10 +156,10 @@ let getSyncActions proxy webresourceFolder solutionName patchSolutionName =
yield! update
}

let syncSolution proxyGen location solutionName patchSolutionName publishAfterSync =
let syncSolution proxyGen location solutionName patchSolutionName publishAfterSync extensions =
let p = proxyGen()

let syncActions = getSyncActions p location solutionName patchSolutionName
let syncActions = getSyncActions p location solutionName patchSolutionName extensions
let patchSolutionNameIfExists = patchSolutionName |> Option.defaultValue solutionName
let patchVerboseString = match patchSolutionName with
| Some _ -> " and added to patch solution"
Expand Down