示例#1
0
        public override bool Equals(object other)
        {
            var otherItem = other as CustomInterval;

            if (otherItem == null)
            {
                return(false);
            }

            return(ReferenceName.Equals(otherItem.ReferenceName) &&
                   Start.Equals(otherItem.Start) &&
                   End.Equals(otherItem.End) &&
                   Type.Equals(otherItem.Type));
        }
示例#2
0
        public override bool Equals(object other)
        {
            var otherItem = other as SupplementaryInterval;

            if (otherItem == null)
            {
                return(false);
            }

            return(ReferenceName.Equals(otherItem.ReferenceName) &&
                   Start.Equals(otherItem.Start) &&
                   End.Equals(otherItem.End) &&
                   VariantType.Equals(otherItem.VariantType) &&
                   (Source?.Equals(otherItem.Source) ?? otherItem.Source == null));
        }
示例#3
0
        /// <summary>
        /// Set value for this field.
        /// </summary>
        private void SetValue(string value, FieldValueType fieldValueType)
        {
            if (_range == null)
            {
                return;
            }

            switch (fieldValueType)
            {
            // Set converted value, add hyperlink to range
            case FieldValueType.PlainText:
            {
                _range.Text = (_converter == null) ? value : _converter.Convert(value, Direction.TfsToOther);
                if (!string.IsNullOrEmpty(Hyperlink))
                {
                    _range.Hyperlinks.Add(_range, Hyperlink);
                }

                break;
            }

            case FieldValueType.BasedOnFieldType:
            {
                if (ReferenceName.Equals(FieldReferenceNames.TestSteps))
                {
                    if (string.IsNullOrEmpty(value) == false)
                    {
                        var template =
                            _range.Application.ListGalleries[WdListGalleryType.wdNumberGallery].ListTemplates[1];
                        if (template != null)
                        {
                            _range.ListFormat.ApplyListTemplate(template, false);
                        }
                    }

                    _range.Text = value;
                }
                break;
            }

            case FieldValueType.DropDownList:
            {
                var contentControlsCache = _range.ContentControls;

                if (contentControlsCache.Count != 1)
                {
                    SyncServiceTrace.E("DropDownList value should be set but the field contains not exactly one FormField.");
                    return;
                }

                var dropDown        = contentControlsCache[1];
                var dropDownEntries = dropDown.DropdownListEntries.Cast <ContentControlListEntry>();

                // if we previously assigned allowed values, check the cache. If not read existing values from dropdown list
                var matchingEntry = dropDownEntries.FirstOrDefault(x => x.Value == value);
                if (matchingEntry == null)
                {
                    SyncServiceTrace.E("DropDownList value should be set but the value is not in the lists of possible values.");
                    return;
                }

                matchingEntry.Select();
                break;
            }

            case FieldValueType.HTML:
            {
                if (string.IsNullOrEmpty(value))
                {
                    // if the value is empty then do not use clipboard
                    _range.Text = value;
                }
                else
                {
                    // Fix for 15925. Editing html fields using vs or browser will not always surround text in tags.
                    // Word appears to only parse strings like "A&amp;B" correctly when they are surrounded with tags.
                    if (!(value.StartsWith("<", StringComparison.Ordinal) && value.EndsWith(">", StringComparison.Ordinal)))
                    {
                        value = $"<span>{value}</span>";
                        SyncServiceTrace.W("Automatically surrounded text with span tags");
                    }

                    value = HtmlHelper.AddMissingImageSizeAttributes(value);
                    // value = HtmlHelper.ShrinkImagesAllSamePercentage(value, 0.8f);

                    // Get the range to work with
                    Range range;
                    if (!string.IsNullOrEmpty(Configuration.WordBookmark))
                    {
                        // Set the Bookmarks
                        // If the Text of the range is empty, add some non blank space to help word with its Bookmarks
                        if (string.IsNullOrWhiteSpace(_range.Text))
                        {
                            _range.Text = "&nbsp;";
                        }

                        _range.Bookmarks.Add(Configuration.WordBookmark);
                        range = _range.Bookmarks[Configuration.WordBookmark].Range;
                    }
                    else
                    {
                        range = _range;
                    }

                    // Get the start of actual range to select whole pasted 'thing'
                    var startRange = range.Start;

                    try
                    {
                        WordHelper.PasteSpecial(range, value);
                    }
                    catch (COMException ce)
                    {
                        if (ce.ErrorCode == WordHelper.CommandFailedCode)
                        {
                            _range.Text = string.Empty;
                            SyncServiceTrace.I("HTML-content \"{0}\" was effectively empty and therefore it has been replaced by an empty string.", value);
                        }
                        else
                        {
                            throw;
                        }
                    }

                    // Set the start back to the previous position to set the pasted 'thing' into this range
                    range.Start = startRange;
                    var parser = new PasteStreamParser();
                    parser.ParseAndRepairAfterPaste(value, range);
                }
                break;
            }
            }

            RefreshBookmarks();
        }