﻿//version:1.0
//published by:Microsoft
//company:http://www.microsoft.com
//description:OOB Workflow Activity
//assembly:System.Workflow.Activities.dll

function SequentialWorkflowActivity(element) {
	this.element = element	
    
    //this.group = quanticks.drag().createsimpleactivity(element, this.innerBar)
    this.Properties = new Array();
	this.RegisteredProperties = new Array();
	this.RegisteredProperties[0] = "Name";
	this.RegisteredProperties[1] = "Description";
	this.RegisteredProperties[2] = "Enabled";	
	this.RegisteredProperties[3] = "Initialize";
    this.RegisteredProperties[4] = "Complete";
    this.EventProperties = new Array();
    this.EventProperties[0] = "Initialized";	
    this.EventProperties[1] = "Completed";	
	this.Parameters = new Array();
	this.ParameterValues = new Array();
	//this.Properties["Name"] = element.id
	

}

SequentialWorkflowActivity.GetToolboxIcon = function()
{
    return "http://netfxlive.com/images/sequence.GIF";
}

SequentialWorkflowActivity.prototype = {
    Initialize : function(id)
    {
	    this.Properties["Name"] = id;
	    this.innerBar=document.createElement("div");
	    this.innerBar.className="wfbar";
        this.innerBar.innerHTML = "<div id='"+id+"_id' class='idlabel'>"+id+"</div>";
        this.element.appendChild(this.innerBar);
    
		var startImg=document.createElement("IMG");
		startImg.src="http://netfxlive.com/Images/start.GIF";
	    this.element.appendChild(startImg);
		
		
		var innerConnector=document.createElement("DIV");
	    innerConnector.className="connector";
	    var innerImg=document.createElement("IMG");
	    innerImg.src="http://netfxlive.com/Images/connector.gif";
        innerConnector.appendChild(innerImg);
	    connectors[connectors.length] = innerConnector;
	    this.element.appendChild(innerConnector);
	    
	    var stopImg=document.createElement("IMG");
		stopImg.src="http://netfxlive.com/Images/stop.GIF";
	    this.element.appendChild(stopImg);
	    
	    activityList[activityCount] = this;
	    activityCount++;
	    updateScrollArrows();
    },
    
    Clear : function()
    {
        this.element.innerHTML = ""        
    },
    
    Serialize : function()
    {
        namespaces = new Array();
        var activityFactory = Quanticks.activityFactory()
        var result = new String("")
        for (var propi = 0;propi<this.RegisteredProperties.length;propi++)
        {
            if (this.RegisteredProperties[propi]=="Name")
                result += "x:";
            if (typeof this.Properties[this.RegisteredProperties[propi]] != "undefined" && this.Properties[this.RegisteredProperties[propi]]!="")
                result += this.RegisteredProperties[propi]+"=\""+this.Properties[this.RegisteredProperties[propi]]+"\" ";
        }
        result += ">\n"
        result += SerializeParameters(this);
        for(var wh=0;wh<workflow.children.length;wh++)
        {
            var childActivity = activityFactory.getActivity(workflow.children[wh])
            if (childActivity!=null)
            {
                result += childActivity.Serialize()
            }
        }        
        
        result += "</ns0:CloudSequentialWorkflow>\n"
        var user = Quanticks.getUser();
        if (user == "") user = "unknown";
        var xomlHeader = "<ns0:CloudSequentialWorkflow x:Class=\""+user.toLowerCase()+"."+this.Properties["Name"]+"\" ";
        for(var ns=0;ns<namespaces.length;ns++)
        {
            xomlHeader += namespaces[ns]+" ";
        }
        xomlHeader += " xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/workflow\" xmlns:ns0=\"http://schemas.microsoft.com/2007/11/CloudWorkflowActivityLibrary\" "
        
        return xomlHeader + result
    }

}
