private void RunWorkflowById(string workflowId) { _workflowInstance = new WorkflowInstance(Guid.NewGuid().ToString(), workflowId, _config.GetList()) { ClientId = _config.Get(Constants._ID, Guid.NewGuid().ToString()) }; //Mapping between the Object and Line No. Log.Debug(_workflowInstance.ToXElement().ToString()); //do we need to register client at controller debugging? Yes, we need it to maintain the status of this only client ClientInstancesManager.GetInstance().Register(_config.SetRegisterBody(XElement.Parse("<Register />"))); //TODO add visual trace here //if workflow is loaded, we can track it. //workflowInstance.Tracker.Tracking = this; _workflowInstance.Start(); var debugMode = _config.Get("ModeDebug", "True").Equals("True", StringComparison.CurrentCultureIgnoreCase); while (true) { var xCommand = _workflowInstance.GetCommand(); if (xCommand == null) break; if (debugMode) MessageBox.Show(xCommand.ToString()); Log.Info(xCommand.ToString()); var xResult = _autoClient.Execute(xCommand); if (debugMode) MessageBox.Show(xResult.ToString()); Log.Info(xResult.ToString()); _workflowInstance.SetResult(xResult); Thread.Sleep(1000); if (_workflowInstance.IsFinished()) break; } /* workflowInstance = null; */ }
public XElement UpdateInstance(XElement instanceInfo) { var _1StNode = ((XElement) instanceInfo.FirstNode); //var name = instanceInfo.GetAttributeValue("TestName"); var scriptGuid = _1StNode.GetAttributeValue("ScriptGUID"); //var defaultURL = _1StNode.GetAttributeValue("DefaultURL"); //var clientId = _1StNode.GetAttributeValue("ClientId"); var guid = _1StNode.GetAttributeValue(Constants._ID); //var status = instanceInfo.GetAttributeValue("Status"); //var language = instanceInfo.GetAttributeValue("Language"); //var suiteName = instanceInfo.GetAttributeValue("SuiteName"); WorkflowInstance instance; if (_instanceList.ContainsKey(guid)) { //instance already existed instance = _instanceList[guid]; } else { //instance not existed, create one instance = new WorkflowInstance(guid, scriptGuid, ((XElement) instanceInfo.FirstNode).GetAttributeList()); //new WorkflowInstance(guid, scriptGuid, name, computer, suiteName, language); _instanceList.Add(guid, instance); } if(instance==null) return XElement.Parse("<Result Result='Error' Reason='Instance is null' />"); instance.Variables = ((XElement)instanceInfo.FirstNode).GetAttributeList(); var status = instance.Status; var instanceId = instance._id; if(string.IsNullOrEmpty(status) || !status.Equals("Invalid")) return XElement.Parse("<Result Result='Success' InstanceId ='"+instanceId+"' />"); return XElement.Parse("<Result Result='Error' Reason='" + status + "' InstanceId ='" + instanceId + "' />"); }
//private static void RemoveResults() //{ // //find root element // var xRoot = DBFactory.GetData().Read(Constants._TYPE, "Root"); // var resultId = xRoot.GetAttributeValue(Constants.RESULT); // var results = DBFactory.GetData().GetChildren(resultId); // foreach (var kids in results.Descendants()) // { // DBFactory.GetData().Delete(kids.GetAttributeValue(Constants._ID)); // } //} //private static void CleanProject() //{ // //find root element // var xRoot = DBFactory.GetData().Read(Constants._TYPE, "Root"); // var root = DBFactory.GetData().GetChildren(xRoot.GetAttributeValue(Constants._ID)); // foreach (var kid in root.Descendants()) // { // var id = kid.GetAttributeValue(Constants._ID); // if (id.Equals(xRoot.GetAttributeValue(Constants._ID))) // continue; // foreach (var grandKid in DBFactory.GetData().GetChildren(id).Descendants()) // { // DBFactory.GetData().Delete(grandKid.GetAttributeValue(Constants._ID)); // } // } //} private static void TestWorkflow() { var auto = new AutoClient(); var workflowInstance = new WorkflowInstance(Guid.NewGuid().ToString(), "7fdcbd7a-b30e-4c36-aa46-58ba74b02401", Configuration.Clone().GetList()); var xCommand = workflowInstance.GetCommand(); Console.WriteLine(xCommand.ToString()); var xResult = auto.Execute(xCommand); Console.WriteLine(xResult); workflowInstance.SetResult(xResult); }
internal void AddToWaitingList(WorkflowInstance workflowInstance) { lock(_waitingList){ _waitingList.Add(workflowInstance); Monitor.Pulse(_waitingList); } }