コード例 #1
0
 /// <summary>
 /// Writes the file to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="file">The file.</param>
 /// <returns>True if it writes successfully, false otherwise.</returns>
 public bool Write(Stream writer, IGenericFile file)
 {
     if (writer is null || file is null)
     {
         return(false);
     }
     try
     {
         using (var Doc = WordprocessingDocument.Create(writer, DocumentFormat.OpenXml.WordprocessingDocumentType.Document))
         {
             Doc.PackageProperties.Title = file.Title;
             Doc.AddMainDocumentPart();
             Doc.MainDocumentPart.Document = new Document
             {
                 Body = new Body()
             };
             if (file is ITable TableFile)
             {
                 AppendTable(Doc, TableFile);
             }
             else
             {
                 AppendFile(Doc, file);
             }
         }
     }
     catch
     {
         return(false);
     }
     return(true);
 }
コード例 #2
0
        /// <summary>
        /// Writes the file to the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="file">The file.</param>
        /// <returns>True if it writes successfully, false otherwise.</returns>
        public async Task <bool> WriteAsync(Stream writer, IGenericFile file)
        {
            if (writer is null || file is null)
            {
                return(false);
            }
            var Builder = new StringBuilder();

            if (file is ITable FileTable)
            {
                Builder.Append(CreateFromTable(FileTable));
            }
            else
            {
                Builder.Append(CreateFromFile(file));
            }
            var ByteData = Encoding.UTF8.GetBytes(Builder.ToString());

            try
            {
                await writer.WriteAsync(ByteData, 0, ByteData.Length).ConfigureAwait(false);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
コード例 #3
0
ファイル: VCardWriter.cs プロジェクト: JaCraig/FileCurator
 /// <summary>
 /// Writes the file to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="file">The file.</param>
 /// <returns>True if it writes successfully, false otherwise.</returns>
 public Task <bool> WriteAsync(Stream writer, IGenericFile file)
 {
     if (file is ICard FileCard)
     {
         return(WriterCardAsync(writer, FileCard));
     }
     return(Task.FromResult(false));
 }
コード例 #4
0
ファイル: VCardWriter.cs プロジェクト: JaCraig/FileCurator
 /// <summary>
 /// Writes the file to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="file">The file.</param>
 /// <returns>True if it writes successfully, false otherwise.</returns>
 public bool Write(Stream writer, IGenericFile file)
 {
     if (file is ICard FileCard)
     {
         return(WriterCard(writer, FileCard));
     }
     return(false);
 }
コード例 #5
0
 /// <summary>
 /// Writes the file to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="file">The file.</param>
 /// <returns>True if it writes successfully, false otherwise.</returns>
 public bool Write(Stream writer, IGenericFile file)
 {
     if (file is ICalendar CalendarFile)
     {
         WriteCalendar(writer, CalendarFile);
         return(true);
     }
     return(false);
 }
コード例 #6
0
 private void AppendFile(WordprocessingDocument doc, IGenericFile file)
 {
     foreach (var ParagraphText in file.ToString().Split('\n'))
     {
         doc.MainDocumentPart.Document.Body.Append(new Paragraph(
                                                       new Run(
                                                           new Text(ParagraphText))));
     }
 }
コード例 #7
0
 /// <summary>
 /// Writes the file to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="file">The file.</param>
 /// <returns>True if it writes successfully, false otherwise.</returns>
 public bool Write(Stream writer, IGenericFile file)
 {
     if (file is IFeed FeedFile)
     {
         WriteFeed(writer, FeedFile);
         return(true);
     }
     return(false);
 }
コード例 #8
0
        /// <summary>
        /// Writes the file to the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="file">The file.</param>
        /// <returns>True if it writes successfully, false otherwise.</returns>
        public async Task <bool> WriteAsync(Stream writer, IGenericFile file)
        {
            if (file is IFeed FeedFile)
            {
                await WriteFeedAsync(writer, FeedFile).ConfigureAwait(false);

                return(true);
            }
            return(false);
        }
コード例 #9
0
        /// <summary>
        /// Writes the file to the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="file">The file.</param>
        /// <returns>True if it writes successfully, false otherwise.</returns>
        public async Task <bool> WriteAsync(Stream writer, IGenericFile file)
        {
            if (file is ICalendar CalendarFile)
            {
                await WriteCalendarAsync(writer, CalendarFile).ConfigureAwait(false);

                return(true);
            }
            return(false);
        }
コード例 #10
0
ファイル: FileInfo.cs プロジェクト: JaCraig/FileCurator
        /// <summary>
        /// Writes the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="mode">The mode.</param>
        /// <returns>True if it was written successfully, false otherwise.</returns>
        public bool Write(IGenericFile data, FileMode mode = FileMode.Create)
        {
            var Format = FormatManager?.FindFormat(FullName, Credentials);

            if (Format is null)
            {
                return(false);
            }
            using var TempStream = new MemoryStream();
            var Success = Format.Write(TempStream, data);

            Write(TempStream.ReadAllBinary(), mode);
            return(Success);
        }
コード例 #11
0
ファイル: FileInfo.cs プロジェクト: JaCraig/FileCurator
        /// <summary>
        /// Writes the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="mode">The mode.</param>
        /// <returns>True if it was written successfully, false otherwise.</returns>
        public async Task <bool> WriteAsync(IGenericFile data, FileMode mode = FileMode.Create)
        {
            var Format = FormatManager?.FindFormat(FullName, Credentials);

            if (Format is null)
            {
                return(false);
            }
            using var TempStream = new MemoryStream();
            var Success = await Format.WriteAsync(TempStream, data).ConfigureAwait(false);

            await WriteAsync(await TempStream.ReadAllBinaryAsync().ConfigureAwait(false), mode).ConfigureAwait(false);

            return(Success);
        }
コード例 #12
0
        /// <summary>
        /// Writes the file to the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="file">The file.</param>
        /// <returns>True if it writes successfully, false otherwise.</returns>
        public bool Write(Stream writer, IGenericFile file)
        {
            if (writer is null)
            {
                return(false);
            }
            var TempData = Encoding.UTF8.GetBytes(file?.ToString() ?? "");

            try
            {
                writer.Write(TempData, 0, TempData.Length);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
コード例 #13
0
        /// <summary>
        /// Writes the file to the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="file">The file.</param>
        /// <returns>True if it writes successfully, false otherwise.</returns>
        public async Task <bool> WriteAsync(Stream writer, IGenericFile file)
        {
            if (writer is null)
            {
                return(false);
            }
            var TempData = Encoding.UTF8.GetBytes(file?.ToString() ?? "");

            try
            {
                await writer.WriteAsync(TempData, 0, TempData.Length).ConfigureAwait(false);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
コード例 #14
0
        /// <summary>
        /// Writes the specified data.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="data">The data.</param>
        /// <param name="mimeType">Type of the MIME.</param>
        /// <returns>True if it was written successfully, false otherwise.</returns>
        public static bool Write(this Stream file, IGenericFile data, MimeType mimeType)
        {
            var Format = InternalManager.FindFormat(file, mimeType);

            return(Format.Write(file, data));
        }
コード例 #15
0
 /// <summary>
 /// Writes the file to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="file">The file.</param>
 /// <returns>True if it writes successfully, false otherwise.</returns>
 public bool Write(Stream writer, IGenericFile file) => false;
コード例 #16
0
 /// <summary>
 /// Writes the file to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="file">The file.</param>
 /// <returns>True if it writes successfully, false otherwise.</returns>
 public Task <bool> WriteAsync(Stream writer, IGenericFile file)
 {
     return(Task.FromResult(Write(writer, file)));
 }
コード例 #17
0
 private string CreateFromFile(IGenericFile file) => "\"" + file?.ToString().Replace("\"", "") + "\"";
コード例 #18
0
 /// <summary>
 /// Writes the file to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="file">The file.</param>
 /// <returns>True if it writes successfully, false otherwise.</returns>
 public bool Write(Stream writer, IGenericFile file) => Writer.Write(writer, file);
コード例 #19
0
 /// <summary>
 /// Writes the file to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="file">The file.</param>
 /// <returns>True if it writes successfully, false otherwise.</returns>
 public Task <bool> WriteAsync(Stream writer, IGenericFile file) => Writer.WriteAsync(writer, file);
コード例 #20
0
ファイル: MSGWriter.cs プロジェクト: JaCraig/FileCurator
 /// <summary>
 /// Writes the file to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="file">The file.</param>
 /// <returns>True if it writes successfully, false otherwise.</returns>
 public bool Write(Stream writer, IGenericFile file)
 {
     return(false);
 }
コード例 #21
0
ファイル: MSGWriter.cs プロジェクト: JaCraig/FileCurator
 /// <summary>
 /// Writes the file to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="file">The file.</param>
 /// <returns>True if it writes successfully, false otherwise.</returns>
 public Task <bool> WriteAsync(Stream writer, IGenericFile file) => Task.FromResult(false);
コード例 #22
0
 /// <summary>
 /// Writes the file to the specified writer.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="file">The file.</param>
 /// <returns>True if it writes successfully, false otherwise.</returns>
 public bool Write(Stream writer, IGenericFile file)
 {
     if (writer is null || file is null)
     {
         return(false);
     }
     try
     {
         using var Document = SpreadsheetDocument.Create(writer, SpreadsheetDocumentType.Workbook);
         Document.AddWorkbookPart();
         Document.WorkbookPart.Workbook = new Workbook();
         Document.WorkbookPart.Workbook.AppendChild(new Sheets());
         var WorksheetPart = InsertSheetInWorksheet(Document.WorkbookPart);
         var Worksheet     = WorksheetPart.Worksheet;
         var SheetData     = Worksheet.GetFirstChild <SheetData>();
         if (!(file is ITable TableFile))
         {
             var Row = new Row {
                 RowIndex = 1
             };
             Row.AppendChild(new Cell
             {
                 CellValue     = new CellValue(file.ToString()),
                 DataType      = new EnumValue <CellValues>(CellValues.String),
                 CellReference = "A1"
             });
             SheetData.AppendChild(Row);
         }
         else
         {
             var headerOffset = 1;
             if (TableFile.Columns.Count > 0)
             {
                 headerOffset = 2;
                 var Row = new Row {
                     RowIndex = 1
                 };
                 for (var x = 0; x < TableFile.Columns.Count; ++x)
                 {
                     Row.AppendChild(new Cell
                     {
                         CellValue     = new CellValue(TableFile.Columns[x]),
                         DataType      = new EnumValue <CellValues>(CellValues.String),
                         CellReference = Column(x + 1) + 1
                     });
                 }
                 SheetData.AppendChild(Row);
             }
             for (var x = 0; x < TableFile.Rows.Count; ++x)
             {
                 var Row = new Row {
                     RowIndex = (uint)(x + 2)
                 };
                 SheetData.AppendChild(Row);
                 for (var y = 0; y < TableFile.Rows[x].Cells.Count; ++y)
                 {
                     Row.AppendChild(new Cell
                     {
                         CellValue     = new CellValue(TableFile.Rows[x].Cells[y].Content),
                         DataType      = new EnumValue <CellValues>(CellValues.String),
                         CellReference = Column(y + 1) + (x + headerOffset)
                     });
                 }
             }
         }
     }