public static void FCKEditingCancel(string domain, string itemID)
        {
            string folderID;
            var    isEdit = !String.IsNullOrEmpty(itemID);

            var store = StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "fckuploaders");

            if (isEdit)
            {
                folderID = FCKUploadsDBManager.GetFolderID(domain, itemID);

                var session = HttpContext.Current.Session;
                var uploads = session["tempFCKUploads"] as List <FCKTempUploadsInfo>;
                if (uploads != null)
                {
                    var tempUploads = uploads.Find(u => String.Equals(u.FolderID, folderID, StringComparison.InvariantCultureIgnoreCase) &&
                                                   String.Equals(u.StoreDomain, domain, StringComparison.InvariantCultureIgnoreCase) &&
                                                   u.IsEdit == isEdit);

                    if (tempUploads != null)
                    {
                        foreach (var file in tempUploads.Files)
                        {
                            try
                            {
                                store.DeleteFiles(domain, folderID + "/", file, false);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
            else
            {
                folderID = GetCurrentFolderID(domain);
                try
                {
                    store.DeleteFiles(domain, folderID + "/", "*", false);
                }
                catch
                {
                }
                ;
            }

            FCKRemoveTempUploads(domain, folderID, isEdit);
        }
Exemplo n.º 2
0
        internal static string FCKAddTempUploads(string domain, string filename, string itemID)
        {
            var    isEdit = !String.IsNullOrEmpty(itemID);
            string folderID;

            if (isEdit)
            {
                folderID = FCKUploadsDBManager.GetFolderID(domain, itemID);
                if (String.IsNullOrEmpty(folderID))
                {
                    folderID = GetCurrentFolderID(domain);
                }
            }
            else
            {
                folderID = GetCurrentFolderID(domain);
            }

            var session = HttpContext.Current.Session;
            var uploads = session["tempFCKUploads"] as List <FCKTempUploadsInfo>;

            if (uploads == null)
            {
                uploads = new List <FCKTempUploadsInfo>();
                session["tempFCKUploads"] = uploads;
            }

            var tempInfo = uploads.Find(u => String.Equals(u.FolderID, folderID, StringComparison.InvariantCultureIgnoreCase) &&
                                        String.Equals(u.StoreDomain, domain, StringComparison.InvariantCultureIgnoreCase) &&
                                        u.IsEdit == isEdit);

            if (tempInfo == null)
            {
                tempInfo = new FCKTempUploadsInfo
                {
                    FolderID    = folderID,
                    StoreDomain = domain,
                    IsEdit      = isEdit,
                    TenantID    = TenantProvider.CurrentTenantID
                };
                uploads.Add(tempInfo);
            }
            tempInfo.Files.Add(filename);
            session["tempFCKUploads"] = uploads;
            return(folderID);
        }
        public static void FCKUploadsRemoveForItem(string domain, string itemID)
        {
            var store    = StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "fckuploaders");
            var folderID = FCKUploadsDBManager.GetFolderID(domain, itemID);

            if (String.IsNullOrEmpty(folderID))
            {
                return;
            }

            FCKUploadsDBManager.RemoveUploadRelation(domain, folderID, itemID);
            try
            {
                store.DeleteFiles(domain, folderID + "/", "*", false);
            }
            catch
            {
            }
        }
        public static void FCKEditingComplete(string domain, string itemID, string editedHtml, bool isEdit)
        {
            if (editedHtml == null)
            {
                throw new ArgumentNullException("editedHtml");
            }

            var    isExistsFolder = false;
            string folderID;

            if (isEdit)
            {
                folderID = FCKUploadsDBManager.GetFolderID(domain, itemID);
                if (String.IsNullOrEmpty(folderID))
                {
                    folderID = GetCurrentFolderID(domain);
                }
                else
                {
                    isExistsFolder = true;
                }
            }
            else
            {
                folderID = GetCurrentFolderID(domain);
            }

            var store          = StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "fckuploaders");
            var existsFileList = new List <Uri>(store.ListFiles(domain, folderID + "/", "*", false)).ConvertAll(uri => uri.ToString());

            var usingUploadFiles = new List <string>();
            var deleteFiles      = new List <string>();

            foreach (var file in new List <string>(existsFileList))
            {
                if (editedHtml.IndexOf(file, StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                    HttpUtility.UrlDecode(editedHtml).IndexOf(file, StringComparison.InvariantCultureIgnoreCase) >= 0 || HttpUtility.HtmlDecode(editedHtml).IndexOf(file, StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    usingUploadFiles.Add(file);
                }
                else
                {
                    deleteFiles.Add(file);
                }

                //HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(string.Format("//*[contains(@src,'{0}')]", file.ToLowerInvariant()));
                //if (nodes != null)
                //    usingUploadFiles.Add(file);
                //else
                //    deleteFiles.Add(file);
            }

            foreach (var df in deleteFiles)
            {
                var fileName = Path.GetFileName(df);
                store.Delete(domain, folderID + "/" + fileName);
            }

            if (usingUploadFiles.Count > 0 && !isExistsFolder)
            {
                FCKUploadsDBManager.SetUploadRelations(domain, folderID, itemID);
            }
            else if (usingUploadFiles.Count == 0)
            {
                FCKUploadsDBManager.RemoveUploadRelation(domain, folderID, itemID);
            }

            FCKRemoveTempUploads(domain, folderID, isEdit);
        }