public void Add(PhraseCustomization pc) { switch (pc.Type) { case PhraseCustomization.CustomizationType.AdditionAfter: case PhraseCustomization.CustomizationType.InsertionBefore: if (AdditionsAndInsertions.Any(a => a.ModifiedPhrase == pc.ModifiedPhrase || a.Type == pc.Type)) { m_isResolved = false; } AdditionsAndInsertions.Add(pc); break; case PhraseCustomization.CustomizationType.Deletion: Deletions.Add(pc); if (Deletions.Count > 1) { m_isResolved = false; } break; case PhraseCustomization.CustomizationType.Modification: if (Modification != null) { throw new InvalidOperationException("Only one modified version of a question/phrase is permitted. Question/phrase '" + pc.OriginalPhrase + "' has already been modified as '" + Modification.ModifiedPhrase + "'. Value of subsequent modification attempt was: '" + pc.ModifiedPhrase + "'."); } Modification = pc; break; } }
/// <summary> /// Result of a Difference Lines operation /// </summary> /// <param name="items"></param> /// <param name="leftValue"></param> /// <param name="rightValue"></param> public LineDifferenceResult(Item[] items, string leftValue, string rightValue) { var aLines = leftValue.Split('\n'); var bLines = rightValue.Split('\n'); var n = 0; for (var fdx = 0; fdx < items.Length; fdx++) { var aItem = items[fdx]; while ((n < aItem.StartB) && (n < bLines.Length)) { Unchanged.Add(bLines[n]); n++; } for (var m = 0; m < aItem.DeletedA; m++) { Deletions.Add(aLines[aItem.StartA + m]); } while (n < aItem.StartB + aItem.InsertedB) { Additions.Add(bLines[n]); n++; } while (n < bLines.Length) { Unchanged.Add(bLines[n]); n++; } } }
private void PerformRemoves() { if (Deletions.Count == 0) { return; } foreach (var tr in Deletions.ToList()) { _contents.RemoveRef(tr); if (tr == null) { continue; } tr.Completed -= Remove; if (Removed != null) { Removed(this, tr); } } Deletions.Clear(); }
private void RemoveDeletionAndAdditionPair(int iDeletion, int iAddition) { RemoveAddition(iAddition); Deletions.RemoveAt(iDeletion); FinishResolvingIfNoMorePairsCanBeDeleted(); }
public SHDObject(T @object, IObservable <Predicate <T> > visible = null, IObservable <Predicate <T> > enable = null, IConvertible id = null) { Object = @object; if (visible != null) { visible.Select(_ => _(Object)).StartWith(true).Subscribe(_ => IsVisible = true); } else { IsVisible = true; } if (enable != null) { enable.StartWith(_ => true).Select(_ => _(Object)).Subscribe(_ => IsEnabled = true); } else { IsEnabled = true; } DeleteCommand = new RelayCommand(() => { Deletions.OnNext(null); }); Id = id; }
private void FinishResolvingIfNoMorePairsCanBeDeleted() { if (Deletions.Any() && AdditionsAndInsertions.Count > Deletions.Count) { return; } if (AdditionsAndInsertions.Count <= 1) { if (Deletions.Count > 1) { // This should probably be an exception, but maybe we can recover... Deletions.RemoveRange(1, Deletions.Count - 1); Debug.Fail($"There were more deletions than additions for {Deletions.Single().Key}."); } } else if (Deletions.Count <= 1) { // REVIEW: We're assuming that the first (remaining) addition is the "base" one (i.e., any other non-duplicates will // be hanging off of it as an insertion or addition). If this is not true, we'll need to look through the list to find // the first one whose OriginalPhrase is not the ModifiedPhrase of any other addition/insertion in the list. var baseAddition = AdditionsAndInsertions[0].ModifiedPhrase; var i = 0; while (i + 1 < AdditionsAndInsertions.Count) { // We assume that earlier ones in the list are older versions whose answers are less likely to be the most desirable // one, so we delete ealier ones first so that the last one survives (and its answer will be inserted first in the // list. Sadly, this is probably the best we can do. var iNewBase = AdditionsAndInsertions.FindIndex(i + 1, a => a.ModifiedPhrase == baseAddition); if (iNewBase < 0) { break; } RemoveAddition(i); i = iNewBase; } } else { return; } if (AllAnswers.Any()) { var bestAnswer = AdditionsAndInsertions.First().Answer; if (!String.IsNullOrWhiteSpace(bestAnswer) && !AllAnswers.Any(a => a.Contains(bestAnswer))) { AllAnswers.Insert(0, bestAnswer); } else if (AllAnswers.Count == 1) { AdditionsAndInsertions.First().Answer = AllAnswers[0]; AllAnswers = null; } } m_isResolved = true; }
public void Remove(ITransient other) { if (other == null) { return; } Additions.RemoveRef(other); Deletions.Add(other); }
protected void DeferAdd(ITransient other) { if (other == null) { return; } Deletions.RemoveRef(other); Additions.Add(other); }
private void SetExcludedAndModified(Question question) { question.IsExcluded = Deletions.SingleOrDefault() != null; Deletions.Clear(); if (ModifiedPhrase != null) { question.ModifiedPhrase = ModifiedPhrase; Modification = null; } }
public void Clear() { Additions.Clear(); foreach (var tr in Contents) { Deletions.Add(tr); } PerformRemoves(); }
public void Add(params ITransient[] others) { foreach (var other in others) { if (other == null) { continue; } Deletions.RemoveRef(other); Additions.Add(other); } }
/// <summary> /// Adds any deletion parameters. /// </summary> /// <param name="command">The command.</param> private bool AddDeletionParameters(IDbCommand command) { bool haveDeletions = Deletions.Count != 0; if (haveDeletions) { foreach (var pair in Deletions.OrderBy(kvp => kvp.Key)) { string typeName = GetTypeName(pair.Key); command.AddTableValuedParameter(string.Format("@delete{0}", typeName), pair.Value); } } return(haveDeletions); }
public SHDObject(T @object, bool?expanded, bool?selected, bool? @checked, bool?visible, bool?enable, bool isReadOnly, IConvertible id = null) { Object = @object; IsVisible = visible; IsEnabled = enable; IsExpanded = expanded; IsSelected = selected; IsChecked = @checked; IsReadOnly = isReadOnly; DeleteCommand = new RelayCommand(() => { Deletions.OnNext(null); }); Id = id; }
private void PerformRemoves() { if (Deletions.Count == 0) { return; } foreach (var tr in Deletions.ToList()) { _contents.RemoveRef(tr); if (tr == null) { continue; } Kernel.Log.Info("Removing {0} from Node {1}", tr, Name); tr.Completed -= Remove; Removed?.Invoke(this, tr); } Deletions.Clear(); }
private GitProcessDiff( string start, string end, string?since, Additions additions, Deletions deletions, string key, string?link, string organization, DateTimeOffset createdAt, string email ) { _start = start; _end = end; _since = since; _additions = additions; _deletions = deletions; _key = key; _link = link; _organization = organization; _createdAt = createdAt; _email = email; }
public override int GetHashCode() { unchecked { return((Filename != null ? Filename.GetHashCode() : 0) ^ (Additions != null ? Additions.GetHashCode() : 0) ^ (Deletions != null ? Deletions.GetHashCode() : 0) ^ (Changes != null ? Changes.GetHashCode() : 0) ^ (Status != null ? Status.GetHashCode() : 0) ^ (RawUrl != null ? RawUrl.GetHashCode() : 0) ^ (BlobUrl != null ? BlobUrl.GetHashCode() : 0) ^ (Patch != null ? Patch.GetHashCode() : 0) ^ (ContentsUrl != null ? ContentsUrl.GetHashCode() : 0)); } }
public void ReInstate(Guid userId) { Deletions.Add(new Deletion(false, userId, DateTime.UtcNow)); Deleted = false; }
public FakeFilePatch(Deletions deletions, Additions additions) { _deletions = deletions; _additions = additions; }
public VersionControlFilePatch(Deletions deletions, Additions additions) { _deletions = deletions; _additions = additions; }
private void ResolveDeletionsAndAdditions() { if (m_isResolved) { return; } AllAnswers = new List <string>(); FinishResolvingIfNoMorePairsCanBeDeleted(); int iDel = 0; // Pass 1: Exact match between deletion and addition on ModifiedPhrase while (!m_isResolved && iDel < Deletions.Count) { iDel = Deletions.Skip(iDel).IndexOf(d => !String.IsNullOrEmpty(d.ModifiedPhrase)); if (iDel < 0) { break; } // Prefer to delete additions that don't have answers int iAdditionToRemove = AdditionsAndInsertions.IndexOf(a => a.ModifiedPhrase == Deletions[iDel].ModifiedPhrase && String.IsNullOrEmpty(a.Answer)); if (iAdditionToRemove < 0) { iAdditionToRemove = AdditionsAndInsertions.IndexOf(a => a.ModifiedPhrase == Deletions[iDel].ModifiedPhrase); } if (iAdditionToRemove >= 0) { RemoveDeletionAndAdditionPair(iDel, iAdditionToRemove); } } iDel = 0; var iDelOrig = iDel; // Pass 2: Neither deletion nor addition have ModifiedPhrase set while (!m_isResolved && iDel < Deletions.Count) { iDel = Deletions.Skip(iDel).IndexOf(d => String.IsNullOrEmpty(d.ModifiedPhrase)); if (iDel < 0) { break; } // Prefer to delete additions that don't have answers int iAdditionToRemove = AdditionsAndInsertions.IndexOf(a => (String.IsNullOrEmpty(a.ModifiedPhrase) || a.ModifiedPhrase == a.OriginalPhrase) && String.IsNullOrEmpty(a.Answer)); if (iAdditionToRemove < 0) { iAdditionToRemove = AdditionsAndInsertions.IndexOf(a => String.IsNullOrEmpty(a.ModifiedPhrase) || a.ModifiedPhrase == a.OriginalPhrase); } if (iAdditionToRemove >= 0) { RemoveDeletionAndAdditionPair(iDel, iAdditionToRemove); } else if (iDel == iDelOrig) { break; } iDelOrig = iDel; } // Pass 3: Pair 'em up and blow 'em away while (!m_isResolved) { // Prefer to delete additions that don't have answers int iAdditionToRemove = AdditionsAndInsertions.IndexOf(a => String.IsNullOrEmpty(a.Answer)); if (iAdditionToRemove < 0) { iAdditionToRemove = 0; } RemoveDeletionAndAdditionPair(0, iAdditionToRemove); } }
public void Reinstate(Guid userId) { Deleted = false; Deletions.Add(new Deletion(userId, Deleted, DateTime.UtcNow)); }
public void Delete(Guid userId) { Deleted = true; Deletions.Add(new Deletion(userId, Deleted, DateTime.UtcNow)); }
public override int GetHashCode() { unchecked { return((Url != null ? Url.GetHashCode() : 0) ^ (HtmlUrl != null ? HtmlUrl.GetHashCode() : 0) ^ (DiffUrl != null ? DiffUrl.GetHashCode() : 0) ^ (PatchUrl != null ? PatchUrl.GetHashCode() : 0) ^ (IssueUrl != null ? IssueUrl.GetHashCode() : 0) ^ (Number != null ? Number.GetHashCode() : 0) ^ (State != null ? State.GetHashCode() : 0) ^ (Title != null ? Title.GetHashCode() : 0) ^ (Body != null ? Body.GetHashCode() : 0) ^ (BodyHtml != null ? BodyHtml.GetHashCode() : 0) ^ (CreatedAt != null ? CreatedAt.GetHashCode() : 0) ^ (UpdatedAt != null ? UpdatedAt.GetHashCode() : 0) ^ (ClosedAt != null ? ClosedAt.GetHashCode() : 0) ^ (MergedAt != null ? MergedAt.GetHashCode() : 0) ^ (Head != null ? Head.GetHashCode() : 0) ^ (Base != null ? Base.GetHashCode() : 0) ^ (User != null ? User.GetHashCode() : 0) ^ (Merged != null ? Merged.GetHashCode() : 0) ^ (Mergeable != null ? Mergeable.GetHashCode() : 0) ^ (MergedBy != null ? MergedBy.GetHashCode() : 0) ^ (Comments != null ? Comments.GetHashCode() : 0) ^ (Commits != null ? Commits.GetHashCode() : 0) ^ (Additions != null ? Additions.GetHashCode() : 0) ^ (Deletions != null ? Deletions.GetHashCode() : 0) ^ (ChangedFiles != null ? ChangedFiles.GetHashCode() : 0)); } }