コード例 #1
0
ファイル: FileManager.cs プロジェクト: yuanbeier/FZY
        public static Stream OpenReadFile(string serverGroup, Guid logicFileID)
        {
            RemoteStreamContext context = new RemoteStreamContext();

            context.ServiceGroup = serverGroup;
            context.FileID       = logicFileID;
            context.FileMode     = FileMode.Open;
            context.FileAccess   = FileAccess.Read;
            return(new RemoteStream(context));
        }
コード例 #2
0
            private IRemoteFileStorage CreateServiceProxy(RemoteStreamContext context)
            {
                IRemoteFileStorage result = null;

                if (!string.IsNullOrEmpty(context.ServiceGroup))
                {
                    result = ServiceProxyProviderFactory.GetProvider(context.ServiceGroup,
                                                                     FMPServiceProxyProviderManager.RemoteFileStorageServiceName) as IRemoteFileStorage;
                }
                return(result);
            }
コード例 #3
0
 public RemoteStream(RemoteStreamContext context)
 {
     this.IsClose    = true;
     _contextWrapper = this.CreateWrapper();
     this._contextWrapper.Initialize(context);
     _lenght          = _contextWrapper._fileLength;
     _origin          = _contextWrapper._origin;
     _bufferCapacity  = context.BufferSize;
     this.IsClose     = false;
     this.NeededWrite = false;
 }
コード例 #4
0
ファイル: FileManager.cs プロジェクト: yuanbeier/FZY
        public static Stream OpenWriteFile(string serverGroup, Guid logicFileID, UpdateMode updateMode, string clientFileName)
        {
            RemoteStreamContext context = new RemoteStreamContext();

            context.ServiceGroup   = serverGroup;
            context.FileID         = logicFileID;
            context.FileMode       = FileMode.OpenOrCreate;
            context.FileAccess     = FileAccess.ReadWrite;
            context.UpdateMode     = updateMode;
            context.ClientFileName = clientFileName;
            return(new RemoteStream(context));
        }
コード例 #5
0
ファイル: FileManager.cs プロジェクト: yuanbeier/FZY
        /// <summary>
        /// 打开文件
        /// </summary>
        /// <param name="serviceGroup"></param>
        /// <param name="logicFileID"></param>
        /// <param name="mode"></param>
        /// <param name="access"></param>
        /// <param name="updateMode"></param>
        /// <param name="clientFileName"></param>
        /// <returns></returns>
        public static Stream OpenFile(string serviceGroup, Guid logicFileID, FileMode mode, FileAccess access, UpdateMode updateMode, string clientFileName)
        {
            RemoteStreamContext context = new RemoteStreamContext();

            context.ServiceGroup   = serviceGroup;
            context.FileID         = logicFileID;
            context.FileMode       = mode;
            context.FileAccess     = access;
            context.UpdateMode     = updateMode;
            context.ClientFileName = clientFileName;
            return(new RemoteStream(context));
        }
コード例 #6
0
            internal void Initialize(RemoteStreamContext context)
            {
                __Error.CheckNullReference(context, "context");
                if (context.FileID == Guid.Empty)
                {
                    __Error.InvalidateFileID();
                }
                _context = context;
                _proxy   = CreateServiceProxy(context);
                //Stopwatch w = new Stopwatch();
                //w.Start();
                _itemResult = FileManager.OpenFile(context, _proxy);
                //w.Stop();
                //Console.WriteLine("Open File execute times:" + w.ElapsedMilliseconds);
                //_logicFileInfo = FileManager.GetFileInfo(context.FileID, context.Version);
                if (context.FileMode == FileMode.None)
                {
                    __Error.InvalidateFileMode();
                }

                FileAccess access = context.FileAccess;

                if (FileMode.Truncate == context.FileMode)
                {
                    access = FileAccess.Write;
                }

                LogicFileInfoData logicFileInfo = LogicFileInfo;

                if (logicFileInfo == null)
                {
                    if (context.FileMode == FileMode.Open ||
                        context.FileMode == FileMode.Append ||
                        context.FileMode == FileMode.Truncate)
                    {
                        __Error.NotExistsFileID(context.FileID);
                    }
                }

                if (logicFileInfo != null)
                {
                    if (logicFileInfo.ReadOnly && this._canWrite)
                    {
                        __Error.FileReadOnly(context.FileID);
                    }

                    if (context.FileMode == FileMode.CreateNew)
                    {
                        __Error.ExistsFileID(context.FileID);
                    }
                }

                this._canRead  = (access & FileAccess.Read) != 0;
                this._canWrite = (access & FileAccess.Write) != 0;

                PhysicalFileInfoData physicalFileInfo = this.PhysicalFileInfo;

                if (physicalFileInfo != null)
                {
                    this._fileLength = physicalFileInfo.FileLength;
                }

                if (context.FileMode == FileMode.Append)
                {
                    _origin = _fileLength;
                }
            }