Beispiel #1
0
        public void PopulateAssetFullPath(WorklistAsset asset)
        {
            if (asset.id == 0)
            {
                asset.FullPath = "/";
            }
            else if (string.IsNullOrWhiteSpace(asset.FullPath))
            {
                var path         = "";
                var workingAsset = asset;
                while (workingAsset.folder_id.HasValue && workingAsset.folder_id != 1)
                {
                    // This is the root - we can stop now
                    if (workingAsset.id == 0)
                    {
                        break;
                    }

                    if (!string.IsNullOrWhiteSpace(workingAsset.FullPath))
                    {
                        // If the full path is available here, we can use it and jump out
                        path = string.Concat(workingAsset.FullPath, path);
                        break;
                    }

                    path         = string.Concat("/", workingAsset.label, path);
                    workingAsset = GetAsset(workingAsset.folder_id.Value);
                }
                asset.FullPath = path;
            }
        }
Beispiel #2
0
        private void ProcessAttachmentsFields(WorklistAsset asset, Dictionary <string, string> fields)
        {
            if (fields == null || !fields.Any())
            {
                return;
            }

            var uploadFields = fields.Where(f => f.Key.StartsWith("upload#") && !string.IsNullOrWhiteSpace(f.Value)).ToArray();

            foreach (var field in uploadFields)
            {
                var key   = field.Key;
                var value = field.Value;
                if (value.IndexOf("/cpt_internal/") < 0 && value.IndexOf("/upload/") < 0)
                {
                    var keySuffix = key.Substring(7);                     // Remove the leading "upload#"
                    if (fields.ContainsKey("upload_name#" + keySuffix))
                    {
                        var originalFilename = fields["upload_name#" + keySuffix];
                        if (_api.Asset.AttachV2(asset.id, originalFilename, Convert.FromBase64String(value), out var displayUrl))
                        {
                            fields[key] = displayUrl;
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public XmlDocument MakeXml(WorklistAsset asset, IEnumerable <KeyValuePair <string, string> > fields)
        {
            var xml = new XmlDocument();
            var pi  = xml.CreateProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");

            xml.AppendChild(pi);
            var element = xml.CreateElement("XtmTranslator.XtmTranslationData");

            xml.AppendChild(element);
            var fieldsElement = xml.CreateElement("fields");

            element.AppendChild(fieldsElement);

            var branchId = asset.branchId;

            if (branchId < 0)
            {
                branchId = asset.id;
            }
            fieldsElement.AppendChild(MakeField(xml, branchId + System.Net.WebUtility.HtmlEncode(asset.FullPath), ""));

            foreach (var kvp in fields)
            {
                fieldsElement.AppendChild(MakeField(xml, kvp.Key, kvp.Value));
            }
            return(xml);
        }
Beispiel #4
0
        private void RelinkAsset(WorklistAsset asset, List <WorklistAsset> sources, string sourcePath, List <WorklistAsset> targets, string targetPath)
        {
            ShowStatus("Relinking " + asset.FullPath + " ...");
            var fields         = _cms.Asset.Fields(asset.id);
            var fieldsToUpdate = new Dictionary <string, string>();

            foreach (var field in fields.Where(f => f.Key.StartsWith("upload#") && f.Value.IndexOf("/cpt_internal/") >= 0))
            {
                var value = RelinkValue(field.Value, sources, sourcePath, targets, targetPath);
                if (value != field.Value)
                {
                    fieldsToUpdate.Add(field.Key, value);
                }
            }
            foreach (var field in fields.Where(f => !f.Key.StartsWith("upload#") && f.Value.IndexOf("/cpt_internal/") >= 0))
            {
                var value = RelinkField(field.Value, sources, sourcePath, targets, targetPath);
                if (value != field.Value)
                {
                    fieldsToUpdate.Add(field.Key, value);
                }
            }

            if (fieldsToUpdate.Any())
            {
                WorklistAsset temp;
                _cms.Asset.Update(asset.id, fieldsToUpdate, out temp);
            }
        }
Beispiel #5
0
        public bool Branch(int id, out WorklistAsset asset)
        {
            string str = this._api.SendRequest("POST", string.Format("/Asset/Branch/{0}", id), "");
            AssetBranchResponse assetBranchResponse = JsonConvert.DeserializeObject <AssetBranchResponse>(str);

            asset = assetBranchResponse.asset;
            return(assetBranchResponse.IsSuccessful);
        }
Beispiel #6
0
            public TemplateDefinition(CmsApi cms, WorklistAsset asset)
            {
                Id = asset.id;
                var fields = cms.Asset.Fields(asset.id);

                IsOptIn    = fields.ContainsKey("opt_in") && fields["opt_in"] == "yes";
                Name       = asset.label;
                TemplateId = fields.ContainsKey("template") ? fields["template"].Split("/".ToCharArray()).Last() : "";
                Fields     = fields.Where(kvp => kvp.Key == "field" || kvp.Key.StartsWith("field:")).Select(kvp => kvp.Value.Trim()).ToArray();
            }
Beispiel #7
0
        public string GetFullPath(WorklistAsset asset)
        {
            // TODO: remove all of this once CMS-6013 is fixed
            if (!string.IsNullOrWhiteSpace(asset.FullPath))
            {
                return(asset.FullPath);
            }

            if (asset.folder_id.HasValue)
            {
                var folderId = asset.folder_id.Value;
                if (_assetsById.ContainsKey(folderId) && !string.IsNullOrWhiteSpace(_assetsById[folderId].FullPath))
                {
                    return(_assetsById[folderId].FullPath + "/" + asset.label);
                }

                IEnumerable <WorklistAsset> assets;
                int normalCount, deletedCount, hiddenCount;
                if (_api.Asset.GetList(asset.folder_id.Value, 0, 1, "Label", OrderType.Ascending, VisibilityType.Normal, false,
                                       false, out assets, out normalCount, out hiddenCount, out deletedCount))
                {
                    assets = assets.ToList();
                    AddList(assets);
                    if (assets.Any())
                    {
                        var a = assets.First();
                        if (!string.IsNullOrWhiteSpace(a.FullPath))
                        {
                            var path = a.FullPath;
                            var i    = path.LastIndexOf("/");
                            if (i >= 0)
                            {
                                path = path.Substring(0, i);
                            }

                            if (_assetsById.ContainsKey(folderId))
                            {
                                // Make sure that the folder asset has the path for next time
                                var folderAsset = _assetsById[folderId];
                                folderAsset.FullPath  = path;
                                _assetsById[folderId] = folderAsset;
                            }

                            path          += "/" + asset.label;
                            asset.FullPath = path;

                            return(path);
                        }
                    }
                }
            }

            return("");
        }
Beispiel #8
0
        public WorklistAsset UpdateAsset(WorklistAsset asset, Dictionary <string, string> fields, List <string> fieldsToDelete)
        {
            WorklistAsset assetOut;

            // TODO: this will add fields, but not remove existing ones
            if (_api.Asset.Update(asset.id, fields, out assetOut, fieldsToDelete))
            {
                UpdateAssetCache(assetOut.id, assetOut);
                return(assetOut);
            }

            return(null);
        }
Beispiel #9
0
        public bool Rename(int id, string newName, out WorklistAsset asset)
        {
            RenameAssetRequest renameAssetRequest = new RenameAssetRequest()
            {
                assetId = id,
                newName = newName
            };
            string str  = JsonConvert.SerializeObject(renameAssetRequest);
            string str1 = this._api.SendRequest("POST", "/Asset/Rename", str);
            AssetRenameResponse assetRenameResponse = JsonConvert.DeserializeObject <AssetRenameResponse>(str1);

            asset = assetRenameResponse.asset;
            return(assetRenameResponse.IsSuccessful);
        }
Beispiel #10
0
        public bool Update(int id, IDictionary <string, string> fields, out WorklistAsset asset, List <string> fieldsToDelete = null, bool runPostInput = false, bool runPostSave = false)
        {
            AssetUpdateRequest assetUpdateRequest = new AssetUpdateRequest()
            {
                assetId      = id,
                fields       = (Dictionary <string, string>)fields,
                runPostInput = runPostInput,
                runPostSave  = runPostSave
            };
            AssetUpdateRequest assetUpdateRequest1 = assetUpdateRequest;

            if (fieldsToDelete != null)
            {
                assetUpdateRequest1.fieldsToDelete = fieldsToDelete;
            }
            string str = this._api.SendRequest("POST", "/Asset/Update", JsonConvert.SerializeObject(assetUpdateRequest1));
            AssetUpdateResponse assetUpdateResponse = JsonConvert.DeserializeObject <AssetUpdateResponse>(str);

            asset = assetUpdateResponse.asset;
            return(assetUpdateResponse.IsSuccessful);
        }
Beispiel #11
0
 private void UpdateAssetCache(int id, WorklistAsset asset)
 {
     // Add the asset to our caches
     if (!_assetsById.ContainsKey(id))
     {
         _assetsById.Add(id, asset);
     }
     else
     {
         _assetsById[id] = asset;
     }
     if (!string.IsNullOrWhiteSpace(asset.FullPath))
     {
         if (!_assetsByPath.ContainsKey(asset.FullPath))
         {
             _assetsByPath.Add(asset.FullPath, id);
         }
         if (!_pathsById.ContainsKey(id))
         {
             _pathsById.Add(id, asset.FullPath);
         }
     }
 }
Beispiel #12
0
        public bool ExecuteWorkflowCommand(int id, int commandId, bool skipDependencies, out WorklistAsset asset)
        {
            ExecuteWorkflowCommandRequest executeWorkflowCommandRequest = new ExecuteWorkflowCommandRequest()
            {
                AssetId          = id,
                CommandId        = commandId,
                SkipDependencies = skipDependencies
            };
            string str  = JsonConvert.SerializeObject(executeWorkflowCommandRequest);
            string str1 = this._api.SendRequest("POST", "/Asset/ExecuteWorkflowCommand", str);
            AssetExecuteWorkflowCommandResponse assetExecuteWorkflowCommandResponse = JsonConvert.DeserializeObject <AssetExecuteWorkflowCommandResponse>(str1);

            asset = assetExecuteWorkflowCommandResponse.asset;
            return(assetExecuteWorkflowCommandResponse.IsSuccessful);
        }
Beispiel #13
0
        public bool Create(string name, int folderId, int modelId, int type, int devTemplateLanguage, int templateId, int workflowId, out WorklistAsset asset, int?subtype = null, bool?runNew = null)
        {
            AssetCreateRequest assetCreateRequest = new AssetCreateRequest()
            {
                newName             = name,
                destinationFolderId = folderId,
                modelId             = modelId,
                type = type,
                devTemplateLanguage = devTemplateLanguage,
                templateId          = templateId,
                workflowId          = workflowId
            };
            AssetCreateRequest value = assetCreateRequest;

            if (subtype.HasValue)
            {
                value.subtype = subtype.Value;
            }
            if (runNew.HasValue)
            {
                value.runNew = runNew.Value;
            }
            string str  = JsonConvert.SerializeObject(value);
            string str1 = this._api.SendRequest("POST", "/Asset/Create", str);
            AssetCreateResponse assetCreateResponse = JsonConvert.DeserializeObject <AssetCreateResponse>(str1);

            asset = assetCreateResponse.asset;
            return(assetCreateResponse.IsSuccessful);
        }
Beispiel #14
0
        public bool Upload(string name, int folderId, int modelId, int workflowId, byte[] bytes, out WorklistAsset asset)
        {
            AssetUploadRequest assetUploadRequest = new AssetUploadRequest()
            {
                newName             = name,
                destinationFolderId = folderId,
                modelId             = modelId,
                workflowId          = workflowId,
                bytes = bytes
            };
            string str  = JsonConvert.SerializeObject(assetUploadRequest);
            string str1 = this._api.SendRequest("POST", string.Format("/Asset/Upload", new object[0]), str);
            AssetUploadResponse assetUploadResponse = JsonConvert.DeserializeObject <AssetUploadResponse>(str1);

            asset = assetUploadResponse.asset;
            return(assetUploadResponse.IsSuccessful);
        }
Beispiel #15
0
 public static bool IsSite(WorklistAsset asset)
 {
     return(asset.subtype.HasValue && (asset.subtype.Value & SITE) > 0);
 }