public void SendDiff(string conferenceId, DiffItem diffItem)
        {
            DiffCommand command = new DiffCommand(conferenceId);

            command.DiffItem = diffItem;
            SendCommand(command);
        }
        // olditem and newitem must be of same type, returning same list of items lists
        private static DiffItem CompareItems(ApiBaseItem oldItem, ApiBaseItem newItem)
        {
            DiffItem diff = new DiffItem();

            diff.DiffType = oldItem == null
                ? DiffType.Added : newItem == null
                    ? DiffType.Removed : DiffType.Changed;
            diff.Item = diff.DiffType == DiffType.Removed
                ? oldItem : newItem;


            ApiBaseItem item = oldItem ?? newItem;

            if (DetailedDetailLog || !(item is IApiType))
            {
                ApiBaseItem[][] oldItemsItems = oldItem?.ApiItemsItems;
                ApiBaseItem[][] newItemsItems = newItem?.ApiItemsItems;
                ApiBaseItem[][] items         = oldItemsItems ?? newItemsItems;

                for (int i = 0; i < items.Length; i++)
                {
                    ApiBaseItem[] oldi = oldItemsItems != null ? oldItemsItems[i] : new ApiBaseItem[0];
                    ApiBaseItem[] newi = newItemsItems != null ? newItemsItems[i] : new ApiBaseItem[0];
                    diff.Children.AddRange(CompareItems(oldi, newi));
                }
            }

            return(diff);
        }
        public async Task <IActionResult> PutDiffItem(long id, DiffItem diffItem)
        {
            if (id != diffItem.id)
            {
                return(BadRequest());
            }

            _context.Entry(diffItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DiffItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <DiffItem> > PostDiffItem(DiffItem diffItem)
        {
            _context.DiffItems.Add(diffItem);
            await _context.SaveChangesAsync();

            //return CreatedAtAction("GetDiffItem", new { id = diffItem.id }, diffItem);
            //CreatedAtAction method returns an HTTP 201 status code if successful (the standard response for an HTTP POST method that creates a new response on the server
            return(CreatedAtAction(nameof(GetDiffItem), new { id = diffItem.id }, diffItem));
        }
Exemple #5
0
 private string objectNameFrom(DiffItem diffItem)
 {
     return
         (displayIf <IFormula>(diffItem, x => ancestorDisplayName(diffItem)) ??
          displayIf <IReactionPartner>(diffItem, x => x.Partner.Name) ??
          displayIf <IReactionPartnerBuilder>(diffItem, x => x.MoleculeName) ??
          displayIf <UsedCalculationMethod>(diffItem, x => x.Category) ??
          displayIf <IObjectPath>(diffItem, x => ancestorDisplayName(diffItem)) ??
          displayIf <ValuePoint>(diffItem, x => ancestorDisplayName(diffItem)) ??
          _displayNameProvider.DisplayNameFor(diffItem.Object1));
 }
Exemple #6
0
 private static void CustomAction(string action, DiffItem item)
 {
     if (action == Actions.Push)
     {
         item.Update(UpdateTypes.AToB);
     }
     else if (action == Actions.Delete)
     {
         item.Update(UpdateTypes.Delete);
     }
 }
Exemple #7
0
 private static bool CheckEnabled(string action, DiffItem item)
 {
     if (action == Actions.Push)
     {
         return(item.Condition == DiffConditions.AOnly || item.Condition == DiffConditions.Different);
     }
     else if (action == Actions.Delete)
     {
         return(item.Condition == DiffConditions.BOnly);
     }
     return(true);
 }
Exemple #8
0
        public List <DiffItem> findDifferences(int currentStateId)
        {
            Dictionary <string, FileItem> dict0 = getFiles(currentStateId - 1);
            Dictionary <string, FileItem> dict1 = getFiles(currentStateId);

            HashSet <string> deletedTopFolders = findDeletedTopFolders(dict0, dict1);

            List <DiffItem> ret = new List <DiffItem>();

            foreach (FileItem oldItem in dict0.Values)
            {
                if (dict1.ContainsKey(oldItem.FullPath))
                {
                    var newItem = dict1.GetValueOrDefault(oldItem.FullPath);

                    if (areDifferent(oldItem, newItem))
                    {
                        DiffItem diff1 = DiffItem.modified(newItem.FullPath, newItem.LastUpdated, newItem.Size);
                        ret.Add(diff1);
                        continue;
                    }

                    continue;
                }

                if (isTopLevelFolder(oldItem, deletedTopFolders))
                {
                    DiffItem diff2 = DiffItem.deletedRecursively(oldItem.FullPath);
                    ret.Add(diff2);
                    continue;
                }

                if (isDescendantOf(oldItem.FullPath, deletedTopFolders))
                {
                    continue;
                }

                DiffItem diff3 = DiffItem.deleted(oldItem.FullPath);
                ret.Add(diff3);
            }

            foreach (FileItem newItem in dict1.Values)
            {
                if (!dict0.ContainsKey(newItem.FullPath))
                {
                    DiffItem diff3 = DiffItem.created(newItem.FullPath, newItem.LastUpdated, newItem.Size);
                    ret.Add(diff3);
                    continue;
                }
            }

            return(ret);
        }
 public DiffItemDTO MapFrom(DiffItem diffItem)
 {
     _diffItemDTO = new DiffItemDTO {
         Description = diffItem.Description
     };
     try
     {
         this.Visit(diffItem);
         return(_diffItemDTO);
     }
     finally
     {
         _diffItemDTO = null;
     }
 }
Exemple #10
0
        private static void ComparePackages(ApiAssembly olda, ApiAssembly newa)
        {
            List <ApiBaseItem> allOld = GetAllItems(olda);

            ApiNamespace[]     oldNss = GetNamespaces(allOld, 1);
            List <ApiBaseItem> allNew = GetAllItems(newa);

            ApiNamespace[]  newNss     = GetNamespaces(allNew, 1);
            List <DiffItem> diffs      = CompareItems(oldNss, newNss).ToList();
            DiffItem        parentDiff = new DiffItem {
                DiffType = DiffType.Changed, Children = diffs, Item = new ApiRoot()
            };

            LogDiffs(parentDiff, "");
        }
Exemple #11
0
        protected override void Context()
        {
            base.Context();
            _diffItem1 = new PropertyValueDiffItem();
            _diffItem2 = new PropertyValueDiffItem();
            _dto1      = new DiffItemDTO();
            _dto2      = new DiffItemDTO();

            _dto1.PathElements[PathElementId.Name] = new PathElement {
                DisplayName = "A"
            };
            _dto2.PathElements[PathElementId.Name] = new PathElement {
                DisplayName = "B"
            };

            _dto1.PathElements[PathElementId.Molecule] = new PathElement {
                DisplayName = "Mol"
            };
            _dto2.PathElements[PathElementId.Molecule] = new PathElement {
                DisplayName = "Mol2"
            };

            _dto1.PathElements[PathElementId.TopContainer] = new PathElement {
                DisplayName = "A"
            };
            _dto2.PathElements[PathElementId.TopContainer] = new PathElement {
                DisplayName = "A"
            };

            _dto1.PathElements[PathElementId.BottomCompartment] = new PathElement {
                DisplayName = ""
            };
            _dto2.PathElements[PathElementId.BottomCompartment] = new PathElement {
                DisplayName = ""
            };


            _report.Add(_diffItem1);
            _report.Add(_diffItem2);
            A.CallTo(() => _diffItemDTOMapper.MapFrom(_diffItem1)).Returns(_dto1);
            A.CallTo(() => _diffItemDTOMapper.MapFrom(_diffItem2)).Returns(_dto2);

            A.CallTo(() => _view.BindTo(A <IEnumerable <DiffItemDTO> > ._))
            .Invokes(x => _allDiffItemDTO = x.GetArgument <IEnumerable <DiffItemDTO> >(0).ToList());
        }
Exemple #12
0
        private static void LogDiffs(DiffItem parentDiff, string prefix)
        {
            IWriter writer = GetWriter(parentDiff);

            if (writer == null)
            {
                return;
            }

            Log($"{prefix}{writer.GetPrefix()}");
            if (writer.Expandable)
            {
                foreach (DiffItem diff in parentDiff.Children)
                {
                    LogDiffs(diff, prefix + Prefix);
                }
            }
            Log($"{prefix}{writer.GetSuffix()}");
        }
Exemple #13
0
        static DiffItem[] CreateDiffs(DiffData diffDataA, DiffData diffDataB)
        {
            var      list = new List <DiffItem>();
            DiffItem item;
            int      startA, startB;
            int      lineA, lineB;

            lineA = 0;
            lineB = 0;
            while (lineA < diffDataA.Length || lineB < diffDataB.Length)
            {
                if ((lineA < diffDataA.Length) && (!diffDataA.modified[lineA]) && (lineB < diffDataB.Length) && (!diffDataB.modified[lineB]))
                {
                    lineA++;
                    lineB++;
                }
                else
                {
                    startA = lineA;
                    startB = lineB;
                    while (lineA < diffDataA.Length && (lineB >= diffDataB.Length || diffDataA.modified[lineA]))
                    {
                        lineA++;
                    }
                    while (lineB < diffDataB.Length && (lineA >= diffDataA.Length || diffDataB.modified[lineB]))
                    {
                        lineB++;
                    }
                    if ((startA < lineA) || (startB < lineB))
                    {
                        item           = new DiffItem();
                        item.StartA    = startA;
                        item.StartB    = startB;
                        item.DeletedA  = lineA - startA;
                        item.InsertedB = lineB - startB;
                        list.Add(item);
                    }
                }
            }
            return(list.ToArray());
        }
Exemple #14
0
 private static IWriter GetWriter(DiffItem diffItem)
 {
     if (diffItem.Item is ApiRoot)
     {
         return(new ApiRootWriter(diffItem, diffTitle));
     }
     if (diffItem.Item is ApiNamespace)
     {
         return(new ApiNamespaceWriter(diffItem));
     }
     if (diffItem.Item is IApiType)
     {
         bool logDetail = DetailedDetailLog && (DetailedRemovedLog || diffItem.DiffType != DiffType.Removed) && diffItem.Children.Any();
         return(new ApiTypeWriter(diffItem, logDetail));
     }
     if (diffItem.Item is IDetail)
     {
         return(new ApiMemberWriter(diffItem));
     }
     return(null);
 }
Exemple #15
0
        public ShowDiffWindow(string oldScript, string newScript)
        {
            InitializeComponent();
            List <DiffItem> diffItems = Diff.DiffTexts(oldScript, newScript);

            for (int i = 0; i < diffItems.Count; i++)
            {
                DiffItem diffItem = diffItems[i];

                BrushConverter bc = new BrushConverter();
                TextRange      tr = new TextRange(scriptText.Document.ContentEnd, scriptText.Document.ContentEnd)
                {
                    Text = diffItem.data + Environment.NewLine
                };
                if (diffItem.type == "Deleted")
                {
                    tr.ApplyPropertyValue(TextElement.BackgroundProperty, "#FFF8FF");
                }
                else if (diffItem.type == "Inserted")
                {
                    tr.ApplyPropertyValue(TextElement.BackgroundProperty, "#F8FFF8");
                }
            }
        }
Exemple #16
0
 public ApiMemberWriter(DiffItem item)
 {
     _item   = item;
     _detail = (item.Item as IDetail) !;
 }
 protected override void Context()
 {
     base.Context();
     _diffItem = new PropertyValueDiffItem();
 }
Exemple #18
0
 private string ancestorDisplayName(DiffItem propertyDiffItem)
 {
     return(_displayNameProvider.DisplayNameFor(propertyDiffItem.CommonAncestor));
 }
 private string ancestorDisplayName(DiffItem propertyDiffItem) => displayNameFor(propertyDiffItem.CommonAncestor);
Exemple #20
0
			/// <summary>
			/// Generates a sequence of DiffItems representing differences in rawDiffStream.
			/// </summary>
			/// <param name="includeUnchangedBlocks">
			/// Indicates whether to generate DiffItems for unchanged blocks.
			/// </param>
			/// <returns>A DiffItem generator.</returns>
			public static IEnumerable<DiffItem> EnumerateDifferences(
				StreamCombiner rawDiffStream, bool includeUnchangedBlocks)
			{
				DiffItem prevItem = null;
				DiffItem item = null;
				string line = null;
				do
				{
					line = rawDiffStream == null ? null : rawDiffStream.ReadLine();

					if (line != null && line.StartsWith("<"))
					{
						++item.BaseLineCount;
					}
					else if (line != null && line.StartsWith("-"))
					{
						continue;
					}
					else if (line != null && line.StartsWith(">"))
					{
						++item.DiffLineCount;
					}
					else if (line != null && line.Equals("\\ No newline at end of file"))
					{   // This is a very annoying perforce thing. But we have to account for it.
						continue;
					}
					else
					{
						if (item != null)
						{
							if (item.DiffLineCount == 0)
								item.DiffType = DiffType.Deleted;
							else if (item.BaseLineCount == 0)
								item.DiffType = DiffType.Added;
							else
								item.DiffType = DiffType.Changed;

							yield return item;
							prevItem = item;
							item = null;
						}

						if (line != null)
						{
							item = new DiffItem();

							Match m = DiffDecoder.Match(line);
							if (!m.Success)
								yield break;

							item.BaseStartLineNumber = Int32.Parse(m.Groups[1].Value);

							// 'a' adds AFTER the line, but we do processing once we get to the line.
							// So we need to really get to the next line.
							if (m.Groups[3].Value.Equals("a"))
								item.BaseStartLineNumber += 1;
						}

						if (includeUnchangedBlocks)
						{
							var unchangedItem = new DiffItem();
							unchangedItem.DiffType = DiffType.Unchanged;
							unchangedItem.BaseStartLineNumber =
								prevItem == null ? 1 : prevItem.BaseStartLineNumber + prevItem.BaseLineCount;
							unchangedItem.BaseLineCount = item == null ?
								int.MaxValue : item.BaseStartLineNumber - unchangedItem.BaseStartLineNumber;
							unchangedItem.DiffLineCount = unchangedItem.BaseLineCount;

							if (unchangedItem.BaseLineCount != 0)
								yield return unchangedItem;
						}
					}
				} while (line != null);
			}
Exemple #21
0
 public ApiTypeWriter(DiffItem item, bool expandable)
 {
     this.item  = item;
     Expandable = expandable;
     api        = item.Item as IApiType;
 }
Exemple #22
0
 public ApiMemberWriter(DiffItem item)
 {
     this.item   = item;
     this.detail = item.Item as IDetail;
 }
Exemple #23
0
 public ApiNamespaceWriter(DiffItem item)
 {
     this.item = item;
     ns        = item.Item as ApiNamespace;
 }
Exemple #24
0
 public ApiRootWriter(DiffItem item, string title)
 {
     this.item  = item;
     this.title = title;
     this.api   = item.Item as ApiNamespace;
 }
        private string displayIf <T>(DiffItem propertyDiffItem, Func <T, string> displayFunc) where T : class
        {
            var castObject = propertyDiffItem.Object1 as T;

            return(castObject == null ? null : displayFunc(castObject));
        }
Exemple #26
0
 public ApiTypeWriter(DiffItem item, bool expandable)
 {
     _item      = item;
     Expandable = expandable;
     _api       = (item.Item as IApiType) !;
 }
Exemple #27
0
 public ApiNamespaceWriter(DiffItem item)
 {
     _item = item;
     _ns   = (item.Item as ApiNamespace) !;
 }
Exemple #28
0
 private DiffItemDTO mapFrom(DiffItem diffItem)
 {
     return(_diffItemDTOMapper.MapFrom(diffItem));
 }
Exemple #29
0
 public void Add(DiffItem diffItem)
 {
     Report.Add(diffItem);
 }