Esempio n. 1
0
        internal static bool GetIntersectingLogs(BackupDataLogKey logKey, int logKeySize,
                                                 out IEnumerable <KeyValuePair <BackupDataLogKey, BackupDataLogValue> >
                                                 target,
                                                 out long startMergedBlockAddress, out long mergedBlockSize)
        {
            target = null;

            startMergedBlockAddress = mergedBlockSize = 0;
            var l = new List <KeyValuePair <BackupDataLogKey, BackupDataLogValue> >();

            if (!LogCollection.Search(logKey))
            {
                if (!LogCollection.MovePrevious())
                {
                    if (!LogCollection.MoveFirst())
                    {
                        return(false);
                    }
                }
            }
            long address1 = logKey.SourceDataAddress;
            int  size1    = logKeySize;

            startMergedBlockAddress = address1;
            mergedBlockSize         = size1;
            bool intersected = false;

            for (int i = 0; i < 3; i++)
            {
                var key   = LogCollection.CurrentKey;
                var value = LogCollection.CurrentValue;
                if (logKey.SourceFilename == key.SourceFilename)
                {
                    long address2 = key.SourceDataAddress;
                    int  size2    = value.DataSize;
                    if (RegionLogic.FirstWithinSecond(address1, size1, address2, size2))
                    {
                        return(true);
                    }
                    if (RegionLogic.Intersect(address1, size1, address2, size2))
                    {
                        l.Add(new KeyValuePair <BackupDataLogKey, BackupDataLogValue>(key, value));
                        i           = 0;
                        intersected = true;
                        if (address2 < startMergedBlockAddress)
                        {
                            startMergedBlockAddress = address2;
                        }
                        if (startMergedBlockAddress + mergedBlockSize < address2 + size2)
                        {
                            long l2 = address2 + size2 - startMergedBlockAddress;
                            if (l2 >= int.MaxValue)
                            {
                                break;
                            }
                            mergedBlockSize = l2;
                        }
                    }
                    else if (intersected)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                if (!LogCollection.MoveNext())
                {
                    break;
                }
            }
            if (l.Count > 0)
            {
                target = l;
                return(true);
            }
            return(false);
        }