static protected byte[] GetDefaultSerializedForm(Activity activity) { DateTime startTime = DateTime.Now; Byte[] result; Debug.Assert(activity != null, "Null activity"); using (MemoryStream stream = new MemoryStream(10240)) { stream.Position = 0; activity.Save(stream); using (MemoryStream compressedStream = new MemoryStream((int)stream.Length)) { using (GZipStream gzs = new GZipStream(compressedStream, CompressionMode.Compress, true)) { gzs.Write(stream.GetBuffer(), 0, (int)stream.Length); } ActivityExecutionContextInfo executionContextInfo = (ActivityExecutionContextInfo)activity.GetValue(Activity.ActivityExecutionContextInfoProperty); TimeSpan timeElapsed = DateTime.Now - startTime; WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "Serialized a {0} with id {1} to length {2}. Took {3}.", executionContextInfo, executionContextInfo.ContextGuid, compressedStream.Length, timeElapsed); result = compressedStream.GetBuffer(); Array.Resize<Byte>(ref result, Convert.ToInt32(compressedStream.Length)); } } return result; }
protected static byte[] GetDefaultSerializedForm(Activity activity) { byte[] buffer; DateTime now = DateTime.Now; using (MemoryStream stream = new MemoryStream(0x2800)) { stream.Position = 0L; activity.Save(stream); using (MemoryStream stream2 = new MemoryStream((int) stream.Length)) { using (GZipStream stream3 = new GZipStream(stream2, CompressionMode.Compress, true)) { stream3.Write(stream.GetBuffer(), 0, (int) stream.Length); } ActivityExecutionContextInfo info = (ActivityExecutionContextInfo) activity.GetValue(Activity.ActivityExecutionContextInfoProperty); TimeSpan span = (TimeSpan) (DateTime.Now - now); WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "Serialized a {0} with id {1} to length {2}. Took {3}.", new object[] { info, info.ContextGuid, stream2.Length, span }); buffer = stream2.GetBuffer(); Array.Resize<byte>(ref buffer, Convert.ToInt32(stream2.Length)); } } return buffer; }
private void SerializeActivity(Activity rootActivity, Guid id) { if (!ActivityIsSerializable(rootActivity)) { Log.LogVerbose(LogTitle, $"The workflow does not support persiting. Id = {id}, Type = {rootActivity.GetType()}"); return; } string filename = GetFileName(id); IFormatter formatter = new BinaryFormatter(); formatter.SurrogateSelector = ActivitySurrogateSelector.Default; using (C1FileStream stream = new C1FileStream(filename, FileMode.OpenOrCreate)) { rootActivity.Save(stream, formatter); stream.Close(); } // Log.LogVerbose(LogTitle, $"Workflow persisted. Id = {id}, Type = {rootActivity.GetType()}"); }
private void SerializeActivity(Activity rootActivity, Guid id) { if (!ActivityIsSerializable(rootActivity)) { LoggingService.LogVerbose("FileWorkFlowPersisetenceService", string.Format("The workflow does not support persiting. Id = {0}, Type = {1}", id, rootActivity.GetType())); return; } string filename = GetFileName(id); IFormatter formatter = new BinaryFormatter(); formatter.SurrogateSelector = ActivitySurrogateSelector.Default; using (C1FileStream stream = new C1FileStream(filename, FileMode.OpenOrCreate)) { rootActivity.Save(stream, formatter); stream.Close(); } // LoggingService.LogVerbose("FileWorkFlowPersisetenceService", string.Format("Workflow persisted. Id = {0}, Type = {1}", id, rootActivity.GetType())); }