internal static StorageMetadata Create(string host, bool isCurrent) { if (string.IsNullOrEmpty(host)) { throw new ArgumentNullException("host"); } StorageMetadata metadata = StorageMetadata.Create(host, isCurrent, Guid.Empty); return(metadata); }
public IStorageMetadata CreateCurrentStorageNode(string host) { if (string.IsNullOrEmpty(host)) { throw new ArgumentNullException("host"); } StorageMetadata storage = StorageMetadata.Create(host, true); return(storage); }
public void SaveStorage(IStorageMetadata storage) { if (storage == null) { throw new ArgumentNullException("storage"); } this.Logger.WriteFormatMessage("SaveStorage: начало host: '{0}' isCurrent: '{1}'", storage.Host, storage.IsCurrent); StorageMetadata typedStorage = (StorageMetadata)storage; this.StorageAdapter.Update(typedStorage); this.Logger.WriteMessage("SaveStorage: конец."); }
public IStorageMetadata GetStorage(string host) { if (string.IsNullOrEmpty(host)) { throw new ArgumentNullException("host"); } this.Logger.WriteFormatMessage("GetStorage начало. host: '{0}'", host); string condition = string.Format("[Host] = N'{0}'", host); StorageMetadata metadata = this.StorageAdapter.GetStorage(condition); this.Logger.WriteFormatMessage("GetStorage начало. host: '{0}'", host); return(metadata); }
public IStorageMetadata GetStorage(Guid uniqueID) { if (uniqueID == Guid.Empty) { throw new ArgumentNullException("uniqueID"); } this.Logger.WriteFormatMessage("GetStorage начало. uniqueID: '{0}'", uniqueID); string condition = string.Format("[UniqueID] = N'{0}'", uniqueID); StorageMetadata metadata = this.StorageAdapter.GetStorage(condition); this.Logger.WriteFormatMessage("GetStorage начало. uniqueID: '{0}'", uniqueID); return(metadata); }
public IStorageMetadata CreateStorageNode(string host, Guid uniqueID) { if (string.IsNullOrEmpty(host)) { throw new ArgumentNullException("host"); } if (uniqueID == Guid.Empty) { throw new ArgumentNullException("uniqueID"); } StorageMetadata storage = StorageMetadata.Create(host, false, uniqueID); return(storage); }
internal ReplicationFolderMetadata(DataRow row, FolderMetadata folder, StorageMetadata storage) { if (folder == null) { throw new ArgumentNullException("folder"); } if (storage == null) { throw new ArgumentNullException("storage"); } this.SourceStorage = storage; this.Folder = folder; this.MetadataRow = row; this.StorageID = storage.ID; this.FolderID = folder.ID; }
internal static StorageMetadata Create(string host, bool isCurrent, Guid nodeUniqueID) { if (string.IsNullOrEmpty(host)) { throw new ArgumentNullException("host"); } if (nodeUniqueID == Guid.Empty) { nodeUniqueID = Guid.NewGuid(); } StorageMetadata metadata = new StorageMetadata() { UniqueID = nodeUniqueID, Host = host, IsCurrent = isCurrent, }; return(metadata); }
/// <summary> /// Возвращает коллекцию папок репликации. /// </summary> /// <param name="condition">Условие на выборку метаданных.</param> /// <returns></returns> internal DBCollection <ReplicationFolderMetadata> GetReplicationFolders(string condition = null) { DBCollection <ReplicationFolderMetadata> replicationFolders = new DBCollection <ReplicationFolderMetadata>(); string resultQuery = null; if (string.IsNullOrEmpty(condition)) { resultQuery = this.SelectQuery; } else { resultQuery = @"{SelectQuery} WHERE {Condition}" .ReplaceKey("SelectQuery", this.SelectQuery) .ReplaceKey("Condition", condition); } DataTable resultTable = this.DataAdapter.GetDataTable(resultQuery); if (resultTable != null) { //собираем все идентификаторы папок и узлов хранилища //чтобы получить их за отдельный запрос Dictionary <int, FolderMetadata> uniqueFolders = new Dictionary <int, FolderMetadata>(); Dictionary <int, StorageMetadata> uniqueStorages = new Dictionary <int, StorageMetadata>(); //сначала заполняем ключи словарей foreach (DataRow row in resultTable.Rows) { int folderID = DataRowReader.GetIntegerValue(row, "FolderID"); if (folderID > 0 && !uniqueFolders.ContainsKey(folderID)) { uniqueFolders.Add(folderID, null); } int storageID = DataRowReader.GetIntegerValue(row, "StorageID"); if (storageID > 0 && !uniqueStorages.ContainsKey(storageID)) { uniqueStorages.Add(storageID, null); } } //потом получаем объекты по этим ключам и "дозаполняем" словарь if (uniqueFolders.Count > 0) { string foldersIdentities = string.Join(",", uniqueFolders.Keys.ToArray()); string foldersCondition = string.Format("[ID] IN ({0})", foldersIdentities); DBCollection <FolderMetadata> folders = this.MetadataAdapter.FolderAdapter.GetFolders(foldersCondition); foreach (FolderMetadata folder in folders) { if (uniqueFolders.ContainsKey(folder.ID)) { uniqueFolders[folder.ID] = folder; } } } if (uniqueStorages.Count > 0) { string storagesIdentities = string.Join(",", uniqueStorages.Keys.ToArray()); string storagesCondition = string.Format("[ID] IN ({0})", storagesIdentities); DBCollection <StorageMetadata> storages = this.MetadataAdapter.StorageAdapter.GetStorages(storagesCondition); foreach (StorageMetadata storage in storages) { if (uniqueStorages.ContainsKey(storage.ID)) { uniqueStorages[storage.ID] = storage; } } } foreach (DataRow row in resultTable.Rows) { FolderMetadata folder = null; StorageMetadata storage = null; int folderID = DataRowReader.GetIntegerValue(row, "FolderID"); if (folderID > 0 && uniqueFolders.ContainsKey(folderID)) { folder = uniqueFolders[folderID]; } int storageID = DataRowReader.GetIntegerValue(row, "StorageID"); if (storageID > 0 && uniqueStorages.ContainsKey(storageID)) { storage = uniqueStorages[storageID]; } if (folder == null) { int rowID = DataRowReader.GetIntegerValue(row, "ID"); throw new Exception(string.Format("Для строки метаданных папки репликации с идентификатором {0} не найдена папка с идентификатором {1}", rowID, folderID)); } if (storage == null) { int rowID = DataRowReader.GetIntegerValue(row, "ID"); throw new Exception(string.Format("Для строки метаданных папки репликации с идентификатором {0} не найден узел хранилища с идентификатором {1}", rowID, storageID)); } ReplicationFolderMetadata metadata = new ReplicationFolderMetadata(row, folder, storage); replicationFolders.Add(metadata); } } return(replicationFolders); }