private void AddCoreServices(IServiceCollection services) { // This method add Newtonsoft serialize services. SerializeOptions.Init(services); // This method add jwt manager services.AddSingleton <IJwtManager, JwtManager>(); // This method add user services services.AddScoped <IUser, UserServices>(); // This method add tender services services.AddScoped <ITender, TenderServices>(); // This method add authenticate services services.AddScoped <IAuthenticate, AuthenticateServices>(); }
static public SerializeOptions GetSerializeOptions(this Preferences value) { var serializeOptions = new SerializeOptions() { IgnoreInferredObjects = value.IgnoreInferredObjects, IgnoreInferredProperties = value.IgnoreInferredProperties, IgnoreTimestamps = value.IgnoreTimestamps, SplitMultilineStrings = value.SplitMultilineStrings, }; serializeOptions.PrefixFilenames = value.SaveToFolder_PrefixFiles; serializeOptions.LocalPerspectives = value.SaveToFolder_LocalPerspectives; serializeOptions.LocalTranslations = value.SaveToFolder_LocalTranslations; serializeOptions.LocalRelationships = value.SaveToFolder_LocalRelationships; serializeOptions.Levels = new HashSet <string>(value.SaveToFolder_Levels); return(serializeOptions); }
/// <summary> /// Serializes the specified object to JSML format, using the specified objectName as the outermost tag name. /// </summary> public static string Serialize(object obj, string objectName, SerializeOptions options) { if (obj == null) { return(null); } using (var sw = new StringWriter()) { var writer = new XmlTextWriter(sw) { Formatting = Formatting.Indented }; Serialize(writer, obj, objectName, options); writer.Close(); return(sw.ToString()); } }
/// <summary>Serializes an <code>XMPMeta</code>-object as RDF into a string.</summary> /// <remarks> /// Serializes an <code>XMPMeta</code>-object as RDF into a string. /// <em>Note:</em> Encoding is forced to UTF-16 when serializing to a /// string to ensure the correctness of "exact packet size". /// </remarks> /// <param name="xmp">a metadata implementation object</param> /// <param name="options"> /// Options to control the serialization (see /// <see cref="iText.Kernel.XMP.Options.SerializeOptions"/> /// ). /// </param> /// <returns>Returns a string containing the serialized RDF.</returns> public static String SerializeToString(XMPMetaImpl xmp, SerializeOptions options) { // forces the encoding to be UTF-16 to get the correct string length options = options ?? new SerializeOptions(); options.SetEncodeUTF16BE(true); MemoryStream output = new MemoryStream(2048); Serialize(xmp, output, options); try { return(new EncodingNoPreamble(IanaEncodings.GetEncodingEncoding(options.GetEncoding())).GetString(output.GetBuffer())); } catch (Exception) { // cannot happen as UTF-8/16LE/BE is required to be implemented in // Java return(GetString(output.GetBuffer())); } }
/// <summary>Serializes an <c>XMPMeta</c>-object as RDF into a string.</summary> /// <remarks> /// <em>Note:</em> Encoding is forced to UTF-16 when serializing to a /// string to ensure the correctness of "exact packet size". /// </remarks> /// <param name="xmp">a metadata implementation object</param> /// <param name="options">Options to control the serialization (see <see cref="SerializeOptions"/>).</param> /// <returns>Returns a string containing the serialized RDF.</returns> /// <exception cref="XmpException">on serialization errors.</exception> public static string SerializeToString(XmpMeta xmp, SerializeOptions options) { // forces the encoding to be UTF-16 to get the correct string length options = options ?? new SerializeOptions(); options.EncodeUtf16Be = true; var output = new MemoryStream(2048); Serialize(xmp, output, options); try { return(options.GetEncoding().GetString(output.ToArray(), 0, (int)output.Length)); } catch { // Should not happen as UTF-8/16LE/BE are all available return(output.ToString()); } }
/// <summary> /// Serializes an <code>XMPMeta</code>-object as RDF into a string. /// <em>Note:</em> Encoding is forced to UTF-16 when serializing to a /// string to ensure the correctness of "exact packet size". /// </summary> /// <param name="xmp"> a metadata implementation object </param> /// <param name="options"> Options to control the serialization (see /// <seealso cref="SerializeOptions"/>). </param> /// <returns> Returns a string containing the serialized RDF. </returns> /// <exception cref="XmpException"> on serializsation errors. </exception> public static string SerializeToString(XmpMetaImpl xmp, SerializeOptions options) { // forces the encoding to be UTF-16 to get the correct string length options = options ?? new SerializeOptions(); options.EncodeUtf16Be = true; MemoryStream @out = new MemoryStream(2048); Serialize(xmp, @out, options); try { return(Encoding.GetEncoding(options.Encoding).GetString(@out.GetBuffer())); } catch (Exception) { // cannot happen as UTF-8/16LE/BE is required to be implemented in // Java return(GetString(@out.GetBuffer())); } }
/// <summary>Serializes an <code>XMPMeta</code>-object as RDF into a string.</summary> /// <remarks> /// Serializes an <code>XMPMeta</code>-object as RDF into a string. /// <em>Note:</em> Encoding is forced to UTF-16 when serializing to a /// string to ensure the correctness of "exact packet size". /// </remarks> /// <param name="xmp">a metadata implementation object</param> /// <param name="options"> /// Options to control the serialization (see /// <see cref="Com.Adobe.Xmp.Options.SerializeOptions"/> /// ). /// </param> /// <returns>Returns a string containing the serialized RDF.</returns> /// <exception cref="Com.Adobe.Xmp.XMPException">on serializsation errors.</exception> public static string SerializeToString(XMPMetaImpl xmp, SerializeOptions options) { // forces the encoding to be UTF-16 to get the correct string length options = options != null ? options : new SerializeOptions(); options.SetEncodeUTF16BE(true); ByteArrayOutputStream @out = new ByteArrayOutputStream(2048); Serialize(xmp, @out, options); try { return(@out.ToString(options.GetEncoding())); } catch (UnsupportedEncodingException) { // cannot happen as UTF-8/16LE/BE is required to be implemented in // Java return(@out.ToString()); } }
private void SaveSettingsCM() { var options = new SerializeOptions(); options.IgnoreTimestamps = chkIgnoreTimestampsCM.Checked; options.IgnoreInferredObjects = chkIgnoreInfObjectsCM.Checked; options.IgnoreInferredProperties = chkIgnoreInfPropsCM.Checked; options.SplitMultilineStrings = chkSplitMultilineCM.Checked; options.PrefixFilenames = chkPrefixFilesCM.Checked; options.LocalPerspectives = chkLocalPerspectivesCM.Checked; options.LocalTranslations = chkLocalTranslationsCM.Checked; options.LocalRelationships = chkLocalRelationshipsCM.Checked; options.Levels = new HashSet <string>(); SaveCheckedNodes(treeView2.Nodes, options.Levels); if (Handler.SerializeOptions != options) { Handler.SerializeOptions = options; } }
/// <summary> /// Initializes a new instance of the TabularObject class. /// </summary> /// <param name="namedMetaDataObject">The Tabular Object Model supertype of the class being abstracted.</param> public TabularObject(NamedMetadataObject namedMetaDataObject) { _name = namedMetaDataObject.Name; //Serialize json SerializeOptions options = new SerializeOptions(); options.IgnoreInferredProperties = true; options.IgnoreInferredObjects = true; options.IgnoreTimestamps = true; options.SplitMultilineStrings = true; _objectDefinition = Tom.JsonSerializer.SerializeObject(namedMetaDataObject, options); //Remove annotations { JToken token = JToken.Parse(_objectDefinition); RemovePropertyFromObjectDefinition(token, "annotations"); _objectDefinition = token.ToString(Formatting.Indented); } //Order table columns if (namedMetaDataObject is Tom.Table) { _objectDefinition = SortArray(_objectDefinition, "columns"); _objectDefinition = SortArray(_objectDefinition, "partitions"); } //Order role members if (namedMetaDataObject is Tom.ModelRole) { _objectDefinition = SortArray(_objectDefinition, "members"); } //Hide privacy setting on structured data sources if (namedMetaDataObject is Tom.StructuredDataSource) { JToken token = JToken.Parse(_objectDefinition); RemovePropertyFromObjectDefinition(token, "PrivacySetting"); _objectDefinition = token.ToString(Formatting.Indented); } }
/// <summary>Static method to serialize the metadata object.</summary> /// <remarks> /// For each serialisation, a new XMPSerializer /// instance is created, either XMPSerializerRDF or XMPSerializerPlain so that its possible to /// serialize the same XMPMeta objects in two threads. /// </remarks> /// <param name="xmp">a metadata implementation object</param> /// <param name="stream">the output stream to serialize to</param> /// <param name="options">serialization options, can be <c>null</c> for default.</param> /// <exception cref="XmpException" /> public static void Serialize(XmpMeta xmp, Stream stream, SerializeOptions options) { options = options ?? new SerializeOptions(); // sort the internal data model on demand if (options.Sort) { xmp.Sort(); } // <#AdobePrivate> This is not very aesthetic, but needed to strip the block // The Plain XMP format is disabled // if (options.getUsePlainXMP()) // { // new XMPSerializerPlain().serialize(xmp, out, options); // return; // } // </#AdobePrivate> new XmpSerializerRdf().Serialize(xmp, stream, options); }
/// <summary>Serializes the XmpDirectory component of <code>Metadata</code> into an <code>OutputStream</code></summary> /// <param name="os">Destination for the xmp data</param> /// <param name="data">populated metadata</param> /// <returns>serialize success</returns> public static bool Write(OutputStream os, Com.Drew.Metadata.Metadata data) { XmpDirectory dir = data.GetFirstDirectoryOfType <XmpDirectory>(); if (dir == null) { return(false); } XMPMeta meta = dir.GetXMPMeta(); try { SerializeOptions so = new SerializeOptions().SetOmitPacketWrapper(true); XMPMetaFactory.Serialize(meta, os, so); } catch (XMPException e) { Sharpen.Runtime.PrintStackTrace(e); return(false); } return(true); }
static public SerializeOptions GetSerializeOptions(this Preferences value, string powerBiDatabaseNameOverride = null) { var serializeOptions = new SerializeOptions() { IgnoreInferredObjects = value.IgnoreInferredObjects, IgnoreInferredProperties = value.IgnoreInferredProperties, IgnoreTimestamps = value.IgnoreTimestamps, SplitMultilineStrings = value.SplitMultilineStrings, }; serializeOptions.PrefixFilenames = value.SaveToFolder_PrefixFiles; serializeOptions.LocalPerspectives = value.SaveToFolder_LocalPerspectives; serializeOptions.LocalTranslations = value.SaveToFolder_LocalTranslations; serializeOptions.LocalRelationships = value.SaveToFolder_LocalRelationships; serializeOptions.Levels = new HashSet <string>(value.SaveToFolder_Levels); if (value.UsePbixFileNameWhenSavingToDisk) { serializeOptions.DatabaseNameOverride = powerBiDatabaseNameOverride; } return(serializeOptions); }
/// <summary>Serializes an <c>XMPMeta</c>-object as RDF into a string.</summary> /// <remarks> /// <em>Note:</em> Encoding is forced to UTF-16 when serializing to a /// string to ensure the correctness of "exact packet size". /// </remarks> /// <param name="xmp">a metadata implementation object</param> /// <param name="options">Options to control the serialization (see <see cref="SerializeOptions"/>).</param> /// <returns>Returns a string containing the serialized RDF.</returns> /// <exception cref="XmpException">on serialization errors.</exception> public static string SerializeToString(XmpMeta xmp, SerializeOptions options) { // forces the encoding to be UTF-16 to get the correct string length options = options ?? new SerializeOptions(); // By default encoding is utf8 // options should be set by the client. Commenting setting utf16 option // so that users can get the string in whichever encoding they want (by setting the options bits) //options.EncodeUtf16Be = true; var output = new MemoryStream(2048); Serialize(xmp, output, options); try { return(options.GetEncoding().GetString(output.ToArray(), 0, (int)output.Length)); } catch { // Should not happen as UTF-8/16LE/BE are all available return(output.ToString()); } }
public void Save(string path, SaveFormat format, SerializeOptions options, bool useAnnotatedSerializeOptions = false) { if (useAnnotatedSerializeOptions) { var annotatedSerializeOptions = Model.GetAnnotation("TabularEditor_SerializeOptions"); if (annotatedSerializeOptions != null) { options = JsonConvert.DeserializeObject <SerializeOptions>(annotatedSerializeOptions); } } if (options == null) { throw new ArgumentNullException("options"); } if (format != SaveFormat.PowerBiTemplate) { Model.SetAnnotation("TabularEditor_SerializeOptions", JsonConvert.SerializeObject(options), false); } switch (format) { case SaveFormat.ModelSchemaOnly: SaveFile(path, options); break; case SaveFormat.PowerBiTemplate: SavePbit(path); break; case SaveFormat.TabularEditorFolder: SaveFolder(path, options); break; case SaveFormat.VisualStudioProject: // TODO throw new NotImplementedException(); // break; } }
/** * Creates an XmpWriter. * @param os * @param utfEncoding * @param extraSpace * @throws IOException */ public XmpWriter(Stream os, String utfEncoding, int extraSpace) { outputStream = os; serializeOptions = new SerializeOptions(); if (UTF16BE.Equals(utfEncoding) || UTF16.Equals(utfEncoding)) { serializeOptions.EncodeUtf16Be = true; } else if (UTF16LE.Equals(utfEncoding)) { serializeOptions.EncodeUtf16Le = true; } serializeOptions.Padding = extraSpace; xmpMeta = XmpMetaFactory.Create(); xmpMeta.ObjectName = XmpConst.TAG_XMPMETA; xmpMeta.ObjectName = ""; try { xmpMeta.SetProperty(XmpConst.NS_DC, DublinCoreProperties.FORMAT, "application/pdf"); xmpMeta.SetProperty(XmpConst.NS_PDF, PdfProperties.PRODUCER, Version.GetInstance().GetVersion); } catch (XmpException) {} }
private void SaveFile(string fileName, SerializeOptions options) { var dbcontent = Serializer.SerializeDB(options); var jObject = JObject.Parse(dbcontent); jObject["name"] = Model.Database?.Name ?? "SemanticModel"; if (Model.Database != null) { if (!Model.Database.Name.EqualsI(Model.Database.ID)) { jObject["id"] = Model.Database.ID; } else if (jObject["id"] != null) { jObject["id"].Remove(); } } dbcontent = jObject.ToString(Formatting.Indented); (new FileInfo(fileName)).Directory.Create(); // Save to Model.bim: File.WriteAllText(fileName, dbcontent); }
/// <summary>Serializes an <code>XMPMeta</code>-object as RDF into a byte buffer.</summary> /// <param name="xmp">a metadata object</param> /// <param name="options"> /// Options to control the serialization (see /// <see cref="Com.Adobe.Xmp.Options.SerializeOptions"/> /// ). /// </param> /// <returns>Returns a byte buffer containing the serialized RDF.</returns> /// <exception cref="XMPException">on serializsation errors.</exception> /// <exception cref="Com.Adobe.Xmp.XMPException"/> public static sbyte[] SerializeToBuffer(XMPMeta xmp, SerializeOptions options) { AssertImplementation(xmp); return(XMPSerializerHelper.SerializeToBuffer((XMPMetaImpl)xmp, options)); }
/// <summary>Serializes an <code>XMPMeta</code>-object as RDF into an <code>OutputStream</code>.</summary> /// <param name="xmp">a metadata object</param> /// <param name="options"> /// Options to control the serialization (see /// <see cref="Com.Adobe.Xmp.Options.SerializeOptions"/> /// ). /// </param> /// <param name="out">an <code>OutputStream</code> to write the serialized RDF to.</param> /// <exception cref="XMPException">on serializsation errors.</exception> /// <exception cref="Com.Adobe.Xmp.XMPException"/> public static void Serialize(XMPMeta xmp, OutputStream @out, SerializeOptions options) { AssertImplementation(xmp); XMPSerializerHelper.Serialize((XMPMetaImpl)xmp, @out, options); }
public void Save(string path, SaveFormat format, SerializeOptions options, bool useAnnotatedSerializeOptions = false, bool resetCheckpoint = false, bool restoreSerializationOptions = true) { var overrideDatabaseName = options?.DatabaseNameOverride; _disableUpdates = true; bool hasOptions = HasSerializeOptions; SerializeOptions optionsBackup = SerializeOptions.Default; if (useAnnotatedSerializeOptions) { // This is invoked when clicking "Save" - always take whatever annotations are currently on the model, // and use those when serializing. options = SerializeOptions; } else { // This is invoked when clicking "Save As" or "Save To Folder", or when the model is being saved. Here, // we don't want to change the annotation on the loaded model - but we still want to apply a (possible different) // annotation to the file that's being saved: optionsBackup = SerializeOptions; SetSerializeOptions(options, false); } options.DatabaseNameOverride = overrideDatabaseName?.Replace(TOMWrapper.Database.InvalidNameCharacters, '_'); try { switch (format) { case SaveFormat.ModelSchemaOnly: if (options != SerializeOptions.Default) { SerializeOptions = options; } SaveFile(path, options); break; case SaveFormat.PowerBiTemplate: SavePbit(path); break; case SaveFormat.TabularEditorFolder: Model.SaveToFolder(path, options); break; case SaveFormat.VisualStudioProject: // TODO throw new NotImplementedException(); // break; } if (resetCheckpoint) { UndoManager.SetCheckpoint(); } Status = format == SaveFormat.TabularEditorFolder ? "Model saved." : "File saved."; } catch { throw; } finally { if (!useAnnotatedSerializeOptions && restoreSerializationOptions) { // Restore serialization options within the currently loaded model: SetSerializeOptions(hasOptions ? optionsBackup : null, false); } _disableUpdates = false; } }
/// <summary>Serializes an <c>XMPMeta</c>-object as RDF into a byte buffer.</summary> /// <param name="xmp">a metadata object</param> /// <param name="options">Options to control the serialization (see <see cref="SerializeOptions"/>).</param> /// <returns>Returns a byte buffer containing the serialized RDF.</returns> /// <exception cref="XmpException">on serialization errors.</exception> public static byte[] SerializeToBuffer(IXmpMeta xmp, SerializeOptions options) { AssertImplementation(xmp); return(XmpSerializerHelper.SerializeToBuffer((XmpMeta)xmp, options)); }
/// <summary> /// Process the response /// </summary> /// <param name="requestedMediaRange">Content type requested by the client</param> /// <param name="model">The model for the given media range</param> /// <param name="context">The nancy context</param> /// <returns>A response</returns> public virtual Response Process(MediaRange requestedMediaRange, dynamic model, NancyContext context) { var pomonaResponse = (PomonaResponse)model; if (pomonaResponse.Entity == PomonaResponse.NoBodyEntity) { return new Response { StatusCode = pomonaResponse.StatusCode } } ; var serializer = GetSerializer(context); var serializeOptions = new SerializeOptions { ExpandedPaths = pomonaResponse.ExpandedPaths, ExpectedBaseType = pomonaResponse.ResultType }; if (IsTextHtmlContentType(requestedMediaRange)) { // Wrap in html var response = new Response(); var htmlLinks = GetHtmlLinks(context); var jsonString = serializer.SerializeToString(pomonaResponse.Entity, serializeOptions); HtmlJsonPrettifier.CreatePrettifiedHtmlJsonResponse(response, htmlLinks, jsonString, "http://failfailtodo"); return(response); } else { var response = new Response { //Headers = {{"Content-Length", bytes.Length.ToString()}}, Contents = stream => { using (var streamWriter = new NonClosingStreamWriter(stream)) { serializer.Serialize(streamWriter, pomonaResponse.Entity, serializeOptions); } }, ContentType = ContentType, StatusCode = pomonaResponse.StatusCode }; if (pomonaResponse.ResponseHeaders != null) { foreach (var kvp in pomonaResponse.ResponseHeaders) { response.Headers.Add(kvp); } } // Add etag header var resourceType = pomonaResponse.ResultType as ResourceType; if (resourceType == null) { return(response); } var etagProperty = resourceType.ETagProperty; if (pomonaResponse.Entity == null || etagProperty == null) { return(response); } var etagValue = (string)etagProperty.GetValue(pomonaResponse.Entity); if (etagValue != null) { // I think defining this as a weak etag will be correct, since we can specify $expand which change data (byte-by-byte). response.Headers["ETag"] = $"W/\"{etagValue}\""; } return(response); } } }
public static string Serialize(object obj, SerializeOptions options = null) { return(new JsonSerializer(options).ToJson(obj)); }
/// <summary>Serializes an <c>XMPMeta</c>-object as RDF into an <c>OutputStream</c>.</summary> /// <param name="xmp">a metadata object</param> /// <param name="options">Options to control the serialization (see <see cref="SerializeOptions"/>).</param> /// <param name="stream">an <c>OutputStream</c> to write the serialized RDF to.</param> /// <exception cref="XmpException">on serialization errors.</exception> public static void Serialize(IXmpMeta xmp, Stream stream, SerializeOptions options = null) { AssertImplementation(xmp); XmpSerializerHelper.Serialize((XmpMeta)xmp, stream, options); }
/// <exception cref="iText.Kernel.XMP.XMPException"/> /// <exception cref="System.IO.IOException"/> public virtual void SetXmpMetadata(XMPMeta xmpMeta, SerializeOptions serializeOptions) { SetXmpMetadata(XMPMetaFactory.SerializeToBuffer(xmpMeta, serializeOptions)); }
public ISerializationContext GetSerializationContext(SerializeOptions options) { options = options ?? new SerializeOptions(); return(new ServerSerializationContext(this.typeMapper, options.ExpandedPaths ?? string.Empty, false, this.uriResolver, this.container)); }
/// <summary> /// Serializes an <code>XMPMeta</code>-object as RDF into an <code>OutputStream</code>. /// </summary> /// <param name="xmp"> a metadata object </param> /// <param name="options"> Options to control the serialization (see <seealso cref="SerializeOptions"/>). </param> /// <param name="out"> an <code>OutputStream</code> to write the serialized RDF to. </param> /// <exception cref="XmpException"> on serializsation errors. </exception> public static void Serialize(IXmpMeta xmp, Stream @out, SerializeOptions options) { AssertImplementation(xmp); XmpSerializerHelper.Serialize((XmpMetaImpl)xmp, @out, options); }
/// <summary>Serializes an <code>XMPMeta</code>-object as RDF into a string.</summary> /// <remarks> /// Serializes an <code>XMPMeta</code>-object as RDF into a string. <em>Note:</em> Encoding /// is ignored when serializing to a string. /// </remarks> /// <param name="xmp">a metadata object</param> /// <param name="options"> /// Options to control the serialization (see /// <see cref="Com.Adobe.Xmp.Options.SerializeOptions"/> /// ). /// </param> /// <returns>Returns a string containing the serialized RDF.</returns> /// <exception cref="XMPException">on serializsation errors.</exception> /// <exception cref="Com.Adobe.Xmp.XMPException"/> public static string SerializeToString(XMPMeta xmp, SerializeOptions options) { AssertImplementation(xmp); return(XMPSerializerHelper.SerializeToString((XMPMetaImpl)xmp, options)); }
public Serializer(XmlWriter writer, SerializeOptions options) : base(options) { _writer = writer; }
/// <summary> /// Serializes the specified object to JSML format, using the specified objectName as the outermost tag name. /// </summary> public static void Serialize(XmlWriter writer, object obj, string objectName, SerializeOptions options) { if (obj == null) { return; } var serializer = new Serializer(writer, options); serializer.Do(obj, objectName); }
internal JsonSerializer(SerializeOptions aOptions = null) { options = aOptions == null ? new SerializeOptions() : aOptions; }