예제 #1
0
        /// <summary>
        /// Creates a file or opens an existing file in this directory.
        /// </summary>
        public TempFile CreateOrOpenFile(string name)
        {
            string filePath = System.IO.Path.Combine(_path, name);

            TempRoot.CreateStream(filePath, FileMode.OpenOrCreate);
            return(_root.AddFile(new DisposableFile(filePath)));
        }
예제 #2
0
        internal TempFile(string prefix, string extension, string directory, string callerSourcePath, int callerLineNumber)
        {
            while (true)
            {
                if (prefix == null)
                {
                    prefix = System.IO.Path.GetFileName(callerSourcePath) + "_" + callerLineNumber.ToString() + "_";
                }

                _path = System.IO.Path.Combine(directory ?? TempRoot.Root, prefix + Guid.NewGuid() + (extension ?? ".tmp"));

                try
                {
                    TempRoot.CreateStream(_path, FileMode.CreateNew);
                    break;
                }
                catch (PathTooLongException)
                {
                    throw;
                }
                catch (DirectoryNotFoundException)
                {
                    throw;
                }
                catch (IOException)
                {
                    // retry
                }
            }
        }