Esempio n. 1
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);
        }
Esempio n. 2
0
        /// <summary>
        /// Deserialize the BPI WITHOUT the DmSet
        /// </summary>
        public static BatchPartInfo DeserializeFromDmSet(DmSet set)
        {
            if (set == null)
            {
                return(null);
            }

            if (!set.Tables.Contains("DotmimSync__BatchPartsInfo"))
            {
                return(null);
            }

            var dmRow = set.Tables["DotmimSync__BatchPartsInfo"].Rows[0];

            var bpi = new BatchPartInfo();

            bpi.Index       = (int)dmRow["Index"];
            bpi.FileName    = dmRow["FileName"] as string;
            bpi.IsLastBatch = (Boolean)dmRow["IsLastBatch"];

            if (dmRow["Tables"] != null)
            {
                var stringTables = dmRow["Tables"] as string;
                var tables       = stringTables.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                bpi.Tables = tables;
            }

            return(bpi);
        }
Esempio n. 3
0
        /// <summary>
        /// Generate a new BatchPartInfo and add it to the current batchInfo
        /// </summary>
        internal BatchPartInfo GenerateBatchInfo(int batchIndex, DmSet changesSet, string batchDirectory)
        {
            var hasData = true;

            if (changesSet == null || changesSet.Tables.Count == 0)
            {
                hasData = false;
            }
            else
            {
                hasData = changesSet.Tables.Any(t => t.Rows.Count > 0);
            }

            if (!hasData)
            {
                return(null);
            }

            BatchPartInfo bpi = null;

            // Create a batch part
            // The batch part creation process will serialize the changesSet to the disk
            if (!InMemory)
            {
                var bpId     = GenerateNewFileName(batchIndex.ToString());
                var fileName = Path.Combine(batchDirectory, this.Directory, bpId);

                bpi = BatchPartInfo.CreateBatchPartInfo(batchIndex, changesSet, fileName, false, false);
            }
            else
            {
                bpi = BatchPartInfo.CreateBatchPartInfo(batchIndex, changesSet, null, true, true);
            }

            // add the batchpartinfo tp the current batchinfo
            this.BatchPartsInfo.Add(bpi);

            return(bpi);
        }
Esempio n. 4
0
        /// <summary>
        /// Serialize the BatchPartInfo WITHOUT the DmSet
        /// </summary>
        internal static void SerializeInDmSet(DmSet set, BatchPartInfo bpi)
        {
            if (set == null)
            {
                return;
            }

            DmTable dmTableBatchPartsInfo = null;

            if (!set.Tables.Contains("DotmimSync__BatchPartsInfo"))
            {
                dmTableBatchPartsInfo = new DmTable("DotmimSync__BatchPartsInfo");
                set.Tables.Add(dmTableBatchPartsInfo);
            }

            dmTableBatchPartsInfo = set.Tables["DotmimSync__BatchPartsInfo"];

            dmTableBatchPartsInfo.Columns.Add <String>("FileName");
            dmTableBatchPartsInfo.Columns.Add <int>("Index");
            dmTableBatchPartsInfo.Columns.Add <Boolean>("IsLastBatch");
            dmTableBatchPartsInfo.Columns.Add <String>("Tables");

            var dmRow = dmTableBatchPartsInfo.NewRow();

            dmRow["FileName"]    = bpi.FileName;
            dmRow["Index"]       = bpi.Index;
            dmRow["IsLastBatch"] = bpi.IsLastBatch;

            if (bpi.Tables != null && bpi.Tables.Length > 0)
            {
                var tablesString = String.Join("|", bpi.Tables);
                dmRow["Tables"] = tablesString;
            }

            dmTableBatchPartsInfo.Rows.Add(dmRow);
        }