protected override Formatter PrepareFormatter(Type type) { var name = ContractEvil.GetContractReference(type); var formatter = RuntimeTypeModel.Default.CreateFormatter(type); return(new Formatter(name, formatter.Deserialize, (o, stream) => formatter.Serialize(stream, o))); }
void ReportFailure(string text, ImmutableEnvelope envelope) { // we do not report failure on attempts to send mail messages // this could be a loop // we can't report them anyway (since mail sending is not available) // note, that this could be an indirect loop. if (text.Contains(typeof(SendMailMessage).Name)) { return; } if (text.Contains(typeof(MessageQuarantined).Name)) { return; } var name = envelope.Message.GetType().Name.Replace("Command", ""); var subject = string.Format("[Error]: S2 fails '{0}'", name); var builder = new StringBuilder(); builder.AppendFormat( @"<p>Support,</p><p>Something just went horribly wrong - there is a problem that I can't resolve. Please check the error log <strong>ASAP</strong>.</p> <p>Here are a few details to help you out:</p><pre>"); builder.AppendLine(WebUtility.HtmlEncode(text)); builder.AppendFormat("</pre><p>You can use S2 Maintenance to get the error details.</p><p>Sincerely,<br /> Hub AI</p>"); // if we don't fit in the limits if (text.Length >= 1024 * 1024) { const string body = "Subj, please notify Lokad support team immediately"; const string subj = "[S2]: Quarantine overflow"; var message = new SendMailMessage(new[] { new Email("*****@*****.**") }, subj, body, false, null, null, null); _writer.SendCommand(message, true); // fail immediately return; } var to = new[] { new Email("*****@*****.**", "Salescast Support"), new Email("*****@*****.**", "Rinat Abdullin") }; var cmd = new SendMailMessage(to, subject, builder.ToString(), true, null, null, null); _writer.SendCommand(cmd, true); var buffer = _streamer.SaveEnvelopeData(envelope); var names = new[] { ContractEvil.GetContractReference(envelope.Message.GetType()) }; _writer.Publish(new MessageQuarantined(text, buffer, names, DateTime.UtcNow)); }
protected override Formatter PrepareFormatter(Type type) { var name = ContractEvil.GetContractReference(type); return(new Formatter(name, stream => JsonSerializer.DeserializeFromStream(type, stream), (o, stream) => JsonSerializer.SerializeToStream(o, type, stream))); }
protected override Formatter PrepareFormatter(Type type) { var name = ContractEvil.GetContractReference(type); return(new Formatter(name, type, s => JsonSerializer.DeserializeFromStream(type, s), (o, s) => { using (var writer = new StreamWriter(s)) { writer.WriteLine(); writer.WriteLine(JsvFormatter.Format(JsonSerializer.SerializeToString(o, type))); } })); }
protected override Formatter PrepareFormatter(Type type) { var name = ContractEvil.GetContractReference(type); return(new Formatter(name, s => JsonSerializer.DeserializeFromStream(type, s), (o, s) => { using (var writer = new StreamWriter(s)) { writer.WriteLine(); writer.WriteLine(JsvFormatter.Format(JsonSerializer.SerializeToString(o, type))); } })); //var formatter = RuntimeTypeModel.Default.CreateFormatter(type); //return new Formatter(name, formatter.Deserialize, (o, stream) => formatter.Serialize(stream, o)); }
protected override Formatter PrepareFormatter(Type type) { var name = ContractEvil.GetContractReference(type); var serializer = new DataContractSerializer(type, KnownTypes); return(new Formatter(name, stream => { using (var reader = XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max)) { return serializer.ReadObject(reader); } }, (o, stream) => { using (var writer = XmlDictionaryWriter.CreateBinaryWriter(stream, null, null, false)) { serializer.WriteObject(writer, o); } })); }
public DataSerializerWithProtoBuf(ICollection <Type> knownTypes) { if (knownTypes.Count == 0) { throw new InvalidOperationException( "ProtoBuf requires some known types to serialize. Have you forgot to supply them?"); } InitIdentityTree(); foreach (var type in knownTypes) { var reference = ContractEvil.GetContractReference(type); var formatter = RuntimeTypeModel.Default.CreateFormatter(type); try { _contract2Type.Add(reference, type); } catch (ArgumentException e) { var msg = string.Format("Duplicate contract '{0}' being added to ProtoBuf dictionary", reference); throw new InvalidOperationException(msg, e); } try { _type2Contract.Add(type, reference); _type2Formatter.Add(type, formatter); } catch (ArgumentException e) { var msg = string.Format("Duplicate type '{0}' being added to ProtoBuf dictionary", type); throw new InvalidOperationException(msg, e); } } }
public void Class_can_override() { var contractReference = ContractEvil.GetContractReference(typeof(CustomDataClass)); Assert.AreEqual("Custom/ProtoBufDataTests/Type", contractReference); }
public void Default_reference_is_type_name() { var contractReference = ContractEvil.GetContractReference(typeof(SimpleDataClass)); Assert.AreEqual("ProtoBufDataTests/SimpleDataClass", contractReference); }
public string GetName() { return(ContractEvil.GetContractReference(Envelope.Message.GetType())); }
public void Class_can_override() { var contractReference = ContractEvil.GetContractReference(typeof(CustomProtoClass)); Assert.AreEqual("ProtoBufNativeTests/Custom", contractReference); }