Ejemplo n.º 1
0
        public static long CopyFile(IFileStorageProviderDataProvider dataProvider, Guid oldPhysicalFileID, Guid newPhysicalFileID, string extensionName)
        {
            long result = 0;
            IFileStorageProvider oldProvider = FileStorageProviderFactory.CreateFileStorageProvider(dataProvider, oldPhysicalFileID, extensionName);
            IFileStorageProvider newProvider = FileStorageProviderFactory.CreateFileStorageProvider(dataProvider, CurrentConfigSetting, newPhysicalFileID, extensionName);

            if (oldProvider != null && newProvider != null)
            {
                try
                {
                    byte[] buffer = GetCacheBuffer(DefaultBufferSize);

                    int readLen = oldProvider.Read(buffer, 0, DefaultBufferSize);
                    while (readLen > 0)
                    {
                        newProvider.Write(buffer, 0, readLen);
                        readLen = oldProvider.Read(buffer, 0, DefaultBufferSize);
                    }
                    result = newProvider.Length;
                }
                finally
                {
                    oldProvider.Close();
                    newProvider.Close();
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static byte[] ReadFile(IFileStorageProviderDataProvider dataProvider, Guid physicalFileID, string extensionName, long position, int readCount)
        {
            LogHelper.Log.ErrorFormat("FileStorageManager.ReadFile(IFileStorageProviderDataProvider dataProvider='{0}', Guid physicalFileID='{1}', string extensionName='{2}', long position='{3}', int readCount='{4}')", dataProvider, physicalFileID, extensionName, position, readCount);

            byte[] result = null;
            IFileStorageProvider provider = FileStorageProviderFactory.CreateFileStorageProvider(dataProvider, physicalFileID, extensionName);

            if (provider != null)
            {
                try
                {
                    if (readCount > 0)
                    {
                        provider.Seek(position, System.IO.SeekOrigin.Begin);
                        byte[] buffer  = GetCacheBuffer(readCount);
                        int    readLen = provider.Read(buffer, 0, readCount);
                        if (readLen > 0)
                        {
                            result = new byte[readLen];
                            Buffer.BlockCopy(buffer, 0, result, 0, readLen);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Log.Error(ex.Message, ex);
                }
                finally
                {
                    provider.Close();
                }
            }
            LogHelper.Log.ErrorFormat("FileStorageManager.ReadFile Result Bytes Length='{0}'", result.Length);
            return(result);
        }
Ejemplo n.º 3
0
        public static long WriteFile(IFileStorageProviderDataProvider dataProvider, Guid physicalFileID, string extensionName, long position, byte[] writeData)
        {
            long result = 0;
            IFileStorageProvider provider = FileStorageProviderFactory.CreateFileStorageProvider(dataProvider, physicalFileID, extensionName);

            if (provider != null)
            {
                try
                {
                    int length = 0;
                    if (writeData != null)
                    {
                        length = writeData.Length;
                    }
                    if (length > 0)
                    {
                        provider.Seek(position, System.IO.SeekOrigin.Begin);
                        provider.Write(writeData, 0, length);
                        result = provider.Length;
                    }
                }
                finally
                {
                    provider.Close();
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        public static void CreateNewFile(IFileStorageProviderDataProvider dataProvider, Guid physicalFileID, string extensionName)
        {
            IFileStorageProvider provider = FileStorageProviderFactory.CreateFileStorageProvider(dataProvider, CurrentConfigSetting, physicalFileID, extensionName);

            if (provider != null)
            {
                try
                {
                    provider.SetLength(0);
                }
                finally
                {
                    provider.Close();
                }
            }
        }
Ejemplo n.º 5
0
        public static void SetFileLength(IFileStorageProviderDataProvider dataProvider, Guid physicalFileID, string extensionName, long length)
        {
            IFileStorageProvider provider = FileStorageProviderFactory.CreateFileStorageProvider(dataProvider, physicalFileID, extensionName);

            if (provider != null)
            {
                try
                {
                    provider.SetLength(length);
                }
                finally
                {
                    provider.Close();
                }
            }
        }