예제 #1
0
 static void FilePathLogic_Retrieved(FilePathEntity fp)
 {
     using (new EntityCache(EntityCacheType.ForceNew))
         fp.SetPrefixPair();
 }
예제 #2
0
 public static void FilePath_PreSaving(FilePathEntity fp, ref bool graphModified)
 {
     if (fp.IsNew && !unsafeMode.Value)
     {
         FileTypeLogic.SaveFile(fp);
     }
 }
예제 #3
0
 static PrefixPair CalculatePrefixPair(FilePathEntity fp)
 {
     using (new EntityCache(EntityCacheType.ForceNew))
        return FileTypeLogic.FileTypes.GetOrThrow(fp.FileType).GetPrefixPair(fp);
 }
예제 #4
0
 static void FilePathLogic_Retrieved(FilePathEntity fp)
 {
     fp.GetPrefixPair();
 }
        public static void SaveFileDefault(FilePathEntity 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;
            }
        }
        public static void FilePath_PreSaving(FilePathEntity fp, ref bool graphModified)
        {
            if (fp.IsNew && !unsafeMode.Value)
            {
                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.prefixPair = alg.GetPrefixPair(fp);

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

                        alg.SaveFile(fp);
                    }
                }
            }
        }
예제 #7
0
        public static void OpenFile(FilePathEntity fp, byte[] file)
        {
            if (fp == null || fp.IsNew)
                return;

            if (file == null)
                file = FileLine.DefaultResolveBinaryFile(fp);

            string fullPath = String.Empty;
            int loop = 0;
            do
            {
                string fileName = loop == 0 ? fp.FileName :
                    "{0}({1}){2}".FormatWith(System.IO.Path.GetFileNameWithoutExtension(fp.FileName),
                    loop, System.IO.Path.GetExtension(fp.FileName));
                fullPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), fileName);
                loop++;
            } while (File.Exists(fullPath));
            File.WriteAllBytes(fullPath, file);
            Process.Start(fullPath);
        }