Пример #1
0
        public override void WriteToOutPutFile(ReaderClass content, string outPutPath)
        {
            StringWriter   stringwriter = new StringWriter();
            HtmlTextWriter writer       = new HtmlTextWriter(stringwriter);

            writer.WriteBeginTag("html");
            writer.Write(HtmlTextWriter.TagRightChar);
            GetHtmlToWrite(content, writer);
            writer.WriteEndTag("html");

            File.WriteAllText(outPutPath + @"\OutPut1.html", writer.InnerWriter.ToString());
            //writer.Write(outPutPath + @"\OutPut1.html");
            //var xDocument = new XDocument(
            //new XDocumentType("html", null, null, null),
            //new XElement("html",
            //    new XElement("head",
            //        new XElement("Title","Activity Log")
            //    ),
            //    new XElement("body", GetHtmlToWrite(content).InnerWriter)
            //    )
            //);


            //var settings = new XmlWriterSettings
            //{
            //    OmitXmlDeclaration = true,
            //    Indent = true,
            //    IndentChars = "\t"
            //};

            //xDocument.Save(outPutPath + @"\OutPut.html");
            writer.Close();
        }
        /// <summary>
        /// function for reading text file
        /// </summary>
        /// <param name="inputPath"></param>
        /// <returns></returns>
        public ReaderClass ReadWriteTextDataFiles(string inputPath)
        {
            ReaderClass readData = new ReaderClass();

            var result = readAllFiles(readData, inputPath);

            result.Wait();

            return(readData);
        }
Пример #3
0
        /// <summary>
        /// function for writing text file into html format
        /// </summary>
        public override void WriteToOutPutFile(ReaderClass content, string outPutPath)
        {
            StringWriter   stringwriter = new StringWriter();
            HtmlTextWriter writer       = new HtmlTextWriter(stringwriter);

            writer.WriteBeginTag("html");
            writer.Write(HtmlTextWriter.TagRightChar);
            GetHtmlToWrite(content, writer);
            writer.WriteEndTag("html");

            File.WriteAllText(outPutPath + @"\Output1.html", writer.InnerWriter.ToString());

            writer.Close();
        }
        /// <summary>
        /// function for writing text file into html format
        /// </summary>
        public override void WriteToOutPutFile(ReaderClass content, string outPutPath)
        {
            StringWriter   stringwriter = new StringWriter();
            HtmlTextWriter writer       = new HtmlTextWriter(stringwriter);

            writer.WriteBeginTag("html");
            writer.Write(HtmlTextWriter.TagRightChar);
            GetHtmlToWrite(content, writer);
            writer.WriteEndTag("html");
            string fileName = "\\OutputHTML_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";

            File.WriteAllText(outPutPath + fileName, writer.InnerWriter.ToString());

            writer.Close();
        }
Пример #5
0
        private HtmlTextWriter GetHtmlToWrite(ReaderClass content, HtmlTextWriter writer)
        {
            List <string> codes       = !string.IsNullOrEmpty(content.Code) ? content.Code.Split(',').ToList() : new List <string>();
            List <string> description = !string.IsNullOrEmpty(content.FileDescription) ? content.FileDescription.Split(',').ToList() : new List <string>();
            List <string> metaHeader  = new List <string> {
                "File", "Code", "Description"
            };
            List <string> dataHeader = new List <string> {
                "Time"
            };

            int fileCount = 0;

            GetHtmlHeader(writer, "Metadata");
            writer.WriteBeginTag("table");
            writer.WriteAttribute("border", "1");
            writer.Write(HtmlTextWriter.TagRightChar);
            GetTableTr(writer, metaHeader, "", "", "");
            foreach (string file in content.FileNames.Split(','))
            {
                dataHeader.Add(codes[fileCount]);
                GetTableTr(writer, null, file, codes[fileCount], description[fileCount]);
                fileCount++;
            }
            writer.WriteEndTag("table");


            GetHtmlHeader(writer, "Activity Data");
            writer.WriteBeginTag("table");
            writer.WriteAttribute("border", "1");
            writer.Write(HtmlTextWriter.TagRightChar);
            GetTableTr(writer, dataHeader, "", "", "");
            foreach (string data in content.Datas)
            {
                GetTableTrData(writer, data);
            }


            writer.WriteEndTag("table");
            return(writer);
        }
Пример #6
0
        public override void WriteToOutPutFile(ReaderClass content, string outPutPath)
        {
            if (!Directory.Exists(outPutPath))
            {
                Directory.CreateDirectory(outPutPath);
            }
            List <string> codes       = !string.IsNullOrEmpty(content.Code)? content.Code.Split(',').ToList() : new List <string>();
            List <string> description = !string.IsNullOrEmpty(content.FileDescription) ? content.FileDescription.Split(',').ToList() : new List <string>();

            XmlTextWriter writer = new XmlTextWriter(outPutPath + "OutPut.xml", System.Text.Encoding.UTF8);

            writer.WriteStartDocument(true);
            writer.Formatting  = Formatting.Indented;
            writer.Indentation = 2;
            writer.WriteStartElement("logData");
            int fileCount = 0;

            foreach (string file in content.FileNames.Split(','))
            {
                writer.WriteStartElement("file");
                writer.WriteAttributeString("name", file);
                createNode("code", codes[fileCount], writer);
                createNode("description", description[fileCount], writer);
                writer.WriteEndElement();
                fileCount++;
            }

            writer.WriteStartElement("datasection");
            createNode("paramList", content.Code, writer);
            foreach (string fileData in content.Datas)
            {
                createNode("data", fileData, writer);
            }
            writer.WriteEndElement();

            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Close();
        }
        /// <summary>
        /// Method for reading the files asynchronously
        /// </summary>
        /// <param name="readData"></param>
        /// <param name="inputPath"></param>
        /// <returns></returns>
        public async Task readAllFiles(ReaderClass readData, string inputPath)
        {
            List <string> fileNames    = new List <string>();
            List <string> codes        = new List <string>();
            List <string> descriptions = new List <string>();
            FileInfo      file;
            List <string> datas = new List <string>();

            string[] fileAry = Directory.GetFiles(inputPath, "*.txt");
            foreach (string filePath in fileAry)
            {
                file = new FileInfo(filePath);
                fileNames.Add(file.Name);

                Task  task = ReadTextAsync(filePath, codes, descriptions, datas);
                await task;
            }
            readData.FileNames       = string.Join(",", fileNames);
            readData.Code            = string.Join(",", codes);
            readData.FileDescription = string.Join(",", descriptions);
            readData.Datas           = datas;
        }
Пример #8
0
 public abstract void WriteToOutPutFile(ReaderClass content, string outPutPath);
Пример #9
0
        public ReaderClass ReadWriteTextDataFiles(string inputPath)
        {
            ReaderClass   readData     = new ReaderClass();
            StringBuilder fileNames    = new StringBuilder();
            StringBuilder codes        = new StringBuilder();
            StringBuilder descriptions = new StringBuilder();
            FileInfo      file;
            List <string> datas = new List <string>();

            string[] fileAry = Directory.GetFiles(inputPath, "*.txt");
            foreach (string filePath in fileAry)
            {
                file = new FileInfo(filePath);
                fileNames.Append(file.Name);
                using (TextReader tr = new StreamReader(filePath))
                {
                    string line;
                    string lineCode = "";
                    bool   nextLine = true;
                    while ((line = tr.ReadLine()) != null)
                    {
                        nextLine = true;
                        if (line == "[Code]")
                        {
                            nextLine = false;
                            lineCode = "Code";
                        }
                        else if (line == "[Description]")
                        {
                            nextLine = false;
                            lineCode = "Desc";
                        }
                        else if (line == "[Data]")
                        {
                            nextLine = false;
                            lineCode = "Data";
                        }
                        if (nextLine)
                        {
                            if (lineCode == "Code")
                            {
                                codes.Append(line);
                            }
                            else if (lineCode == "Desc")
                            {
                                descriptions.Append(line);
                            }
                            else if (lineCode == "Data")
                            {
                                datas.Add(line);
                            }
                        }
                    }

                    tr.Close();
                    tr.Dispose();
                }
            }
            readData.FileNames       = string.Join(",", fileNames);
            readData.Code            = string.Join(",", codes);
            readData.FileDescription = string.Join(",", descriptions);
            readData.Datas           = datas;
            return(readData);
        }