示例#1
0
        private static IEnumerable <TestResult> GetResult(TestArguments arguments)
        {
            //Prepare data
            var blockCollection = new BlockCollection <int>();

            for (int i = 0; i < BlockCount; i++)
            {
                blockCollection.Add(GetFilledBlock(ElementsInBlockCount));
            }

            var blockStructure = new ArrayMap <int>(new FixedBalancer(), blockCollection);

            //Prepare measure engine
            var method = GetMethodInfo(arguments.MethodName);

            foreach (var currentCount in arguments.TestCountArray)
            {
                List <object> argumentList = new List <object> {
                    blockStructure, currentCount
                };

                //Get middle estimation of several times calling
                long timeOfAllInvoketionsMs = 0;
                int  countOfInvokations     = 3;

                for (int i = 0; i < countOfInvokations; i++)
                {
                    timeOfAllInvoketionsMs += MeasureEngine.MeasureStaticMethod(method, argumentList);
                }

                yield return(new TestResult(currentCount, timeOfAllInvoketionsMs / countOfInvokations));
            }
        }
示例#2
0
        public FlowDocument GetFlowDocument()
        {
            FlowDocument doc = (FlowDocument)Application.LoadComponent(
                new Uri("/Daytimer.DatabaseHelpers;component/Templates/NoteTemplate.xaml",
                        UriKind.Relative));

            NotebookSection section  = NoteDatabase.GetSection(_page.SectionID);
            Notebook        notebook = NoteDatabase.GetNotebook(section.NotebookID);

            ((Paragraph)doc.FindName("Title")).Inlines.Add(_page.Title);
            ((Paragraph)doc.FindName("Created")).Inlines.Add(FormatHelpers.FormatDate(_page.Created.Date) + " "
                                                             + RandomFunctions.FormatTime(_page.Created.TimeOfDay));
            ((Paragraph)doc.FindName("Notebook")).Inlines.Add(notebook.Title);
            ((Paragraph)doc.FindName("Section")).Inlines.Add(section.Title);

            Section details = (Section)doc.FindName("Details");

            FlowDocument detailsDoc = _page.DetailsDocument;

            if (detailsDoc != null)
            {
                BlockCollection blocks = _page.DetailsDocument.Copy().Blocks;

                while (blocks.Count > 0)
                {
                    details.Blocks.Add(blocks.FirstBlock);
                }
            }

            return(doc);
        }
示例#3
0
 private void LoadDataSource()
 {
     try
     {
         _blocks = BlockCollection.Load(Config.ConfigFolder + BlockCollection.BadBlocksFile);
         if (_blocks == null)
         {
             _blocks = new BlockCollection();
         }
     }
     catch
     {
         _blocks = new BlockCollection();
     }
     try
     {
         comboBoxItems.ValueMember   = "Value";
         comboBoxItems.DisplayMember = "Name";
         comboBoxItems.DataSource    = new BindingSource(ItemDictonary.GetInstance(), null);
     }
     catch
     {
     }
     dgvBadBlocks.DataSource = new BindingSource(_blocks, null);
 }
 /// <summary>
 /// Called to render a block element.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="currentBlocks"></param>
 private void RendnerBlock(MarkdownBlock element, BlockCollection currentBlocks)
 {
     switch (element.Type)
     {
         case MarkdownBlockType.Paragraph:
             RenderPargraph((ParagraphBlock)element, currentBlocks);
             break;
         case MarkdownBlockType.Quote:
             RenderQuote((QuoteBlock)element, currentBlocks);
             break;
         case MarkdownBlockType.Code:
             RenderCode((CodeBlock)element, currentBlocks);
             break;
         case MarkdownBlockType.Header:
             RenderHeader((HeaderBlock)element, currentBlocks);
             break;
         case MarkdownBlockType.ListElement:
             RenderListElement((ListElementBlock)element, currentBlocks);
             break;
         case MarkdownBlockType.HorizontalRule:
             RenderHorizontalRule((HorizontalRuleBlock)element, currentBlocks);
             break;
         case MarkdownBlockType.LineBreak:
             RenderLineBreak((LineBreakBlock)element, currentBlocks);
             break;
     }
 }
 public override object Render(MarkdownObject markdownObject)
 {
     Root   = new FlowDocument();
     Blocks = Root.Blocks;
     Write(markdownObject);
     return(null);
 }
 public InlineUIContainer GetUIElementUnderSelection() {
     BlockCollection col = Document.Blocks;
     if(Selection.Start.GetNextInsertionPosition(LogicalDirection.Forward) == null ||
         Selection.Start.GetNextInsertionPosition(LogicalDirection.Forward).CompareTo(Selection.End) != 0)
         return null;
     return GetUIElementUnderSelection(col);
 }
 private void WalkDocumentTree(Action <TextElement> action, BlockCollection bc)
 {
     foreach (Block block in bc)
     {
         if (block is Section)
         {
             WalkDocumentTree(action, (Section)block);
         }
         else if (block is Paragraph)
         {
             WalkDocumentTree(action, (Paragraph)block);
         }
         else if (block is List)
         {
             WalkDocumentTree(action, (List)block);
         }
         else if (block is Table)
         {
             WalkDocumentTree(action, (Table)block);
         }
         else if (block is BlockUIContainer)
         {
             WalkDocumentTree(action, (BlockUIContainer)block);
         }
         else
         {
             System.Diagnostics.Debug.Fail("TextElement type not matched ??");
         }
     }
 }
示例#8
0
        private static void WriteObject(BlockCollection blocks, HashSet <object> objects, object o)
        {
            if (o == null)
            {
                blocks.Add(CreatePara(new Run("<null>")));
                return;
            }

            if (!(o is string))
            {
                var enumerable = o as IEnumerable;
                if (enumerable != null)
                {
                    WriteEnumerable(blocks, objects, enumerable);
                    return;
                }
            }

            if (o is UIElement)
            {
                blocks.Add(CreatePara(new Figure(new BlockUIContainer((UIElement)o))));
                return;
            }



            WriteProperties(blocks, objects, o);
        }
 public void InsertParagraph(BlockCollection block, InlineCollection inlineCollection, IEnumerable <RichTextItem> items)
 {
     foreach (var item in items)
     {
         if (item.TextType == RichTextType.Text)
         {
             inlineCollection.Add(new Run(item.Text)
             {
                 Foreground = new SolidColorBrush(item.Foreground)
             });
         }
         else if (item.TextType == RichTextType.Hyperlink)
         {
             var hyperlink = new Hyperlink()
             {
                 NavigateUri = new Uri(item.Link)
             };
             InsertParagraph(block, hyperlink.Inlines, item.Children);
             inlineCollection.Add(hyperlink);
         }
         else
         {
             var paragraph = new Paragraph()
             {
                 Margin = new Thickness(0, 3, 0, 3)
             };
             InsertParagraph(block, paragraph.Inlines, item.Children);
             block.Add(paragraph);
         }
     }
 }
示例#10
0
        //=====================================================================

        /// <summary>
        /// This extension method is used to append the content of a flow document stored as a resource
        /// to the given flow document block collection.
        /// </summary>
        /// <param name="blocks">The block collection to which the elements are added</param>
        /// <param name="resourceName">The fully qualified name of the flow document resource</param>
        public static void AppendFrom(this BlockCollection blocks, string resourceName)
        {
            if (blocks == null)
            {
                throw new ArgumentNullException(nameof(blocks));
            }

            try
            {
                using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                {
                    FlowDocument flowDocument = (FlowDocument)XamlReader.Load(s);

                    foreach (var b in flowDocument.Blocks.ToArray())
                    {
                        flowDocument.Blocks.Remove(b);
                        blocks.Add(b);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format(CultureInfo.CurrentCulture, "Unable to load flow document " +
                                              "resource '{0}'.\r\n\r\nReason: {1}", resourceName, ex.Message), "Installer",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#11
0
        public BlockView()
        {
            //Initialize
            blocks         = new BlockCollection(this);
            verticalScroll = new VScrollBar();

            //
            // verticalScroll
            //
            verticalScroll.Scroll     += VerticalScroll_Scroll;
            verticalScroll.Dock        = DockStyle.Right;
            verticalScroll.Visible     = false;
            verticalScroll.LargeChange = 1;
            verticalScroll.SmallChange = 1;
            verticalScroll.Value       = 0;
            verticalScroll.Maximum     = 1;

            //
            // this
            //
            DoubleBuffered = true;
            Size           = new Size(150, 150);
            Controls.Add(verticalScroll);
            BackColor = Color.Gainsboro;
        }
示例#12
0
        public InlineUIContainer GetUIElementUnderSelection(BlockCollection blocks) {
            foreach(Block block in blocks) {
                Paragraph ph = block as Paragraph;
                if(ph != null) {
                    foreach(object obj in ph.Inlines) {
                        if(obj is Run)
                            continue;
                        InlineUIContainer cont = obj as InlineUIContainer;
                        if(cont != null && cont.ContentStart.CompareTo(Selection.Start) > 0 && cont.ContentStart.CompareTo(Selection.End) < 0) {
                            return cont;
                        }
                    }
                }
 else {
                    List lst = block as List;
                    if(lst != null) {
                        foreach(ListItem lstItem in lst.ListItems) {
                            InlineUIContainer retVal = GetUIElementUnderSelection(lstItem.Blocks);
                            if(retVal != null)
                                return retVal;
                        }
                    }
                }
            }
            return null;

        }
示例#13
0
        void AddSection(Inline title, Action addChildren)
        {
            var section = new Section();

            AddBlock(section);
            var oldBlockCollection = blockCollection;

            try
            {
                blockCollection  = section.Blocks;
                inlineCollection = null;

                if (title != null)
                {
                    AddInline(new Bold(title));
                }

                addChildren();
                FlushAddedText(false);
            }
            finally
            {
                blockCollection  = oldBlockCollection;
                inlineCollection = null;
            }
        }
示例#14
0
 public static IEnumerable <T> FindDocumentChildren <T>(BlockCollection blocks)
 {
     foreach (var childOfChild in blocks)
     {
         if (childOfChild is T t)
         {
             yield return(t);
         }
         else if (childOfChild is Paragraph p)
         {
             foreach (var childOfChildOfChild in p.Inlines)
             {
                 if (childOfChildOfChild is T t2)
                 {
                     yield return(t2);
                 }
             }
         }
         else if (childOfChild is Section s)
         {
             foreach (var thing in FindDocumentChildren <T>(s.Blocks))
             {
                 yield return(thing);
             }
         }
     }
 }
示例#15
0
        /// <summary>
        /// Transforms equation object into a tex representation
        /// </summary>
        /// <param name="c">block collection</param>
        public void ToDocument(BlockCollection c)
        {
            Paragraph p = new Paragraph();

            p.Margin = new System.Windows.Thickness(50.0d, 0, 0, 0);
            if (this.IsTexMode)
            {
                Run r = new Run("Réponse:");
                r.Foreground = System.Windows.Media.Brushes.GreenYellow;
                p.Inlines.Add(new Underline(r));
                p.Inlines.Add(new LineBreak());
                this.InsertPhraseIntoDocument(p, this.Get(proposalName), null);
                p.Inlines.Add(new LineBreak());
            }
            else
            {
                Run r = new Run("Réponse:");
                r.Foreground = System.Windows.Media.Brushes.GreenYellow;
                p.Inlines.Add(new Underline(r));
                p.Inlines.Add(new LineBreak());
                p.Inlines.Add(this.Get(proposalName));
                p.Inlines.Add(new LineBreak());
            }
            c.Add(p);
            this.Get(showName).ToDocument(c);
        }
        /// <summary>
        /// Called to render a block element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="currentBlocks"></param>
        private void RendnerBlock(MarkdownBlock element, BlockCollection currentBlocks)
        {
            switch (element.Type)
            {
            case MarkdownBlockType.Paragraph:
                RenderPargraph((ParagraphBlock)element, currentBlocks);
                break;

            case MarkdownBlockType.Quote:
                RenderQuote((QuoteBlock)element, currentBlocks);
                break;

            case MarkdownBlockType.Code:
                RenderCode((CodeBlock)element, currentBlocks);
                break;

            case MarkdownBlockType.Header:
                RenderHeader((HeaderBlock)element, currentBlocks);
                break;

            case MarkdownBlockType.ListElement:
                RenderListElement((ListElementBlock)element, currentBlocks);
                break;

            case MarkdownBlockType.HorizontalRule:
                RenderHorizontalRule((HorizontalRuleBlock)element, currentBlocks);
                break;

            case MarkdownBlockType.LineBreak:
                RenderLineBreak((LineBreakBlock)element, currentBlocks);
                break;
            }
        }
示例#17
0
        public MainWindow()
        {
            InitializeComponent();
            PrevNetworkDimText = Tb_NetworkDimensions.Text;
            Output = Rtb_Out.Document.Blocks;
            Network = new NetworkGuiLink();
            DataContext = Network;
            Network.PropertyChanged += NetworkPropertyChanged;

            //Defaults
            Tb_ImgDimensions.Text = "12";
            Tb_ImgPath.Text = @"E:\Handwriting Data\HSF_0";
            Tb_LearnRate.Text = "0.001";
            Tb_LoadBatchSize.Text = "300";
            Tb_MicroBatchSize.Text = "1"; //Using micro batches improves parallelism but severely degrades effectivity of backpropagation
            Tb_NetworkDimensions.Text = "144*30*10";
            Rb_Charset_Digits.IsChecked = true;
            Rb_TFunc_HyperTan.IsChecked = true;

            Closing += (s, a) => {
                Network?.Dispose();
            };

            Log("UI init complete!");
        }
示例#18
0
 /// <summary>
 /// Update the view from the view model
 /// </summary>
 private void UpdateFromViewModel()
 {
     if (DataContext is TextFormatterViewModel)
     {
         // Update the View from the ViewModel (ideally we would automatically data-bind to the RichTextBox,
         // but this does not appear to be supported, so we do it manually here).
         var             textForDisplay = ((TextFormatterViewModel)DataContext).FormattedText;
         BlockCollection blocks         = MainTextBox.Document.Blocks;
         for (int i = 0; i < blocks.Count && i < textForDisplay.Count; ++i)
         {
             if (blocks.ElementAt <Block>(i) is Paragraph)
             {
                 // Clear all of the inlines from the paragraph and then add them back from textForDisplay
                 Paragraph p = (Paragraph)blocks.ElementAt <Block>(i);
                 p.Inlines.Clear();
                 foreach (var txtElem in textForDisplay[i])
                 {
                     p.Inlines.Add(new Run(txtElem.Item1)
                     {
                         Foreground = txtElem.Item2 ? Brushes.Red : Brushes.Black
                     });
                 }
             }
         }
     }
 }
示例#19
0
        private static T FindBlock <T>(BlockCollection blocks, TextPointer position) where T : Block
        {
            T     result = null;
            Block block  = blocks.FirstOrDefault(x => x.ContentStart.CompareTo(position) == -1 && x.ContentEnd.CompareTo(position) == 1);

            if (block is T)
            {
                result = (T)block;
            }
            else if (block is Table)
            {
                Table table = (Table)block;
                foreach (TableRowGroup rowGroup in table.RowGroups)
                {
                    foreach (TableRow row in rowGroup.Rows)
                    {
                        foreach (TableCell cell in row.Cells)
                        {
                            result = FindBlock <T>(cell.Blocks, position);
                            if (result != null)
                            {
                                return(result);
                            }
                        }
                    }
                }
            }

            return(result);
        }
示例#20
0
        public FlowDocument GetFlowDocument()
        {
            FlowDocument doc = (FlowDocument)Application.LoadComponent(
                new Uri("/Daytimer.DatabaseHelpers;component/Templates/AppointmentTemplate.xaml",
                        UriKind.Relative));

            string subject = _appointment.FormattedSubject;

            ((Paragraph)doc.FindName("Subject")).Inlines.Add(!string.IsNullOrEmpty(subject) ? subject : "(No Subject)");
            ((Paragraph)doc.FindName("Where")).Inlines.Add(_appointment.Location);
            ((Paragraph)doc.FindName("When")).Inlines.Add(GetWhen());
            ((Paragraph)doc.FindName("ShowAs")).Inlines.Add(GetShowAs());
            ((Paragraph)doc.FindName("Recurrence")).Inlines.Add(
                _appointment.IsRepeating ? _appointment.Recurrence.ToString().Capitalize()
                                : "None");

            Section details = (Section)doc.FindName("Details");

            FlowDocument detailsDoc = _appointment.DetailsDocument;

            if (detailsDoc != null)
            {
                BlockCollection blocks = detailsDoc.Copy().Blocks;

                while (blocks.Count > 0)
                {
                    details.Blocks.Add(blocks.FirstBlock);
                }
            }

            return(doc);
        }
        /// <summary>
        /// Renders a horizontal rule element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="currentBlocks"></param>
        private void RenderHorizontalRule(HorizontalRuleBlock element, BlockCollection currentBlocks)
        {
            // This is going to be weird. To make this work we need to make a UI element
            // and fill it with text to make it stretch. If we don't fill it with text I can't
            // make it stretch the width of the box, so for now this is an "ok" hack.
            InlineUIContainer contianer = new InlineUIContainer();
            Grid grid = new Grid();

            grid.Height     = 2;
            grid.Background = new SolidColorBrush(Color.FromArgb(255, 153, 153, 153));

            // Add the expanding text block.
            TextBlock magicExpandingTextBlock = new TextBlock();

            magicExpandingTextBlock.Foreground = new SolidColorBrush(Color.FromArgb(255, 153, 153, 153));
            magicExpandingTextBlock.Text       = "This is Quinn writing magic text. You will never see this. Like a ghost! I love Marilyn Welniak! This needs to be really long! RRRRREEEEEAAAAALLLLYYYYY LLLOOOONNNGGGG. This is Quinn writing magic text. You will never see this. Like a ghost! I love Marilyn Welniak! This needs to be really long! RRRRREEEEEAAAAALLLLYYYYY LLLOOOONNNGGGG";
            grid.Children.Add(magicExpandingTextBlock);

            // Add the grid.
            contianer.Child = grid;

            // Make the new horizontal rule paragraph
            Paragraph horzPara = new Paragraph();

            horzPara.Margin = new Thickness(0, 12, 0, 12);
            horzPara.Inlines.Add(contianer);

            // Add it
            currentBlocks.Add(horzPara);
        }
示例#22
0
        private void SetCommands(BlockCollection blocks)
        {
            var res = from block in blocks
                      from inline in (block as Paragraph).Inlines
                      where inline.GetType() == typeof(InlineUIContainer)
                      select inline;

            foreach (var block in blocks)
            {
                Paragraph p = block as Paragraph;

                foreach (var inline in p.Inlines)
                {
                    Hyperlink hlink = inline as Hyperlink;
                    if (hlink != null)
                    {
                        string uri = hlink.NavigateUri.AbsoluteUri;
                        if (uri.StartsWith(PREFIX))
                        {
                            // We have a CommandParameter
                            hlink.Command = _performCommand;
                            // Delete the following once CommandParameter is supported in TextSelection.Xaml
                            hlink.CommandParameter = uri.Substring(PREFIX.Length);
                        }
                    }
                }
            }
        }
        private static void ChangePropertyValueRecursive(BlockCollection blocks,
                                                         DependencyProperty propertyToChange, object newValue, object priorValue = null)
        {
            foreach (var block in blocks)
            {
                var currentValue = block.GetValue(propertyToChange);

                if (priorValue == null || priorValue.ValuesAreEqual(currentValue))
                {
                    block.SetValue(propertyToChange, newValue);
                }
                if (block is Paragraph)
                {
                    var para = block as Paragraph;
                    ChangePropertyValueRecursive(para.Inlines, propertyToChange, newValue, priorValue);
                }
                else if (block is List)
                {
                    var list = block as List;

                    foreach (var listItem in list.ListItems)
                    {
                        ChangePropertyValueRecursive(listItem.Blocks, propertyToChange, newValue, priorValue);
                    }
                }
            }
        }
示例#24
0
        private static IEnumerable<TestResult> GetResult(TestArguments arguments)
        {
            //Prepare data
            var blockCollection = new BlockCollection<int>();
            for (int i = 0; i < BlockCount; i++)
            {
                blockCollection.Add(GetFilledBlock(ElementsInBlockCount));
            }

            var blockStructure = new ArrayMap<int>(new FixedBalancer(),  blockCollection);

            //Prepare measure engine
            var method = GetMethodInfo(arguments.MethodName);

            foreach (var currentCount in arguments.TestCountArray)
            {
                List<object> argumentList = new List<object> { blockStructure, currentCount};

                //Get middle estimation of several times calling
                long timeOfAllInvoketionsMs = 0;
                int countOfInvokations = 3;

                for (int i = 0; i < countOfInvokations; i++)
                {
                    timeOfAllInvoketionsMs += MeasureEngine.MeasureStaticMethod(method, argumentList);
                }

                yield return new TestResult(currentCount, timeOfAllInvoketionsMs / countOfInvokations);
            }
        }
示例#25
0
        public FlowDocument GetFlowDocument()
        {
            FlowDocument doc = (FlowDocument)Application.LoadComponent(
                new Uri("/Daytimer.DatabaseHelpers;component/Templates/TaskTemplate.xaml",
                        UriKind.Relative));

            ((Paragraph)doc.FindName("Subject")).Inlines.Add(_task.Subject);
            ((Paragraph)doc.FindName("Start")).Inlines.Add(_task.StartDate.HasValue ? _task.StartDate.Value.ToString("MMMM d, yyyy") : "None");
            ((Paragraph)doc.FindName("Due")).Inlines.Add(_task.DueDate.HasValue ? _task.DueDate.Value.ToString("MMMM d, yyyy") : "None");
            ((Paragraph)doc.FindName("Status")).Inlines.Add(_task.Status.ConvertToString());
            ((Paragraph)doc.FindName("Priority")).Inlines.Add(_task.Priority.ToString());
            ((Paragraph)doc.FindName("Progress")).Inlines.Add(_task.Progress.ToString() + "%");

            Section details = (Section)doc.FindName("Details");

            FlowDocument detailsDoc = _task.DetailsDocument;

            if (detailsDoc != null)
            {
                BlockCollection blocks = _task.DetailsDocument.Copy().Blocks;

                while (blocks.Count > 0)
                {
                    details.Blocks.Add(blocks.FirstBlock);
                }
            }

            return(doc);
        }
示例#26
0
 public void FormatBlocks(FlowDocument doc, BlockCollection blocks, StringBuilder buf, int indent)
 {
     foreach (Block block in blocks)
     {
         FormatBlock(doc, block, buf, indent);
     }
 }
示例#27
0
 public static void WriteError(BlockCollection blockCollection, Exception ex)
 {
     blockCollection.Add(CreatePara(new Run(ex.Message)
     {
         Foreground = Brushes.Red
     }));
 }
示例#28
0
        void UpdateDescription()
        {
            if (descriptionRichTextBox == null)
            {
                return;
            }
            BlockCollection blocks =
                descriptionRichTextBox.Document.Blocks;

            if (treeListView.FocusedRowHandle == GridControl.InvalidRowHandle)
            {
                return;
            }
            string newDescription = list.FieldDescriptions[treeListView.FocusedRowHandle].TemplateName + "Description";

            if (newDescription == lastDescription)
            {
                return;
            }
            lastDescription = newDescription;
            ContentControl control = new ContentControl()
            {
                Template = Resources[newDescription] as ControlTemplate
            };

            control.ApplyTemplate();
            ParagraphContainer container = VisualTreeHelper.GetChild(control, 0) as ParagraphContainer;

            blocks.Clear();
            blocks.Add(container.Paragraph);
        }
示例#29
0
        public static void AddAndInsert()
        {
            var blockCollection = new BlockCollection<int>();
            blockCollection.Add(new Block<int>(DefaultBlockSize) { 1 });
            blockCollection.Insert(0, new Block<int>(DefaultBlockSize) { 0 });
            blockCollection.Insert(2, new Block<int>(DefaultBlockSize) { 2 });
            blockCollection.Add(new Block<int>(DefaultBlockSize) { 3 });

            var checkArray = new[] { 0, 1, 2, 3 };
            Assert.AreEqual(blockCollection.Count, checkArray.Length);

            for (int i = 0; i < checkArray.Length; i++)
            {
                Assert.AreEqual(blockCollection[i][0], checkArray[i]);
            }

            //Exceptions
            Assert.IsTrue(ExceptionManager.IsThrowActionException<ArgumentNullException, Block<int>>
                (blockCollection.Add, null));
            Assert.IsTrue(ExceptionManager.IsThrowActionException<ArgumentNullException, int, Block<int>>
                (blockCollection.Insert, 0, null));

            Assert.IsTrue(ExceptionManager.IsThrowActionException<ArgumentOutOfRangeException, int, Block<int>>
                (blockCollection.Insert, -1, new Block<int>(DefaultBlockSize)));
            Assert.IsTrue(ExceptionManager.IsThrowActionException<ArgumentOutOfRangeException, int, Block<int>>
                (blockCollection.Insert, blockCollection.Count + 1, new Block<int>(DefaultBlockSize)));
        }
示例#30
0
    public static BlockCollection ReadBlocks()
    {
        var blocks = new BlockCollection();

        try {
            using var r = new StreamReader(Path);
            var json = r.ReadToEnd();
            blocks = JsonUtility.FromJson <BlockCollection>(json);
            r.Close();
        } catch (Exception e) {
            Debug.Log("ERROR: No block file found.");
            Debug.Log(e.Message);
        }

        BlockIndexDictionary.Clear();
        BlockColorDictionary.Clear();
        for (var i = 0; i < blocks.blocks.Count; i++)
        {
            var block = blocks.blocks[i];
            if (!BlockIndexDictionary.ContainsKey(block.blockType))
            {
                BlockIndexDictionary.Add(block.blockType, i);
                BlockColorDictionary.Add(block.blockType, block.color);
            }
        }

        return(blocks);
    }
示例#31
0
 public void FormatBlocks(FlowDocument doc, BlockCollection blocks, StringBuilder buf, int indent)
 {
     foreach (Block block in blocks)
      {
     FormatBlock (doc, block, buf, indent);
      }
 }
示例#32
0
        private void rtb_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.V)
            {
                if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                {
                    //执行Ctrl+E事件后的业务
                    // MessageBox.Show("粘贴事件:" + rtb.Xaml);
                    //  rtb.Xaml
                    char            s   = '\r';
                    BlockCollection bco = rtb.Blocks;
                    for (int i = 0; i < rtb.Blocks.Count; i++)
                    {
                        Paragraph aPara = (Paragraph)rtb.Blocks[i];
                        for (int j = 0; j < aPara.Inlines.Count; j++)
                        {
                            TextElement element = (TextElement)aPara.Inlines[j];

                            if (element.GetType().Equals(typeof(Run)))
                            {
                                StringBuilder buder = new StringBuilder();
                                Run           aRun  = (Run)element;
                                //  MessageBox.Show("粘贴事件:" + aRun.Text.Split(s)[0].ToString());

                                string[] strtr = aRun.Text.Split(s);
                                if (strtr.Length > 1)
                                {
                                    for (int m = 0; m < strtr.Length - 1; m++)
                                    {
                                        //  bco = new BlockCollection();

                                        // aRun.Text = str;
                                        Paragraph para = new Paragraph();
                                        //  para = (Paragraph)rtb.Blocks[0];

                                        // InlineCollection l = new InlineCollection();
                                        para.Inlines.Add("aa");
                                        TextElement elementdd = (TextElement)para.Inlines[0];
                                        Run         aRundd    = (Run)elementdd;
                                        aRundd.Text = strtr[m];
                                        rtb.Selection.Insert(para);
                                        //  MessageBox.Show("粘贴事件:" + aRun.Text.Split(s)[m].ToString()+"/n"+rtb.Xaml);
                                    }
                                    rtb.Blocks.Remove(rtb.Blocks[i]);
                                }
                            }
                        }
                    }
                }
            }

            if (rtb.Blocks.Count > 1 || (rtb.Blocks.Count == 1 && (rtb.Blocks[0] as Paragraph).Inlines.Count > 0))
            {
                IsDirty = true;
            }
            else
            {
                IsDirty = false;
            }
        }
示例#33
0
        public override BlockCollection Serialize()
        {
            var blocks = new BlockCollection();

            blocks.AddBlock("Data.Items", SerializeTable(Items, Item.FieldSize, DataStreamExtensions.WriteItem));

            return(blocks);
        }
示例#34
0
        public Form()
        {
            items = new ItemCollection();
            materials = new MaterialCollection();
            blocks = new BlockCollection(items, materials);

            InitializeComponent();
        }
示例#35
0
        internal Block GetBlockUnsafe(int x, int y, int z)
        {
            Block b;

            BlockCollection.TryGetBlock(GetBlockIDUnsafe(x, y, z), out b);

            return(b);
        }
示例#36
0
        /// <summary>
        /// Create new empty instance of <see cref="BigArray{T}"/> with specified <paramref name="configuration"/>.
        /// </summary>
        /// <param name="configuration">Configation object of new array.</param>
        public BigArray(BigArrayConfiguration <T> configuration)
        {
            _balancer        = configuration.Balancer;
            _blockCollection = new BlockCollection <T>(_balancer, configuration.BlockCollection);
            _arrayMap        = new ArrayMap <T>(_balancer, _blockCollection);

            _containsOperation = JITOMethodFactory.GetContainsOperation(this, configuration.UseJustInTimeOptimization);
        }
 private static void AddBlocks(RichTextBox richTextBox, BlockCollection blocks)
 {
     var list = blocks.ToList();
     foreach (var block in list)
     {
         blocks.Remove(block);
         richTextBox.Blocks.Add(block);
     }
 }
示例#38
0
 public PricesBlocksForm(MinecraftHandler mc)
 {
     InitializeComponent();
     dgvBadBlocks.AutoGenerateColumns = false;
     UpdateCombobox(0);
     GenerateColumns();
     this.mc = mc;
     this._blocks = mc.PricedBlocks;
     LoadDataSource();
     this.Dock = DockStyle.Fill;
 }
        private static int GetCharOffsetToPosition(BlockCollection blockCollection, TextPointer position, out TextPointer result)
        {
            int offset = 0;
            foreach (var block in blockCollection)
            {
                offset += GetCharOffsetToPosition(block, position, out result);
                if (result == null || result.CompareTo(position) >= 0)
                    return offset;
            }

            result = null;
            return offset;
        }
示例#40
0
        public static void AddNewBlockAndInsertNewBlock()
        {
            var blockCollection = new BlockCollection<int>();

            //Add
            blockCollection.AddNewBlock();
            Assert.AreEqual(blockCollection.Count, 1);
            //Add
            blockCollection.AddNewBlock();
            Assert.AreEqual(blockCollection.Count, 2);
            //Insert
            blockCollection.InsertNewBlock(1);
            Assert.AreEqual(blockCollection.Count, 3);
        }
示例#41
0
        private static void GetText(StringBuilder builder, BlockCollection blocks)
        {
            foreach (var block in blocks)
            {
                Paragraph paragraph = block as Paragraph;
                if (paragraph != null)
                {
                    GetText(builder, paragraph.Inlines);
                }

                Section section = block as Section;
                if (section != null)
                {
                    GetText(builder, section.Blocks);
                }
            }
        }
示例#42
0
        public static void AddRangeAndInsertRange()
        {
            var blockCollection = new BlockCollection<int>();
            blockCollection.AddRange(new List<Block<int>>
            {
                new Block<int>(DefaultBlockSize) {1},
                new Block<int>(DefaultBlockSize) {2}
            });
            blockCollection.InsertRange(0, new List<Block<int>>
            {
                new Block<int>(DefaultBlockSize) {0}
            });
            blockCollection.AddRange(new List<Block<int>>
            {
                new Block<int>(DefaultBlockSize) {3}
            });
            blockCollection.InsertRange(4, new List<Block<int>>
            {
                new Block<int>(DefaultBlockSize) {4},
                new Block<int>(DefaultBlockSize) {5}
            });

            var checkArray = new[] { 0, 1, 2, 3, 4, 5 };
            Assert.AreEqual(blockCollection.Count, checkArray.Length);

            for (int i = 0; i < checkArray.Length; i++)
            {
                Assert.AreEqual(blockCollection[i][0], checkArray[i]);
            }

            //Exceptions
            ExceptionManager.IsThrowActionException
                <ArgumentNullException, ICollection<Block<int>>>
                (blockCollection.AddRange, null);
            ExceptionManager.IsThrowActionException
                <ArgumentNullException, int, ICollection<Block<int>>>
                (blockCollection.InsertRange, 0, null);

            ExceptionManager.IsThrowActionException
                <ArgumentNullException, int, ICollection<Block<int>>>
                (blockCollection.InsertRange, -1, new Collection<Block<int>>());
            ExceptionManager.IsThrowActionException
                <ArgumentNullException, int, ICollection<Block<int>>>
                (blockCollection.InsertRange, blockCollection.Count + 1, new Collection<Block<int>>());
        }
示例#43
0
        private static void WriteEnumerable(BlockCollection blocks, HashSet<object> objects, IEnumerable enumerable)
        {
            //var list = new List();
            //foreach (var item in enumerable)
            //{
            //    var listItem = new ListItem();
            //    WriteProperties(listItem.Blocks, objects, item);
            //    list.ListItems.Add(listItem);
            //}
            //blocks.Add(list);

            foreach (var e in enumerable)
            {
                var section = new Section { TextAlignment = TextAlignment.Left };
                WriteProperties(section.Blocks, objects, e);
                blocks.Add(section);
            }
        }
示例#44
0
 private static void WriteProperties(BlockCollection blocks, HashSet<object> objects, object o)
 {
     if (!objects.Add(o))
     {
         return;
     }
     var type = o.GetType();
     if (type.IsValueType || type == typeof(string))
     {
         blocks.Add(CreatePara(new Run(o.ToString())));
         return;
     }
     var rowGroup = new TableRowGroup();
     foreach (var propertyInfo in type.GetProperties())
     {
         if (propertyInfo.CanRead && propertyInfo.GetIndexParameters().Length == 0)
         {
             var row = new TableRow();
             row.Cells.Add(new TableCell(CreatePara(new Run(propertyInfo.Name))));
             var valueCell = new TableCell();
             object propertyValue;
             try
             {
                 propertyValue = propertyInfo.GetValue(o, null);
             }
             catch (Exception ex)
             {
                 propertyValue = null;
                 WriteError(valueCell.Blocks, ex);
             }
             if (propertyValue != null)
             {
                 WriteObject(valueCell.Blocks, objects, propertyValue);
             }
             row.Cells.Add(valueCell);
             rowGroup.Rows.Add(row);
         }
     }
     var table = new Table { BorderBrush = Brushes.Gainsboro, BorderThickness = new Thickness(1) };
     table.Columns.Add(new TableColumn());
     table.Columns.Add(new TableColumn());
     table.RowGroups.Add(rowGroup);
     blocks.Add(new Paragraph { Inlines = { new Run("Floater"), new Floater(table) { HorizontalAlignment = HorizontalAlignment.Right } } });
 }
    public CSharpDocumentationBuilder(IAmbience ambience) {
      this.ambience = ambience;
      this.flowDocument = new FlowDocument();
      this.blockCollection = flowDocument.Blocks;

      this.ShowSummary = true;
      this.ShowAllParameters = true;
      this.ShowReturns = true;
      this.ShowThreadSafety = true;
      this.ShowExceptions = true;
      this.ShowTypeParameters = true;

      this.ShowExample = true;
      this.ShowPreliminary = true;
      this.ShowSeeAlso = true;
      this.ShowValue = true;
      this.ShowPermissions = true;
      this.ShowRemarks = true;
    }
示例#46
0
 private static void CollectInlineFromBlocks(BlockCollection blocks, List<Inline> ic)
 {
     IEnumerator<Block> enumerator = blocks.GetEnumerator();
     enumerator.Reset();
     while (enumerator.MoveNext())
     {
         Block current = enumerator.Current;
         if (current is Paragraph)
         {
             Paragraph paragraph = current as Paragraph;
             IEnumerator<Inline> enumerator2 = paragraph.Inlines.GetEnumerator();
             enumerator2.Reset();
             while (enumerator2.MoveNext())
             {
                 Inline item = enumerator2.Current;
                 if (item is InlineUIContainer)
                 {
                     InlineUIContainer container = item as InlineUIContainer;
                     UIElement childUIElement = ReplaceWithMyControls(container.Child);
                     ic.Add(new InlineUIContainer(childUIElement));
                 }
                 else
                 {
                     ic.Add(item);
                 }
             }
             ic.Add(new LineBreak());
         }
         else if (current is Section)
         {
             Section section = current as Section;
             CollectInlineFromBlocks(section.Blocks, ic);
         }
         else if (current is BlockUIContainer)
         {
             BlockUIContainer container2 = current as BlockUIContainer;
             UIElement element2 = ReplaceWithMyControls(container2.Child);
             ic.Add(new InlineUIContainer(element2));
             ic.Add(new LineBreak());
         }
     }
 }
		public DocumentationUIBuilder(IAmbience ambience = null)
		{
			this.ambience = ambience ?? AmbienceService.GetCurrentAmbience();
			this.flowDocument = new FlowDocument();
			this.blockCollection = flowDocument.Blocks;
			
			this.ShowSummary = true;
			this.ShowAllParameters = true;
			this.ShowReturns = true;
			this.ShowThreadSafety = true;
			this.ShowExceptions = true;
			this.ShowTypeParameters = true;
			
			this.ShowExample = true;
			this.ShowPreliminary = true;
			this.ShowSeeAlso = true;
			this.ShowValue = true;
			this.ShowPermissions = true;
			this.ShowRemarks = true;
		}
示例#48
0
        private static void WriteObject(BlockCollection blocks, HashSet<object> objects, object o)
        {
            if (o == null)
            {
                blocks.Add(CreatePara(new Run("<null>")));
                return;
            }

            if (!(o is string))
            {
                var enumerable = o as IEnumerable;
                if (enumerable != null)
                {
                    WriteEnumerable(blocks, objects, enumerable);
                    return;
                }
            }

            WriteProperties(blocks, objects, o);
        }
示例#49
0
        /// <summary>
        /// Traverses passed block collection
        /// </summary>
        /// <param name="blocks"></param>
        public void TraverseBlockCollection(BlockCollection blocks)
        {
            foreach (Block b in blocks)
            {
                Paragraph p = b as Paragraph;
                if (p != null)
                    TraverseParagraph(p);
                else
                {
                    BlockUIContainer bui = b as BlockUIContainer;
                    if (bui != null)
                    {
                        VisualVisited(this, bui.Child, true);
                    }
                    else
                    {
                        Section s = b as Section;
                        if (s != null)
                            TraverseBlockCollection(s.Blocks);
                        else
                        {
                            Table t = b as Table;
                            if (t != null)
                            {
                                VisualVisited(this, t, true);
                                foreach (TableRowGroup trg in t.RowGroups)
                                {
                                    foreach (TableRow tr in trg.Rows)
                                    {
                                        foreach (TableCell tc in tr.Cells)
                                            TraverseBlockCollection(tc.Blocks);
                                    }
                                }
                                VisualVisited(this, t, false);
                            }
                        }
                    }
                }

            }
        }
示例#50
0
        private void LoadDataSource()
        {
            try
            {
                _blocks = BlockCollection.Load(Config.ConfigFolder + BlockCollection.BadBlocksFile);
                if (_blocks == null)
                {
                    _blocks = new BlockCollection();
                }
            }
            catch
            {
                _blocks = new BlockCollection();
            }
            try
            {
                comboBoxItems.ValueMember = "Value";
                comboBoxItems.DisplayMember = "Name";
                comboBoxItems.DataSource = new BindingSource(ItemDictonary.GetInstance(), null);
            }
            catch
            {

            }
            dgvBadBlocks.DataSource = new BindingSource(_blocks,null);
        }
        void FlushBuffer(BlockCollection blocks)
        {
            if (buffer != null)
            {
                if (buffer.Inlines.Count > 0)
                    blocks.Add(buffer);

                buffer = null;
            }
        }
示例#52
0
        private static ArrayMap<int> CteareTestStructure()
        {
            //Prepare block collection
            var blockCollection = new BlockCollection<int>();

            for (int i = 0; i < CountOfBlocks; i++)
            {
                var block = new Block<int>(BlockSize);
                for (int element = 0; element < BlockSize; element++)
                {
                    block.Add(element);
                }
                blockCollection.Add(block);
            }

            //Create block structure
            return new ArrayMap<int>(new FixedBalancer(),  blockCollection);
        }
示例#53
0
 public FlowDocument()
 {
     Blocks = new BlockCollection();
 }
示例#54
0
 private static void ParseBlocks(BlockCollection blocks, List<TextElement> list)
 {
     foreach (Block block in blocks)
     {
         if (block is Paragraph)
         {
             ParseParagraph(block as Paragraph, list);
         }
         else if (block is BlockUIContainer)
         {
             ParseBlockUIContainer(block as BlockUIContainer, list);
         }
     }
 }
示例#55
0
        public MinecraftHandler(String rules, String kits, String banlist, String playerlist, String adminlist, String config)
        {
            _strRulesList = rules;
            _strBanList = banlist;
            _strPlayerList = playerlist;
            try
            {
                Config = XObject<Config>.Load(Config.ConfigFolder + Config.ConfigFile);
            }
            catch
            {
                Config = new Config();
            }
            try
            {
                PricedBlocks = BlockCollection.Load(Config.ConfigFolder + BlockCollection.PricedBlocksFile);
                if (PricedBlocks == null)
                {
                    PricedBlocks = new BlockCollection();
                }
            }
            catch
            {
                PricedBlocks = new BlockCollection();
            }
            String badBlocksFile = Path.Combine(Config.ConfigFolder,BlockCollection.BadBlocksFile);
            if (!File.Exists(badBlocksFile))
            {
                new BlockCollection().Save(badBlocksFile);
            }

            Plugins = AddonLoader.GetInstance(this).Plugins;
            timerCommandReader.Interval = 1000;
            timerCommandReader.Enabled = true;
        }
		void AddSection(Inline title, Action addChildren)
		{
			var section = new Section();
			AddBlock(section);
			var oldBlockCollection = blockCollection;
			try {
				blockCollection = section.Blocks;
				inlineCollection = null;
				
				if (title != null)
					AddInline(new Bold(title));
				
				addChildren();
				FlushAddedText(false);
			} finally {
				blockCollection = oldBlockCollection;
				inlineCollection = null;
			}
		}
示例#57
0
 private void btDiscard_Click(object sender, EventArgs e)
 {
     mc.PricedBlocks = BlockCollection.Load(Config.ConfigFolder + BlockCollection.PricedBlocksFile);
     _blocks = mc.PricedBlocks;
     UpdateDataGrid();
 }
		void AddList(string type, IEnumerable<XmlDocumentationElement> items)
		{
			List list = new List();
			AddBlock(list);
			list.Margin = new Thickness(0, 5, 0, 5);
			if (type == "number")
				list.MarkerStyle = TextMarkerStyle.Decimal;
			else if (type == "bullet")
				list.MarkerStyle = TextMarkerStyle.Disc;
			var oldBlockCollection = blockCollection;
			try {
				foreach (var itemElement in items) {
					if (itemElement.Name == "listheader" || itemElement.Name == "item") {
						ListItem item = new ListItem();
						blockCollection = item.Blocks;
						inlineCollection = null;
						foreach (var prop in itemElement.Children) {
							AddDocumentationElement(prop);
						}
						FlushAddedText(false);
						list.ListItems.Add(item);
					}
				}
			} finally {
				blockCollection = oldBlockCollection;
			}
		}
 private void RemoveEmptyParagraphs(BlockCollection blocks)
 {
     foreach (var b in new List<Block>(blocks))
     {
         var par = b as Paragraph;
         if (par!=null)
         {
             if (String.IsNullOrWhiteSpace(new TextRange(par.ContentStart, par.ContentEnd).Text))
             {
                 blocks.Remove(par);
             }
             continue;
         }
         var sec = b as Section;
         if (sec!=null)
         {
             RemoveEmptyParagraphs(sec.Blocks);
             continue;
         }
     }
 }
 public void InsertSections(BlockCollection blocks, int hdDepth)
 {
     var cur = blocks.FirstBlock;
     while (cur != null)
     {
         if (GetHeadingDepth(cur) >= hdDepth)
         {
             var sec = new Section();
             sec.BorderThickness = new Thickness(2);
             sec.BorderBrush = new SolidColorBrush(Colors.Gray);
             sec.Margin = new Thickness(5);
             blocks.InsertBefore(cur, sec);
             blocks.Remove(cur);
             sec.Blocks.Add(cur);
             cur = sec.NextBlock;
             while (cur != null)
             {
                 int depth = GetHeadingDepth(cur);
                 if (0<depth && depth <= hdDepth) break;
                 var next = cur.NextBlock;
                 blocks.Remove(cur);
                 sec.Blocks.Add(cur);
                 cur = next;
             }
             InsertSections(sec.Blocks, hdDepth + 1);
         }
         else
         {
             cur = cur.NextBlock;
         }
     }
 }