Esempio n. 1
0
        private static Conflicts NextClassesAtDifferentAddress(ScheduleList allClasses)
        {
            var conflicts = new Conflicts();
            var message   = "Адреса двух аудиторий, в которых проходят два соседних занятия, различны.";

            var classes = from c in allClasses
                          orderby c.Group.Name, c.Time.Day, c.Time.Number
            select c;

            var prevClass = classes.ElementAt(0);

            for (int i = 1; i < allClasses.Count; ++i)
            {
                var currClass = classes.ElementAt(i);
                if (prevClass.Time.Day == currClass.Time.Day &&
                    currClass.Time.Number - prevClass.Time.Number <= 1 &&
                    prevClass.Classroom.Address != currClass.Classroom.Address)
                {
                    var conflictingClasses = new List <FullClassRecord> {
                        prevClass, currClass
                    };
                    conflicts.Add(new Conflict(message, ConflictType.Warning, conflictingClasses));
                }
            }
            return(conflicts);
        }
Esempio n. 2
0
 private void Add(EntityChange local, EntityChange remote)
 {
     Debug.WriteLine(local != null ? local.Headers : remote.Headers);
     Debug.WriteLine(string.Format("Local value:{0}", local != null ? local.ToString() : "null"));
     Debug.WriteLine(string.Format("Remote value:{0}", remote != null ? remote.ToString() : "null"));
     Conflicts.Add(new Conflict(_entityInfo, local, remote, _syncSessionInfo));
 }
Esempio n. 3
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));
        }
Esempio n. 4
0
        public ApplyTransactionResult Apply(TrackedTransaction trackedTransaction)
        {
            var result = ApplyTransactionResult.Passed;
            var hash   = trackedTransaction.Key.TxId;

            foreach (var coin in trackedTransaction.ReceivedCoins)
            {
                if (UTXOByOutpoint.ContainsKey(coin.Outpoint))
                {
                    result = ApplyTransactionResult.Conflict;
                    Conflicts.Add(coin.Outpoint, hash);
                }
            }

            foreach (var spentOutpoint in trackedTransaction.SpentOutpoints)
            {
                if (_KnownInputs.Contains(spentOutpoint) ||
                    (!UTXOByOutpoint.ContainsKey(spentOutpoint) && SpentUTXOs.Contains(spentOutpoint)))
                {
                    result = ApplyTransactionResult.Conflict;
                    Conflicts.Add(spentOutpoint, hash);
                }
            }
            if (result == ApplyTransactionResult.Conflict)
            {
                return(result);
            }

            _TransactionTimes.Add(trackedTransaction.FirstSeen);

            foreach (var coin in trackedTransaction.ReceivedCoins)
            {
                UTXOByOutpoint.TryAdd(coin.Outpoint, coin);
            }

            if (trackedTransaction.ReceivedCoins.Count == 0 && trackedTransaction.Transaction != null)
            {
                UTXOByOutpoint.Prunable.Add(new Prunable()
                {
                    PrunedBy = hash, TransactionId = hash
                });
            }

            foreach (var spentOutpoint in trackedTransaction.SpentOutpoints)
            {
                if (UTXOByOutpoint.Remove(spentOutpoint, hash))
                {
                    SpentUTXOs.Add(spentOutpoint);
                }
                _KnownInputs.Add(spentOutpoint);
            }
            return(result);
        }
Esempio n. 5
0
        public void ReadManifest(XmlReader reader, PlugIn plugIn)
        {
            if (reader.AttributeCount != 0)
            {
                throw new Exception(PlugInConst.Manifest + " node cannot have attributes.");
            }
            if (reader.IsEmptyElement)
            {
                throw new Exception(PlugInConst.Manifest + " node cannot be empty.");
            }

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    string     nodeName   = reader.LocalName;
                    Properties properties = Properties.ReadFromAttributes(reader);
                    switch (nodeName)
                    {
                    case PlugInConst.ManifestIdentity:
                        AddIdentity(properties["name"], properties["version"], plugIn.PlugInDir);
                        break;

                    case PlugInConst.ManifestDependency:
                        Dependencies.Add(PlugInReference.Create(properties, plugIn.PlugInDir));
                        break;

                    case PlugInConst.ManifestConflict:
                        Conflicts.Add(PlugInReference.Create(properties, plugIn.PlugInDir));
                        break;

                    default:
                        throw new Exception("Unknown node in " + PlugInConst.Manifest + " section:" + nodeName + " plugIn:" + plugIn.PlugInFile);
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (reader.LocalName == PlugInConst.Manifest)
                    {
                        return;
                    }
                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 6
0
        private void CheckConflictsWithFile(FileSystemInfo file)
        {
            if (file.IsDirectory())
            {
                List <string> childFiles = ListFiles(file);
                Conflicts.AddRange(childFiles);
            }
            else
            {
                FileSystemInfo parent = Directory.GetParent(file.FullName);
                if (parent == null)
                {
                    return;
                }

                while (!parent.Equals(_root))
                {
                    if (parent.IsDirectory())
                    {
                        break;
                    }

                    if (parent.IsFile())
                    {
                        Conflicts.Add(Repository.StripWorkDir(_root, parent));
                        break;
                    }

                    parent = Directory.GetParent(parent.FullName);
                    if (parent == null)
                    {
                        return;
                    }
                }
            }
        }
Esempio n. 7
0
        public ApplyTransactionResult Apply(Transaction tx)
        {
            var result = ApplyTransactionResult.Passed;
            var hash   = tx.GetHash();

            for (int i = 0; i < tx.Outputs.Count; i++)
            {
                var output   = tx.Outputs[i];
                var outpoint = new OutPoint(hash, i);
                if (CoinsByOutpoint.ContainsKey(outpoint))
                {
                    result = ApplyTransactionResult.Conflict;
                    Conflicts.Add(outpoint, hash);
                }
            }

            for (int i = 0; i < tx.Inputs.Count; i++)
            {
                var input = tx.Inputs[i];
                if (_KnownInputs.Contains(input.PrevOut) ||
                    (!CoinsByOutpoint.ContainsKey(input.PrevOut) && SpentOutpoints.Contains(input.PrevOut)))
                {
                    result = ApplyTransactionResult.Conflict;
                    Conflicts.Add(input.PrevOut, hash);
                }
            }
            if (result == ApplyTransactionResult.Conflict)
            {
                return(result);
            }

            var matches = MatchScript(tx.Outputs.Select(o => o.ScriptPubKey).ToArray());

            for (int i = 0; i < tx.Outputs.Count; i++)
            {
                var output  = tx.Outputs[i];
                var matched = matches[i];
                if (matched)
                {
                    var outpoint = new OutPoint(hash, i);
                    if (CoinsByOutpoint.TryAdd(outpoint, new Coin(outpoint, output)))
                    {
                        AddEvent(new UTXOEvent()
                        {
                            Received = true, Outpoint = outpoint, TxId = hash
                        });
                    }
                }
            }

            for (int i = 0; i < tx.Inputs.Count; i++)
            {
                var input = tx.Inputs[i];
                if (CoinsByOutpoint.Remove(input.PrevOut))
                {
                    AddEvent(new UTXOEvent()
                    {
                        Received = false, Outpoint = input.PrevOut, TxId = hash
                    });
                    SpentOutpoints.Add(input.PrevOut);
                }
                _KnownInputs.Add(input.PrevOut);
            }
            return(result);
        }
Esempio n. 8
0
        private void ProcessEntry(TreeEntry h, TreeEntry m, GitIndex.Entry i)
        {
            ObjectId iId = (i == null ? null : i.ObjectId);
            ObjectId mId = (m == null ? null : m.Id);
            ObjectId hId = (h == null ? null : h.Id);

            string name = (i != null ? i.Name : (h != null ? h.FullName : m.FullName));

            if (i == null)
            {
                //
                //				    I (index)                H        M        Result
                //			        -------------------------------------------------------
                //			        0 nothing             nothing  nothing  (does not happen)
                //			        1 nothing             nothing  exists   use M
                //			        2 nothing             exists   nothing  remove path from index
                //			        3 nothing             exists   exists   use M

                if (h == null)
                {
                    _updated.Add(name, mId);
                }
                else if (m == null)
                {
                    Removed.Add(name);
                }
                else
                {
                    _updated.Add(name, mId);
                }
            }
            else if (h == null)
            {
                //
                //					  clean I==H  I==M       H        M        Result
                //			         -----------------------------------------------------
                //			        4 yes   N/A   N/A     nothing  nothing  keep index
                //			        5 no    N/A   N/A     nothing  nothing  keep index
                //
                //			        6 yes   N/A   yes     nothing  exists   keep index
                //			        7 no    N/A   yes     nothing  exists   keep index
                //			        8 yes   N/A   no      nothing  exists   fail
                //			        9 no    N/A   no      nothing  exists   fail

                if (m == null || mId.Equals(iId))
                {
                    if (HasParentBlob(_merge, name))
                    {
                        if (i.IsModified(_root, true))
                        {
                            Conflicts.Add(name);
                        }
                        else
                        {
                            Removed.Add(name);
                        }
                    }
                }
                else
                {
                    Conflicts.Add(name);
                }
            }
            else if (m == null)
            {
                //
                //					10 yes   yes   N/A     exists   nothing  remove path from index
                //			        11 no    yes   N/A     exists   nothing  fail
                //			        12 yes   no    N/A     exists   nothing  fail
                //			        13 no    no    N/A     exists   nothing  fail
                //

                if (hId.Equals(iId))
                {
                    if (i.IsModified(_root, true))
                    {
                        Conflicts.Add(name);
                    }
                    else
                    {
                        Removed.Add(name);
                    }
                }
                else
                {
                    Conflicts.Add(name);
                }
            }
            else
            {
                if (!hId.Equals(mId) && !hId.Equals(iId) && !mId.Equals(iId))
                {
                    Conflicts.Add(name);
                }
                else if (hId.Equals(iId) && !mId.Equals(iId))
                {
                    if (i.IsModified(_root, true))
                    {
                        Conflicts.Add(name);
                    }
                    else
                    {
                        _updated.Add(name, mId);
                    }
                }
            }
        }