public static bool SaveReport(string Filename, FixedDocumentSequence fqs) { bool result; try { File.Delete(Filename); SerializerProvider serializerProvider = new SerializerProvider(); SerializerDescriptor serializerDescriptor = null; foreach (SerializerDescriptor current in serializerProvider.InstalledSerializers) { if (current.IsLoadable && Filename.EndsWith(current.DefaultFileExtension)) { serializerDescriptor = current; break; } } if (serializerDescriptor != null) { Stream stream = File.Create(Filename); SerializerWriter serializerWriter = serializerProvider.CreateSerializerWriter(serializerDescriptor, stream); serializerWriter.Write(((IDocumentPaginatorSource)fqs).DocumentPaginator, null); stream.Close(); } result = true; } catch (Exception) { result = false; } return(result); }
public XPSDocumentPageWrapper(DocumentPage documentPage) { if (documentPage != null) { //Serialize the DocumentPage XpsSerializerFactory factory = new XpsSerializerFactory(); MemoryStream ms = new MemoryStream(); SerializerWriter writer = factory.CreateSerializerWriter(ms); writer.Write(documentPage.Visual); m_XPSDocumentPageObject = ms.ToArray(); } }
public static void Write(OutputModel outputModel, DatabasePlan databasePlan) { var s = $@" namespace {databasePlan.Namespace}; public class {databasePlan.DbClassName} : Cosmogenesis.Core.DbBase {{ /// <summary>Mocking constructor</summary> protected {databasePlan.DbClassName}() {{ }} public {databasePlan.DbClassName}( Microsoft.Azure.Cosmos.Container container, Cosmogenesis.Core.DbSerializerBase? serializer = null, bool isReadOnly = false, bool validateStateBeforeSave = true) : base( container: container, serializer: serializer ?? {databasePlan.Namespace}.{databasePlan.SerializerClassName}.Instance, isReadOnly: isReadOnly, validateStateBeforeSave: validateStateBeforeSave) {{ }} {databasePlan.Namespace}.{databasePlan.PartitionsClassName}? partition; public virtual {databasePlan.Namespace}.{databasePlan.PartitionsClassName} Partition => this.partition ??= new(this); internal new System.Threading.Tasks.Task<T?> ReadByIdAsync<T>( string id, Microsoft.Azure.Cosmos.PartitionKey partitionKey, string type) where T : Cosmogenesis.Core.DbDoc => base.ReadByIdAsync<T>( id: id, partitionKey: partitionKey, type: type); internal new System.Threading.Tasks.Task<T?[]> ReadByIdsAsync<T>( System.Collections.Generic.IEnumerable<string> ids, Microsoft.Azure.Cosmos.PartitionKey partitionKey, string type) where T : Cosmogenesis.Core.DbDoc => base.ReadByIdsAsync<T>( ids: ids, partitionKey: partitionKey, type: type); internal new System.Threading.Tasks.Task<Cosmogenesis.Core.DbDoc?> ReadByIdAsync( string id, Microsoft.Azure.Cosmos.PartitionKey partitionKey) => base.ReadByIdAsync( id: id, partitionKey: partitionKey); internal new System.Threading.Tasks.Task<Cosmogenesis.Core.DbDoc?[]> ReadByIdsAsync( System.Collections.Generic.IEnumerable<string> ids, Microsoft.Azure.Cosmos.PartitionKey partitionKey) => base.ReadByIdsAsync( ids: ids, partitionKey: partitionKey); {databasePlan.Namespace}.{databasePlan.QueryBuilderClassName}? crossPartitionQueryBuilder; /// <summary> /// Methods to build a cross-partition query for later execution. /// </summary> public virtual {databasePlan.Namespace}.{databasePlan.QueryBuilderClassName} CrossPartitionQueryBuilder => this.crossPartitionQueryBuilder ??= new(this); {databasePlan.Namespace}.{databasePlan.QueryClassName}? crossPartitionQuery; /// <summary> /// Methods to execute cross-partition queries. /// </summary> public virtual {databasePlan.Namespace}.{databasePlan.QueryClassName} CrossPartitionQuery => this.crossPartitionQuery ??= new(this, this.CrossPartitionQueryBuilder); {databasePlan.Namespace}.{databasePlan.ReadClassName}? read; /// <summary> /// Methods to read documents by providing pk & id. /// </summary> public virtual {databasePlan.Namespace}.{databasePlan.ReadClassName} Read => this.read ??= new(this); }} "; outputModel.Context.AddSource($"db_{databasePlan.DbClassName}.cs", s); ConverterWriter.Write(outputModel, databasePlan); SerializerWriter.Write(outputModel, databasePlan); TypesWriter.Write(outputModel, databasePlan); DbReadWriter.Write(outputModel, databasePlan); DbQueryWriter.Write(outputModel, databasePlan); DbQueryBuilderWriter.Write(outputModel, databasePlan); PartitionsWriter.Write(outputModel, databasePlan); BatchHandlersWriter.Write(outputModel, databasePlan); ChangeFeedProcessorWriter.Write(outputModel, databasePlan); }
}// end:SaveDocumentAsFile() // --------------------------- SaveToFile ----------------------------- /// <summary> /// Saves the current document to a specified file.</summary> /// <param name='fileName'> /// The name of file to save to.</param> /// <returns> /// true if the document was saved successfully; otherwise, false /// if there was an error or the user canceled the save.</returns> private bool SaveToFile(string fileName) { if (fileName == null) { throw new ArgumentNullException(nameof(fileName)); } // If the file already exists, delete it (replace). if (File.Exists(fileName)) { File.Delete(fileName); } FlowDocument flowDocument = FDPV.Document as FlowDocument; string fileContent = null; try { // Create a SerializerProvider for accessing plug-in serializers. SerializerProvider serializerProvider = new SerializerProvider(); // Locate the serializer that matches the fileName extension. SerializerDescriptor selectedPlugIn = null; foreach (SerializerDescriptor serializerDescriptor in serializerProvider.InstalledSerializers) { if (serializerDescriptor.IsLoadable && fileName.EndsWith(serializerDescriptor.DefaultFileExtension)) { // The plug-in serializer and fileName extensions match. selectedPlugIn = serializerDescriptor; break; // foreach } } // If a match for a plug-in serializer was found, // use it to output and store the document. if (selectedPlugIn != null) { Stream package = File.Create(fileName); SerializerWriter serializerWriter = serializerProvider.CreateSerializerWriter(selectedPlugIn, package); IDocumentPaginatorSource idoc = flowDocument as IDocumentPaginatorSource; serializerWriter.Write(idoc.DocumentPaginator, null); package.Close(); return(true); } else if (fileName.EndsWith(".xml")) { // Save as a WordXML document. WordXmlSerializer.SaveToFile(fileName, flowDocument.ContentStart, flowDocument.ContentEnd); return(true); } } catch (Exception e) { MessageBox.Show( "Error occurred during a conversion to this file format: " + fileName + "\n" + e.ToString(), this.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error); return(false); } if (fileContent == null) { MessageBox.Show("A serializer for the given file extension" + "could not be found.\n" + fileName, this.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error); return(false); } // Output the formatted content to the specified file. try { // Write the file content. StreamWriter writer = new StreamWriter(fileName); writer.WriteLine(fileContent); writer.Close(); } catch (Exception e) { MessageBox.Show("Error occurred during document save: " + fileName + "\n" + e.ToString(), this.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error); return(false); } return(true); }// end:SaveToFile()