コード例 #1
0
        public void ArchiveTableData(IDictionary <ITable, IEnumerable <IEnumerable <IDataObjectBase> > > tableData, bool includeEmptyTables, object syncRoot)
        {
            if (tableData == null)
            {
                throw new ArgumentNullException(nameof(tableData));
            }
            if (syncRoot == null)
            {
                throw new ArgumentNullException(nameof(syncRoot));
            }

            try
            {
                CreateDirectory(TablesFolder);
                foreach (var data in tableData)
                {
                    if (data.Value.Any() == false && includeEmptyTables == false)
                    {
                        continue;
                    }

                    var table = data.Key;
                    Tuple <int, FileInfo, TableXsd> tableParams;
                    lock (syncRoot)
                    {
                        if (_tableCache.TryGetValue(table, out tableParams) == false)
                        {
                            var tableNo = _tableCache.Count + 1;
                            // Create the table folder.
                            var tableFolder = $@"{TablesFolder}\table{tableNo}";
                            CreateDirectory(tableFolder);
                            // Create file information for table data file.
                            var tableXmlFileInfo = new FileInfo($@"{tableFolder}\table{tableNo}.xml");
                            // Create the XML schema for the table.
                            var tableXsdFileInfo = new FileInfo($@"{tableFolder}\table{tableNo}.xsd");
                            var tableXsd         = ArchiveTableXsd(tableXsdFileInfo, table, tableNo);
                            // Append to cache.
                            _tableCache.Add(table, new Tuple <int, FileInfo, TableXsd>(tableNo, tableXmlFileInfo, tableXsd));
                            tableParams = _tableCache[table];
                        }
                    }

                    var rowCount = ArchiveTableXml(tableParams.Item2, tableParams.Item3, table, data.Value, tableParams.Item1, syncRoot);
                    lock (syncRoot)
                    {
                        _tableIndex.AddTable(table, $"table{tableParams.Item1}", rowCount);
                    }
                }
                lock (syncRoot)
                {
                    _tableIndex.Persist();
                    _fileIndex.Persist();
                }
            }
            catch (TargetInvocationException ex)
            {
                if (ex.InnerException == null)
                {
                    throw new DeliveryEngineRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.RepositoryError, GetType().Name, ex.Message), ex);
                }
                throw new DeliveryEngineRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.RepositoryError, GetType().Name, ex.InnerException.Message), ex.InnerException);
            }
            catch (DeliveryEngineRepositoryException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new DeliveryEngineRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.RepositoryError, GetType().Name, ex.Message), ex);
            }
        }