protected void btnProcess_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                var reader   = new StreamReader(FileUpload1.FileContent);
                var document = reader.ReadToEnd();
                reader.Close();
                string fileName = tbFileName.Text;
                bool   success  = gen.saveDocument(document, path, fileName, fileName);
                if (success)
                {
                    int batchSize     = 1000;
                    var isCustomBatch = int.TryParse(tbBatchSize.Text, out batchSize);
                    if (isCustomBatch)
                    {
                        lblBatchSize.Text = string.Format("Batch Size {0}", batchSize);
                    }
                    var docList = gen.splitDocument(document, batchSize, true);

                    // update dictionary entry
                    MasterDictionary.UpdateEntry(fileName, true, 0);

                    int docCount = 1;
                    foreach (var doc in docList)
                    {
                        var name = fileName + "_" + docCount.ToString();
                        gen.saveDocument(doc, path, fileName, name);
                        docCount++;
                    }

                    lblProcess.ForeColor = System.Drawing.Color.Green;
                    lblProcess.Text      = "Done: Sucess!";
                }

                else
                {
                    lblFileUpload.ForeColor = System.Drawing.Color.Red;
                    lblFileUpload.Text      = "Upload Failed: File not stored to server";
                }
            }
            else
            {
                lblFileUpload.ForeColor = System.Drawing.Color.Red;
                lblFileUpload.Text      = "Upload Failed: File not found";
            }
        }
Esempio n. 2
0
        protected async void btnProcess_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                var reader   = new StreamReader(FileUpload1.FileContent);
                var document = reader.ReadToEnd();
                reader.Close();
                string fileName = tbFileName.Text;
                bool   success  = gen.saveDocument(document, path, fileName, fileName);
                if (success)
                {
                    int batchSize     = 1000;
                    var isCustomBatch = int.TryParse(tbBatchSize.Text, out batchSize);
                    if (isCustomBatch)
                    {
                        lblBatchSize.Text = string.Format("Batch Size {0}", batchSize);
                    }
                    var docList = gen.splitDocument(document, batchSize, true);

                    int docCount = 1;
                    List <BatchManager.BatchResult> results = null;
                    foreach (var doc in docList)
                    {
                        var batch = new BatchData();
                        batch.Id = docCount;
                        var name = fileName + "_" + docCount.ToString();
                        batch.Key          = name;
                        batch.Data         = doc.Replace("\r", "");
                        batch.LastComplete = 0;
                        batch.isAvail      = true;
                        gen.saveDocument(doc, path, fileName, name);
                        docCount++;
                        results = await BatchManager.Instance.Add(batch);
                    }

                    if (!results.Contains(BatchManager.BatchResult.Success))
                    {
                        foreach (var result in results)
                        {
                            logger.Log(typeof(Admin), null, null, result);
                        }
                    }

                    BatchManager.Instance.SetTotal(docCount);

                    lblProcess.ForeColor = System.Drawing.Color.Green;
                    lblProcess.Text      = "Done: Sucess!";
                }

                else
                {
                    lblFileUpload.ForeColor = System.Drawing.Color.Red;
                    lblFileUpload.Text      = "Upload Failed: File Already Exists";
                }
            }
            else
            {
                lblFileUpload.ForeColor = System.Drawing.Color.Red;
                lblFileUpload.Text      = "Upload Failed: File not found";
            }
        }