Пример #1
0
        public static void DeleteHistoryFile(int id, IFileSystem fileSystem, string virtualHistoryPath)
        {
            string historyServerName = string.Empty;

            using (IDataReader reader = SharedFile.GetHistoryFileAsIDataReader(id))
            {
                if (reader.Read())
                {
                    historyServerName = reader["ServerFileName"].ToString();
                }
            }

            if (historyServerName.Length > 0)
            {
                //File.Delete(Path.Combine(historyPath, Path.GetFileName(historyServerName)));
                string fullPath = VirtualPathUtility.Combine(virtualHistoryPath, historyServerName);
                fileSystem.DeleteFile(fullPath);
            }
        }
Пример #2
0
        public static bool RestoreHistoryFile(
            int historyId,
            IFileSystem fileSystem,
            string virtualSourcePath,
            string virtualHistoryPath)
        {
            bool historyRestored = false;

            if (string.IsNullOrEmpty(virtualSourcePath))
            {
                return(historyRestored);
            }
            if (string.IsNullOrEmpty(virtualHistoryPath))
            {
                return(historyRestored);
            }
            if (fileSystem == null)
            {
                return(historyRestored);
            }


            int      itemId              = 0;
            int      moduleId            = 0;
            string   historyFriendlyName = string.Empty;
            string   historyOriginalName = string.Empty;
            string   historyServerName   = string.Empty;
            DateTime historyUploadDate   = DateTime.Now;
            int      historyUploadUserID = 0;
            int      historyFileSize     = 0;

            using (IDataReader reader = SharedFile.GetHistoryFileAsIDataReader(historyId))
            {
                if (reader.Read())
                {
                    itemId              = Convert.ToInt32(reader["ItemID"]);
                    moduleId            = Convert.ToInt32(reader["ModuleID"]);
                    historyFriendlyName = reader["FriendlyName"].ToString();
                    historyOriginalName = reader["OriginalFileName"].ToString();
                    historyServerName   = reader["ServerFileName"].ToString();
                    historyFileSize     = Convert.ToInt32(reader["SizeInKB"]);
                    historyUploadUserID = Convert.ToInt32(reader["UploadUserID"]);
                    historyUploadDate   = DateTime.Parse(reader["UploadDate"].ToString());
                }
            }

            SharedFile sharedFile = new SharedFile(moduleId, itemId);

            CreateHistory(sharedFile, fileSystem, virtualSourcePath, virtualHistoryPath);

            //File.Move(Path.Combine(historyPath, Path.GetFileName(historyServerName)), Path.Combine(sourcePath, Path.GetFileName(historyServerName)));
            fileSystem.MoveFile(
                VirtualPathUtility.Combine(virtualHistoryPath, historyServerName),
                VirtualPathUtility.Combine(virtualSourcePath, historyServerName),
                true);

            sharedFile.ServerFileName   = historyServerName;
            sharedFile.OriginalFileName = historyOriginalName;
            sharedFile.FriendlyName     = historyFriendlyName;
            sharedFile.SizeInKB         = historyFileSize;
            sharedFile.UploadDate       = historyUploadDate;
            sharedFile.UploadUserId     = historyUploadUserID;
            historyRestored             = sharedFile.Save();
            SharedFile.DeleteHistory(historyId);

            fileSystem.DeleteFile(VirtualPathUtility.Combine(virtualHistoryPath, historyServerName));


            return(historyRestored);
        }