示例#1
0
        public virtual void SaveFile(IFilePath fp)
        {
            using (new EntityCache(EntityCacheType.ForceNew))
            {
                if (WeakFileReference)
                {
                    return;
                }

                string sufix = CalculateSuffix(fp);
                if (!sufix.HasText())
                {
                    throw new InvalidOperationException("Sufix not set");
                }

                fp.SetPrefixPair(GetPrefixPair(fp));

                int i = 2;
                fp.Suffix = sufix;
                while (RenameOnCollision && File.Exists(fp.FullPhysicalPath()))
                {
                    fp.Suffix = RenameAlgorithm(sufix, i);
                    i++;
                }

                SaveFileInDisk(fp);
            }
        }
示例#2
0
        internal static void SaveFile(IFilePath fp)
        {
            using (new EntityCache(EntityCacheType.ForceNew))
            {
                FileTypeAlgorithm alg = FileTypes.GetOrThrow(fp.FileType);

                if (alg.TakesOwnership)
                {
                    string sufix = alg.CalculateSufix(fp);
                    if (!sufix.HasText())
                        throw new InvalidOperationException("Sufix not set");

                    fp.SetPrefixPair(alg.GetPrefixPair(fp));

                    int i = 2;
                    fp.Suffix = sufix;
                    while (alg.RenameOnCollision && File.Exists(fp.FullPhysicalPath()))
                    {
                        fp.Suffix = alg.RenameAlgorithm(sufix, i);
                        i++;
                    }

                    alg.SaveFileInDisk(fp);
                }
            }
        }
示例#3
0
        public virtual void MoveFile(IFilePath ofp, IFilePath fp)
        {
            if (WeakFileReference)
            {
                return;
            }

            System.IO.File.Move(ofp.FullPhysicalPath(), fp.FullPhysicalPath());
        }
示例#4
0
        public virtual void SaveFileInDisk(IFilePath fp)
        {
            string?fullPhysicalPath = null;

            try
            {
                string path = Path.GetDirectoryName(fp.FullPhysicalPath());
                fullPhysicalPath = path;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                File.WriteAllBytes(fp.FullPhysicalPath(), fp.BinaryFile);
                fp.BinaryFile = null !;
            }
            catch (IOException ex)
            {
                ex.Data.Add("FullPhysicalPath", fullPhysicalPath);
                ex.Data.Add("CurrentPrincipal", System.Threading.Thread.CurrentPrincipal.Identity.Name);

                throw;
            }
        }
示例#5
0
 public virtual byte[] ReadAllBytes(IFilePath path)
 {
     return(File.ReadAllBytes(path.FullPhysicalPath()));
 }
示例#6
0
 public virtual Stream OpenRead(IFilePath path)
 {
     return(File.OpenRead(path.FullPhysicalPath()));
 }
示例#7
0
        public static void SaveFileDefault(IFilePath fp)
        {
            string fullPhysicalPath = null;
            try
            {
                string path = Path.GetDirectoryName(fp.FullPhysicalPath());
                fullPhysicalPath = path;
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);
                File.WriteAllBytes(fp.FullPhysicalPath(), fp.BinaryFile);
                fp.BinaryFile = null;
            }
            catch (IOException ex)
            {
                ex.Data.Add("FullPhysicalPath", fullPhysicalPath);
                ex.Data.Add("CurrentPrincipal", System.Threading.Thread.CurrentPrincipal.Identity.Name);

                throw;
            }
        }