/// <summary>
        /// Fill a checked list box with all the tags from a category, and set their check state
        /// A tag will be checked if there is a row in aVew whose aTagColumnName column has the tag value
        /// \note Its expected that aView has already been filtered for a specific item
        /// </summary>

        /*public static void FillCheckedList(CheckedListBox aCheckedList, string aCategoryName,
         *                                 DataView aView, string aTagColumnName)
         * {
         *  aCheckedList.BeginUpdate();
         *  aCheckedList.Items.Clear();
         *  aCheckedList.CheckOnClick = true;
         *
         *  var tagSet = SystemTags.GetTagSet(aCategoryName);
         *  foreach (var tag in tagSet.Tags.Values)
         *  {
         *      int index = aCheckedList.Items.Add(tag, false);
         *      foreach (DataRowView dbRow in aView)
         *      {
         *          if ((int)dbRow[aTagColumnName] == tag.Value)
         *          {
         *              aCheckedList.SetItemChecked(index, true);
         *              break;
         *          }
         *      }
         *  }
         *
         *  aCheckedList.EndUpdate();
         * }*/

        public static void Fill(this CheckedListBox value, string categoryName, int tagSetId)
        {
            Validation.IsNotNull(value, "value");
            Validation.IsNotNullOrEmpty(categoryName, "categoryName");

            value.BeginUpdate();
            value.Items.Clear();
            value.CheckOnClick = true;

            var dbContext         = Program.NinjectKernel.Get <IRealmDbContext>();
            var checkedTagSetList = dbContext.TagSets.Include(x => x.Tags).Where(x => x.Id == tagSetId);

            if (!checkedTagSetList.Any() || checkedTagSetList.Count() > 1)
            {
                value.EndUpdate();
                return;
            }
            var tagList = checkedTagSetList.First().Tags.ToList();

            var tagSet = SystemTags.GetTagSet(categoryName);

            foreach (var tag in tagSet.Tags.Values.Where(tag => tagList.Exists(x => x.Id == tag.Id)))
            {
                value.SetItemChecked(value.Items.Add(tag, false), true);
                break;
            }

            value.EndUpdate();
        }
示例#2
0
 public void AddSystemTag(string name, bool appliesToExpenses, bool appliesToTimesheets)
 {
     if (SystemTags.Any(x => x.Name.Equals(name)))
     {
         throw DuplicateSystemTagException.Create(name);
     }
     ApplyChange(new SystemTagAdded(Id, name, appliesToExpenses, appliesToTimesheets));
 }
示例#3
0
        private void Apply(SystemTagAdded e)
        {
            var systemTag = new SystemTag(e.Name, e.AppliesToExpenses, e.AppliesToTimesheets);
            var newList   = SystemTags.ToList();

            newList.Add(systemTag);
            SystemTags = new ReadOnlyCollection <SystemTag>(newList);
        }
        /// <summary>
        /// Fill a combobox with the tags for a category, and optionally select a specified tag
        /// If nullEntryName is non-empty, then a NULL tag will be added
        /// </summary>
        public static void Fill(this ComboBox value, string categoryName, int selectTag, string nullEntryName)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value), Resources.NullParameterErrorMessage);
            }
            if (string.IsNullOrEmpty(categoryName))
            {
                throw new ArgumentNullException(nameof(categoryName), Resources.NullParameterErrorMessage);
            }
            if (nullEntryName == null)
            {
                throw new ArgumentNullException(nameof(nullEntryName), Resources.NullParameterErrorMessage);
            }

            value.BeginUpdate();
            value.Items.Clear();

            if (nullEntryName.Length > 0)
            {
                var sysTag = new SystemTag(0, nullEntryName);
                var index  = value.Items.Add(sysTag);
                if (sysTag.Id == selectTag)
                {
                    value.SelectedIndex = index;
                }
            }

            var categoryTags = SystemTags.GetTagSet(categoryName);

            foreach (var sysTag in categoryTags.Tags.Values)
            {
                var index = value.Items.Add(sysTag);
                if (sysTag.Id == selectTag)
                {
                    value.SelectedIndex = index;
                }
            }

            if (value.SelectedIndex == -1 && value.Items.Count > 0)
            {
                value.SelectedIndex = 0;
            }

            value.EndUpdate();
        }
        public static void Fill(this CheckedListBox value, string categoryName, bool defaultCheckState)
        {
            Validation.IsNotNull(value, "value");
            Validation.IsNotNullOrEmpty(categoryName, "categoryName");

            value.BeginUpdate();
            value.Items.Clear();
            value.CheckOnClick = true;

            var tagSet = SystemTags.GetTagSet(categoryName);

            foreach (var tag in tagSet.Tags.Values)
            {
                value.Items.Add(tag, defaultCheckState);
            }

            value.EndUpdate();
        }
示例#6
0
        public override XElement Serialize()
        {
            var data = new object[]
            {
                new XElement("ID", _id),
                new XElement("Tags", Tags.Select(p => new XElement("Tag", p)).Cast <object>().ToArray()),
                new XElement("Deleted", _deleted),
                new XElement("ShareURL", _shareURL),
                new XElement("PublishURL", _publicURL),
                new XElement("SystemTags", SystemTags.Select(p => new XElement("STag", p)).Cast <object>().ToArray()),
                new XElement("Content", XHelper.ConvertToC80Base64(_content)),
                new XElement("ModificationDate", XHelper.ToString(ModificationDate)),
                new XElement("CreationDate", XHelper.ToString(_creationDate)),
                new XElement("LocalVersion", _localVersion),
            };

            var r = new XElement("simplenote", data);

            r.SetAttributeValue("plugin", SimpleNotePlugin.Name);
            r.SetAttributeValue("pluginversion", SimpleNotePlugin.Version.ToString());

            return(r);
        }
示例#7
0
        private static ReplaceResult ReplaceImpl(IInput context, Stream input, SystemTags tag, ReplaceTextOptions options, PointF offset, PdfTextStyle style, YesNo useTestMode)
        {
            var outputStream = new MemoryStream();

            try
            {
                using (var reader = new PdfReader(input))
                    using (var stamper = new PdfStamper(reader, outputStream))
                    {
                        var pages = reader.NumberOfPages;
                        for (var page = 1; page <= pages; page++)
                        {
                            var strategy = new CustomLocationTextExtractionStrategy();
                            var cb       = stamper.GetOverContent(page);

                            // Send some data contained in PdfContentByte, looks like the first is always cero for me and the second 100,
                            // but i'm not sure if this could change in some cases.
                            strategy.UndercontentCharacterSpacing  = cb.CharacterSpacing;
                            strategy.UndercontentHorizontalScaling = cb.HorizontalScaling;

                            // It's not really needed to get the text back, but we have to call this line ALWAYS,
                            // because it triggers the process that will get all chunks from PDF into our strategy Object
                            var allStrings   = PdfTextExtractor.GetTextFromPage(reader, page, strategy);
                            var stringsArray = allStrings.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                            // The real getter process starts in the following line
                            var textMatchesFound = strategy.GetExtendedTextLocations(tag.GetDescription(), options).ToList();

                            // Text matches found contains all text with locations, so do whatever you want with it
                            foreach (var match in textMatchesFound)
                            {
                                // Delete tag
                                var bColor = BaseColor.WHITE;
                                cb.SetColorFill(bColor);
                                cb.Rectangle(match.Rect.Left, match.Rect.Bottom, match.Rect.Width, match.Rect.Height);
                                cb.Fill();

                                // Calculates new rectangle
                                var r = BuildRectangleByStrategies(match, tag.GetDescription(), strategy, cb, (string[])stringsArray.Clone(), options);

                                // Add table
                                var table = new PdfPTable(1)
                                {
                                    TotalWidth = r.Width - offset.X
                                };

                                // New text
                                string newText = string.Empty;
                                switch (tag)
                                {
                                case SystemTags.PageNumber:
                                    newText = page.ToString();
                                    break;

                                case SystemTags.TotalPages:
                                    newText = pages.ToString();
                                    break;
                                }

                                table.AddCell(PdfHelper.CreateCell(newText, style, useTestMode));
                                table.WriteSelectedRows(-1, -1, r.X + offset.X, r.Y - offset.Y, cb);
                                cb.Fill();
                            }

                            cb.Fill();
                            cb.Stroke();
                        }

                        stamper.Close();
                        reader.Close();
                    }

                return(ReplaceResult.CreateSuccessResult(new ReplaceResultData
                {
                    Context = context,
                    InputStream = input,
                    OutputStream = new MemoryStream(outputStream.GetBuffer())
                }));
            }
            catch (Exception ex)
            {
                return(ReplaceResult.FromException(
                           ex,
                           new ReplaceResultData
                {
                    Context = context,
                    InputStream = input,
                    OutputStream = input
                }));
            }
        }
示例#8
0
        private void InitAll()
        {
            try
            {
                SystemTags.Init();

                treeBrowse.Nodes.Clear();

                imagesSystem.Images.Clear();
                imagesSystem.Images.Add("openFolder", ShellIcon.extractIconFromFile("shell32.dll", 4, false));
                foreach (var builder in EditorFactory.Builders.Values)
                {
                    imagesSystem.Images.Add(builder.DisplayName, builder.Icon);
                }

                treeBrowse.BeginUpdate();
                treeBrowse.ImageList = imagesSystem;
                tabContent.ImageList = imagesSystem;

                var filterText = txtFilter.Text.Trim();
                Program.MainForm.ProgressStatus.Minimum = 0;
                Program.MainForm.ProgressStatus.Maximum = EditorFactory.Builders.Count;
                Program.MainForm.ProgressStatus.Value   = Program.MainForm.ProgressStatus.Minimum;

                // Initialize the interface with the registered editors
                foreach (var builder in EditorFactory.Builders.Values)
                {
                    if (!builder.IsVisible)
                    {
                        continue;
                    }

                    var dbContext = Program.NinjectKernel.Get <IRealmDbContext>();
                    var classList = dbContext.SystemClasses
                                    .Where(x => x.SystemType == builder.SystemType)
                                    .Where(x => x.ParentClassId == null)
                                    .ToList();

                    if (classList.Count > 1)
                    {
                        throw new EditorException("Multiple parent classes for system [" + builder.SystemType + "]");
                    }

                    if (!classList.Any())
                    {
                        throw new EditorException($"No parent class for system [{builder.SystemType}]");
                    }

                    var classId = classList.First().Id;

                    var rootNode   = new TreeNode(builder.DisplayPlural);
                    var browseInfo = new EditorBrowseInfo(builder.SystemType, builder.DisplayName, classId, 0);
                    rootNode.Tag              = browseInfo;
                    rootNode.ImageKey         = Resources.ClosedFolderImageKey;
                    rootNode.ContextMenuStrip = contextBrowseFolder;

                    rootNode.SetupBrowseTree(builder, true, filterText);
                    if (!builder.HasDelete())
                    {
                        // This will disable for everything...?
                        // contextBrowseNode.Items[0].Enabled = false;
                    }
                    builder.PopulateBrowseNode(rootNode, browseInfo.ClassId, contextBrowseNode, txtFilter.Text.Trim());
                    treeBrowse.Nodes.Add(rootNode);
                    Program.MainForm.ProgressStatus.Value += 1;
                }

                treeBrowse.EndUpdate();
                Application.DoEvents();
                Program.MainForm.SetStatusMessage($"{EditorFactory.Builders.Count} builders initialized.");
                Program.Log.InfoFormat(Resources.TEXT_BUILDER_INIT_SUMMARY.Replace("{0}",
                                                                                   EditorFactory.Builders.Count.ToString()));
            }
            catch (Exception ex)
            {
                Program.Log.Error(ex.Message, ex);
            }
        }
示例#9
0
 private void TagEditorFormFormClosing(object sender, FormClosingEventArgs e)
 {
     SystemTags.Init();
 }