public static string FormatDbFileName(string format, object identity, string extension) { long l; object groupKey; string s; if (identity == null) { groupKey = "_"; } else if (identity is Guid) { s = ((Guid)identity).ToString("N"); identity = s; groupKey = s.Substring(0, 2); } else { s = identity.ToString(); if (long.TryParse(s, out l)) { groupKey = l / 1000; } else if (s.Length == 0) { groupKey = "_"; } else { groupKey = s.SafeSubstring(0, 2); } } return(String.Format(format, identity, groupKey, TemporaryFileHelper.RandomFileCode(), DateTime.Now) + extension); }
internal static string CreateDatabaseFilesForScript(string script, string hash) { var cachedPath = Path.Combine(DbSettings.Current.RootPath, "cache_" + hash + ".mdf"); Tuple <byte[], byte[]> data; lock (fileCacheLock) { if (!fileCache.TryGetValue(cachedPath, out data)) { data = null; } } Func <string> writeDb = delegate() { var rnd = TemporaryFileHelper.RandomFileCode(); var instancePath = Path.Combine(DbSettings.Current.RootPath, "test_" + rnd + ".mdf"); WriteDb(instancePath, data.Item1, data.Item2); return(instancePath); }; if (data != null) { return(writeDb()); } if (!File.Exists(cachedPath)) { try { CreateDb("cache_" + hash, cachedPath, script); } finally { DetachDb("cache_" + hash); } } else { DetachDb("cache_" + hash); } if (!File.Exists(cachedPath)) { throw new InvalidOperationException("Test için cache veritabanı oluşturulamadı!"); } data = new Tuple <byte[], byte[]>( File.ReadAllBytes(cachedPath), File.ReadAllBytes(Path.ChangeExtension(cachedPath, ".ldf"))); lock (fileCacheLock) fileCache[cachedPath] = data; return(writeDb()); }
public static string FormatFilename(FormatFilenameOptions options) { object groupKey; string s; object identity = options.EntityId; if (identity == null) { groupKey = "_"; } else if (identity is Guid g) { s = g.ToString("N"); identity = s; groupKey = s.Substring(0, 2); } else { s = identity.ToString(); if (long.TryParse(s, out long l)) { groupKey = l / 1000; } else if (s.Length == 0) { groupKey = "_"; } else { groupKey = s.SafeSubstring(0, 2); } } var formatted = string.Format(options.Format, identity, groupKey, TemporaryFileHelper.RandomFileCode(), DateTime.Now, Path.GetFileNameWithoutExtension(options.OriginalName)) + Path.GetExtension(options.OriginalName); if (options.PostFormat != null) { formatted = options.PostFormat(formatted); } return(formatted); }
public static string CreateDatabaseFilesForScript(string script) { var hash = GetHash(script); var cachedPath = Path.Combine(DbSettings.Current.RootPath, "cache_" + hash + ".mdf"); if (!File.Exists(cachedPath)) { try { CreateDb("cache_" + hash, cachedPath, script); } finally { DetachDb("cache_" + hash); } } else { DetachDb("cache_" + hash); } if (!File.Exists(cachedPath)) { throw new InvalidOperationException("Test için cache veritabanı oluşturulamadı!"); } var rnd = TemporaryFileHelper.RandomFileCode(); var instancePath = Path.Combine(DbSettings.Current.RootPath, "test_" + rnd + ".mdf"); CopyDb(cachedPath, instancePath); return(instancePath); }
public static string FormatDbFileName(string format, Int64 identity, string extension) { return(String.Format(format, identity, identity / 1000, TemporaryFileHelper.RandomFileCode()) + extension); }