Friday, April 6, 2007

SQL 2005 XML Datatype for Serialize Object

In order to save xml deserialized object to SQL 2005, make sure it is "utf-8" encoding.


public string ToXml()
{
using(MemoryStream memStream = new MemoryStream())
{
XmlSerializer sr = new XmlSerializer(this.GetType());
sr.Serialize(memStream, this);
// NOTE: Using UTF8 Encoding to support saving to SQL 2005 Database


return System.Text.Encoding.UTF8.GetString(memStream.ToArray());
}
}


public static T XmlDeserialize(string xml)
{
if (string.IsNullOrEmpty(xml))
return default(T);

System.IO.Stream stream =
new System.IO.MemoryStream (System.Text.Encoding.UTF8.GetBytes(xml));

XmlSerializer sr = new XmlSerializer(typeof(T));

return (T)sr.Deserialize(stream);
}


I have issue on using on using "utf-16" which is a native xml serialization. Unicode (UTF-16) Encoding currently is not supported in XML DataType Columns (without Schemas). if including Root Element in XML Text.

References:
Retrieving Objects from SQL Server Using SQLXML and Serialization By Gianluca Nuzzo


Wednesday, January 3, 2007

Windows Workflow Activities Definitions

If you are new to the new Windows Workflow Foundation then we are on the same boat. What are each of these out of the box activies and how to I use it. I like to document my findings here...

This blog will cover Flow Activities




FlowExecutionEventsWeb ServicesState
IfElseTransactionScopeEventDrivenWebServiceInputSetState
WhileSequenceListenWebServiceOutputState
CAGCompensateHandleExternalEventWebServiceFaultStateInitialization
PolicySynchronizationScopeEventHandlingScopeInvokeWebServiceStateFinalization
ReplicatorCodeDelay
ThrowParallel
SuspendInvokeWorkflow
TerminateCallExternalMethod
FaultHandlerCompensatableSequence
CompensatableTransactionScope





IfElseActivity : Contains an ordered set of IfElseBranchActivity classes. Runs the first branch when the condition evaluates to true. The final branch is not required to have a condition, in which case it always evaluates to true.

WhileActivity : Runs a child activity iteratively as long as a certain condition is true.


ConditionedActivityGroup : Runs and re-executes child activities based on the evaluation of their when conditions. All rules are evaluated whenever required based on their data and state change dependencies. When the completion rule of the ConditionedActivityGroup evaluates to true, it immediately cancels any currently executing child activities and finishes.

PolicyActivity : Represents a collection of Rule class instances to be run as part of a workflow's execution as a single step/activity.

ReplicatorActivity : similar to a For Each statement in code. By default, a ReplicatorActivity is completed when all child instances have completed. You can override this behavior with a custom condition to use when the activity finishes. If this condition evaluates to true before all child instances have completed, then any running incomplete child instances will be canceled.

Throw : Raises exceptions declaratively, usually in response to exceptional conditions detected in a workflow.

Suspend : Stops the execution of the current workflow

Terminate : Immediately end all activities of a running workflow instance.

FaultHandler : It is a wrapper for other activities that perform the work that is done when the specified exception occurs.


References: http://msdn2.microsoft.com/en-us/library/ms733615.aspx