public SqlServerApiResourceStore(IIdentityDbContext identityDbContext, IEventService eventService, IUserResolverService userResolverService, ISerializationSettings serializationSettings) : base(identityDbContext, eventService, userResolverService, serializationSettings) { }
/// <summary> /// Creates a <see cref="DataContractJsonSerializer" /> /// </summary> /// <param name="serializationSettings">The settings to use to create the <see cref="DataContractJsonSerializer" /></param> /// <exception cref="System.InvalidOperationException"> /// <see cref="DataContractJsonSerializer" /> does not support a <see cref="DataContractResolver" /> /// </exception> /// <returns>A new <see cref="DataContractJsonSerializer" /></returns> public static DataContractJsonSerializer GetSerializer <T>(ISerializationSettings serializationSettings) { if (serializationSettings == null) { return(new DataContractJsonSerializer(typeof(T))); } DataContractJsonSerializer ser = null; bool knownTypesExist = serializationSettings.KnownTypes.AnySafe(); bool resolverExists = serializationSettings.Resolver != null; if (!knownTypesExist && !resolverExists) { ser = new DataContractJsonSerializer(typeof(T)); } else if (resolverExists) { throw new InvalidOperationException("Json serialization doesn't use a resolver."); } else if (knownTypesExist) { ser = new DataContractJsonSerializer(typeof(T), serializationSettings.KnownTypes); } return(ser); }
protected EntityAuditEvent(string username, string clientId, string subject, string documentId, string category, string name, int id, T entity, ISerializationSettings serializationSettings) : this(username, clientId, subject, documentId, category, name, id, serializationSettings) { Entity = ObfuscateEntity(entity); }
public AuditingDocumentDbService(IUserResolverService userResolverService, IEventService eventService, Decorator <IDocumentDbService> decorator, ISerializationSettings serializationSettings) { _serializationSettings = serializationSettings; _eventService = eventService ?? throw new ArgumentNullException(nameof(eventService)); _innerDocumentDbService = decorator.Instance ?? throw new ArgumentNullException(nameof(decorator)); _userResolveService = userResolverService ?? throw new ArgumentNullException(nameof(userResolverService)); }
/// <summary> /// Serializes an object into a Json string /// </summary> /// <typeparam name="T">The target type (must be serializable)</typeparam> /// <param name="target">Target to serialize</param> /// <param name="settings">Serialization Settings</param> /// <returns>A Json string representation of the object</returns> public string SerializeObject <T>(T target, ISerializationSettings settings = null) { if (target == null) { return(""); } return(target.SerializeJson(LoggingService, true, settings)); }
public SqlServerPersistedGrantStore(IIdentityDbContext identityDbContext, ILogger logger, IEventService eventService, IUserResolverService userResolverService, ISerializationSettings serializationSettings) : base(identityDbContext, eventService, userResolverService, serializationSettings) { _logger = logger; }
/// <summary> /// Serializes an object into a Json string /// </summary> /// <typeparam name="T">The target type (must be serializable)</typeparam> /// <param name="target">Target to serialize</param> /// <returns>A Json string representation of the object</returns> public string SerializeObject <T>(T target, ISerializationSettings settings = null) { if (target == null) { return(""); } return(SerializeJson(target)); }
/// <summary> /// Deserializes an object from Json Stream /// </summary> /// <typeparam name="T">The target type (must be serializable)</typeparam> /// <param name="target">The Json Stream that contains a string representation of the object</param> /// <returns>The object deserialized from the Json Stream</returns> public T DeserializeObject <T>(Stream target, ISerializationSettings settings = null) { if (target == null) { return(default(T)); } return(DeserializeJson <T>(GetString(target))); }
/// <summary> /// Deserializes an object from Json string /// </summary> /// <typeparam name="T">The target type (must be serializable)</typeparam> /// <param name="target">The Json string representation of the object</param> /// <returns>The object deserialized from the Json string</returns> public T DeserializeObject <T>(string target, ISerializationSettings settings = null) { if (string.IsNullOrWhiteSpace(target)) { return(default(T)); } return(DeserializeJson <T>(target)); }
public CouchDbAccessService(ICouchDbSettings config, ILogger logger, ISerializationSettings serializationSettings) { _couchDbSettings = config; _logger = logger; _serializationSettings = serializationSettings; _logger.Debug( $"couchDb configuration properties: Server: {config.Server} -- DatabaseName: {config.DatabaseName}"); }
protected SqlServerBaseStore(IIdentityDbContext identityDbContext, IEventService eventService, IUserResolverService userResolverService, ISerializationSettings serializationSettings) { IdentityDbContext = identityDbContext; EventService = eventService; UserResolverService = userResolverService; SerializationSettings = serializationSettings; }
public RedisProviderSettings(ISerializationService serializationService, ICacheServiceSettings serializableSettings , ConfigurationOptions configurationOptions, ISerializationSettings serializationSettings = null) { SerializationService = serializationService; ServiceSettings = serializableSettings; SerializationSettings = serializationSettings; ConfigurationOptions = configurationOptions == null ? ConfigurationOptions.Parse(ServiceSettings.ConfigurationOptions, true) : configurationOptions; }
public EntityCreatedAuditEvent(string userName, string clientId, string subject, string documentId, T entity, ISerializationSettings serializationSettings) : base(userName, clientId, subject, documentId, FabricIdentityConstants.AuditEventCategory, FabricIdentityConstants.CustomEventNames.EntityCreatedAudit, FabricIdentityConstants.CustomEventIds.EntityCreatedAudit, entity, serializationSettings) { }
protected EntityAuditEvent(string username, string clientId, string subject, string documentId, string category, string name, int id, ISerializationSettings serializationSettings) : base(category, name, EventTypes.Information, id) { _serializationSettings = serializationSettings; Username = username; ClientId = clientId; Subject = subject; DocumentId = documentId; EntityType = typeof(T).FullName; }
/// <summary> /// Normalizes line endings, converting "\r" into "\r\n" and "\n" into "\r\n". /// </summary> public static TextReader Normalize(string s, ISerializationContext ctx) { // Replace \r and \n with \r\n. s = Regex.Replace(s, @"((\r(?=[^\n]))|((?<=[^\r])\n))", "\r\n"); ISerializationSettings settings = ctx.GetService(typeof(ISerializationSettings)) as ISerializationSettings; if (settings == null || !settings.EnsureAccurateLineNumbers) { s = RemoveEmptyLines(UnwrapLines(s)); } return(new StringReader(s)); }
/// <summary> /// Deserializes a json string to an object /// </summary> /// <param name="jsonString">The json string representation of an object.</param> /// <typeparam name="T">The type to deserialize to.</typeparam> /// <returns>The object represented by the jsonString.</returns> public static T DeserializeJson <T>(this string jsonString, ISerializationSettings serializationSettings = null) { if (string.IsNullOrWhiteSpace(jsonString)) { return(default(T)); } DataContractJsonSerializer ser = DataContractJsonSerializerHelpers.GetSerializer <T>(serializationSettings); T obj; using (Stream stream = jsonString.ToStream()) { obj = (T)ser.ReadObject(stream); } return(obj); }
public void SaveToStream(IFeed feed, Stream stream, ISerializationSettings settings, InclusionNode inclusionTree) { if (feed is SyncFeed) { XmlTextWriter xmlWriter = new XmlTextWriter(stream, Encoding.UTF8); xmlWriter.WriteStartDocument(); // TODO: HANDLE AS ERROR(404) IF FEEDTYPE IS 'ENTRY' AND NO ENTRY EXISTS. ((SyncFeed)feed).WriteXml(xmlWriter); xmlWriter.WriteEndDocument(); xmlWriter.Flush(); } }
public override string SerializeToString(object obj) { if (obj != null) { ISerializationSettings settings = GetService <ISerializationSettings>(); List <string> values = new List <string>(); if (obj is string) { // Object to be serialied is a string already values.Add((string)obj); } else if (obj is IEnumerable) { // Object is a list of objects (probably IList<string>). foreach (object child in (IEnumerable)obj) { values.Add(child.ToString()); } } else { // Serialize the object as a string. values.Add(obj.ToString()); } ICalendarObject co = SerializationContext.Peek() as ICalendarObject; if (co != null) { // Encode the string as needed. EncodableDataType dt = new EncodableDataType(); dt.AssociatedObject = co; for (int i = 0; i < values.Count; i++) { values[i] = Encode(dt, Escape(values[i])); } return(string.Join(",", values.ToArray())); } for (int i = 0; i < values.Count; i++) { values[i] = Escape(values[i]); } return(string.Join(",", values.ToArray())); } return(null); }
/// <summary> /// Serializes an object to json if possible /// </summary> /// <param name="target">The object to serialize</param> /// <param name="loggingService">The logging service to use</param> /// <param name="throwOnFail">If the serialization should throw upon failure to serialize</param> /// <param name="serializationSettings">The object that provides known types and data contract resolvers</param> /// <returns>The serialized json string representation of an object</returns> /// <exception cref="System.Exception"> /// Thrown when the serialization fails, and will be the type that serializer throws. Not thrown if <c>throwOnFail</c> is false. /// </exception> public static string SerializeJson <T>(this T target, ILoggingService loggingService = null, bool throwOnFail = true , ISerializationSettings serializationSettings = null) { if (target == null) { return(string.Empty); } try { using (MemoryStream stream = new MemoryStream()) { DataContractJsonSerializer ds = DataContractJsonSerializerHelpers.GetSerializer <T>(serializationSettings); ds.WriteObject(stream, target); string jsonString = stream.GetString(); stream.Close(); return(jsonString); } } catch (Exception ex) { // if it wasn't serializable, that's ok, we expected as much if (!target.IsSerializable()) { loggingService?.LogMessage("Attempted serialization failed", "Attempted to serialize " + target.GetType().Name + ", but it's not serializable.", LogLevel.Warning); if (throwOnFail) { throw; } return(string.Empty); } loggingService?.LogException(ex, "ObjectExtensions.SerializeJson Exception. Target type - " + target.GetType()); if (throwOnFail) { throw; } return(string.Empty); } }
/// <summary> /// Converts a string found in cache to an object /// </summary> /// <typeparam name="T">Object type to convert to</typeparam> /// <param name="stringToConvert">String to convert to an object</param> /// <param name="key">The key that was used to get the value</param> /// <param name="serializationSettings">The datacontract resolver to use for serialization /// (polymorphic dtos)</param> /// <returns>Object from string</returns> protected internal virtual T ConvertString <T>(string stringToConvert, RedisId key, ISerializationSettings serializationSettings = null) { T retVal = default(T); if (string.IsNullOrWhiteSpace(stringToConvert)) { return(retVal); } if (typeof(T) == typeof(string)) { retVal = (T)Convert.ChangeType(stringToConvert, typeof(T)); } else { ISerializationService serializationService = GetSerializationService <T>(); retVal = serializationService.DeserializeObject <T>(stringToConvert, _cacheSettings.SerializationSettings); } return(retVal); }
public override object Deserialize(TextReader tr) { if (tr != null) { string value = tr.ReadToEnd(); // NOTE: this can deserialize into an IList<string> or simply a string, // depending on the input text. Anything that uses this serializer should // be prepared to receive either a string, or an IList<string>. bool serializeAsList = false; // Determine if we can serialize this property // with multiple values per line. ICalendarObject co = SerializationContext.Peek() as ICalendarObject; if (co is ICalendarProperty) { serializeAsList = GetService <IDataTypeMapper>().GetPropertyAllowsMultipleValues(co); } value = TextUtil.Normalize(value, SerializationContext).ReadToEnd(); // Try to decode the string EncodableDataType dt = null; if (co != null) { dt = new EncodableDataType(); dt.AssociatedObject = co; } List <string> escapedValues = new List <string>(); List <string> values = new List <string>(); int i = 0; if (serializeAsList) { MatchCollection matches = Regex.Matches(value, @"[^\\](,)"); foreach (Match match in matches) { string newValue = dt != null?Decode(dt, value.Substring(i, match.Index - i + 1)) : value.Substring(i, match.Index - i + 1); escapedValues.Add(newValue); values.Add(Unescape(newValue)); i = match.Index + 2; } } if (i < value.Length) { string newValue = dt != null?Decode(dt, value.Substring(i, value.Length - i)) : value.Substring(i, value.Length - i); escapedValues.Add(newValue); values.Add(Unescape(newValue)); } if (co is ICalendarProperty) { // Determine if our we're supposed to store extra information during // the serialization process. If so, let's store the escaped value. ICalendarProperty property = (ICalendarProperty)co; ISerializationSettings settings = GetService <ISerializationSettings>(); if (settings != null && settings.StoreExtraSerializationData) { // Store the escaped value co.SetService("EscapedValue", escapedValues.Count == 1 ? (object)escapedValues[0] : (object)escapedValues); } } // Return either a single value, or the entire list. if (values.Count == 1) { return(values[0]); } else { return(values); } } return(null); }
public IICalendarCollection icalendar( ISerializationContext ctx ) //throws RecognitionException, TokenStreamException { IICalendarCollection iCalendars = new iCalendarCollection(); SerializationUtil.OnDeserializing(iCalendars); IICalendar iCal = null; ISerializationSettings settings = ctx.GetService(typeof(ISerializationSettings)) as ISerializationSettings; { // ( ... )* for (;;) { if ((LA(1) == CRLF || LA(1) == BEGIN)) { { // ( ... )* for (;;) { if ((LA(1) == CRLF)) { match(CRLF); } else { goto _loop4_breakloop; } } _loop4_breakloop :; } // ( ... )* match(BEGIN); match(COLON); match(VCALENDAR); { // ( ... )* for (;;) { if ((LA(1) == CRLF)) { match(CRLF); } else { goto _loop6_breakloop; } } _loop6_breakloop :; } // ( ... )* ISerializationProcessor <IICalendar> processor = ctx.GetService(typeof(ISerializationProcessor <IICalendar>)) as ISerializationProcessor <IICalendar>; // Do some pre-processing on the calendar: if (processor != null) { processor.PreDeserialization(iCal); } iCal = (IICalendar)SerializationUtil.GetUninitializedObject(settings.iCalendarType); SerializationUtil.OnDeserializing(iCal); // Push the iCalendar onto the serialization context stack ctx.Push(iCal); icalbody(ctx, iCal); match(END); match(COLON); match(VCALENDAR); { // ( ... )* for (;;) { if ((LA(1) == CRLF) && (LA(2) == EOF || LA(2) == CRLF || LA(2) == BEGIN) && (tokenSet_0_.member(LA(3)))) { match(CRLF); } else { goto _loop8_breakloop; } } _loop8_breakloop :; } // ( ... )* // Do some final processing on the calendar: if (processor != null) { processor.PostDeserialization(iCal); } // Notify that the iCalendar has been loaded iCal.OnLoaded(); iCalendars.Add(iCal); SerializationUtil.OnDeserialized(iCal); // Pop the iCalendar off the serialization context stack ctx.Pop(); } else { goto _loop9_breakloop; } } _loop9_breakloop :; } // ( ... )* SerializationUtil.OnDeserialized(iCalendars); return(iCalendars); }
public void SaveToStream <T>(T feedEntry, Stream stream, ISerializationSettings settings) where T : FeedEntry, new() { SaveToStream <T>(feedEntry, stream, settings, null); }
public void SaveToStream(IFeed feed, Stream stream, ISerializationSettings settings) { SaveToStream(feed, stream, settings); }
/// <param name="settings">The settings to use with the Serialization Service</param> public JwtJsonSerializer(ISerializationSettings settings = null) { Settings = settings; }
public void SetProvider(ISerializationSettings settings) { Guard.ArgumentNotNull(settings, "settings"); _current = settings; }
public RedisProviderSettings(ISerializationService serializationService, string configurationOptionsString , ICacheServiceSettings serializableSettings, ISerializationSettings serializationSettings = null) : this(serializationService, serializableSettings, ConfigurationOptions.Parse(configurationOptionsString, true) , serializationSettings) { }
public SerializationService() { _jsonSerializerSettings = null; _serializationSettings = null; }
public RedisProviderSettings(ISerializationService serializationService, ICacheServiceSettings serializableSettings , ISerializationSettings serializationSettings = null) : this(serializationService, serializableSettings, null, serializationSettings) { }
public void SaveToStream <T>(T feedEntry, Stream stream, ISerializationSettings settings, InclusionNode inclusionTree) where T : FeedEntry, new() { throw new NotImplementedException(); }