예제 #1
0
        private void btSubmit_Click(object sender, EventArgs e)
        {
            CreateDocumentLibrary(tbDocLib.Text);
            tbResult.Text = ">>Start process.\r\n";
            bool isconnect = false;// CheckConnection();

            using (SourceEntities db = new SourceEntities())
            {
                int             limit = int.Parse(tbLimit.Text);
                List <UPLOADER> list  = db.UPLOADERs.Where(item => item.PROCESS_FLAG == true && item.FILEPATH != null && item.FILEPATH != "").Take(limit).ToList();
                tbResult.Text += string.Format("Total valid records for processing: {0}\r\n", list.Count);
                //for (int i = 0; i < list.Count; i++)
                //{
                //    tbResult.Text += string.Format("DocID: {0}, success\r\n", list[i].DOCID);
                //}

                foreach (UPLOADER file in list)
                {
                    string result  = UploadDocuments(file.FILEPATH);
                    bool   success = false;
                    if (result.StartsWith("https"))
                    {
                        file.PROCESS_FLAG  = false;
                        file.PROCESSEDTIME = DateTime.Now;
                        file.RESULT        = "OK";
                        file.UPLOADEDURL   = result;
                        tbResult.Text     += string.Format("DocID: {0}, success\r\n", file.DOCID);
                        success            = true;
                    }
                    else
                    {
                        file.RESULT       = "ERROR";
                        file.ERRORMESSAGE = result;
                        tbResult.Text    += string.Format("DocID: {0}, fail, {1}\r\n", file.DOCID, result);
                    }
                    db.SaveChanges();
                    if (success && isconnect)
                    {
                        using (DestinationEntities db2 = new DestinationEntities())
                        {
                            T_STG_DOC doc = db2.T_STG_DOC.FirstOrDefault(item => item.DocID == file.DOCID);
                            if (doc != null)
                            {
                                doc.DOCURL              = file.UPLOADEDURL;
                                file.ISUPDATEDSTAGING   = true;
                                file.STAGINGUPDATEDTIME = DateTime.Now;
                            }
                            else
                            {
                                file.ERRORMESSAGE = "cannot find record to update";
                            }
                            db.SaveChanges();
                            db2.SaveChanges();
                        }
                    }
                }
            }
            tbResult.Text += ">>Finish process.\n";
        }
예제 #2
0
 public bool CheckConnection()
 {
     try
     {
         using (DestinationEntities db2 = new DestinationEntities())
         {
             T_STG_DOC doc = db2.T_STG_DOC.FirstOrDefault(item => item.DocID == "");
         }
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }