Пример #1
0
        private Paragraph CreateParagraph(string text, JustificationValues justification)
        {
            Paragraph paragraph = new Paragraph(
                new ParagraphProperties(
                    new ParagraphStyleId()
            {
                Val = "Bold"
            },
                    new Justification()
            {
                Val = justification
            },
                    new ParagraphMarkRunProperties()
                    ),
                new Run(
                    new RunProperties(new FontSize()
            {
                Val = "30"
            }, new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            }),
                    new Text(text)
            {
                Space = SpaceProcessingModeValues.Preserve
            }));

            return(paragraph);
        }
Пример #2
0
        /// <summary>
        /// Populates the processing document and gets its body element.
        /// </summary>
        /// <returns>Body of the document that will hold the dictionary.</returns>
        private Body GetDocumentBody(WordprocessingDocument processingDocument)
        {
            // Create a MainDocumentPart instance
            MainDocumentPart mainDocPart = processingDocument.AddMainDocumentPart();

            mainDocPart.Document = new Document();

            // Create a Document instance
            Document document = mainDocPart.Document;

            // Create a Body instance
            Body body = document.AppendChild(new Body());


            // Create 2 columns for page layout
            SectionProperties sectionProperties = new SectionProperties();
            Columns           columns           = new Columns()
            {
                ColumnCount = 2
            };

            columns.Separator = OnOffValue.FromBoolean(true);
            sectionProperties.Append(columns);

            body.Append(sectionProperties);

            return(body);
        }
Пример #3
0
 internal DigitalInput(int numberOfInputOnGroup, NeuronGroup neuronGroup, ushort registerNumber, ushort bitInRegister)
 {
     _registerNumber  = registerNumber;
     _bitInRegister   = bitInRegister;
     UniqueIdentifyer = new UniqueIdentifier(neuronGroup, NeuronResource.DigitalInput, numberOfInputOnGroup);
     _currentValue    = OnOffValue.Unknown;
 }
Пример #4
0
 private void RaiseOnDigitalOutputStateChanged(IDigitalOutput digitaloutput, OnOffValue value)
 {
     Task.Run(() =>
     {
         OnOutputStateChanged?.Invoke(digitaloutput, value);
     });
 }
Пример #5
0
        //Create paragraph that contain the text.
        private static Paragraph generateParagraph(string text, bool isHeader)
        {
            Paragraph paragraph     = new Paragraph();
            Run       run_paragraph = new Run();

            paragraph.Append(run_paragraph);
            //if isHeader=true style the text as header.
            if (isHeader)
            {
                RunProperties runProperties = run_paragraph.AppendChild(new RunProperties());
                Bold          bold          = new Bold();
                bold.Val = OnOffValue.FromBoolean(true);
                runProperties.AppendChild(bold);
                FontSize fontSize = new FontSize();
                fontSize.Val        = "26";
                runProperties.Color = new Color()
                {
                    Val = "0E6EB8"
                };
                runProperties.AppendChild(fontSize);
            }
            run_paragraph.AppendChild(new Text(text));
            if (!isHeader)
            {
                run_paragraph.AppendChild(new Break());
            }
            return(paragraph);
        }
Пример #6
0
        internal static void Italic(this Run run)
        {
            RunProperties runProperties = run.GetOrCreate <RunProperties>(true);
            Italic        prop          = runProperties.GetOrCreate <Italic>();

            prop.Val = OnOffValue.FromBoolean(true);
        }
Пример #7
0
        private void UpdateLocalValue(bool raiseEvent = false)
        {
            var value = _neuronSpiConnector.GetSingleRegisterValue(_neuronGroup, _registerNumber);

            if (value == null)
            {
                return;
            }

            if (IsBitSet(value.Value, _bitNumber))
            {
                if (_currentValue != OnOffValue.On)
                {
                    _currentValue = OnOffValue.On;
                    raiseEvent    = true;
                }
            }
            else
            {
                if (_currentValue != OnOffValue.Off)
                {
                    _currentValue = OnOffValue.Off;
                    raiseEvent    = true;
                }
            }

            if (raiseEvent)
            {
                RaiseOnDigitalOutputStateChanged(this, _currentValue);
            }
        }
Пример #8
0
        static Texto TestComment(WordDoc wordDoc)
        {
            Comentario comentario = wordDoc.CreateComment();

            comentario.Append(
                "Descrição do comentário",
                new RunProperties()
            {
                Caps = new Caps()
                {
                    Val = OnOffValue.FromBoolean(true)
                }
            }
                );

            Texto texto = new Texto();

            texto.Append("Aqui vai começar um comentário, ");
            texto.StartComment(comentario.Id);
            texto.Append(
                "Texto de comentário, ",
                new RunProperties()
            {
                Bold = new Bold()
                {
                    Val = OnOffValue.FromBoolean(true)
                }
            }
                );
            texto.EndComment(comentario.Id);
            texto.Append("Texto fora do comentário,");

            return(texto);
        }
Пример #9
0
        private static Style CreateStyle(string fontcolor, string styleid, string stylename,
                                         string stylebasedon, string stylenextpara, string fontname, int fontsize, JustificationValues just, bool isBold, int spacing)
        {
            // we have to set the properties
            RunProperties rPr   = new RunProperties();
            Color         color = new Color()
            {
                Val = fontcolor
            };                                       // the color
            RunFonts rFont = new RunFonts();

            rFont.Ascii = fontname; // the font
            rPr.Append(color);
            rPr.Append(rFont);
            if (isBold)
            {
                rPr.Append(new Bold());
            }
            rPr.Append(new FontSize()
            {
                Val = fontsize.ToString()
            });                                                   //font size (in 1/72  of an inch)
            ParagraphProperties pPr = new ParagraphProperties();

            if (spacing > 0)
            {
                pPr.Append(new SpacingBetweenLines()
                {
                    Line              = spacing.ToString(),
                    LineRule          = LineSpacingRuleValues.Auto,
                    BeforeAutoSpacing = OnOffValue.FromBoolean(true)
                });
            }
            //creation of a style
            Style style = new Style();

            style.StyleId = styleid; //this is the ID of the style
            style.Append(new Name()
            {
                Val = stylename
            });                                       //this is name
            style.Append(new BasedOn()
            {
                Val = stylebasedon
            });                                             // our style based on ... style
            style.Append(new NextParagraphStyle()
            {
                Val = stylenextpara
            });                // the next paragraph is ... type
            style.Append(pPr); //we are adding properties previously defined
            style.Append(rPr); //we are adding properties previously defined
            //lets make it centered)
            style.Append(new ParagraphProperties(
                             new Justification()
            {
                Val = just
            }));
            return(style);
        }
Пример #10
0
        /**public void getFooterWithPageNumber()
         * {
         *  foreach (Section wordSection in this.adoc.Sections)
         *  {
         *      Range footerRange = wordSection.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
         *      footerRange.InlineShapes.AddHorizontalLineStandard();
         *      footerRange.Font.ColorIndex = WdColorIndex.wdDarkRed;
         *      footerRange.Font.Size = 10;
         *      footerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
         *      adoc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.Add();
         *  }
         * }**/

        public void generateCoverPage(string data)
        {
            body.Append(new Paragraph(new Run(new Break())));
            body.Append(new Paragraph(new Run(new Break())));
            body.Append(new Paragraph(new Run(new Break())));
            body.Append(new Paragraph(new Run(new Break())));

            //heading
            Paragraph           heading = new Paragraph();
            ParagraphProperties hp      = new ParagraphProperties();

            hp.Justification = new Justification()
            {
                Val = JustificationValues.Center
            };
            heading.Append(hp);
            Run           r             = new Run();
            RunProperties runProperties = r.AppendChild(new RunProperties());
            Bold          bold          = new Bold();

            bold.Val = OnOffValue.FromBoolean(true);
            FontSize size = new FontSize();

            size.Val = "60";
            runProperties.AppendChild(bold);
            runProperties.AppendChild(size);
            Text t = new Text(data);

            r.Append(t);
            heading.Append(r);
            body.Append(heading);

            //subheading
            Paragraph           subheading = new Paragraph();
            ParagraphProperties shp        = new ParagraphProperties();

            shp.Justification = new Justification()
            {
                Val = JustificationValues.Center
            };
            subheading.Append(shp);
            Run           rs           = new Run();
            RunProperties rhProperties = rs.AppendChild(new RunProperties());
            Bold          bs           = new Bold();

            bs.Val = OnOffValue.FromBoolean(true);
            FontSize sh = new FontSize();

            sh.Val = "40";
            rhProperties.AppendChild(bs);
            rhProperties.AppendChild(sh);
            Text subhead = new Text("BUSINESS PLAN");

            rs.Append(subhead);
            subheading.Append(rs);
            body.Append(subheading);
            addPageBreak();
        }
Пример #11
0
        private static RunProperties Bold()
        {
            RunProperties runProperties = new RunProperties();

            Bold bold = new Bold();

            bold.Val = OnOffValue.FromBoolean(true);
            return(runProperties);
        }
Пример #12
0
        // Add the bold style at a Run object used by a Paragraph in order to insert text in a Document.
        public RunProperties getBold(Run run)
        {
            RunProperties runProperties = run.AppendChild(new RunProperties());
            var           bold          = new Bold();

            bold.Val = OnOffValue.FromBoolean(true);
            runProperties.AppendChild(bold);
            return(runProperties);
        }
Пример #13
0
        internal static void ManageFooterRow(Models.Document document, Models.Table table, Table wordTable, TableLook tableLook, ContextModel context, OpenXmlPart documentPart, IFormatProvider formatProvider)
        {
            // add footer row
            if (table.FooterRow != null)
            {
                wordTable.AppendChild(table.FooterRow.Render(document, wordTable, context, documentPart, false, false, formatProvider));

                tableLook.LastRow = OnOffValue.FromBoolean(true);
            }
        }
Пример #14
0
        internal UserLed(int ledNumber, NeuronGroup neuronGroup, ushort coilNumber, NeuronSpiConnector neuronSpiConnector, ushort registerNumber, ushort bitNumber)
        {
            UniqueIdentifyer = new UniqueIdentifier(neuronGroup, NeuronResource.UserLed, ledNumber);

            _coilNumber         = coilNumber;
            _neuronSpiConnector = neuronSpiConnector;
            _registerNumber     = registerNumber;
            _bitNumber          = bitNumber;
            _currentValue       = OnOffValue.Unknown;
        }
Пример #15
0
 private void UserLedOnOnUserLedStateChanged(IUserLed userLed, OnOffValue value)
 {
     if (value == OnOffValue.On)
     {
         IndicatocColor = _onColor;
     }
     else
     {
         IndicatocColor = _offColor;
     }
 }
Пример #16
0
        /// <summary>
        /// This is the addParagraph method.
        /// It is used to create a paragraph and append to body with style
        /// and preference according to the given parameters.
        /// </summary>
        /// <param name="body">the location where the content push to</param>
        /// <param name="content">the content push to the body</param>
        /// <param name="bold">determine the paragraph is bold or not</param>
        /// <param name="spacing">spacing between lines</param>
        /// <param name="insertParagraphBefore">determine whether a blank paragraph before the content push</param>
        /// <param name="insertParagraphAfter">determine whether a blank paragraph after the content push</param>
        private void addParagraph(Body body, String content, Boolean bold, int spacing, bool insertParagraphBefore, bool insertParagraphAfter, bool entryTitle = false)
        {
            // insert a new paragraph before the body
            if (insertParagraphBefore)
            {
                body.Append(new Paragraph());
            }

            ParagraphProperties pPr       = new ParagraphProperties();
            Paragraph           paragraph = new Paragraph(pPr);

            if (spacing != 0)
            {
                paragraph.ParagraphProperties.Append(new SpacingBetweenLines()
                {
                    BeforeLines = spacing,
                    AfterLines  = spacing
                });
            }

            // make header style
            if (entryTitle)
            {
                pPr.ParagraphStyleId = new ParagraphStyleId()
                {
                    Val = "entry_heading"
                };
            }

            Run run = new Run(new RunProperties());

            if (bold)
            {
                run.RunProperties.Append(new Bold()
                {
                    Val = OnOffValue.FromBoolean(true)
                });
            }

            Text text = new Text(content);

            // set text of the paragraph and append it to the body
            run.Append(text);
            paragraph.Append(run);
            body.Append(paragraph);

            // insert a new paragraph after the body
            if (insertParagraphAfter)
            {
                body.Append(new Paragraph());
            }
        }
Пример #17
0
        public void BeforeAfter_AutoSpacingTest()
        {
            _instance.Element = new SpacingBetweenLines()
            {
                Before            = "0",
                After             = "0",
                AfterAutoSpacing  = OnOffValue.FromBoolean(true),
                BeforeAutoSpacing = new OnOffValue()
            };

            Assert.IsNull(_instance.After);
            Assert.IsNull(_instance.Before);
        }
Пример #18
0
        private static Run GetWordTextElement(
            string text,
            int fSize,
            bool isUnderlined  = false,
            bool isSuperscript = false)
        {
            Run           run           = new Run();
            RunProperties runProperties = run.AppendChild(new RunProperties());
            Italic        italic        = new Italic();

            italic.Val = OnOffValue.FromBoolean(true);
            FontSize fontSize = new FontSize()
            {
                Val = fSize.ToString()
            };

            runProperties.AppendChild(italic);
            runProperties.AppendChild(fontSize);
            RunFonts font = new RunFonts()
            {
                Ascii         = "GOST type B",
                HighAnsi      = "GOST type B",
                ComplexScript = "GOST type B"
            };

            runProperties.Append(font);
            if (isUnderlined)
            {
                Underline underline = new Underline()
                {
                    Val = UnderlineValues.Single,
                };
                runProperties.Append(underline);
            }
            if (isSuperscript)
            {
                VerticalTextAlignment vertAlign = new VerticalTextAlignment()
                {
                    Val = VerticalPositionValues.Superscript,
                };
                runProperties.Append(vertAlign);
            }
            run.AppendChild(new Text()
            {
                Text  = text,
                Space = SpaceProcessingModeValues.Preserve,
            });
            return(run);
        }
Пример #19
0
        private static RunProperties FontTable()
        {
            RunProperties runProperties = new RunProperties(
                new RunFonts()
            {
                Ascii = "Times New Roman",
            });

            runProperties.FontSize = new FontSize()
            {
                Val = "26"
            };
            Bold bold = new Bold();

            bold.Val = OnOffValue.FromBoolean(true);
            return(runProperties);
        }
Пример #20
0
        public static RunProperties GetRunProperties(ResumeFont resumeFont)
        {
            var runProperties = new RunProperties();

            if (resumeFont.FontWeight == ResumeFontWeight.Bold)
            {
                var bold = new Bold
                {
                    Val = OnOffValue.FromBoolean(true)
                };
                runProperties.AppendChild(bold);
            }

            runProperties.AppendChild(GetFontSize(resumeFont));


            return(runProperties);
        }
Пример #21
0
        // Add properties with a stykle similar to Heading 3 style at a Run object used by a Paragraph in order to insert text in a Document.
        public RunProperties getHeading3(Run run)
        {
            RunProperties runProperties = run.AppendChild(new RunProperties());
            var           bold          = new Bold();

            bold.Val = OnOffValue.FromBoolean(true);
            var color = new Color {
                Val = "365F91", ThemeColor = ThemeColorValues.Accent1, ThemeShade = "BF"
            };
            var size = new FontSize {
                Val = new StringValue("25")
            };

            runProperties.AppendChild(bold);
            runProperties.AppendChild(color);
            runProperties.AppendChild(size);
            return(runProperties);
        }
Пример #22
0
        /// <summary>
        /// Makes a paragraph text italic
        /// </summary>
        /// <returns></returns>
        public Paragraph Italic()
        {
            if (Runs.Count() == 0)
            {
                var paragraphProperties        = paragraph.GetOrCreate <ParagraphProperties>();
                var paragraphMarkRunProperties = paragraphProperties.GetOrCreate <ParagraphMarkRunProperties>();

                Italic Italic = paragraphMarkRunProperties.GetOrCreate <Italic>();
                Italic.Val = OnOffValue.FromBoolean(true);
            }
            else
            {
                foreach (var run in Runs)
                {
                    run.Italic();
                }
            }

            return(this);
        }
        public static string ToPlainText(System.IO.Stream stream)
        {
            using WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(stream, false);
            var hideSpellingErrors = new HideSpellingErrors();

            hideSpellingErrors.Val = OnOffValue.FromBoolean(true);
            wordprocessingDocument.MainDocumentPart.Document.Append(hideSpellingErrors);

            var sb = new StringBuilder();

            foreach (var paragraph in wordprocessingDocument.MainDocumentPart.RootElement.Descendants <Paragraph>())
            {
                foreach (var run in paragraph.Elements <Run>())
                {
                    string text = run.Elements <Text>().Aggregate("", (s, t) => s + " " + t.Text);
                    run.RemoveAllChildren <Text>();
                    run.AppendChild(new Text(text));
                    sb.Append(run.InnerText);
                }
            }
            return(sb.ToString());
        }
        public OpenXmlElement SectionTitlePart(int sectionNumber)
        {
            var paragraph = new Paragraph();

            var run = new Run();

            var runProperties = new RunProperties();
            var bold          = new Bold();

            bold.Val = OnOffValue.FromBoolean(true);
            runProperties.Append(bold);

            run.Append(runProperties);

            var text = new Text($"( {sectionNumber} ) {Section}");

            run.Append(text);

            paragraph.Append(run);

            return(paragraph);
        }
Пример #25
0
        private void addParagraph(Body body, String content, Boolean bold, int spacing, bool insertParagraphBefore, bool insertParagraphAfter)
        {
            if (insertParagraphBefore)
            {
                body.Append(new Paragraph());
            }

            Paragraph paragraph = new Paragraph(new ParagraphProperties());

            if (spacing != 0)
            {
                paragraph.ParagraphProperties.Append(new SpacingBetweenLines()
                {
                    BeforeLines = spacing,
                    AfterLines  = spacing
                });
            }

            Run run = new Run(new RunProperties());

            if (bold)
            {
                run.RunProperties.Append(new Bold()
                {
                    Val = OnOffValue.FromBoolean(true)
                });
            }

            Text text = new Text(content);

            run.Append(text);
            paragraph.Append(run);
            body.Append(paragraph);

            if (insertParagraphAfter)
            {
                body.Append(new Paragraph());
            }
        }
Пример #26
0
        private void SetValues(string before, string after, string lines, bool?beforeAuto = null, bool?afterAuto = null)
        {
            OnOffValue beforeAutoOnOff = null;
            OnOffValue afterAutoOnOff  = null;

            if (beforeAuto.HasValue)
            {
                beforeAutoOnOff = OnOffValue.FromBoolean(beforeAuto.Value);
            }
            if (afterAuto.HasValue)
            {
                afterAutoOnOff = OnOffValue.FromBoolean(afterAuto.Value);
            }

            _instance.Element = new SpacingBetweenLines()
            {
                Before            = before,
                After             = after,
                Line              = lines,
                BeforeAutoSpacing = beforeAutoOnOff,
                AfterAutoSpacing  = afterAutoOnOff
            };
        }
Пример #27
0
        public void SetRegisterValue(ushort registerNumber, ushort value)
        {
            if (registerNumber != _registerNumber)
            {
                return;
            }

            var bitValue = IsBitSet(value, _bitInRegister);

            if (bitValue && _currentValue != OnOffValue.On)
            {
                _currentValue = OnOffValue.On;
                RaiseOnDigitalInputChanged(this, _currentValue);
            }

            if (bitValue || _currentValue == OnOffValue.Off)
            {
                return;
            }

            _currentValue = OnOffValue.Off;

            RaiseOnDigitalInputChanged(this, _currentValue);
        }
Пример #28
0
        public void OpenXmlSimpleTypeConverterTest()
        {
            // 1. Base64BinaryValue
            Base64BinaryValue base64 = new Base64BinaryValue();

            base64 = "AA3322";
            Assert.True(base64 == "AA3322");
            Assert.Equal("AA3322", base64.Value);
            base64 = Base64BinaryValue.FromString("1234");
            Assert.Equal("1234", base64.ToString());
            Assert.Equal("1234", Base64BinaryValue.ToString(base64));

            // 2. BooleanValue
            BooleanValue booleanValue = new BooleanValue();

            booleanValue = true;
            Assert.True(booleanValue);
            Assert.True(booleanValue.Value);
            booleanValue = BooleanValue.FromBoolean(false);
            Assert.False(booleanValue);
            Assert.False(BooleanValue.ToBoolean(booleanValue));

            // 3. ByteValue
            ByteValue byteValue = new ByteValue();
            byte      bt        = 1;

            byteValue = bt;
            Assert.True(bt == byteValue);
            Assert.Equal(bt, byteValue.Value);
            bt        = 2;
            byteValue = ByteValue.FromByte(bt);
            Assert.Equal(bt, ByteValue.ToByte(byteValue));

            // 4. DateTimeValue
            DateTimeValue dtValue = new DateTimeValue();
            DateTime      dt      = DateTime.Now;

            dtValue = dt;
            Assert.True(dt == dtValue);
            dt      = DateTime.Now.AddDays(1);
            dtValue = DateTimeValue.FromDateTime(dt);
            Assert.Equal(dt, dtValue.Value);
            Assert.Equal(dt, DateTimeValue.ToDateTime(dt));

            // 5. DecimalValue
            DecimalValue decimalValue = new DecimalValue();
            decimal      dcm          = 10;

            decimalValue = dcm;
            Assert.True(dcm == decimalValue);
            decimalValue = DecimalValue.FromDecimal(20);
            Assert.Equal(20, decimalValue.Value);
            Assert.Equal(20, DecimalValue.ToDecimal(decimalValue));

            // 6. DoubleValue
            DoubleValue doubleValue = new DoubleValue();
            double      dbl         = 1.1;

            doubleValue = dbl;
            Assert.True(dbl == doubleValue);
            doubleValue = DoubleValue.FromDouble(2.2);
            Assert.Equal(2.2, doubleValue.Value);
            Assert.Equal(2.2, DoubleValue.ToDouble(doubleValue));

            // 7. HexBinaryValue
            HexBinaryValue hexBinaryValue = new HexBinaryValue();
            string         hex            = "0X99CCFF";

            hexBinaryValue = hex;
            Assert.True(hex == hexBinaryValue);
            hex            = "111111";
            hexBinaryValue = HexBinaryValue.FromString(hex);
            Assert.Equal(hex, hexBinaryValue.Value);
            Assert.Equal(hex, HexBinaryValue.ToString(hexBinaryValue));

            // 8. Int16
            Int16Value int16Value = new Int16Value();
            short      int16      = 16;

            int16Value = int16;
            Assert.True(int16 == int16Value);
            int16      = 17;
            int16Value = Int16Value.FromInt16(int16);
            Assert.Equal(int16, int16Value.Value);
            Assert.Equal(int16, Int16Value.ToInt16(int16Value));

            // 9. Int32
            Int32Value int32Value = new Int32Value();
            int        int32      = 32;

            int32Value = int32;
            Assert.True(int32 == int32Value);
            int32      = 33;
            int32Value = Int32Value.FromInt32(int32);
            Assert.Equal(int32, int32Value.Value);
            Assert.Equal(int32, Int32Value.ToInt32(int32Value));

            // 10. Int64
            Int64Value int64Value = new Int64Value();
            long       int64      = 64;

            int64Value = int64;
            Assert.True(int64 == int64Value);
            int64      = 17;
            int64Value = Int64Value.FromInt64(int64);
            Assert.Equal(int64, int64Value.Value);
            Assert.Equal(int64, Int64Value.ToInt64(int64Value));

            // 11. IntegerValue
            IntegerValue integerValue = new IntegerValue();
            int          integer      = 64;

            integerValue = integer;
            Assert.True(integer == integerValue);
            integer      = 17;
            integerValue = IntegerValue.FromInt64(integer);
            Assert.Equal(integer, integerValue.Value);
            Assert.Equal(integer, IntegerValue.ToInt64(integerValue));

            // 12. OnOffValue
            OnOffValue onOffValue = new OnOffValue();

            onOffValue = true;
            Assert.True(onOffValue);
            onOffValue = OnOffValue.FromBoolean(false);
            Assert.False(onOffValue.Value);
            Assert.False(OnOffValue.ToBoolean(onOffValue));

            // 13. SByteValue
            SByteValue sbyteValue = new SByteValue();
            sbyte      sbt        = sbyte.MaxValue;

            sbyteValue = sbt;
            Assert.True(sbt == sbyteValue);
            sbt        = sbyte.MinValue;
            sbyteValue = SByteValue.FromSByte(sbt);
            Assert.Equal(sbt, sbyteValue.Value);
            Assert.Equal(sbt, SByteValue.ToSByte(sbt));

            // 14. SingleValue
            SingleValue singleValue = new SingleValue();
            float       single      = float.MaxValue;

            singleValue = single;
            Assert.True(single == singleValue);
            single      = float.NaN;
            singleValue = SingleValue.FromSingle(single);
            Assert.Equal(single, singleValue.Value);
            Assert.Equal(single, SingleValue.ToSingle(singleValue));

            // 15. StringValue
            StringValue stringValue = new StringValue();
            string      str         = "Ethan";

            stringValue = str;
            Assert.True(str == stringValue);
            str         = "Yin";
            stringValue = StringValue.FromString(str);
            Assert.Equal(str, stringValue.Value);
            Assert.Equal(str, stringValue.ToString());
            Assert.Equal(str, StringValue.ToString(stringValue));

            // 16. TrueFalseBlankValue
            TrueFalseBlankValue tfbValue = new TrueFalseBlankValue();

            tfbValue = true;
            Assert.True(tfbValue);
            tfbValue = TrueFalseBlankValue.FromBoolean(false);
            Assert.False(tfbValue.Value);
            Assert.False(TrueFalseBlankValue.ToBoolean(tfbValue));

            // 17. TrueFalseValue
            TrueFalseValue tfValue = new TrueFalseValue();

            tfValue = true;
            Assert.True(tfValue);
            tfValue = TrueFalseValue.FromBoolean(false);
            Assert.False(tfValue.Value);
            Assert.False(TrueFalseValue.ToBoolean(tfValue));

            // 18. UInt16Value
            UInt16Value uint16Value = new UInt16Value();
            ushort      uint16      = ushort.MaxValue;

            uint16Value = uint16;
            Assert.True(uint16 == uint16Value);
            uint16      = ushort.MinValue;
            uint16Value = UInt16Value.FromUInt16(uint16);
            Assert.Equal(uint16, uint16Value.Value);
            Assert.Equal(uint16, UInt16Value.ToUInt16(uint16Value));

            // 19. UInt32Value
            UInt32Value uint32Value = new UInt32Value();
            uint        uint32      = uint.MaxValue;

            uint32Value = uint32;
            Assert.True(uint32 == uint32Value);
            uint32      = uint.MinValue;
            uint32Value = UInt32Value.FromUInt32(uint32);
            Assert.Equal(uint32, uint32Value.Value);
            Assert.Equal(uint32, UInt32Value.ToUInt32(uint32Value));

            // 20. UInt64Value
            UInt64Value uint64Value = new UInt64Value();
            ulong       uint64      = ulong.MaxValue;

            uint64Value = uint64;
            Assert.True(uint64 == uint64Value);
            uint64      = ulong.MinValue;
            uint64Value = UInt64Value.FromUInt64(uint64);
            Assert.Equal(uint64, uint64Value.Value);
            Assert.Equal(uint64, UInt64Value.ToUInt64(uint64Value));
        }
Пример #29
0
        public void OnOffValueTest()
        {
            OnOffValue target = new OnOffValue();

            Assert.False(target.HasValue);

            target.InnerText = "true";
            Assert.True(target.HasValue);
            Assert.True(target.Value);
            Assert.True(target == true);

            target.InnerText = "false";
            Assert.True(target.HasValue);
            Assert.False(target.Value);
            Assert.True(target == false);

            target.InnerText = "on";
            Assert.True(target.HasValue);
            Assert.True(target.Value);
            Assert.True(target == true);

            target.InnerText = "off";
            Assert.True(target.HasValue);
            Assert.False(target.Value);
            Assert.True(target == false);

            target.InnerText = "1";
            Assert.True(target.HasValue);
            Assert.True(target.Value);
            Assert.True(target == true);

            target.InnerText = "0";
            Assert.True(target.HasValue);
            Assert.False(target.Value);
            Assert.True(target == false);

            target.InnerText = "invalid";
            Assert.False(target.HasValue);
            try
            {
                bool v = target.Value;
                Assert.True(false); // Assert.Fail("FormatException is not thrown.");
            }
            catch (FormatException)
            {
            }

            target.Value = true;
            Assert.Equal("true", target.InnerText);

            target.Value = false;
            Assert.Equal("false", target.InnerText);

            target = true;
            Assert.Equal("true", target.InnerText);

            target = false;
            Assert.Equal("false", target.InnerText);

            OnOffValue target2 = new OnOffValue(true);

            Assert.True(target2.HasValue);
            Assert.True(target2.Value);

            OnOffValue target3 = new OnOffValue(false);

            Assert.True(target3.HasValue);
            Assert.False(target3.Value);

            OnOffValue target4 = new OnOffValue(target2);

            Assert.True(target4.HasValue);
            Assert.True(target4.Value);

            OnOffValue target5 = new OnOffValue(target3);

            Assert.False(target5.Value);
        }
Пример #30
0
 public static bool IsOn(this OnOffValue onOffValue, bool ifNull = false)
 {
     return(onOffValue?.Value ?? ifNull);
 }
Пример #31
0
        public void OnOffValueTest()
        {
            OnOffValue target = new OnOffValue();

            Assert.False(target.HasValue);

            target.InnerText = "true";
            Assert.True(target.HasValue);
            Assert.Equal(true, target.Value);
            Assert.True(true == target);

            target.InnerText = "false";
            Assert.True(target.HasValue);
            Assert.Equal(false, target.Value);
            Assert.True(false == target);

            target.InnerText = "on";
            Assert.True(target.HasValue);
            Assert.Equal(true, target.Value);
            Assert.True(true == target);

            target.InnerText = "off";
            Assert.True(target.HasValue);
            Assert.Equal(false, target.Value);
            Assert.True(false == target);

            target.InnerText = "1";
            Assert.True(target.HasValue);
            Assert.Equal(true, target.Value);
            Assert.True(true == target);

            target.InnerText = "0";
            Assert.True(target.HasValue);
            Assert.Equal(false, target.Value);
            Assert.True(false == target);

            target.InnerText = "invalid";
            Assert.False(target.HasValue);
            try
            {
                bool v = target.Value;
                Assert.True(false); // Assert.Fail("FormatException is not thrown.");
            }
            catch (FormatException)
            {
            }

            target.Value = true;
            Assert.Equal("true", target.InnerText);

            target.Value = false;
            Assert.Equal("false", target.InnerText);

            target = true;
            Assert.Equal("true", target.InnerText);

            target = false;
            Assert.Equal("false", target.InnerText);

            OnOffValue target2 = new OnOffValue(true);
            Assert.True(target2.HasValue);
            Assert.Equal(true, target2.Value);

            OnOffValue target3 = new OnOffValue(false);
            Assert.True(target3.HasValue);
            Assert.Equal(false, target3.Value);

            OnOffValue target4 = new OnOffValue(target2);
            Assert.True(target4.HasValue);
            Assert.Equal(true, target4.Value);

            OnOffValue target5 = new OnOffValue(target3);
            Assert.Equal(false, target5.Value);

        }
Пример #32
0
        public void OpenXmlSimpleTypeConverterTest()
        {
            // 1. Base64BinaryValue
            Base64BinaryValue base64 = new Base64BinaryValue();
            base64 = "AA3322";
            Assert.True("AA3322" == base64);
            Assert.Equal("AA3322", base64.Value);
            base64 = Base64BinaryValue.FromString("1234");
            Assert.Equal("1234", base64.ToString());
            Assert.Equal("1234", Base64BinaryValue.ToString(base64));

            // 2. BooleanValue
            BooleanValue booleanValue = new BooleanValue();
            booleanValue = true;
            Assert.True(booleanValue);
            Assert.True(booleanValue.Value);
            booleanValue = BooleanValue.FromBoolean(false);
            Assert.False(booleanValue);
            Assert.Equal(false, BooleanValue.ToBoolean(booleanValue));

            // 3. ByteValue
            ByteValue byteValue = new ByteValue();
            Byte bt = 1;
            byteValue = bt;
            Assert.True(bt == byteValue);
            Assert.Equal(bt, byteValue.Value);
            bt = 2;
            byteValue = ByteValue.FromByte(bt);
            Assert.Equal(bt, ByteValue.ToByte(byteValue));

            // 4. DateTimeValue
            DateTimeValue dtValue = new DateTimeValue();
            DateTime dt = DateTime.Now;
            dtValue = dt;
            Assert.True(dt == dtValue);
            dt = DateTime.Now.AddDays(1);
            dtValue = DateTimeValue.FromDateTime(dt);
            Assert.Equal(dt, dtValue.Value);
            Assert.Equal(dt, DateTimeValue.ToDateTime(dt));

            // 5. DecimalValue
            DecimalValue decimalValue = new DecimalValue();
            decimal dcm = 10;
            decimalValue = dcm;
            Assert.True(dcm == decimalValue);
            decimalValue = DecimalValue.FromDecimal(20);
            Assert.Equal(20, decimalValue.Value);
            Assert.Equal(20, DecimalValue.ToDecimal(decimalValue));

            // 6. DoubleValue
            DoubleValue doubleValue = new DoubleValue();
            double dbl = 1.1;
            doubleValue = dbl;
            Assert.True(dbl == doubleValue);
            doubleValue = DoubleValue.FromDouble(2.2);
            Assert.Equal(2.2, doubleValue.Value);
            Assert.Equal(2.2, DoubleValue.ToDouble(doubleValue));

            // 7. HexBinaryValue
            HexBinaryValue hexBinaryValue = new HexBinaryValue();
            string hex = "0X99CCFF";
            hexBinaryValue = hex;
            Assert.True(hex == hexBinaryValue);
            hex = "111111";
            hexBinaryValue = HexBinaryValue.FromString(hex);
            Assert.Equal(hex, hexBinaryValue.Value);
            Assert.Equal(hex, HexBinaryValue.ToString(hexBinaryValue));

            // 8. Int16
            Int16Value int16Value = new Int16Value();
            Int16 int16 = 16;
            int16Value = int16;
            Assert.True(int16 == int16Value);
            int16 = 17;
            int16Value = Int16Value.FromInt16(int16);
            Assert.Equal(int16, int16Value.Value);
            Assert.Equal(int16, Int16Value.ToInt16(int16Value));

            // 9. Int32
            Int32Value int32Value = new Int32Value();
            Int32 int32 = 32;
            int32Value = int32;
            Assert.True(int32 == int32Value);
            int32 = 33;
            int32Value = Int32Value.FromInt32(int32);
            Assert.Equal(int32, int32Value.Value);
            Assert.Equal(int32, Int32Value.ToInt32(int32Value));

            // 10. Int64
            Int64Value int64Value = new Int64Value();
            Int64 int64 = 64;
            int64Value = int64;
            Assert.True(int64 == int64Value);
            int64 = 17;
            int64Value = Int64Value.FromInt64(int64);
            Assert.Equal(int64, int64Value.Value);
            Assert.Equal(int64, Int64Value.ToInt64(int64Value));

            // 11. IntegerValue
            IntegerValue integerValue = new IntegerValue();
            int integer = 64;
            integerValue = integer;
            Assert.True(integer == integerValue);
            integer = 17;
            integerValue = IntegerValue.FromInt64(integer);
            Assert.Equal(integer, integerValue.Value);
            Assert.Equal(integer, IntegerValue.ToInt64(integerValue));

            // 12. OnOffValue
            OnOffValue onOffValue = new OnOffValue();
            onOffValue = true;
            Assert.True(onOffValue);
            onOffValue = OnOffValue.FromBoolean(false);
            Assert.Equal(false, onOffValue.Value);
            Assert.Equal(false, OnOffValue.ToBoolean(onOffValue));

            // 13. SByteValue
            SByteValue sbyteValue = new SByteValue();
            SByte sbt = SByte.MaxValue;
            sbyteValue = sbt;
            Assert.True(sbt == sbyteValue);
            sbt = SByte.MinValue;
            sbyteValue = SByteValue.FromSByte(sbt);
            Assert.Equal(sbt, sbyteValue.Value);
            Assert.Equal(sbt, SByteValue.ToSByte(sbt));

            // 14. SingleValue
            SingleValue singleValue = new SingleValue();
            Single single = Single.MaxValue;
            singleValue = single;
            Assert.True(single == singleValue);
            single = Single.NaN;
            singleValue = SingleValue.FromSingle(single);
            Assert.Equal(single, singleValue.Value);
            Assert.Equal(single, SingleValue.ToSingle(singleValue));

            // 15. StringValue
            StringValue stringValue = new StringValue();
            String str = "Ethan";
            stringValue = str;
            Assert.True(str == stringValue);
            str = "Yin";
            stringValue = StringValue.FromString(str);
            Assert.Equal(str, stringValue.Value);
            Assert.Equal(str, stringValue.ToString());
            Assert.Equal(str, StringValue.ToString(stringValue));

            // 16. TrueFalseBlankValue
            TrueFalseBlankValue tfbValue = new TrueFalseBlankValue();
            tfbValue = true;
            Assert.True(tfbValue);
            tfbValue = TrueFalseBlankValue.FromBoolean(false);
            Assert.Equal(false, tfbValue.Value);
            Assert.Equal(false, TrueFalseBlankValue.ToBoolean(tfbValue));

            // 17. TrueFalseValue
            TrueFalseValue tfValue = new TrueFalseValue();
            tfValue = true;
            Assert.True(tfValue);
            tfValue = TrueFalseValue.FromBoolean(false);
            Assert.Equal(false, tfValue.Value);
            Assert.Equal(false, TrueFalseValue.ToBoolean(tfValue));

            // 18. UInt16Value
            UInt16Value uint16Value = new UInt16Value();
            UInt16 uint16 = UInt16.MaxValue;
            uint16Value = uint16;
            Assert.True(uint16 == uint16Value);
            uint16 = UInt16.MinValue;
            uint16Value = UInt16Value.FromUInt16(uint16);
            Assert.Equal(uint16, uint16Value.Value);
            Assert.Equal(uint16, UInt16Value.ToUInt16(uint16Value));

            // 19. UInt32Value
            UInt32Value uint32Value = new UInt32Value();
            UInt32 uint32 = UInt32.MaxValue;
            uint32Value = uint32;
            Assert.True(uint32 == uint32Value);
            uint32 = UInt32.MinValue;
            uint32Value = UInt32Value.FromUInt32(uint32);
            Assert.Equal(uint32, uint32Value.Value);
            Assert.Equal(uint32, UInt32Value.ToUInt32(uint32Value));

            // 20. UInt64Value
            UInt64Value uint64Value = new UInt64Value();
            UInt64 uint64 = UInt64.MaxValue;
            uint64Value = uint64;
            Assert.True(uint64 == uint64Value);
            uint64 = UInt64.MinValue;
            uint64Value = UInt64Value.FromUInt64(uint64);
            Assert.Equal(uint64, uint64Value.Value);
            Assert.Equal(uint64, UInt64Value.ToUInt64(uint64Value));
        }