コード例 #1
0
        public IFolderMetadata EnsureFolder(string folderUrl)
        {
            if (String.IsNullOrEmpty(folderUrl))
            {
                throw new ArgumentNullException("folderUrl");
            }

            this.Logger.WriteFormatMessage("EnsureFolder:начало folderUrl={0}", folderUrl);

            FolderMetadata folder = (FolderMetadata)this.GetFolder(folderUrl, false);

            if (folder == null)
            {
                this.Logger.WriteFormatMessage("EnsureFolder: создание папки.folderUrl={0}", folderUrl);

                lock (_locker)
                {
                    folder = (FolderMetadata)this.GetFolder(folderUrl, false);
                    if (folder == null)
                    {
                        folder     = new FolderMetadata();
                        folder.Url = folderUrl;
                        this.FolderAdapter.UpdateFolder(folder);
                    }
                }

                this.Logger.WriteMessage("EnsureFolder: конец создания папки.");
            }

            this.Logger.WriteMessage("EnsureFolder: конец операции.");

            return(folder);
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        public IFolderMetadata GetFolder(int id, bool throwIfNotExists = true)
        {
            FolderMetadata folder = null;

            this.Logger.WriteFormatMessage("GetFolder: начало  id={0}", id);

            string query = String.Format("[ID] = {0}", id);

            folder = this.FolderAdapter.GetFolder(query);

            if (folder == null && throwIfNotExists)
            {
                throw new Exception(String.Format("Не найдена папка с ID: '{0}'", id));
            }

            this.Logger.WriteMessage("GetFolder: конец операции.");

            return(folder);
        }
コード例 #4
0
        public IFolderMetadata GetFolder(string folderUrl, bool throwIfNotExists = true)
        {
            if (String.IsNullOrEmpty(folderUrl))
            {
                throw new ArgumentNullException("folderUrl");
            }

            FolderMetadata folder = null;

            this.Logger.WriteFormatMessage("GetFolder: начало  folderUrl={0}", folderUrl);

            string query = String.Format("[Url] = N'{0}'", folderUrl);

            folder = this.FolderAdapter.GetFolder(query);

            if (folder == null && throwIfNotExists)
            {
                throw new Exception(String.Format("Не найдена папка с Url: '{0}'", folderUrl));
            }

            this.Logger.WriteMessage("GetFolder конец операции.");

            return(folder);
        }
コード例 #5
0
        /// <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);
        }