示例#1
0
        /// <summary>
        /// Method to check if file is image file
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private bool CheckIfImageFile(IFormFile file)
        {
            var ms = new MemoryStream();

            file.CopyTo(ms);
            return(WriterHelper.GetImageFormat(ms) != WriterHelper.ImageFormat.unknown);
        }
示例#2
0
        /// <summary>
        /// Formats a Graph Header by creating an <strong>&lt;rdf:RDF&gt;</strong> element and adding namespace definitions.
        /// </summary>
        /// <param name="g">Graph.</param>
        /// <returns></returns>
        public string FormatGraphHeader(IGraph g)
        {
            _mapper = new QNameOutputMapper(g.NamespaceMap);
            StringBuilder output = new StringBuilder();

            output.Append(GetGraphHeaderBase());
            foreach (String prefix in g.NamespaceMap.Prefixes)
            {
                if (!prefix.Equals("rdf"))
                {
                    if (prefix.Equals(String.Empty))
                    {
                        output.Append(" xmlns=\"" + WriterHelper.EncodeForXml(g.NamespaceMap.GetNamespaceUri(prefix).AbsoluteUri) + "\"");
                    }
                    else
                    {
                        output.Append(" xmlns:" + prefix + "=\"" + WriterHelper.EncodeForXml(g.NamespaceMap.GetNamespaceUri(prefix).AbsoluteUri) + "\"");
                    }
                }
            }
            if (g.BaseUri != null)
            {
                output.Append(" xml:base=\"" + WriterHelper.EncodeForXml(g.BaseUri.AbsoluteUri) + "\"");
            }
            output.Append(">");
            return(output.ToString());
        }
        public void checkChars_7(XmlWriterUtils utils, string indentChars)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.OmitXmlDeclaration = true;
            wSettings.CheckCharacters    = true;
            wSettings.CloseOutput        = true;
            wSettings.Indent             = true;
            wSettings.IndentChars        = indentChars;
            if (indentChars == "~surogate~")
            {
                wSettings.IndentChars = "\uDD12\uDD01";
            }

            XmlWriter w = null;

            try
            {
                w = WriterHelper.Create("writer.out", wSettings, overrideAsync: true, async: utils.Async);
            }
            catch (ArgumentException e)
            {
                CError.WriteLineIgnore(e.ToString());
                return;
            }
            finally
            {
                if (w != null)
                {
                    w.Dispose();
                }
            }

            Assert.True(false, "Did not throw exception");
        }
        public void checkChars_9(XmlWriterUtils utils)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.OmitXmlDeclaration  = true;
            wSettings.CheckCharacters     = true;
            wSettings.CloseOutput         = true;
            wSettings.NewLineOnAttributes = true;
            wSettings.Indent      = true;
            wSettings.IndentChars = "foo";

            XmlWriter w = null;

            try
            {
                w = WriterHelper.Create("writer.out", wSettings, overrideAsync: true, async: utils.Async);
            }
            catch (ArgumentException e)
            {
                CError.WriteLineIgnore(e.ToString());
                return;
            }
            finally
            {
                if (w != null)
                {
                    w.Dispose();
                }
            }

            CError.WriteLine("Did not throw exception");
            Assert.True(false);
        }
        public static string loopTab(string tabName, string pathName)
        {
            Process[] procsChrome = Process.GetProcessesByName("chrome");

            if (procsChrome.Length <= 0)
            {
                return(null);
            }

            //trim received tabName

            if (tabName.Contains("Audio playing"))
            {
                tabName = tabName.Replace("Audio playing", "").Trim();
            }

            foreach (Process proc in procsChrome)
            {
                WriterHelper writer = new WriterHelper();
                // the chrome process must have a window
                if (proc.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                AutomationElement root       = AutomationElement.FromHandle(proc.MainWindowHandle);
                Condition         condNewTab = new PropertyCondition(AutomationElement.NameProperty, "New Tab");
                AutomationElement elmNewTab  = root.FindFirst(TreeScope.Descendants, condNewTab);
                // get the tabstrip by getting the parent of the 'new tab' button
                TreeWalker        treewalker  = TreeWalker.ControlViewWalker;
                AutomationElement elmTabStrip = treewalker.GetParent(elmNewTab);
                // loop through all the tabs and get the names which is the page title
                Condition condTabItem = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem);
                foreach (AutomationElement tabitem in elmTabStrip.FindAll(TreeScope.Children, condTabItem))
                {
                    if (tabitem.Current.Name.Contains(tabName))
                    {
                        while (true)
                        {
                            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3));
                            List <string> tempList = new List <string>();
                            string        temp     = tabitem.Current.Name;
                            if (temp.Contains("Audio playing"))
                            {
                                temp = temp.Replace("Audio playing", "").Trim();
                            }
                            tempList.Add(temp);
                            //Console.WriteLine(tabitem.Current.Name);
                            writer.WriterText(pathName, @"\youtubetitle.txt", tempList);
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }

            return(null);
        }
示例#6
0
 private static void Header()
 {
     Console.Clear();
     Shared.Header();
     Console.WriteLine("Enter Activity\n");
     Console.WriteLine("[0] Exit");
     WriterHelper.RedText("=", 119);
 }
示例#7
0
        public void WriteTerminalToken(Token token, int depth)
        {
            string initSpaces = WriterHelper.GetSpacesDepth(depth);

            _streamWriter.Write(initSpaces + "<" + token.GetTokenTypeName() + "> ");
            _streamWriter.Write(token.OutputValue);
            _streamWriter.WriteLine(" </" + token.GetTokenTypeName() + ">");
        }
示例#8
0
        protected void CreateWriter(WriteThru writeThru)
        {
            // Assumption is that the Create method doesn't throw NullReferenceException and
            // it is not the goal of this framework to test if they are thrown anywhere.
            // but if they are thrown that's a problem and they shouldn't be caught but exposed.

            Log("Writing thru : " + writeThru);

            try
            {
                switch (writeThru)
                {
                case WriteThru.Stream:
                    _factoryWriter = WriterHelper.Create(_stream, _settings);
                    break;

                case WriteThru.StringBuilder:
                    _factoryWriter = WriterHelper.Create(_stringBuilder, _settings);
                    break;

                case WriteThru.TextWriter:
                    _factoryWriter = WriterHelper.Create(_textWriter, _settings);
                    break;

                case WriteThru.XmlWriter:
                    _factoryWriter = WriterHelper.Create(_underlyingWriter, _settings);
                    break;
                }

                pstate = TestState.CreateSuccess;
            }
            catch (Exception ane)
            {
                Log(ane.ToString());
                if (!IsVariationValid)
                {
                    if (!CheckException(ane))
                    {
                        pstate = TestState.Error;
                        DumpVariationInfo();
                        throw new CTestFailedException(
                                  "Exception Thrown in CreateMethod, is your variation data correct?");
                    }
                    else
                    {
                        //This means that the Exception was checked and everything is fine.
                        pstate = TestState.Pass;
                    }
                }//Else valid variation threw exception
                else
                {
                    pstate = TestState.Error;
                    DumpVariationInfo();
                    throw new CTestFailedException(
                              "Exception Thrown in CreateMethod, is your variation data correct?");
                }
            }
        }
        /// <summary>
        /// Formats a SPARQL Result
        /// </summary>
        /// <param name="result">SPARQL Result</param>
        /// <returns></returns>
        public string Format(SparqlResult result)
        {
            StringBuilder output = new StringBuilder();

            output.AppendLine(" <result>");
            foreach (String var in result.Variables)
            {
                if (result.HasValue(var))
                {
                    INode value = result[var];
                    if (value != null)
                    {
                        output.Append("  <binding name=\"" + var + "\">");
                        switch (value.NodeType)
                        {
                        case NodeType.Blank:
                            output.Append("<bnode>" + ((IBlankNode)value).InternalID + "</bnode>");
                            break;

                        case NodeType.GraphLiteral:
                            throw new RdfOutputException(WriterErrorMessages.GraphLiteralsUnserializable("SPARQL XML Results"));

                        case NodeType.Literal:
                            ILiteralNode lit = (ILiteralNode)value;
                            output.Append("<literal");
                            if (lit.DataType != null)
                            {
                                output.Append(" datatype=\"" + WriterHelper.EncodeForXml(lit.DataType.AbsoluteUri) + "\">" + WriterHelper.EncodeForXml(lit.Value) + "</literal>");
                            }
                            else if (!lit.Language.Equals(String.Empty))
                            {
                                output.Append(" xml:lang=\"" + lit.Language + "\">" + lit.Value + "</literal>");
                            }
                            else
                            {
                                output.Append(">" + WriterHelper.EncodeForXml(lit.Value) + "</literal>");
                            }
                            break;

                        case NodeType.Uri:
                            output.Append("<uri>" + WriterHelper.EncodeForXml(value.ToString()) + "</uri>");
                            break;

                        case NodeType.Variable:
                            throw new RdfOutputException(WriterErrorMessages.VariableNodesUnserializable("SPARQL XML Results"));

                        default:
                            throw new RdfOutputException(WriterErrorMessages.UnknownNodeTypeUnserializable("SPARQL XML Results"));
                        }
                        output.AppendLine("</binding>");
                    }
                }
            }
            output.Append(" </result>");
            return(output.ToString());
        }
示例#10
0
        public void CloseOutput_4(XmlWriterUtils utils, string outputType)
        {
            Stream            writerStream = FilePathUtil.getStream("writer.out");
            XmlWriterSettings wSettings    = new XmlWriterSettings();

            wSettings.CloseOutput = true;
            XmlWriter w = null;

            switch (utils.WriterType)
            {
            case WriterType.UTF8Writer:
                wSettings.Encoding = Encoding.UTF8;
                break;

            case WriterType.UnicodeWriter:
                wSettings.Encoding = Encoding.Unicode;
                break;
            }

            switch (outputType)
            {
            case "Stream":
                w = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                break;

            case "Textwriter":
                StreamWriter tw = new StreamWriter(writerStream, wSettings.Encoding);
                w = WriterHelper.Create(tw, wSettings, overrideAsync: true, async: utils.Async);
                break;
            }

            bool bResult = false;

            try
            {
                w.WriteStartDocument();
                w.WriteStartDocument();
            }
            catch (Exception e)
            {
                CError.WriteLineIgnore("Exception: " + e.ToString());
                if (writerStream != null && writerStream.CanWrite)
                {
                    bResult = true;
                }
                else
                {
                    bResult = false;
                }
            }
            finally
            {
                writerStream.Dispose();
            }
            Assert.True(bResult);
        }
示例#11
0
 private bool CheckIfImageFile(IFormFile file)
 {
     byte[] fileBytes;
     using (var ms = new MemoryStream())
     {
         file.CopyTo(ms);
         fileBytes = ms.ToArray();
     }
     return(WriterHelper.GetImageFormat(fileBytes) != WriterHelper.ImageFormat.unknown);
 }
示例#12
0
 private bool IsImageValid(IFormFile image)
 {
     byte[] fileBytes;
     using (var ms = new MemoryStream())
     {
         image.CopyTo(ms);
         fileBytes = ms.ToArray();
     }
     return(WriterHelper.GetImageFormat(fileBytes) != WriterHelper.ImageFormat.unknown);
 }
        public XmlWriter CreateMemWriter(XmlWriterUtils utils, Stream writerStream, XmlWriterSettings settings)
        {
            XmlWriterSettings wSettings = settings.Clone();

            wSettings.CloseOutput        = false;
            wSettings.OmitXmlDeclaration = true;
            wSettings.CheckCharacters    = false;
            XmlWriter w = null;

            switch (utils.WriterType)
            {
            case WriterType.UTF8Writer:
                wSettings.Encoding = Encoding.UTF8;
                w = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                break;

            case WriterType.UnicodeWriter:
                wSettings.Encoding = Encoding.Unicode;
                w = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                break;

            case WriterType.WrappedWriter:
                XmlWriter ww = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                w = WriterHelper.Create(ww, wSettings, overrideAsync: true, async: utils.Async);
                break;

            case WriterType.CharCheckingWriter:
                XmlWriter         cw  = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                XmlWriterSettings cws = settings.Clone();
                cws.CheckCharacters = true;
                w = WriterHelper.Create(cw, cws, overrideAsync: true, async: utils.Async);
                break;

            case WriterType.CustomWriter:
                wSettings.Async = utils.Async;
                w = new CustomWriter(writerStream, wSettings);
                break;

            case WriterType.UTF8WriterIndent:
                wSettings.Encoding = Encoding.UTF8;
                wSettings.Indent   = true;
                w = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                break;

            case WriterType.UnicodeWriterIndent:
                wSettings.Encoding = Encoding.Unicode;
                wSettings.Indent   = true;
                w = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                break;

            default:
                throw new Exception("Unknown writer type");
            }
            return(w);
        }
示例#14
0
        /// <summary>
        /// Main Menu
        /// </summary>
        public static void MainMenu()
        {
            int?selection = null;

            Console.Clear();
            Header();
            Console.WriteLine("Main Menu \n");
            Console.WriteLine("[1] Enter Activity");
            Console.WriteLine("[2] View Tracked Data");
            Console.WriteLine("[3] Run Calculations \n");
            Console.WriteLine("[0] Exit");
            WriterHelper.RedText("=", 119);
            if (!string.IsNullOrWhiteSpace(PersistenceData.TempMessage))
            {
                Console.WriteLine(PersistenceData.TempMessage);
            }
            else
            {
                Console.WriteLine($"Welcome {PersistenceData.ActiveUser.FirstName}");
            }
            PersistenceData.TempMessage = string.Empty;
            Console.Write("Selection: ");
            var read = Console.ReadLine();

            selection = Convert.ToInt32(read);

            switch (selection)
            {
            case 1:
                Activities.Add();
                break;

            case 2:
                TrackedData.ViewBy();
                break;

            case 3:
                Calculations.View();
                break;

            case 0:
                Console.Clear();
                Console.WriteLine("Goodbye...");
                Console.ReadLine();
                PersistenceData.ActiveUser = new User();
                Environment.Exit(0);
                break;

            default:
                Console.WriteLine("Invalid selection, try again");
                Console.ReadLine();
                MainMenu();
                break;
            }
        }
示例#15
0
 private static void Header()
 {
     Console.Clear();
     Shared.Header();
     Console.WriteLine("View Tracked Data\n");
     Console.WriteLine("[1] View By Date");
     Console.WriteLine("[2] View By Category");
     Console.WriteLine("[3] View By Description\n");
     Console.WriteLine("[0] Main Menu");
     WriterHelper.RedText("=", 119);
 }
示例#16
0
 private String EncodeAttribute(String value)
 {
     value = WriterHelper.EncodeForXml(value);
     if (value.EndsWith("&"))
     {
         value += "amp;";
     }
     value = value.Replace("\"", "&quot;");
     value = value.Replace("<", "&lt;");
     value = value.Replace(">", "&gt;");
     return(value);
 }
示例#17
0
 public static void Header()
 {
     Console.Clear();
     Shared.Header();
     Console.WriteLine("Calculations \n");
     Console.WriteLine("[1] Time Spent Working Out              [5] Time Spent Sleep");
     Console.WriteLine("[2] Percentage of time Working Out      [6] Percentage of time Sleeping");
     Console.WriteLine("[3] Time Spent Class                    [7] Time Spent Relaxation");
     Console.WriteLine("[4] Percentage of time Class            [8] Percentage of time Relaxation\n");
     Console.WriteLine("[0] Main Menu");
     WriterHelper.RedText("=", 119);
 }
示例#18
0
        protected override void _commit_to_surface(ShapeSheetSurface surface)
        {
            // Do nothing if there aren't any updates
            if (this.ValueItems.Count < 1)
            {
                return;
            }

            var stream   = SRC.ToStream(this.StreamItems);
            var formulas = WriterHelper.build_formulas_array(this.ValueItems);
            var flags    = this.ComputeGetFormulaFlags();
            int c        = surface.SetFormulas(stream, formulas, (short)flags);
        }
示例#19
0
 /// <summary>
 /// Method to check if file is image file
 /// </summary>
 /// <param name="file"></param>
 /// <returns></returns>
 public bool CheckIfImageFile(IFormFile file)
 {
     if (file != null)
     {
         byte[] fileBytes;
         using (MemoryStream ms = new MemoryStream())
         {
             file.CopyTo(ms);
             fileBytes = ms.ToArray();
         }
         return(WriterHelper.GetImageFormat(fileBytes) != WriterHelper.ImageFormat.unknown);
     }
     return(false);
 }
示例#20
0
        public static void View()
        {
            var selection = default(int);

            Header();
            if (!string.IsNullOrEmpty(PersistenceData.TempResult))
            {
                Console.WriteLine($"{PersistenceData.TempResult}");
                WriterHelper.RedText("=", 119);
            }
            PersistenceData.TempResult = String.Empty;
            Console.Write("Selection: ");
            selection = Convert.ToInt32(Console.ReadLine());
            CalculationMenu(selection);
        }
        //[Variation(Desc = "Wrapped writer tests for various types of nodes with 'Entitize'", Param = NewLineHandling.Entitize, Priority = 2)]
        //[Variation(Desc = "Wrapped writer tests for various types of nodes with 'Replace'", Param = NewLineHandling.Replace, Priority = 2)]
        //[Variation(Desc = "Wrapped writer tests for various types of nodes with 'None'", Param = NewLineHandling.None, Priority = 2)]
        public int EOF_Handling_19()
        {
            if (WriterType == WriterType.UTF8WriterIndent || WriterType == WriterType.UnicodeWriterIndent)
            {
                CError.Skip("skipped");
            }
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.NewLineHandling = (NewLineHandling)CurVariation.Param;
            wSettings.CheckCharacters = false;
            XmlWriter         ww = CreateMemWriter(wSettings);
            XmlWriterSettings ws = wSettings.Clone();

            ws.NewLineHandling = NewLineHandling.Replace;
            ws.CheckCharacters = true;
            XmlWriter w = WriterHelper.Create(ww, ws);

            string NewLines = "\r \n " + nl;

            w.WriteStartElement("root");
            w.WriteCData(NewLines);
            w.WriteChars(NewLines.ToCharArray(), 0, NewLines.Length);
            w.WriteEndElement();
            w.WriteProcessingInstruction("pi", NewLines);
            w.WriteWhitespace(NewLines);
            w.WriteComment(NewLines);
            w.Dispose();

            string expOut;

            if ((NewLineHandling)CurVariation.Param == NewLineHandling.Entitize)
            {
                expOut = "<root><![CDATA[" + NewLines + "]]>" + ExpectedOutput(NewLines, NewLineHandling.Entitize, false) + "</root>" + "<?pi " + NewLines + "?>" + ExpectedOutput(NewLines, NewLineHandling.Entitize, false) + "<!--" + NewLines + "-->";
            }
            else
            {
                expOut = ExpectedOutput("<root><![CDATA[" + NewLines + "]]>" + NewLines + "</root><?pi " + NewLines + "?>" + NewLines + "<!--" + NewLines + "-->", NewLineHandling.Replace, false);
            }

            VerifyOutput(expOut);
            return(TEST_PASS);
        }
示例#22
0
        public void CloseOutput_3(XmlWriterUtils utils, string outputType)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.CloseOutput = true;
            XmlWriter w = null;

            switch (utils.WriterType)
            {
            case WriterType.UTF8Writer:
                wSettings.Encoding = Encoding.UTF8;
                break;

            case WriterType.UnicodeWriter:
                wSettings.Encoding = Encoding.Unicode;
                break;
            }

            Stream writerStream = FilePathUtil.getStream("writer.out");

            switch (outputType)
            {
            case "Stream":
                w = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                break;

            case "Textwriter":
                StreamWriter tw = new StreamWriter(writerStream, wSettings.Encoding);
                w = WriterHelper.Create(tw, wSettings, overrideAsync: true, async: utils.Async);
                break;
            }

            w.WriteStartElement("root");
            w.WriteEndElement();
            w.Dispose();

            if (writerStream.CanWrite)
            {
                writerStream.Dispose();
                Assert.True(false);
            }
        }
示例#23
0
        public void CloseOutput_1(XmlWriterUtils utils, string outputType)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();
            XmlWriter         w         = null;

            switch (utils.WriterType)
            {
            case WriterType.UTF8Writer:
                wSettings.Encoding = Encoding.UTF8;
                break;

            case WriterType.UnicodeWriter:
                wSettings.Encoding = Encoding.Unicode;
                break;
            }
            Stream writerStream = new MemoryStream();

            switch (outputType)
            {
            case "Stream":
                w = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                break;

            case "Textwriter":
                StreamWriter tw = new StreamWriter(writerStream, wSettings.Encoding);
                w = WriterHelper.Create(tw, wSettings, overrideAsync: true, async: utils.Async);
                break;
            }

            w.WriteStartElement("root");
            w.WriteEndElement();
            w.Dispose();

            if (writerStream.CanWrite)
            {
                writerStream.Dispose();
                return;
            }
            CError.WriteLine("Error: XmlWriter closed the stream when CloseOutput = false");
            Assert.True(false);
        }
示例#24
0
        public void CloseOutput_2(XmlWriterUtils utils, bool closeOutput)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            switch (utils.WriterType)
            {
            case WriterType.UTF8Writer:
                wSettings.Encoding = Encoding.UTF8;
                break;

            case WriterType.UnicodeWriter:
                wSettings.Encoding = Encoding.Unicode;
                break;
            }
            wSettings.CloseOutput = closeOutput;

            XmlWriter w = WriterHelper.Create("writer.out", wSettings, overrideAsync: true, async: utils.Async);

            w.WriteStartElement("root");
            w.WriteEndElement();
            w.Dispose();

            // Check if you can open the file in ReadWrite mode
            Stream fs = null;

            try
            {
                fs = FilePathUtil.getStream("writer.out");/*new FileStream("writer.out", FileMode.Open, FileAccess.ReadWrite);*/
            }
            catch (Exception e)
            {
                CError.WriteLineIgnore("Exception: " + e.ToString());
                CError.WriteLine("Uri stream is not closed by writer");
                Assert.True(false);
            }
            finally
            {
                fs.Dispose();
            }
            return;
        }
示例#25
0
        private void SerialiseReferenceMappingInternal(TableReferenceMapping mapping, XmlWriter writer)
        {
            if (mapping.FromTable == null)
            {
                throw new ArgumentNullException("mapping", string.Format("mapping.FromTable cannot be null [{0}]", mapping.DisplayName));
            }
            if (mapping.ToReference == null)
            {
                throw new ArgumentNullException("mapping", string.Format("mapping.ToReference cannot be null [{0}]", mapping.DisplayName));
            }

            WriterHelper document = new WriterHelper(writer);

            using (document.Element("TableReferenceMapping"))
            {
                writer.WriteElementString("FromTable", mapping.FromTable.Name);
                writer.WriteElementString("FromSchema", mapping.FromTable.Schema);
                writer.WriteElementString("ToReference", mapping.ToReference.Identifier.ToString());

                ProcessScriptBase(mapping, writer);
            }
        }
        public void EOF_Handling_19(XmlWriterUtils utils, NewLineHandling nlHandling)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.NewLineHandling = nlHandling;
            wSettings.CheckCharacters = false;
            XmlWriter         ww = CreateMemWriter(utils, wSettings);
            XmlWriterSettings ws = wSettings.Clone();

            ws.NewLineHandling = NewLineHandling.Replace;
            ws.CheckCharacters = true;
            XmlWriter w = WriterHelper.Create(ww, ws, overrideAsync: true, async: utils.Async);

            string NewLines = "\r \n " + Environment.NewLine;

            w.WriteStartElement("root");
            w.WriteCData(NewLines);
            w.WriteChars(NewLines.ToCharArray(), 0, NewLines.Length);
            w.WriteEndElement();
            w.WriteProcessingInstruction("pi", NewLines);
            w.WriteWhitespace(NewLines);
            w.WriteComment(NewLines);
            w.Dispose();

            string expOut;

            if (nlHandling == NewLineHandling.Entitize)
            {
                expOut = "<root><![CDATA[" + NewLines + "]]>" + ExpectedOutput(NewLines, NewLineHandling.Entitize, false) + "</root>" + "<?pi " + NewLines + "?>" + ExpectedOutput(NewLines, NewLineHandling.Entitize, false) + "<!--" + NewLines + "-->";
            }
            else
            {
                expOut = ExpectedOutput("<root><![CDATA[" + NewLines + "]]>" + NewLines + "</root><?pi " + NewLines + "?>" + NewLines + "<!--" + NewLines + "-->", NewLineHandling.Replace, false);
            }

            VerifyOutput(expOut);
            return;
        }
示例#27
0
        public void SerialiseRelationshipMappingInternal(RelationshipReferenceMapping mapping, XmlWriter writer)
        {
            if (mapping.FromRelationship == null)
            {
                //throw new ArgumentNullException("mapping", string.Format("mapping.FromRelationship cannot be null [{0}]", mapping.DisplayName));
                return;
            }
            if (mapping.ToReference == null)
            {
                //throw new ArgumentNullException("mapping", string.Format("mapping.ToReference cannot be null [{0}]", mapping.DisplayName));
                return;
            }

            WriterHelper document = new WriterHelper(writer);

            using (document.Element("RelationshipReferenceMapping"))
            {
                writer.WriteElementString("FromRelationship", mapping.FromRelationship.Identifier.ToString());
                writer.WriteElementString("ToReference", mapping.ToReference.Identifier.ToString());

                ProcessScriptBase(mapping, writer);
            }
        }
示例#28
0
        /// <summary>
        /// Formats a Graph Header by creating an <strong>&lt;rdf:RDF&gt;</strong> element and adding namespace definitions
        /// </summary>
        /// <param name="namespaces">Namespaces</param>
        /// <returns></returns>
        public string FormatGraphHeader(INamespaceMapper namespaces)
        {
            this._mapper = new QNameOutputMapper(namespaces);
            StringBuilder output = new StringBuilder();

            output.Append(this.GetGraphHeaderBase());
            foreach (String prefix in namespaces.Prefixes)
            {
                if (!prefix.Equals("rdf"))
                {
                    if (prefix.Equals(String.Empty))
                    {
                        output.Append(" xmlns=\"" + WriterHelper.EncodeForXml(namespaces.GetNamespaceUri(prefix).ToString()) + "\"");
                    }
                    else
                    {
                        output.Append(" xmlns:" + prefix + "=\"" + WriterHelper.EncodeForXml(namespaces.GetNamespaceUri(prefix).ToString()) + "\"");
                    }
                }
            }
            output.Append(">");
            return(output.ToString());
        }
        private XmlWriter CreateMemWriter(XmlWriterSettings settings)
        {
            XmlWriterSettings wSettings = settings.Clone();

            wSettings.CloseOutput        = false;
            wSettings.OmitXmlDeclaration = true;
            wSettings.CheckCharacters    = false;
            XmlWriter w = null;

            switch (WriterType)
            {
            case WriterType.UTF8Writer:
                wSettings.Encoding = Encoding.UTF8;
                if (_strWriter != null)
                {
                    _strWriter.Dispose();
                }
                _strWriter = new StringWriter();
                w          = WriterHelper.Create(_strWriter, wSettings);
                break;

            case WriterType.UnicodeWriter:
                wSettings.Encoding = Encoding.Unicode;
                if (_strWriter != null)
                {
                    _strWriter.Dispose();
                }
                _strWriter = new StringWriter();
                w          = WriterHelper.Create(_strWriter, wSettings);
                break;

            case WriterType.WrappedWriter:
                if (_strWriter != null)
                {
                    _strWriter.Dispose();
                }
                _strWriter = new StringWriter();
                XmlWriter ww = WriterHelper.Create(_strWriter, wSettings);
                w = WriterHelper.Create(ww, wSettings);
                break;

            case WriterType.CharCheckingWriter:
                if (_strWriter != null)
                {
                    _strWriter.Dispose();
                }
                _strWriter = new StringWriter();
                XmlWriter         cw  = WriterHelper.Create(_strWriter, wSettings);
                XmlWriterSettings cws = settings.Clone();
                cws.CheckCharacters = true;
                w = WriterHelper.Create(cw, cws);
                break;

            case WriterType.UTF8WriterIndent:
                wSettings.Encoding = Encoding.UTF8;
                wSettings.Indent   = true;
                if (_strWriter != null)
                {
                    _strWriter.Dispose();
                }
                _strWriter = new StringWriter();
                w          = WriterHelper.Create(_strWriter, wSettings);
                break;

            case WriterType.UnicodeWriterIndent:
                wSettings.Encoding = Encoding.Unicode;
                wSettings.Indent   = true;
                if (_strWriter != null)
                {
                    _strWriter.Dispose();
                }
                _strWriter = new StringWriter();
                w          = WriterHelper.Create(_strWriter, wSettings);
                break;

            default:
                throw new Exception("Unknown writer type");
            }
            return(w);
        }
示例#30
0
        protected override void Test()
        {
            Log("Testing : " + TestFileName);
            Log("Overload : " + _overload);
            switch (_overload)
            {
            case WriterOverload.MemoryStream:
                _stream = new MemoryStream();
                CreateWriter(WriteThru.Stream);
                break;

            case WriterOverload.StreamWriter:
                _textWriter = new StreamWriter(new MemoryStream());
                CreateWriter(WriteThru.TextWriter);
                break;

            case WriterOverload.StringBuilder:
                _stringBuilder = new StringBuilder();
                CreateWriter(WriteThru.StringBuilder);
                break;

            case WriterOverload.StringWriter:
                _textWriter = new StringWriter();
                CreateWriter(WriteThru.TextWriter);
                break;

            case WriterOverload.UnicodeWriter:
                _underlyingSettings          = new XmlWriterSettings();
                _underlyingSettings.Encoding = Encoding.Unicode;
                _underlyingWriter            = WriterHelper.Create(TestFileName, _underlyingSettings);
                CreateWriter(WriteThru.XmlWriter);
                break;

            case WriterOverload.UTF8Writer:
                _underlyingSettings          = new XmlWriterSettings();
                _underlyingSettings.Encoding = Encoding.UTF8;
                _underlyingWriter            = WriterHelper.Create(TestFileName, _underlyingSettings);
                CreateWriter(WriteThru.XmlWriter);
                break;

            default:
                throw new CTestFailedException("Unknown WriterOverload: " + _overload);
            }

            if (pstate == TestState.Pass)
            {
                return;
            }

            CError.Compare(pstate, TestState.CreateSuccess, "Invalid State after Create: " + pstate);

            //By this time the factory Reader is already set up correctly. So we must go Consume it now.
            CError.Compare(pstate != TestState.Pass && pstate == TestState.CreateSuccess, "Invalid state before Consuming Reader: " + pstate);

            //Call TestWriter to Consume Reader;
            TestWriter();
            if (pstate == TestState.Pass)
            {
                return;
            }
            CError.Compare(pstate != TestState.Pass && pstate == TestState.Consume, "Invalid state after Consuming Reader: " + pstate);
        }