Exemple #1
0
        private static Dictionary.DictionaryItem GetTop(Dictionary.DictionaryItem item)
        {
            if (!item.IsTopMostItem())
            {
                LogHelper.Debug <SyncDictionaryItems>("is Top Most [{0}]", () => item.IsTopMostItem());
                try
                {
                    if (item.Parent != null)
                    {
                        LogHelper.Debug <SyncDictionaryItems>("parent [{0}]", () => item.Parent.key);
                        return(GetTop(item.Parent));
                    }
                }
                catch (ApplicationException ex)
                {
                    LogHelper.Debug <SyncDictionaryItems>("Exception (just like null)");
                }
                catch (ArgumentException ex)
                {
                    LogHelper.Debug <SyncDictionaryItems>("Exception (just like null)");
                }
            }

            return(item);
        }
Exemple #2
0
        static void DictionaryItem_Deleting(Dictionary.DictionaryItem sender, EventArgs e)
        {
            if (!uSync.EventsPaused)
            {
                lock (_deleteLock)
                {
                    if (sender.hasChildren)
                    {
                        // we get the delets in a backwards order, so we add all the children of this
                        // node to the list we are not going to delete when we get asked to.
                        //
                        foreach (Dictionary.DictionaryItem child in sender.Children)
                        {
                            _dChildren.Add(child.id);
                        }
                    }

                    if (_dChildren.Contains(sender.id))
                    {
                        // this is a child of a parent we have already deleted.
                        _dChildren.Remove(sender.id);
                        LogHelper.Debug <SyncDictionary>("No Deleteing Dictionary item {0} because we deleted it's parent",
                                                         () => sender.key);
                    }
                    else
                    {
                        //actually delete


                        LogHelper.Debug <SyncDictionary>("Deleting Dictionary Item {0}", () => sender.key);

                        // when you delete a tree, the top gets called before the children.
                        //
                        if (!sender.IsTopMostItem())
                        {
                            // if it's not top most, we save it's parent (that will delete)

                            SaveToDisk(GetTop(sender));
                        }
                        else
                        {
                            // it's top we need to delete
                            helpers.XmlDoc.ArchiveFile("Dictionary", sender.key);
                        }
                    }
                }
            }
        }
Exemple #3
0
        public void Dictionary_IsTopMostItem()
        {
            var parent = CreateNew();

            //create a child
            var childId = Dictionary.DictionaryItem.addKey("Test" + Guid.NewGuid().ToString("N"), "", parent.key);

            Assert.IsTrue(childId > 0);
            var child = new Dictionary.DictionaryItem(childId);

            Assert.IsTrue(TypeHelper.IsTypeAssignableFrom <Dictionary.DictionaryItem>(child));

            Assert.IsTrue(parent.IsTopMostItem());
            Assert.IsFalse(child.IsTopMostItem());

            DeleteItem(child);
            DeleteItem(parent);
        }
Exemple #4
0
        public void Dictionary_IsTopMostItem()
        {
            var parent = CreateNew();

            //create a child
            var childId = Dictionary.DictionaryItem.addKey("Test" + Guid.NewGuid().ToString("N"), "", parent.key);

            Assert.IsTrue(childId > 0);
            var child = new Dictionary.DictionaryItem(childId);

            Assert.IsInstanceOfType(child, typeof(Dictionary.DictionaryItem));

            Assert.IsTrue(parent.IsTopMostItem());
            Assert.IsFalse(child.IsTopMostItem());

            DeleteItem(child);
            DeleteItem(parent);
        }