Пример #1
0
 public virtual void Commit()
 {
     _isCommiting = true;
     if (!DirectoryInfo.Exists)
     {
         DirectoryInfo.Create();
     }
     foreach (var item in Cached)
     {
         var filename = Path.Combine(RecordsPath, item.Key + ".json");
         if (Removed.Contains(item.Key))
         {
             if (File.Exists(filename))
             {
                 File.Delete(filename);
             }
         }
         else
         {
             if (item.Value.Changed)
             {
                 var json = InvertJsonExtensions.SerializeObject(item.Value);
                 File.WriteAllText(filename, json.ToString(true));
             }
             item.Value.Changed = false;
         }
     }
     _isCommiting = false;
 }
Пример #2
0
        internal void PrescanOneTree()
        {
            var visitor = new AbstractIndexTreeVisitor
            {
                VisitEntry = (m, i, f) =>
                {
                    if (m != null)
                    {
                        if (!f.IsFile())
                        {
                            CheckConflictsWithFile(f);
                        }
                    }
                    else
                    {
                        if (f.Exists)
                        {
                            Removed.Add(i.Name);
                            Conflicts.Remove(i.Name);
                        }
                    }
                }
            };

            new IndexTreeWalker(_index, _merge, _root, visitor).Walk();

            Conflicts.RemoveAll(conflict => Removed.Contains(conflict));
        }
Пример #3
0
        public void Commit()
        {
            _isCommiting = true;
            if (!DirectoryInfo.Exists)
            {
                DirectoryInfo.Create();
            }
            foreach (var item in Cached)
            {
                //filename is calculated inside of the if scopes, because, Path.Combine seems to be a bottleneck. ECSDemoProject took around 4000 invokcations to this method and took average
                //time of 1000ms to process all the Path.Combine.
                if (Removed.Contains(item.Key))
                {
                    var filename = Path.Combine(RecordsPath, item.Key + ".json");

                    if (File.Exists(filename))
                    {
                        File.Delete(filename);
                    }
                }
                else
                {
                    if (item.Value.Changed)
                    {
                        var filename = Path.Combine(RecordsPath, item.Key + ".json");
                        var json     = InvertJsonExtensions.SerializeObject(item.Value);
                        File.WriteAllText(filename, json.ToString(true));
                    }
                    item.Value.Changed = false;
                }
            }
            _isCommiting = false;
        }
Пример #4
0
        internal void PrescanTwoTrees()
        {
            var visitor = new AbstractIndexTreeVisitor
            {
                VisitEntryAux = (treeEntry, auxEntry, indexEntry, file) =>
                {
                    if (treeEntry is Tree || auxEntry is Tree)
                    {
                        throw new ArgumentException("Can't pass me a tree!");
                    }

                    ProcessEntry(treeEntry, auxEntry, indexEntry);
                },

                FinishVisitTree = (tree, auxTree, currentDirectory) =>
                {
                    if (currentDirectory.Length == 0)
                    {
                        return;
                    }
                    if (auxTree == null)
                    {
                        return;
                    }

                    if (_index.GetEntry(currentDirectory) != null)
                    {
                        Removed.Add(currentDirectory);
                    }
                }
            };

            new IndexTreeWalker(_index, _head, _merge, _root, visitor).Walk();

            // if there's a conflict, don't list it under
            // to-be-removed, since that messed up our next
            // section
            Removed.RemoveAll(removed => Conflicts.Contains(removed));

            foreach (string path in _updated.Keys)
            {
                if (_index.GetEntry(path) == null)
                {
                    FileSystemInfo file = new FileInfo(Path.Combine(_root.DirectoryName(), path));
                    if (file.IsFile())
                    {
                        Conflicts.Add(path);
                    }
                    else if (file.IsDirectory())
                    {
                        CheckConflictsWithFile(file);
                    }
                }
            }

            Conflicts.RemoveAll(conflict => Removed.Contains(conflict));
        }
Пример #5
0
        public void RegisterDirty(TModel e)
        {
            TIdentity id = createIdentity(e);

            if (!All.ContainsKey(id))
            {
                return;
            }

            if (!Removed.Contains(e) && !Dirty.Contains(e))
            {
                Dirty.Add(e);
            }
        }
Пример #6
0
        //public void RegisterClean(TModel e)
        //{
        //    Dirty.Remove(e);
        //}

        public TModel RegisterRemoved(TModel e)
        {
            if (New.Remove(e))
            {
                return(e);
            }

            Dirty.Remove(e);
            if (!Removed.Contains(e))
            {
                Removed.Add(e);
            }

            return(e);
        }
Пример #7
0
        public void Add(IDataRecord o)
        {
            if (Removed.Contains(o.Identifier))
            {
                Removed.Remove(o.Identifier);
            }

            o.Changed = true;
            if (string.IsNullOrEmpty(o.Identifier))
            {
                o.Identifier = Guid.NewGuid().ToString();
            }
            o.Repository = this.Repository;
            if (!Cached.ContainsKey(o.Identifier))
            {
                Cached.Add(o.Identifier, o);
                Repository.Signal <IDataRecordInserted>(_ => _.RecordInserted(o));
            }
        }
Пример #8
0
        /// <summary>
        /// Merges a <see cref="ModelValueChangeEvent"/> into the current event.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        protected override bool OnMerge(ModelEvent e)
        {
            // Ensure the events are for the same reference property
            var listChange = (ModelListChangeEvent)e;

            if (listChange.Property != Property)
            {
                return(false);
            }

            // Highly likely not to be right
            var mergeAdded = Added.ToList();

            mergeAdded.RemoveAll(i => listChange.Removed.Contains(i));

            var mergeRemoved = Removed.ToList();

            mergeRemoved.RemoveAll(i => listChange.Added.Contains(i));

            mergeAdded   = mergeAdded.Union(listChange.Added.Where(i => !Removed.Contains(i))).ToList();
            mergeRemoved = mergeRemoved.Union(listChange.Removed.Where(i => !Added.Contains(i))).ToList();

            Added   = mergeAdded.ToArray();
            Removed = mergeRemoved.ToArray();


            var mergeAddedIds = AddedIds.ToList();

            mergeAddedIds.RemoveAll(i => listChange.RemovedIds.Contains(i));

            var mergeRemovedIds = RemovedIds.ToList();

            mergeRemovedIds.RemoveAll(i => listChange.AddedIds.Contains(i));

            mergeAddedIds   = mergeAddedIds.Union(listChange.AddedIds.Where(i => !RemovedIds.Contains(i))).ToList();
            mergeRemovedIds = mergeRemovedIds.Union(listChange.RemovedIds.Where(i => !AddedIds.Contains(i))).ToList();

            AddedIds   = mergeAddedIds.ToArray();
            RemovedIds = mergeRemovedIds.ToArray();

            return(true);
        }
Пример #9
0
        public IEnumerable <IDataRecord> GetAll()
        {
            LoadRecordsIntoCache();

            return(Cached.Values.Where(p => !Removed.Contains(p.Identifier)));
        }
Пример #10
0
 public bool IsRemoved(IDataRecord item)
 {
     return(Removed.Contains(item.Identifier));
 }