/// <summary>
        /// 创建Json属性
        /// </summary>
        /// <param name="member">属性</param>
        /// <param name="memberSerialization"></param>
        /// <returns></returns>
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            var property    = base.CreateProperty(member, memberSerialization);
            var annotations = Annotations.GetAnnotations(member, this.formatScope);

            if (string.IsNullOrEmpty(annotations.AliasName) == false)
            {
                property.PropertyName = annotations.AliasName;
            }
            else if (this.useCamelCase == true)
            {
                property.PropertyName = FormatOptions.CamelCase(property.PropertyName);
            }

            if (string.IsNullOrEmpty(annotations.DateTimeFormat) == false)
            {
                property.Converter = new IsoDateTimeConverter {
                    DateTimeFormat = annotations.DateTimeFormat
                };
            }

            if (annotations.IgnoreWhenNull == true)
            {
                property.NullValueHandling = NullValueHandling.Ignore;
            }

            property.Ignored = annotations.IgnoreSerialized;
            return(property);
        }
Ejemplo n.º 2
0
        private void ShowAllAnnotationsForDocumentButton_Click(object sender, EventArgs e)
        {
            var focused = documentsListView.FocusedItem;

            if (focused?.Selected != true || !(focused.Tag is PdfFile file))
            {
                MessageBox.Show("Please select a document first.", "No document selected", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                return;
            }

            var annotations = Annotations.GetAnnotations(file.Md5);

            if (!(annotations?.Count >= 0))
            {
                MessageBox.Show($"There are no existing annotations saved for this document.", "No Saved Annotations for Document", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                return;
            }

            using (var frm = new AllAnnotationsForm(_context, annotations))
            {
                frm.ShowDialog();
                if (frm.DidChangesToAnnotationsInContext)
                {
                    DidChangesToAnnotationsInContext = true;
                }
            }
        }
Ejemplo n.º 3
0
 private void AllAnnotationsForm_Load(object sender, EventArgs e)
 {
     if (_annotations == null)
     {
         _annotations = Annotations.GetAnnotations(true);
     }
     RefreshAnnotationList();
 }
Ejemplo n.º 4
0
        public void AliasNameTest()
        {
            var member = typeof(MyClass).GetProperty("Name");

            var annotations = Annotations.GetAnnotations(member, FormatScope.JsonFormat);

            Assert.Equal("MyName", annotations.AliasName);

            annotations = Annotations.GetAnnotations(member, FormatScope.KeyValueFormat);
            Assert.Equal("MyName", annotations.AliasName);
        }
        public void DateTimeFormatTest()
        {
            var member = typeof(MyClass).GetProperty("Birthday");

            var annotations = Annotations.GetAnnotations(member, FormatScope.JsonFormat);

            Assert.Equal("yyyy年MM月", annotations.DateTimeFormat);

            annotations = Annotations.GetAnnotations(member, FormatScope.KeyValueFormat);
            Assert.Equal("yyyy年MM月", annotations.DateTimeFormat);
        }
Ejemplo n.º 6
0
        public void IgnoreSerializedTest()
        {
            var member = typeof(MyClass).GetProperty("Birthday");

            var annotations = Annotations.GetAnnotations(member, FormatScope.JsonFormat);

            Assert.True(annotations.IgnoreSerialized);

            annotations = Annotations.GetAnnotations(member, FormatScope.KeyValueFormat);
            Assert.True(annotations.IgnoreSerialized);
        }
Ejemplo n.º 7
0
        public void IgnoreWhenNullTest()
        {
            var birthday = typeof(MyClass).GetProperty("Birthday");
            var name     = typeof(MyClass).GetProperty("Name");

            var annotations = Annotations.GetAnnotations(birthday, FormatScope.JsonFormat);

            Assert.False(annotations.IgnoreWhenNull);

            annotations = Annotations.GetAnnotations(birthday, FormatScope.KeyValueFormat);
            Assert.True(annotations.IgnoreWhenNull);

            annotations = Annotations.GetAnnotations(name, FormatScope.KeyValueFormat);
            Assert.False(annotations.IgnoreWhenNull);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 返回成员的名称
        /// </summary>
        /// <param name="member">成员</param>
        /// <returns></returns>
        protected virtual string GetMemberName(MemberInfo member)
        {
            var annotations = Annotations.GetAnnotations(member, FormatScope.JsonFormat);

            if (string.IsNullOrEmpty(annotations.AliasName) == false)
            {
                return(annotations.AliasName);
            }

            var jsonProperty = member.GetCustomAttribute <JsonPropertyAttribute>();

            if (jsonProperty != null && string.IsNullOrEmpty(jsonProperty.PropertyName) == false)
            {
                return(jsonProperty.PropertyName);
            }

            return(member.Name);
        }
Ejemplo n.º 9
0
        private void LoadSavedAnnotationsForOpenFile()
        {
            var saved = Annotations.GetAnnotations(_ctx.OpenFile.Md5);

            if (saved == null)
            {
                (var oldPdf, var annotations) = Annotations.GetAnnotationsByPath(_ctx.OpenFile.Path);
                if (oldPdf == null || annotations == null)
                {
                    return;
                }
                if (MessageBox.Show(
                        $@"There are no saved annotations for the file you opened, but for another file which existed at the same path. 
Possibly you updated the file's contents. Do you want to load the saved annotations corresponding to the old file, which was last modified {oldPdf.LastSeen}?",
                        "File mismatch", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
                saved = annotations;
            }

            var added = 0;

            foreach (var a in saved)
            {
                var wrd = _ctx.Words.FirstOrDefault(w => w.Text == a.Word);
                if (wrd == null)
                {
                    continue;
                }
                AddAnnotation(wrd, a.Content);
                added++;
            }

            if (added != saved.Count)
            {
                MessageBox.Show(
                    $"{added} of {saved.Count} saved annotations had corresponding words in this PDF document and were loaded.",
                    "Not all annotations loaded", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }