示例#1
0
        /// <summary>
        /// Add a File object to the Set
        /// </summary>
        /// <param name="f"></param>
        /// <param name="f"> </param>
        /// <returns></returns>
        public IFile Add(IFile f)
        {
            if (this.Btree.File.Server.ReadOnly)
            {
                throw new InvalidOperationException("Object Server is in read only mode.");
            }
            if (f == null)
            {
                throw new ArgumentNullException("f");
            }

            return(Locker.Invoke(() =>
            {
                if (!Btree.Contains(f.Name))
                {
                    if (f.Server == null)
                    {
                        f.Server = this.Btree.File.Server;
                    }
                    if (!f.IsOpen)
                    {
                        f.Open();
                    }
                    if (f.IsDirty)
                    {
                        f.Flush();
                    }
                    Btree.Add(f.Name, f);
                    //Btree.Flush();
                    return f;
                }
                throw new ArgumentException(string.Format("File object with Name '{0}' is already in FileSet", f.Name));
            }));
        }
示例#2
0
        static void Main(string[] args)
        {
            Btree Alpha = new Btree(new Node("head"));

            Alpha.Add(Alpha.head, new Node("leaf4"), false);
            Alpha.Add(Alpha.head, new Node("node1"), true);

            Alpha.Add(Alpha.head.getRight(), new Node("leaf3"), false);
            Alpha.Add(Alpha.head.getRight(), new Node("node2"), true);

            Alpha.Add(Alpha.head.getRight().getRight(), new Node("leaf2"), false);
            Alpha.Add(Alpha.head.getRight().getRight(), new Node("leaf1"), true);

            Node output = ParentFinder(Alpha, Alpha.head.getRight().getRight().getRight(), Alpha.head.getRight().getLeft());

            Console.WriteLine("The common parent is " + output.getName() + "!");

            printBTree(Alpha, output);

            Console.WriteLine("Please press enter to end:");
            Console.ReadLine();
        }
示例#3
0
 public void Add(System.Collections.Generic.KeyValuePair <TKey, TValue> item)
 {
     Btree.Add(item.Key, item.Value);
 }
示例#4
0
 /// <summary>
 /// Add adds an entry with the provided key and value into the BTree.
 /// Duplicate keys are allowed in BTree unlike in a Dictionary/HashTable
 /// where key is required to be unique.
 /// </summary>
 /// <param name="key">key of item you want to add to the collection</param>
 /// <param name="value">item you want to add to the collection</param>
 public virtual void Add(TKey key, TValue value)
 {
     Btree.Add(key, value);
 }
示例#5
0
        public Btree <Guid, Bookmark> LoadAllMailboxBookmarks(Bookmark currentDatabaseBookmark)
        {
            ExTraceGlobals.EventAccessTracer.TraceDebug <EventAccess, Bookmark>((long)this.GetHashCode(), "{0}: Loading all mailbox bookmarks. Current database watermark is {1}", this, currentDatabaseBookmark);
            int numberOfActiveMailboxesWithDecayedWatermarks = 0;
            int numberOfStaleMailboxesWithDecayedWatermarks  = 0;
            Dictionary <Guid, MailboxInformation> mailboxesWithDecayedWatermarks = new Dictionary <Guid, MailboxInformation>();
            Btree <Guid, Bookmark> allBookmarks = new Btree <Guid, Bookmark>(100);

            this.CallEventManager(delegate
            {
                long lowestEventCounter = this.GetLowestEventCounter();
                ExTraceGlobals.EventAccessTracer.TraceDebug <EventAccess, long>((long)this.GetHashCode(), "{0}: Lowest Event Counter: {1}", this, lowestEventCounter);
                foreach (AssistantCollectionEntry assistantCollectionEntry in this.assistantCollection)
                {
                    Watermark[] watermarksForAssistant = this.GetWatermarksForAssistant(assistantCollectionEntry.Identity);
                    ExTraceGlobals.EventAccessTracer.TraceDebug <EventAccess, int, LocalizedString>((long)this.GetHashCode(), "{0}: Retrieved {1} watermarks for assistant {2}", this, watermarksForAssistant.Length, assistantCollectionEntry.Instance.Name);
                    foreach (Watermark watermark in watermarksForAssistant)
                    {
                        if (watermark.MailboxGuid == Guid.Empty)
                        {
                            ExTraceGlobals.EventAccessTracer.TraceDebug <EventAccess>((long)this.GetHashCode(), "{0}: Skipping database watermark.", this);
                        }
                        else
                        {
                            if (EventAccess.IsWatermarkBehindEventCounter(watermark.EventCounter, lowestEventCounter))
                            {
                                MailboxInformation mailboxInformation;
                                if (!mailboxesWithDecayedWatermarks.TryGetValue(watermark.MailboxGuid, out mailboxInformation))
                                {
                                    ExTraceGlobals.EventAccessTracer.TraceDebug((long)this.GetHashCode(), "{0}: Found a decayed watermark {1} for mailbox {2} and assistant {3}", new object[]
                                    {
                                        this,
                                        watermark.EventCounter,
                                        watermark.MailboxGuid,
                                        assistantCollectionEntry.Name
                                    });
                                    mailboxInformation = MailboxInformation.Create(this.exRpcAdmin, watermark.MailboxGuid, this.databaseInfo.Guid);
                                    mailboxesWithDecayedWatermarks.Add(watermark.MailboxGuid, mailboxInformation);
                                    if (!mailboxInformation.Active)
                                    {
                                        numberOfStaleMailboxesWithDecayedWatermarks++;
                                    }
                                    else
                                    {
                                        numberOfActiveMailboxesWithDecayedWatermarks++;
                                    }
                                }
                                else
                                {
                                    ExTraceGlobals.EventAccessTracer.TraceDebug((long)this.GetHashCode(), "{0}: Found another decayed watermark {1} for mailbox {2} and assistant {3}", new object[]
                                    {
                                        this,
                                        watermark.EventCounter,
                                        watermark.MailboxGuid,
                                        assistantCollectionEntry.Name
                                    });
                                }
                                if (!mailboxInformation.Active)
                                {
                                    ExTraceGlobals.EventAccessTracer.TraceDebug <EventAccess, Guid>((long)this.GetHashCode(), "{0}: Mailbox {1} was identified as stale.", this, mailboxInformation.MailboxGuid);
                                    this.DeleteWatermark(assistantCollectionEntry.Identity, mailboxInformation.MailboxGuid);
                                    goto IL_2A5;
                                }
                            }
                            Bookmark bookmark;
                            if (!allBookmarks.TryGetValue(watermark.MailboxGuid, out bookmark))
                            {
                                bookmark = Bookmark.CreateFromDatabaseBookmark(watermark.MailboxGuid, currentDatabaseBookmark);
                                allBookmarks.Add(bookmark);
                            }
                            bookmark[assistantCollectionEntry.Identity] = watermark.EventCounter;
                        }
                        IL_2A5:;
                    }
                }
            });
            if (numberOfStaleMailboxesWithDecayedWatermarks != 0 || numberOfActiveMailboxesWithDecayedWatermarks != 0)
            {
                ExTraceGlobals.EventAccessTracer.TraceDebug <EventAccess, int, int>((long)this.GetHashCode(), "{0}: Found a total of {1} active mailbox(s) and {2} stale mailbox(s) with decayed watermarks.", this, numberOfActiveMailboxesWithDecayedWatermarks, numberOfStaleMailboxesWithDecayedWatermarks);
                int           num           = Math.Min(100, numberOfActiveMailboxesWithDecayedWatermarks + numberOfStaleMailboxesWithDecayedWatermarks);
                StringBuilder stringBuilder = new StringBuilder(num * 100);
                using (Dictionary <Guid, MailboxInformation> .Enumerator enumerator = mailboxesWithDecayedWatermarks.GetEnumerator())
                {
                    while (enumerator.MoveNext() && num-- > 0)
                    {
                        stringBuilder.Append(Environment.NewLine);
                        StringBuilder stringBuilder2 = stringBuilder;
                        object[]      array          = new object[4];
                        object[]      array2         = array;
                        int           num2           = 0;
                        KeyValuePair <Guid, MailboxInformation> keyValuePair = enumerator.Current;
                        array2[num2] = keyValuePair.Value.DisplayName;
                        array[1]     = " (";
                        object[] array3 = array;
                        int      num3   = 2;
                        KeyValuePair <Guid, MailboxInformation> keyValuePair2 = enumerator.Current;
                        array3[num3] = keyValuePair2.Key;
                        array[3]     = ")";
                        stringBuilder2.Append(string.Concat(array));
                    }
                }
                base.LogEvent(AssistantsEventLogConstants.Tuple_MailboxesWithDecayedWatermarks, null, new object[]
                {
                    numberOfActiveMailboxesWithDecayedWatermarks,
                    numberOfStaleMailboxesWithDecayedWatermarks,
                    this.databaseInfo.DisplayName,
                    stringBuilder.ToString()
                });
            }
            return(allBookmarks);
        }
示例#6
0
 /// <summary>
 /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"/>.
 /// </summary>
 /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"/>.
 ///                 </param><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.
 ///                 </exception>
 public void Add(KeyValuePair <TKey, TValue> item)
 {
     Locker.Lock();
     Btree.Add(item.Key, item.Value);
     Locker.Unlock();
 }
示例#7
0
 /// <summary>
 /// Adds an element with the provided key and value to the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
 /// </summary>
 /// <param name="key">The object to use as the key of the element to add.
 ///                 </param><param name="value">The object to use as the value of the element to add.
 ///                 </param><exception cref="T:System.ArgumentNullException"><paramref name="key"/> is null.
 ///                 </exception><exception cref="T:System.ArgumentException">An element with the same key already exists in the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
 ///                 </exception><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.IDictionary`2"/> is read-only.
 ///                 </exception>
 public void Add(TKey key, TValue value)
 {
     Locker.Lock();
     Btree.Add(key, value);
     Locker.Unlock();
 }