Beispiel #1
0
        // single interaction with the user. The user enters a string in the console and that
        // string is used to resume the ReadLine activity bookmark
        static void Interact(WorkflowApplication application, AutoResetEvent resetEvent)
        {
            Console.WriteLine("Workflow is ready for input");
            Console.WriteLine("Special commands: 'unload', 'exit'");

            bool done = false;
            while (!done)
            {
                Console.Write("> ");
                string s = Console.ReadLine();
                if (s.Equals("unload"))
                {
                    try
                    {
                        // attempt to unload will fail if the workflow is idle within a NoPersistZone
                        application.Unload(TimeSpan.FromSeconds(5));
                        done = true;
                    }
                    catch (TimeoutException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                else if (s.Equals("exit"))
                {
                    application.ResumeBookmark("inputBookmark", s);
                    done = true;
                }
                else
                {
                    application.ResumeBookmark("inputBookmark", s);
                }
            }
            resetEvent.WaitOne();
        }
    private void GetReimbursementVoid(Guid id)
    {
        // Initialize Windows Workflow Foundation
          WorkflowApplication _wfApp = new WorkflowApplication(new ReimbursementRequest());

          SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(ConfigurationManager.ConnectionStrings["workflows"].ConnectionString);
          _wfApp.InstanceStore = store;
          _wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs ex)
          {
               return PersistableIdleAction.Persist;
          };
          _wfApp.Run();
          _wfApp.Unload();
          Session["wfid"] = _wfApp.Id;
    }
        static void Main(string[] args)
        {
            SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(connectionString);
            WorkflowApplication.CreateDefaultInstanceOwner(store, null, WorkflowIdentityFilter.Any);

            IDictionary<WorkflowIdentity, DynamicUpdateInfo> updateMaps = LoadMaps();

            foreach (Guid id in GetIds())
            {
                // Get a proxy to the instance.
                WorkflowApplicationInstance instance =
                    WorkflowApplication.GetInstance(id, store);

                Console.WriteLine("Inspecting: {0}", instance.DefinitionIdentity);

                // Only update v1 workflows.
                if (instance.DefinitionIdentity != null &&
                    instance.DefinitionIdentity.Version.Equals(new Version(1, 0, 0, 0)))
                {
                    DynamicUpdateInfo info = updateMaps[instance.DefinitionIdentity];

                    // Associate the persisted WorkflowApplicationInstance with
                    // a WorkflowApplication that is configured with the updated
                    // definition and updated WorkflowIdentity.
                    Activity wf = WorkflowVersionMap.GetWorkflowDefinition(info.newIdentity);
                    WorkflowApplication wfApp =
                        new WorkflowApplication(wf, info.newIdentity);

                    // Apply the Dynamic Update.
                    wfApp.Load(instance, info.updateMap);

                    // Persist the updated instance.
                    wfApp.Unload();

                    Console.WriteLine("Updated to: {0}", info.newIdentity);
                }
                else
                {
                    // Not updating this instance, so unload it.
                    instance.Abandon();
                }
            }
        }
        private void cmdUpdateInstance_Click(object sender, RoutedEventArgs e)
        {

            SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore();

            instanceStore.ConnectionString =
                @"Data Source=(LocalDB)\v11.0;Initial Catalog=WFPersist;Integrated Security=True";

            WorkflowApplicationInstance wfInstance =
                WorkflowApplication.GetInstance(new Guid(txtUpdateInstance.Text), instanceStore);

            DataContractSerializer s = new DataContractSerializer(typeof(DynamicUpdateMap));
            using (FileStream fs = File.Open(txtUpdateMapFile.Text, FileMode.Open))
            {
                updateMap = s.ReadObject(fs) as DynamicUpdateMap;
            }

            var wfApp =
                new WorkflowApplication(new MovieRentalProcess(),
                     new WorkflowIdentity
                     {
                         Name = "v2MovieRentalProcess",
                         Version = new System.Version(2, 0, 0, 0)
                     });

            IList<ActivityBlockingUpdate> act;
            if (wfInstance.CanApplyUpdate(updateMap, out act))
            {
                wfApp.Load(wfInstance, updateMap);
                wfApp.Unload();
            }
        }
    //end
    protected void btnEdit_ServerClick(object sender, EventArgs e)
    {
        if (this.DropDown_sp.SelectedValue.Length == 0)
        {
            MessageBox.Show(this, "请您选择审核结果");
        }
        else
        {
            Model.SelectRecord selectRecords = new Model.SelectRecord("view_DocumentInfo", "", "*", "where id='" + id + "'");
            DataTable dt = BLL.SelectRecord.SelectRecordData(selectRecords).Tables[0];
            //ziyunhx add 2013-8-5 workflow Persistence
            if (dt == null)
            {
                return;
            }
            Model.SelectRecord selectRecord = new Model.SelectRecord("WorkFlow", "", "*", "where id='" + dt.Rows[0]["WorkFlowID"].ToString() + "'");
            DataTable table = BLL.SelectRecord.SelectRecordData(selectRecord).Tables[0];

            string content = File.ReadAllText(System.Web.HttpContext.Current.Request.MapPath("../") + table.Rows[0]["URL"].ToString());

            instance = engineManager.createInstance(content, null, null);
            if (instanceStore == null)
            {
                instanceStore = new SqlWorkflowInstanceStore(SqlHelper.strconn);
                view = instanceStore.Execute(instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));
                instanceStore.DefaultInstanceOwner = view.InstanceOwner;
            }
            instance.InstanceStore = instanceStore;
            Guid guid = new Guid(dt.Rows[0]["FlowInstranceID"].ToString());
            instance.Load(guid);
            //end

            if (this.DropDown_sp.SelectedValue == "true")
            {
                string[] s = dt.Rows[0]["OID"].ToString().Split(new char[] { ',' });
                if (s[s.Length - 1] == "1")
                {
                    Model.SelectRecord selectExecut = new Model.SelectRecord("WorkFlowExecution", "", "*", "where DID='" + id + "' and step ='" + dt.Rows[0]["WStep"].ToString() + "' and UID='"+this.Session["admin"].ToString()+"'");
                    DataTable executdt = BLL.SelectRecord.SelectRecordData(selectExecut).Tables[0];
                    if (executdt.Rows.Count > 0)
                    {
                        MessageBox.ShowAndRedirect(this, "该公文您已审核,请等待其他人审核!", "/document/DocumentList.aspx");
                    }
                    else {
                        Model.SelectRecord selectExecutCount = new Model.SelectRecord("WorkFlowExecution", "", "distinct UID", "where DID='" + id + "' and step ='" + dt.Rows[0]["WStep"].ToString() + "'");
                        DataTable dtcount = BLL.SelectRecord.SelectRecordData(selectExecutCount).Tables[0];

                        string where = "where IsState=2 AND (1=2 ";

                        string[] str = dt.Rows[0]["OID"].ToString().Split(new char[] { ',' });
                        for (int j = 1; j < str.Length-1; j++)
                        {
                            where += "OR OID like '%" + str[j].ToString() + "%' ";
                        }
                        where += ") order by id desc";

                        Model.SelectRecord selectUserCount = new Model.SelectRecord("Users", "", "ID", where);
                        DataTable usercount = BLL.SelectRecord.SelectRecordData(selectUserCount).Tables[0];

                        if (dtcount.Rows.Count + 1 == usercount.Rows.Count)
                        {
                            if (instance.GetBookmarks().Count(p => p.BookmarkName == dt.Rows[0]["value"].ToString()) == 1)
                            {
                                instance.ResumeBookmark(dt.Rows[0]["value"].ToString(), this.DropDown_sp.SelectedValue.ToString());
                            }
                        }

                    }
                }
                else
                {
                    //一旦审批未通过,删除该公文当前流转步骤信息
                    BLL.GeneralMethods.GeneralDelDB("WorkFlowExecution", "where DID ='" + id + "' and step='" + dt.Rows[0]["WStep"].ToString() + "'");
                    if (instance.GetBookmarks().Count(p => p.BookmarkName == dt.Rows[0]["value"].ToString()) == 1)
                    {
                        instance.ResumeBookmark(dt.Rows[0]["value"].ToString(), this.DropDown_sp.SelectedValue.ToString());
                    }
                }

                Model.WorkFlowExecution workexe = new Model.WorkFlowExecution
                {
                    DID = dt.Rows[0]["ID"].ToString(),
                    UID = this.Session["admin"].ToString(),
                    step = dt.Rows[0]["WStep"].ToString(),
                    Remark = this.txtSP.Value.Trim(),
                    Result = "1",
                };

                BLL.WorkFlowExecution.Add(workexe);
            }
            else
            {
                Model.WorkFlowExecution workexe = new Model.WorkFlowExecution
                {
                    DID = dt.Rows[0]["ID"].ToString(),
                    UID = this.Session["admin"].ToString(),
                    step = dt.Rows[0]["WStep"].ToString(),
                    Remark = this.txtSP.Value.Trim(),
                    Result = "2",
                };

                BLL.WorkFlowExecution.Add(workexe);

                if (instance.GetBookmarks().Count(p => p.BookmarkName == dt.Rows[0]["value"].ToString()) == 1)
                {
                    instance.ResumeBookmark(dt.Rows[0]["value"].ToString(), this.DropDown_sp.SelectedValue.ToString());
                }
            }
            UserOperatingManager.InputUserOperating(this.Session["admin"].ToString(), "公文管理", "公文审核" + dt.Rows[0]["Name"].ToString() + "的信息成功");
            MessageBox.ShowAndRedirect(this, "审核公文成功!", "/document/DocumentList.aspx");

            instance.Unload();
        }
    }
Beispiel #6
0
        /// <summary>
        /// Invoked when a web request arrives.
        /// </summary>
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                // bind ourselves to the context
                Context = context;

                // request was for a resource
                if (Request[ResourceQueryKey] != null)
                {
                    // handle it and return, no need to deal with workflow
                    ProcessResourceRequest(Request[ResourceQueryKey]);
                    return;
                }

                // obtain our activity instance
                Activity = CreateActivity();

                // configure application
                WorkflowApplication = Request[InstanceIdQueryKey] == null ? new WorkflowApplication(Activity, GetArguments()) : new WorkflowApplication(Activity);
                WorkflowApplication.Extensions.Add<ITwilioContext>(() => this);
                WorkflowApplication.SynchronizationContext = new SynchronizedSynchronizationContext();
                WorkflowApplication.InstanceStore = CreateInstanceStore();
                WorkflowApplication.Aborted = OnAborted;
                WorkflowApplication.Completed = OnCompleted;
                WorkflowApplication.Idle = OnIdle;
                WorkflowApplication.OnUnhandledException = OnUnhandledException;
                WorkflowApplication.PersistableIdle = OnPersistableIdle;
                WorkflowApplication.Unloaded = OnUnloaded;

                // attempt to resolve current instance id and reload workflow state
                if (Request[InstanceIdQueryKey] != null)
                    WorkflowApplication.Load(Guid.Parse(Request[InstanceIdQueryKey]), Timeout);

                // postback to resume a bookmark
                if (Request[BookmarkQueryKey] != null)
                    WorkflowApplication.ResumeBookmark(Request[BookmarkQueryKey], GetPostData(), Timeout);
                else
                    // begin running the workflow from the start
                    WorkflowApplication.Run(Timeout);

                // throw exception
                if (UnhandledExceptionInfo != null)
                    UnhandledExceptionInfo.Throw();

                // strip off temporary attributes
                foreach (var element in TwilioResponse.DescendantsAndSelf())
                    foreach (var attribute in element.Attributes())
                        if (attribute.Name.Namespace == tmpNs)
                            attribute.Remove();

                // write finished twilio output
                Response.ContentType = "text/xml";
                using (var wrt = XmlWriter.Create(Response.Output))
                    TwilioResponse.WriteTo(wrt);

                // if we've reached the end, no need to force unload
                WorkflowApplication = null;
            }
            finally
            {
                // clean up application if possible
                if (WorkflowApplication != null)
                {
                    try
                    {
                        WorkflowApplication.Unload(Timeout);
                        WorkflowApplication = null;
                    }
                    catch
                    {
                        // ignore
                    }
                }
            }
        }