internal static ProjectKey?GetFileStorageProjectKey(string path) { string descriptionFilename = System.IO.Path.Combine(path, FileStorageConfig); if (System.IO.File.Exists(descriptionFilename)) { try { FileStorageDescription x = JsonUtils.LoadFromFile <FileStorageDescription>(descriptionFilename); return(new ProjectKey(x.HostName, x.ProjectName)); } catch (Exception ex) // Any exception from JsonUtils.LoadFromFile() { ExceptionHandlers.Handle("Cannot read serialized FileStorageDescription object", ex); } } return(null); }
internal static void InitalizeFileStorage(string path, ProjectKey projectKey) { System.Diagnostics.Debug.Assert(FullShaLength >= RevisionLength); string descriptionFilepath = System.IO.Path.Combine(path, FileStorageConfig); if (System.IO.File.Exists(descriptionFilepath)) { return; } if (!System.IO.Directory.Exists(path)) { try { System.IO.Directory.CreateDirectory(path); } catch (Exception ex) // Any exception from System.IO.Directory.CreateDirectory() { throw new ArgumentException(String.Format("Cannot create a file storage at {0}", path), ex); } } FileStorageDescription fileStorageDescription = new FileStorageDescription { HostName = projectKey.HostName, ProjectName = projectKey.ProjectName }; try { JsonUtils.SaveToFile(descriptionFilepath, fileStorageDescription); } catch (Exception ex) // Any exception from JsonUtils.SaveToFile() { throw new ArgumentException(String.Format("Cannot initialize a file storage at {0}", path), ex); } }