Exemple #1
0
        /// <summary>
        /// Get all parts containing this table
        /// Could be multiple parts, since the table may be spread across multiples files
        /// </summary>
        public IEnumerable <DmTable> GetTable(string tableName)
        {
            foreach (var batchPartinInfo in this.BatchPartsInfo)
            {
                bool isSerialized = false;

                if (batchPartinInfo.Tables.Contains(tableName))
                {
                    // Batch not readed, so we deserialized the batch and get the table
                    if (batchPartinInfo.Set == null)
                    {
                        // Set is not already deserialized so we try to get the batch
                        BatchPart batchPart = batchPartinInfo.GetBatch();

                        // Unserialized and set in memory the DmSet
                        batchPartinInfo.Set = batchPart.DmSetSurrogate.ConvertToDmSet();

                        isSerialized = true;
                    }

                    // return the table
                    if (batchPartinInfo.Set.Tables.Contains(tableName))
                    {
                        yield return(batchPartinInfo.Set.Tables[tableName]);

                        if (isSerialized)
                        {
                            batchPartinInfo.Set.Clear();
                            batchPartinInfo.Set = null;
                        }
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Create a new BPI, and serialize the changeset if not in memory
        /// </summary>
        internal static BatchPartInfo CreateBatchPartInfo(int batchIndex, DmSet changesSet, string fileName, Boolean isLastBatch, Boolean inMemory)
        {
            BatchPartInfo bpi = null;

            // Create a batch part
            // The batch part creation process will serialize the changesSet to the disk
            if (!inMemory)
            {
                // Serialize the file !
                BatchPart.Serialize(new DmSetSurrogate(changesSet), fileName);

                bpi = new BatchPartInfo {
                    FileName = fileName
                };
            }
            else
            {
                bpi = new BatchPartInfo {
                    Set = changesSet
                };
            }

            bpi.Index       = batchIndex;
            bpi.IsLastBatch = isLastBatch;

            // Even if the set is empty (serialized on disk), we should retain the tables names
            bpi.Tables = changesSet.Tables.Select(t => t.TableName).ToArray();

            return(bpi);
        }
Exemple #3
0
 /// <summary>
 /// Delete the DmSet surrogate affiliated with the BatchPart, if exists.
 /// </summary>
 public void Clear()
 {
     if (this.batch != null)
     {
         this.batch.Clear();
         this.batch = null;
     }
     if (this.Set != null)
     {
         this.Set.Clear();
         this.Set = null;
     }
 }
Exemple #4
0
        /// <summary>
        /// Gets or sets the batch file included in this batch part
        /// </summary>
        public BatchPart GetBatch()
        {
            if (batch != null)
            {
                return(batch);
            }

            if (String.IsNullOrEmpty(this.FileName))
            {
                throw new ArgumentException("Cant get a batchpart if filename is null");
            }

            // Get a Batch part, and deserialise the file into a DmSetSurrogate
            batch = BatchPart.Deserialize(this.FileName);

            return(batch);
        }
        public static BatchPart Deserialize(string fileName)
        {
            if (String.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("Cant get a Batch part if fileName doesn't exist");
            }

            if (!File.Exists(fileName))
            {
                throw new ArgumentException($"file {fileName} doesn't exist");
            }

            BatchPart bp = new BatchPart();

            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                BinaryFormatter serializer = new BinaryFormatter();
                bp.DmSetSurrogate = serializer.Deserialize(fs) as DmSetSurrogate;
            }

            return(bp);
        }