Exemplo n.º 1
0
        public virtual object Start(HttpContext context)
        {
            YZRequest request        = new YZRequest(context);
            Guid      draftid        = request.GetGuid("draftid", false);
            string    memberfullname = request.GetString("memberfullname");
            string    uid            = request.GetString("uid");

            using (BPMConnection cn = new BPMConnection())
            {
                string orguid = YZAuthHelper.LoginUserAccount;
                YZAuthHelper.SetAuthCookie(uid);
                try
                {
                    cn.WebOpen();
                }
                finally
                {
                    YZAuthHelper.SetAuthCookie(orguid);
                }

                BPMDraft draft = new BPMDraft();
                draft.Open(cn, draftid);

                JObject jDraftHeader = null;
                if (!String.IsNullOrEmpty(draft.Header))
                {
                    jDraftHeader = JObject.Parse(draft.Header);
                }

                PostInfo postInfo = BPMProcess.GetPostInfo(cn, draft.ProcessName, null, memberfullname, -1);
                if (postInfo.Links.Count == 0)
                {
                    throw new BPMException(BPMExceptionType.MissOutLink, postInfo.NodeName);
                }

                string postXml = @"{0}
                    <XForm>
                        <Header>
                            <Method>Post</Method>
                            <ProcessName>{1}</ProcessName>
                            <OwnerMemberFullName>{2}</OwnerMemberFullName>
                            <Action>{3}</Action>
                            <Comment>{4}</Comment>
                            {5}
                        </Header>
                        {6}
                    </XForm>";

                StringBuilder sb = new StringBuilder();
                if (jDraftHeader != null)
                {
                    foreach (KeyValuePair <string, JToken> jProp in jDraftHeader)
                    {
                        string line = String.Format("<{0}>{1}</{0}>", jProp.Key, YZUtility.EncodeXMLInnerText(jProp.Value.ToString()));
                        sb.AppendLine(line);
                    }
                }

                postXml = String.Format(postXml,
                                        "<?xml version=\"1.0\"?>",
                                        YZUtility.EncodeXMLInnerText(draft.ProcessName),
                                        YZUtility.EncodeXMLInnerText(memberfullname),
                                        YZUtility.EncodeXMLInnerText(postInfo.Links[0].DisplayString),
                                        YZUtility.EncodeXMLInnerText(draft.Comments),
                                        sb.ToString(),
                                        draft.xml);

                using (MemoryStream postStream = new MemoryStream(Encoding.UTF8.GetBytes(postXml)))
                {
                    PostResult postResult = BPMProcess.Post(cn, postStream);

                    return(new
                    {
                        success = true,
                        TaskID = postResult.TaskID,
                        SN = postResult.SN
                    });
                }
            }
        }