Exemplo n.º 1
0
        private RecordLockedData CreateLockData(OpenFileItemData itemParam, ref LogicFileInfoData logicFileInfo, Guid userID, DbTransaction trans)
        {
            RecordLockedData result     = null;
            FileAccess       access     = itemParam.FileAccess;
            FileMode         mode       = itemParam.FileMode;
            long             fileLength = -1;

            if (mode == FileMode.Truncate)
            {
                access    |= FileAccess.Write;
                fileLength = 0;
            }
            bool canWrite = (access & FileAccess.Write) != 0;

            if (canWrite)
            {
                if (logicFileInfo == null)
                {
                    logicFileInfo = CreateNewFile(itemParam, userID, trans);
                }
                else
                {
                    logicFileInfo = UpdateFile(itemParam, logicFileInfo, fileLength, userID, trans);
                }
                if (logicFileInfo != null)
                {
                    result = Lock(logicFileInfo.ID, userID);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        private LogicFileInfoData UpdateFile(OpenFileItemData itemParam, LogicFileInfoData logicFileInfo, long fileLength, Guid userID, DbTransaction trans)
        {
            LogicFileInfoData result     = logicFileInfo;
            UpdateMode        updateMode = itemParam.UpdateMode;
            FileMode          mode       = itemParam.FileMode;
            long length = 0;

            if (updateMode == UpdateMode.None)
            {
                updateMode = UpdateMode.Override;
            }
            if (updateMode == UpdateMode.NewVersion)
            {
                PhysicalFileInfoData oldFileData = logicFileInfo.PhysicalFileInfos[logicFileInfo.PhysicalFileInfos.Count - 1];
                Guid physcicalFileID             = CombineGuid.NewComboGuid();
                switch (mode)
                {
                case FileMode.Truncate:
                case FileMode.Create:
                    FileStorageManager.SetFileLength(this.DataProvider, physcicalFileID, result.LogicFileExt, 0);
                    break;

                default:
                    length = FileStorageManager.CopyFile(this.DataProvider, oldFileData.ID, physcicalFileID, logicFileInfo.LogicFileExt);
                    break;
                }
                PhysicalFileInfoData fileData = new PhysicalFileInfoData();
                fileData.ID          = physcicalFileID;
                fileData.LogicFileID = result.ID;
                fileData.FileLength  = length;
                fileData.Version     = GetFileVersion(logicFileInfo, trans);
                fileData.StoreModeID = FileStorageManager.GetCurrentStoreModeID(this.DataProvider);
                this.DataProvider.CreatePhysicalFileInfo(fileData, trans);
                result.PhysicalFileInfos.Add(fileData);
                result.LatestPhysicalFileID = physcicalFileID;
                this.DataProvider.UpdateFileInfo(logicFileInfo, trans);
            }
            else if (updateMode == UpdateMode.Override)
            {
                switch (mode)
                {
                case FileMode.Truncate:
                case FileMode.Create:
                    FileStorageManager.SetFileLength(this.DataProvider, logicFileInfo.LatestPhysicalFileID, result.LogicFileExt, 0);
                    break;
                }
            }
            return(result);
        }