private void AddOrUpdateContent(Repository repository, IncomingQueue queueItem)
        {
            var textContent        = (Dictionary <string, object>)queueItem.Object;
            var values             = textContent.ToNameValueCollection();
            var files              = values.GetFilesFromValues();
            var medias             = values.GetMediaFromValues();
            var newVirtualPathDict = new Dictionary <string, string>();

            for (int i = 0, len = medias.Count; i < len; i++)
            {
                var virtualPath = this._repositoryNameRegex.Replace(medias[i].FileName, string.Format("$1{0}$3", repository.Name));
                var folder      = this._repositoryNameRegex.Match(virtualPath).Groups["mediaFolder"].Value;

                if (!string.IsNullOrWhiteSpace(virtualPath))
                {
                    newVirtualPathDict.Add(medias[i].FileName, virtualPath);

                    var physicalPath = Kooboo.Web.Url.UrlUtility.MapPath(virtualPath);

                    var mediaFolder = new MediaFolder(repository, folder);
                    if (mediaFolder.AsActual() == null)
                    {
                        this._mediaFolderManager.Add(repository, mediaFolder);
                    }

                    var folderPath = Path.GetDirectoryName(physicalPath);

                    var fileName = Path.GetFileName(physicalPath);

                    this._mediaContentManager.Add(repository, mediaFolder,
                                                  fileName, medias[i].InputStream, false);
                }
            }

            foreach (var prop in values.AllKeys)
            {
                if (!prop.StartsWith("__"))
                {
                    if (values[prop] != null && values[prop] is string && this._mediaPathField.IsMediaPathField(values[prop].ToString()))
                    {
                        var fieldValue = values[prop].ToString();
                        foreach (var key in newVirtualPathDict.Keys)
                        {
                            fieldValue = fieldValue.Replace(key, newVirtualPathDict[key]);
                        }
                        values[prop] = fieldValue;
                    }
                }
            }

            var categories = values.GetCategories().Select(it => new TextContent(repository.Name, "", it.CategoryFolder)
            {
                UUID = it.CategoryUUID
            }).ToArray();

            var textFolder = new TextFolder(repository, values["FolderName"]);

            _textContentManager.Delete(repository, textFolder, values["UUID"]);
            _textContentManager.Add(textFolder.Repository, textFolder, values, files, categories, values["UserId"]);
        }
Beispiel #2
0
 public virtual ActionResult IsFolderNameAvailable(string name, string folderName)
 {
     if (!string.IsNullOrEmpty(name))
     {
         string fullName = name;
         if (!string.IsNullOrEmpty(folderName))
         {
             fullName = FolderHelper.CombineFullName(new[] { folderName, name });
         }
         var folder = new MediaFolder(Repository, fullName);
         if (folder.AsActual() != null)
         {
             return(Json("The name already exists.".Localize(), JsonRequestBehavior.AllowGet));
         }
     }
     return(Json(true, JsonRequestBehavior.AllowGet));
 }