c#-如何通过c#程序在Web应用程序上调用/链接工作流?

时间:2018-11-09 03:10:29

标签: c#

我有一个C#(WinForms)应用程序,可以通过打印机扫描文档。扫描后,我将能够在其上输入文档详细信息,并有一个按钮来确定文档。文档详细信息和信息将存储在我的数据库ABC中的某些表中。

现在,我有另一个用Java(IntelliJ)编写的Web应用程序,该应用程序具有一些按钮功能,可以上传文档,然后启动工作流并将其路由到另一个用户以批准文档。我不会详细介绍细节。该应用程序还连接到相同的数据库ABC。

因此,现在更困难的部分是,我需要以最终确定文档的方式链接这两个应用程序 在C#应用程序上,它必须在Web应用程序端自动触发工作流程。它只是调用或触发工作流,而不是在Web应用程序上手动启动工作流,因此我完全不需要访问Web应用程序即可启动该过程。

 private void FinButton_Click(object sender, EventArgs e)
        {


            int count = 0;
            var txtBoxFields = new List<TextBox>
            {
                textBox1,
                textBox2,
                textBox3,
                textBox4,
                textBox5,
                textBox6,
                textBox7,
                textBox8,
                textBox9,
                textBox10,
                textBox11,
                textBox12,
                textBox13,
                textBox14,
                textBox15
            };

            var templateFields = new List<String>
            {
                "T1",
                "T2",
                "T3",
                "T4",
                "T5",
                "T6",
                "T7",
                "T8",
                "T9",
                "T10",
                "T11",
                "T12",
                "T13",
                "T14",
                "T15"
            };

            //long tid = 0;

            //Start insert query into templatebatch table in db
            var dbConnection2 = DBConnection.Instance();
            dbConnection2.DatabaseName = ConfigurationManager.AppSettings["dbName"];
            if (dbConnection2.IsConnect())
            {
                bool test = true;

                for (int i = 1; i <= 15; i++)
                {
                    var input = txtBoxFields[i - 1].Text;
                    var insertQuery = "INSERT INTO templateinfo(TID, THEADER, " + templateFields[i - 1] + ") VALUES(@tid, @theader,@t" + i + ")";
                    var insertCmd = new MySqlCommand(insertQuery, dbConnection2.Connection);
                    insertCmd.Parameters.AddWithValue("@tid", tid);
                    insertCmd.Parameters.AddWithValue("@theader", "N");


                    if (String.IsNullOrEmpty(input))
                    {
                        count = 1;
                        insertCmd.Parameters.AddWithValue("@t" + i, String.Empty);
                        break;
                    }
                    else
                    {
                        if (test)
                        {
                            insertCmd.Parameters.AddWithValue("@t" + i, txtBoxFields[i - 1].Text);
                            insertCmd.ExecuteNonQuery();
                            test = false;

                            var selectQuery = "select TINFOID from templateinfo where TID=" + tid + " and THEADER = 'N'";
                            var selectCmd = new MySqlCommand(selectQuery, dbConnection2.Connection);
                            var selectReader = selectCmd.ExecuteReader();

                            using (MySqlDataReader dr = selectReader)
                            {
                                while (dr.Read())
                                {
                                    tinfoid = Convert.ToInt32(dr["TINFOID"]);
                                }
                            }
                        }
                        else
                        {
                            var updateQuery = "update templateinfo set " + templateFields[i - 1] + "='" + txtBoxFields[i - 1].Text + "' where TINFOID = '" + tinfoid + "' and TID=" + tid + " and THEADER='N'";
                            var updateCmd = new MySqlCommand(updateQuery, dbConnection2.Connection);
                            var updateReader = updateCmd.ExecuteReader();
                            using (var reader = updateReader)
                            {

                            }
                        }
                    }
                }


            }


            if (count == 1)
            {
                //MessageBox.Show("Input field(s) cannot be left empty.");
            }

            //Finalize here
            var client = new LTATImagingServiceClient();
            client.Finalize(userID, tid, tinfoid, batchID);

            Debug.WriteLine(userID + ", " + tid + ", " + tinfoid + ", " + batchID);

            var batchName = templateView.SelectedNode.Text;

            var folderPath = @"C:\temp\batches\" + mastertemplatename + @"\" + subtemplatename + @"\" + batchName + @"\";


            ThumbnailLists.Items.Clear();
          //  var img = Image.FromFile(@"C:\temp\batch-done.png");

            if (ImageBox.Image != null)
            {
                ImageBox.Image.Dispose();
            }

            ImageBox.Image = null;

            try
            {
                using (new Impersonation(_remoteDomain, _remoteUser, _remotePassword))
                {
                  //  MessageBox.Show(_remoteUser);
                  //  MessageBox.Show(_remotePassword);
                    var tPath = @"\\126.32.3.178\PantonSys\SAM\Storage\3\" + mastertemplatename + @"\" + subtemplatename + @"\" + batchName + @"\";
                    bool exists = System.IO.Directory.Exists(tPath);

                    if (!exists)
                    {
                        System.IO.Directory.CreateDirectory(tPath);
                    }

                    string[] fileList = Directory.GetFiles(folderPath, "*");
                    foreach (var file in fileList)
                    {
                        File.Copy(file, tPath + Path.GetFileName(file));
                    }

                    CurrentPageBox.Text = "";
                    NumberPageBox.Text = "";
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                MessageBox.Show(ex.Message);
            }

            var dbConnection = DBConnection.Instance();
            dbConnection.DatabaseName = ConfigurationManager.AppSettings["dbName"];

            if (dbConnection.IsConnect())
            {
                var deleteBatchQuery = "DELETE FROM templatebatch WHERE batchname ='" + templateView.SelectedNode.Text + "'";
                var deleteBatchCmd = new MySqlCommand(deleteBatchQuery, dbConnection.Connection);
                var deleteBatchReader = deleteBatchCmd.ExecuteReader();
                using (var reader = deleteBatchReader)
                {
                    while (reader.Read())
                    {

                    }
                }

                templateView.Nodes.Remove(templateView.SelectedNode);
                Directory.Delete(folderPath, true);
                MessageBox.Show("Successfully Transferred.");

                foreach (var txtFields in txtBoxFields)
                {
                    txtFields.Text = "";
                    txtFields.Enabled = false;
                }

                finButton.Visible = false;
                finButton.Enabled = false;

            }

            bindButton.Visible = false;

        }

这是否有可能实现或牵强? 我对此表示任何建议或指点。让我知道我的解释中是否有任何不清楚的地方。

编辑:

Request URL: http://126.32.3.178:8111/process/taskmanager/start/start.jsp
Request Method: POST
Status Code: 200 OK
Remote Address: 126.32.3.178:8111
Referrer Policy: no-referrer-when-downgrade

有没有一种方法可以从C#应用程序中调用它?

1 个答案:

答案 0 :(得分:1)

您可以使用Http client直接从C#应用程序发送文件。这是代码示例:

private async Task<bool> Upload(string filePath)
{
    const string actionUrl = @"http://126.32.3.178:8111/process/taskmanager/start/start.jsp";
    var fileName = Path.GetFileName(filePath);

    var fileBytes = File.ReadAllBytes(filePath);
    var fileContent = new ByteArrayContent(fileBytes);

    using (var client = new HttpClient())
    using (var formData = new MultipartFormDataContent())
    {
        formData.Add(fileContent, fileName);
        var response = await client.PostAsync(actionUrl, formData);
        return response.IsSuccessStatusCode;
    }
}

另外,请注意,在发布请求之前,可能应该执行某种身份验证。