Exemplo n.º 1
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)));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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.Gray, BorderThickness = new Thickness(1)
            };

            table.Columns.Add(new TableColumn {
                Width = GridLength.Auto
            });
            table.Columns.Add(new TableColumn {
                Width = GridLength.Auto
            });
            table.RowGroups.Add(rowGroup);
            blocks.Add(table);
        }
        public void Push(Block block, BlockCollection blocks, IEnumerable <MarkdownObject> children)
        {
            var currentBlocks = Blocks;

            Blocks.Add(block);
            Blocks = blocks;
            foreach (var child in children)
            {
                Write(child);
            }
            Blocks = currentBlocks;
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 public static void WriteError(BlockCollection blockCollection, Exception ex)
 {
     blockCollection.Add(CreatePara(new Run(ex.Message)
     {
         Foreground = Brushes.Red
     }));
 }
Exemplo n.º 8
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));
            }
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 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);
            }
        }
        /// <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);
        }
Exemplo n.º 12
0
 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);
         }
     }
 }
Exemplo n.º 13
0
        public static void CopyTo()
        {
            var blockCollection = new BlockCollection <int>();

            blockCollection.Add(new Block <int>(DefaultBlockSize)
            {
                0, 1, 2
            });
            blockCollection.Add(new Block <int>(DefaultBlockSize)
            {
                3, 4, 5
            });
            blockCollection.Add(new Block <int>(DefaultBlockSize)
            {
                6, 7, 8
            });

            //Without shift
            var array1 = new Block <int> [3];

            blockCollection.CopyTo(array1, 0);
            for (int i = 0; i < blockCollection.Count; i++)
            {
                Assert.AreEqual(blockCollection[i], array1[i]);
            }

            //With shift
            var array2 = new Block <int> [4];

            blockCollection.CopyTo(array2, 1);
            for (int i = 0; i < blockCollection.Count; i++)
            {
                Assert.AreEqual(blockCollection[i], array2[i + 1]);
            }

            //Exceptions
            Assert.IsTrue(ExceptionManager.IsThrowActionException
                          <ArgumentNullException, Block <int>[], int>
                              (blockCollection.CopyTo, null, 0));

            Assert.IsTrue(ExceptionManager.IsThrowActionException
                          <ArgumentOutOfRangeException, Block <int>[], int>
                              (blockCollection.CopyTo, array1, array1.Length - blockCollection.Count + 1));
            Assert.IsTrue(ExceptionManager.IsThrowActionException
                          <ArgumentOutOfRangeException, Block <int>[], int>
                              (blockCollection.CopyTo, array1, -1));
        }
Exemplo n.º 14
0
 private void btAdd_Click(object sender, EventArgs e)
 {
     try
     {
         _blocks.Add(new BlockItem(Convert.ToInt32(((KeyValuePair <String, String>)comboBoxItems.SelectedItem).Value)));
         UpdateDataGrid();
     }
     catch { }
 }
Exemplo n.º 15
0
 private void Log(string s) => Dispatcher.InvokeAsync(() => {
     BlockCollection blocks = TbLog.Document.Blocks;
     if (blocks.Count >= 1000)
     {
         blocks.Remove(blocks.FirstBlock);
     }
     var paragraph = new Paragraph(new Run(s));
     blocks.Add(paragraph);
 });
        /// <summary>
        /// Renders a line break element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="currentBlocks"></param>
        private void RenderLineBreak(LineBreakBlock element, BlockCollection currentBlocks)
        {
            // Make the new horizontal rule paragraph
            Paragraph lineBreakPara = new Paragraph();

            lineBreakPara.Margin = new Thickness(0, 12, 0, 12);

            // Add it
            currentBlocks.Add(lineBreakPara);
        }
Exemplo n.º 17
0
        public override void AddScriptGlobal(ScenarioScriptGlobal scenarioScriptGlobal)
        {
            BlockCollection <HsGlobalsBlock> globalBlocks = scenarioValues._globalsList;
            HsGlobalsBlock globalBlock = new HsGlobalsBlock();

            globalBlock.Name = new FixedLengthString(scenarioScriptGlobal.Name);
            globalBlock.Type = new Enum(scenarioScriptGlobal.Type);
            globalBlock.InitializationExpressionIndex = new LongInteger(scenarioScriptGlobal.InitialisationExpressionIndex);

            globalBlocks.Add(globalBlock);
        }
        /// <summary>
        /// Renders a list element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="currentBlocks"></param>
        private void RenderListElement(ListElementBlock element, BlockCollection currentBlocks)
        {
            // Create a grid for the dot and the text
            Grid grid = new Grid();

            // The first column for the dot the second for the text
            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Auto)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });

            // Make the dot container and the new text box
            TextBlock dotText = new TextBlock();

            dotText.Text = element.ListBullet;
            Grid.SetColumn(dotText, 0);
            // Add the indent
            dotText.Margin = new Thickness(12 * element.ListIndent, 2, 0, 2);
            grid.Children.Add(dotText);

            RichTextBlock listText = new RichTextBlock();

            Grid.SetColumn(listText, 1);
            // Give the text some space from the dot and also from the top and bottom
            listText.Margin = new Thickness(6, 2, 0, 2);
            grid.Children.Add(listText);

            // Make the inline container
            InlineUIContainer uiConainter = new InlineUIContainer();

            uiConainter.Child = grid;

            // Make a paragraph to hold our list
            Paragraph blockParagraph = new Paragraph();

            blockParagraph.Inlines.Add(uiConainter);

            // Make a paragraph to hold our list test
            Paragraph inlineParagraph = new Paragraph();

            listText.Blocks.Add(inlineParagraph);

            // Add it to the blocks
            currentBlocks.Add(blockParagraph);

            // Render the children into the rich.
            bool trimTextStart = true;

            RenderInlineChildren(element, inlineParagraph.Inlines, ref trimTextStart);
        }
Exemplo n.º 19
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)));
        }
Exemplo n.º 20
0
        public override void AddScript(ScenarioScript scenarioScript)
        {
            BlockCollection <HsScriptsBlock> scriptBlocks = scenarioValues._scriptsList;
            HsScriptsBlock scriptBlock = new HsScriptsBlock();

            scriptBlock.Name                = new FixedLengthString(scenarioScript.Name);
            scriptBlock.ReturnType          = new Enum(scenarioScript.ReturnType);
            scriptBlock.RootExpressionIndex = new LongInteger(scenarioScript.RootExpressionIndex * 0x10000);
            scriptBlock.ScriptType          = new Enum(scenarioScript.ScriptType);

            scriptBlocks.Add(scriptBlock);
        }
Exemplo n.º 21
0
        void FlushBuffer(BlockCollection blocks)
        {
            if (buffer != null)
            {
                if (buffer.Inlines.Count > 0)
                {
                    blocks.Add(buffer);
                }

                buffer = null;
            }
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
0
        static void FormatBlocks(Settings settings, CMBlock cmBlock, BlockCollection wdBlocks)
        {
            for (; cmBlock != null; cmBlock = cmBlock.NextSibling)
            {
                switch (cmBlock.Tag)
                {
                case BlockTag.AtxHeading:
                case BlockTag.SetextHeading:
                case BlockTag.Paragraph:
                    var wdParagraph = new Paragraph();
                    if (cmBlock.Tag != BlockTag.Paragraph)
                    {
                        // FIXME: this should probably be a Section with header
                        // level stored in Section.Tag or a custom style so it
                        // can be configured in XAML. Out of time.
                        wdParagraph.FontWeight = FontWeights.Bold;
                        wdParagraph.FontSize   = 14;
                    }
                    FormatInlines(settings, cmBlock.InlineContent, wdParagraph.Inlines);
                    wdBlocks.Add(wdParagraph);
                    break;

                case BlockTag.List:
                    var wdList = new List();
                    for (var cmChildBlock = cmBlock.FirstChild;
                         cmChildBlock != null;
                         cmChildBlock = cmChildBlock.NextSibling)
                    {
                        var wdListItem = new ListItem();
                        FormatBlocks(settings, cmChildBlock.FirstChild, wdListItem.Blocks);
                        wdList.ListItems.Add(wdListItem);
                    }
                    wdBlocks.Add(wdList);
                    break;

                default:
                    throw new NotImplementedException($"BlockTag.{cmBlock.Tag}");
                }
            }
        }
Exemplo n.º 24
0
 internal void FillPreviewFromFile(BlockCollection blocks, ResultItem resultLine)
 {
     using (var reader = new StreamReader(resultLine.linePath))
     {
         try
         {
             string    line;
             int       lineNumber = 0;
             int       countEmpty = 0;
             Paragraph paragraph  = new Paragraph();
             blocks.Add(paragraph);
             //Pre
             for (int i = resultLine.lineNumber.Value - 2; i < 1; i++)
             {
                 paragraph.Inlines.Add(new Run("\n"));
                 countEmpty++;
             }
             while (lineNumber <= Math.Max(1, resultLine.lineNumber.Value + 2))
             {
                 line = reader.ReadLine();
                 lineNumber++;
                 //Pre
                 if (lineNumber >= resultLine.lineNumber.Value - 2 && lineNumber < resultLine.lineNumber.Value)
                 {
                     paragraph.Inlines.Add(new Run(line + "\n"));
                 }
                 //Res
                 else if (lineNumber == resultLine.lineNumber.Value)
                 {
                     (string pre, string res, string post) = resultLine.GetSplitLine(line, false);
                     paragraph.Inlines.Add(new Run(pre));
                     paragraph.Inlines.Add(new Run(res)
                     {
                         Foreground = Brushes.Red
                     });
                     paragraph.Inlines.Add(new Run(post + "\n"));
                 }
                 //Post
                 else if (lineNumber > resultLine.lineNumber.Value && lineNumber <= resultLine.lineNumber.Value + 2)
                 {
                     paragraph.Inlines.Add(new Run(line + "\n"));
                 }
             }
         }
         finally
         {
             reader.Close();
         }
     }
 }
Exemplo n.º 25
0
        //Hongjia's codes end

        /// <summary>
        /// Loops through children of an <see cref="INode"/> and appends as <see cref="UIElement"/> to given <see cref="UIElementCollection"/>.
        /// </summary>
        /// <param name="node">The parent <see cref="INode"/>.</param>
        /// <param name="elements">The <see cref="UIElementCollection"/> collection to add elements to.</param>
        protected void AddChildren(INode node, BlockCollection elements)
        {
            var nodeQueue = UnfoldTagToCollection(node);

            foreach (var child in nodeQueue)
            {
                var element = GenerateBlockForNode(child, elements);

                if (elements.LastOrDefault() != element)
                {
                    elements.Add(element);
                }
            }
        }
Exemplo n.º 26
0
        //Support functions
        private static BlockCollection <int> CreateNewCollection(int countOfBlocks = 8)
        {
            var blockCollection = new BlockCollection <int>();

            for (int i = 0; i < countOfBlocks; i++)
            {
                blockCollection.Add(new Block <int>(DefaultBlockSize)
                {
                    i
                });
            }

            return(blockCollection);
        }
Exemplo n.º 27
0
    public void SpawnBlockLine(int Count)
    {
        Count = Mathf.Clamp(Count, 0, 5);
        char[] BlockPosition = new char[5];
        for (int i = 0; i < 5; i++)
        {
            BlockPosition[i] = (char)0;
        }
        while (Count > 0)
        {
            int RandomPosition = Random.Range(0, 4);
            if (BlockPosition[RandomPosition] != 0)
            {
                continue;
            }
            BlockPosition[RandomPosition] = (char)1;
            Count--;
        }
        for (int i = 0; i < 5; i++)
        {
            if (BlockPosition[i] == 0 && Random.Range(0, 10) <= 1)
            {
                BlockPosition[i] = (char)2;
            }
        }
        for (int i = 0; i < 5; i++)
        {
            switch ((int)BlockPosition[i])
            {
            case 1:
            {
                var BlockTri = Object.Instantiate(Resources.Load <GameObject>("BlockTri"));
                BlockTri.transform.position            = new Vector3((i - 2) * 0.9f, -3.8f);
                BlockTri.GetComponent <Block>().Health = Random.Range(GameRound, GameRound * 3);
                BlockCollection.Add(BlockTri);
            }
            break;

            case 2:
            {
                var AddBall = Object.Instantiate(Resources.Load <GameObject>("AddBall"));
                AddBall.transform.position = new Vector3((i - 2) * 0.9f, -3.8f);
                BlockCollection.Add(AddBall);
            }
            break;
            }
        }
        GameRound++;
    }
        private Paragraph GetOrCreateLastParagraph(BlockCollection blocks)
        {
            var lastBlock = blocks.LastOrDefault();

            if (lastBlock != null)
            {
                return((Paragraph)lastBlock);
            }

            var paragraph = new Paragraph();

            blocks.Add(paragraph);

            return(paragraph);
        }
        /// <summary>
        /// Renders a quote element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="currentBlocks"></param>
        private void RenderQuote(QuoteBlock element, BlockCollection currentBlocks)
        {
            // Make the new quote paragraph
            Paragraph quotePara = new Paragraph();

            quotePara.Margin     = new Thickness(element.QuoteIndent * 12, 12, 12, 12);
            quotePara.Foreground = new SolidColorBrush(Color.FromArgb(180, 255, 255, 255));

            // Add it to the blocks
            currentBlocks.Add(quotePara);

            // Render the children into the para inline.
            bool trimTextStart = true;

            RenderInlineChildren(element, quotePara.Inlines, ref trimTextStart);
        }
        /// <summary>
        /// Renders a paragraph element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="currentBlocks"></param>
        private void RenderPargraph(ParagraphBlock element, BlockCollection currentBlocks)
        {
            // Make a new paragraph
            Paragraph paragraph = new Paragraph();

            // Add some padding to differentiate the blocks
            paragraph.Margin = new Thickness(0, 12, 0, 0);

            // Add it to the blocks
            currentBlocks.Add(paragraph);

            // Render the children into the para inline.
            bool trimTextStart = true;

            RenderInlineChildren(element, paragraph.Inlines, ref trimTextStart);
        }
 protected void HandleBlocks(BlockCollection destBlockColl, TreeNode node, Inline nodeRun)
 {
     if (nodeRun != null)
     {
         destBlockColl.Add(new Paragraph(nodeRun));
     }
     if (node.ChildCount > 0)
     {
         HtmlBlockExtractionVisitor blockVisitor = new HtmlBlockExtractionVisitor(TextChannel);
         foreach (TreeNode child in node.ListOfChildren)
         {
             child.AcceptDepthFirst(blockVisitor);
         }
         destBlockColl.AddRange(blockVisitor.ExtractedBlocks);
     }
 }
        /// <summary>
        /// Renders a code element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="currentBlocks"></param>
        private void RenderCode(CodeBlock element, BlockCollection currentBlocks)
        {
            // Make the new code paragraph
            Paragraph codePara = new Paragraph();

            codePara.Margin     = new Thickness(12 * element.CodeIndent, 0, 0, 0);
            codePara.Foreground = new SolidColorBrush(Color.FromArgb(180, 255, 255, 255));
            codePara.FontFamily = new FontFamily("Courier New");

            // Add it to the blocks
            currentBlocks.Add(codePara);

            // Render the children into the para inline.
            bool trimTextStart = true;

            RenderInlineChildren(element, codePara.Inlines, ref trimTextStart);
        }
Exemplo n.º 33
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);
            }
        }
Exemplo n.º 34
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);
        }
Exemplo n.º 35
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 } } });
 }
Exemplo n.º 36
0
        public static void CopyTo()
        {
            var blockCollection = new BlockCollection<int>();
            blockCollection.Add(new Block<int>(DefaultBlockSize) { 0, 1, 2 });
            blockCollection.Add(new Block<int>(DefaultBlockSize) { 3, 4, 5 });
            blockCollection.Add(new Block<int>(DefaultBlockSize) { 6, 7, 8 });

            //Without shift
            var array1 = new Block<int>[3];
            blockCollection.CopyTo(array1, 0);
            for (int i = 0; i < blockCollection.Count; i++)
            {
                Assert.AreEqual(blockCollection[i], array1[i]);
            }

            //With shift
            var array2 = new Block<int>[4];
            blockCollection.CopyTo(array2, 1);
            for (int i = 0; i < blockCollection.Count; i++)
            {
                Assert.AreEqual(blockCollection[i], array2[i + 1]);
            }

            //Exceptions
            Assert.IsTrue(ExceptionManager.IsThrowActionException
                <ArgumentNullException, Block<int>[], int>
                (blockCollection.CopyTo, null, 0));

            Assert.IsTrue(ExceptionManager.IsThrowActionException
                <ArgumentOutOfRangeException, Block<int>[], int>
                (blockCollection.CopyTo, array1, array1.Length - blockCollection.Count + 1));
            Assert.IsTrue(ExceptionManager.IsThrowActionException
                <ArgumentOutOfRangeException, Block<int>[], int>
                (blockCollection.CopyTo, array1, -1));
        }
        /// <summary>
        /// Renders a list element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="currentBlocks"></param>
        private void RenderListElement(ListElementBlock element, BlockCollection currentBlocks)
        {
            // Create a grid for the dot and the text
            Grid grid = new Grid();

            // The first column for the dot the second for the text
            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) });
            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });

            // Make the dot container and the new text box
            TextBlock dotText = new TextBlock();
            dotText.Text = element.ListBullet;
            Grid.SetColumn(dotText, 0);
            // Add the indent
            dotText.Margin = new Thickness(12 * element.ListIndent, 2, 0, 2);
            grid.Children.Add(dotText);

            RichTextBlock listText = new RichTextBlock();
            Grid.SetColumn(listText, 1);
            // Give the text some space from the dot and also from the top and bottom
            listText.Margin = new Thickness(6, 2, 0, 2);
            grid.Children.Add(listText);

            // Make the inline container
            InlineUIContainer uiConainter = new InlineUIContainer();
            uiConainter.Child = grid;

            // Make a paragraph to hold our list
            Paragraph blockParagraph = new Paragraph();
            blockParagraph.Inlines.Add(uiConainter);

            // Make a paragraph to hold our list test
            Paragraph inlineParagraph = new Paragraph();
            listText.Blocks.Add(inlineParagraph);

            // Add it to the blocks
            currentBlocks.Add(blockParagraph);

            // Render the children into the rich.
            bool trimTextStart = true;
            RenderInlineChildren(element, inlineParagraph.Inlines, ref trimTextStart);
        }
        /// <summary>
        /// Renders a header element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="currentBlocks"></param>
        private void RenderHeader(HeaderBlock element, BlockCollection currentBlocks)
        {
            // Make the new header paragraph
            Paragraph headerPara = new Paragraph();
            headerPara.Margin = new Thickness(0, 18, 0, 12);

            // Set the style
            switch (element.HeaderLevel)
            {
                case 1:
                    headerPara.FontSize = 20;
                    headerPara.FontWeight = FontWeights.Bold;
                    break;
                case 2:
                    headerPara.FontSize = 20;
                    break;
                case 3:
                    headerPara.FontSize = 17;
                    headerPara.FontWeight = FontWeights.Bold;
                    break;
                case 4:
                    headerPara.FontSize = 17;
                    break;
                case 5:
                default:
                    headerPara.FontWeight = FontWeights.Bold;
                    break;
            }

            // Add it to the blocks
            currentBlocks.Add(headerPara);

            // Render the children into the para inline.
            bool trimTextStart = true;
            RenderInlineChildren(element, headerPara.Inlines, ref trimTextStart);
        }
        /// <summary>
        /// Renders a line break element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="currentBlocks"></param>
        private void RenderLineBreak(LineBreakBlock element, BlockCollection currentBlocks)
        {
            // Make the new horizontal rule paragraph
            Paragraph lineBreakPara = new Paragraph();
            lineBreakPara.Margin = new Thickness(0, 12, 0, 12);

            // Add it
            currentBlocks.Add(lineBreakPara);
        }
        /// <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);
        }
        /// <summary>
        /// Renders a quote element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="currentBlocks"></param>
        private void RenderQuote(QuoteBlock element, BlockCollection currentBlocks)
        {
            // Make the new quote paragraph
            Paragraph quotePara = new Paragraph();
            quotePara.Margin = new Thickness(element.QuoteIndent * 12, 12, 12, 12);
            quotePara.Foreground = new SolidColorBrush(Color.FromArgb(180, 255, 255, 255));

            // Add it to the blocks
            currentBlocks.Add(quotePara);

            // Render the children into the para inline.
            bool trimTextStart = true;
            RenderInlineChildren(element, quotePara.Inlines, ref trimTextStart);
        }
Exemplo n.º 42
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);
        }
        void FlushBuffer(BlockCollection blocks)
        {
            if (buffer != null)
            {
                if (buffer.Inlines.Count > 0)
                    blocks.Add(buffer);

                buffer = null;
            }
        }
        /// <summary>
        /// Renders a code element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="currentBlocks"></param>
        private void RenderCode(CodeBlock element, BlockCollection currentBlocks)
        {
            // Make the new code paragraph
            Paragraph codePara = new Paragraph();
            codePara.Margin = new Thickness(12 * element.CodeIndent, 0, 0, 0);
            codePara.Foreground = new SolidColorBrush(Color.FromArgb(180, 255, 255, 255));
            codePara.FontFamily = new FontFamily("Courier New");

            // Add it to the blocks
            currentBlocks.Add(codePara);

            // Render the children into the para inline.
            bool trimTextStart = true;
            RenderInlineChildren(element, codePara.Inlines, ref trimTextStart);
        }
Exemplo n.º 45
0
 public static void WriteError(BlockCollection blockCollection, Exception ex)
 {
     blockCollection.Add(CreatePara(new Run(ex.Message) { Foreground = Brushes.Red }));
 }
        /// <summary>
        /// Renders a paragraph element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="currentBlocks"></param>
        private void RenderPargraph(ParagraphBlock element, BlockCollection currentBlocks)
        {
            // Make a new paragraph
            Paragraph paragraph = new Paragraph();

            // Add some padding to differentiate the blocks
            paragraph.Margin = new Thickness(0, 12, 0, 0);

            // Add it to the blocks
            currentBlocks.Add(paragraph);

            // Render the children into the para inline.
            bool trimTextStart = true;
            RenderInlineChildren(element, paragraph.Inlines, ref trimTextStart);
        }
Exemplo n.º 47
0
        //Support functions
        private static BlockCollection<int> CreateNewCollection(int countOfBlocks = 8)
        {
            var blockCollection = new BlockCollection<int>();
            for (int i = 0; i < countOfBlocks; i++)
            {
                blockCollection.Add(new Block<int>(DefaultBlockSize) { i });
            }

            return blockCollection;
        }