Example #1
0
        private static void Configure()
        {
            lock (configurationLockObject)
            {
                if (!configured)
                {
                    var maximumSize = defaultBufferMaximumSize;
                    var blockSize   = defaultBufferBlockSize;
                    var path        = TemporaryDataStorage.defaultPath;

                    if (maximumSize < blockSize || maximumSize % blockSize != 0)
                    {
                        maximumSize = defaultBufferMaximumSize;
                        blockSize   = defaultBufferBlockSize;
                    }

                    defaultBufferMaximumSize = maximumSize;
                    defaultBufferBlockSize   = blockSize;

                    var defaultPath = Path.GetTempPath();

                    if (path != null)
                    {
                        path = ValidatePath(path);
                    }

                    if (path == null)
                    {
                        path = defaultPath;
                    }

                    TempFileStream.SetTemporaryPath(path);

                    configured = true;
                }
            }
        }
Example #2
0
        public override void Write(long position, byte[] buffer, int offset, int count)
        {
            if (isReadOnly)
            {
                throw new InvalidOperationException("Write to read-only DataStorage");
            }

            if (count != 0)
            {
                if (fileStream == null)
                {
                    fileStream = TempFileStream.CreateInstance();
                }

                fileStream.Write(buffer, offset, count);

                position += count;

                if (position > totalLength)
                {
                    totalLength = position;
                }
            }
        }
Example #3
0
 // Token: 0x06000CAB RID: 3243 RVA: 0x0006EADB File Offset: 0x0006CCDB
 public static TempFileStream CreateInstance(string prefix)
 {
     return(TempFileStream.CreateInstance(prefix, true));
 }
Example #4
0
 // Token: 0x06000CAA RID: 3242 RVA: 0x0006EACF File Offset: 0x0006CCCF
 public static TempFileStream CreateInstance()
 {
     return(TempFileStream.CreateInstance("Cts"));
 }
Example #5
0
 // Token: 0x06000C41 RID: 3137 RVA: 0x0006C1C4 File Offset: 0x0006A3C4
 private static void Configure()
 {
     if (TemporaryDataStorage.Configured)
     {
         return;
     }
     lock (TemporaryDataStorage.configurationLockObject)
     {
         if (!TemporaryDataStorage.Configured)
         {
             int    num  = TemporaryDataStorage.DefaultBufferMaximumSize;
             int    num2 = TemporaryDataStorage.DefaultBufferBlockSize;
             string text = TemporaryDataStorage.DefaultPath;
             IList <CtsConfigurationSetting> configuration = ApplicationServices.Provider.GetConfiguration(null);
             foreach (CtsConfigurationSetting ctsConfigurationSetting in configuration)
             {
                 if (ctsConfigurationSetting.Name.Equals("TemporaryStorage", StringComparison.OrdinalIgnoreCase))
                 {
                     foreach (CtsConfigurationArgument ctsConfigurationArgument in ctsConfigurationSetting.Arguments)
                     {
                         if (ctsConfigurationArgument.Name.Equals("Path", StringComparison.OrdinalIgnoreCase))
                         {
                             text = ctsConfigurationArgument.Value.Trim();
                         }
                         else if (ctsConfigurationArgument.Name.Equals("MaximumBufferSize", StringComparison.OrdinalIgnoreCase))
                         {
                             if (!int.TryParse(ctsConfigurationArgument.Value.Trim(), out num))
                             {
                                 ApplicationServices.Provider.LogConfigurationErrorEvent();
                                 num = TemporaryDataStorage.DefaultBufferMaximumSize;
                             }
                             else if (num < 16 || num > 10240)
                             {
                                 ApplicationServices.Provider.LogConfigurationErrorEvent();
                                 num = TemporaryDataStorage.DefaultBufferMaximumSize;
                             }
                             else
                             {
                                 num *= 1024;
                             }
                         }
                         else if (ctsConfigurationArgument.Name.Equals("BufferIncrement", StringComparison.OrdinalIgnoreCase))
                         {
                             if (!int.TryParse(ctsConfigurationArgument.Value.Trim(), out num2))
                             {
                                 ApplicationServices.Provider.LogConfigurationErrorEvent();
                                 num2 = TemporaryDataStorage.DefaultBufferBlockSize;
                             }
                             else if (num2 < 4 || num2 > 64)
                             {
                                 ApplicationServices.Provider.LogConfigurationErrorEvent();
                                 num2 = TemporaryDataStorage.DefaultBufferBlockSize;
                             }
                             else
                             {
                                 num2 *= 1024;
                             }
                         }
                         else
                         {
                             ApplicationServices.Provider.LogConfigurationErrorEvent();
                         }
                     }
                 }
             }
             if (num < num2 || num % num2 != 0)
             {
                 ApplicationServices.Provider.LogConfigurationErrorEvent();
                 num  = TemporaryDataStorage.DefaultBufferMaximumSize;
                 num2 = TemporaryDataStorage.DefaultBufferBlockSize;
             }
             TemporaryDataStorage.DefaultBufferMaximumSize = num;
             TemporaryDataStorage.DefaultBufferBlockSize   = num2;
             string systemTempPath = TemporaryDataStorage.GetSystemTempPath();
             if (text != null)
             {
                 text = TemporaryDataStorage.ValidatePath(text);
             }
             if (text == null)
             {
                 text = systemTempPath;
             }
             TempFileStream.SetTemporaryPath(text);
             TemporaryDataStorage.Configured = true;
         }
     }
 }
Example #6
0
        public static TempFileStream CreateInstance(string prefix, bool deleteOnClose)
        {
            var securityAttribute = new NativeMethods.SecurityAttributes(false);

            var tempPath = Path;



            new FileIOPermission(FileIOPermissionAccess.Write, tempPath).Demand();

            SafeFileHandle safeHandle;
            string         tempFile;
            var            errorCode = 0;


            var retry = 10;

            do
            {
                var id = (uint)Interlocked.Increment(ref NextId);

                tempFile =
                    System.IO.Path.Combine(
                        tempPath,
                        string.Concat(prefix, id.ToString("X5"), ".tmp"));

                var deleteOnCloseFlag = (deleteOnClose) ? NativeMethods.FILE_FLAG_DELETE_ON_CLOSE : 0;
                safeHandle = NativeMethods.CreateFile(
                    tempFile,
                    NativeMethods.FILE_GENERIC_READ | NativeMethods.FILE_GENERIC_WRITE,
                    0,
                    ref securityAttribute,
                    NativeMethods.CREATE_NEW,
                    NativeMethods.FILE_ATTRIBUTE_TEMPORARY | deleteOnCloseFlag | NativeMethods.FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,
                    IntPtr.Zero);

                retry--;

                if (safeHandle.IsInvalid)
                {
                    errorCode = Marshal.GetLastWin32Error();

                    if (errorCode == NativeMethods.ERROR_FILE_EXISTS)
                    {
                        retry++;
                    }


                    Interlocked.Add(ref NextId, Process.GetCurrentProcess().Id);
                }
                else
                {
                    retry = 0;
                }
            }while (retry > 0);

            if (safeHandle.IsInvalid)
            {
                var message = Strings.CreateFileFailed(tempFile);
                throw new IOException(message, new Win32Exception(errorCode, message));
            }

            var tempFileStream = new TempFileStream(safeHandle);

            tempFileStream.filePath = tempFile;
            return(tempFileStream);
        }