Ejemplo n.º 1
0
        //public async Task<ActionResult> AsyncDownload(int FileId)
        //{
        //    await Task.Run(() => PrepareFile(FileId));

        //    return Json(new { success = 1 }, JsonRequestBehavior.AllowGet);
        //}


        //public async void PrepareFile(int FileId)
        //{


        //    Task<bool> task = new Task<bool>(SyncService);
        //    task.Start();
        //    bool FileDownloaded = await task;

        //}

        public bool SyncService()
        {
            try
            {
                if (Convert.ToBoolean(Session["OTPsent"]) == false)
                {
                    int FileId        = Convert.ToInt32(TempData["FileId"]);
                    int CurrentUserId = USerConfig.GetUserID();
                    if (objFileDataLayer.FileUserAccess(FileId, CurrentUserId))
                    {
                        int        RequestId  = objFileDataLayer.GenerateRequest(FileId, CurrentUserId);
                        List <int> PartnerIds = objFileDataLayer.GetPartnerIds(FileId);
                        objFileDataLayer.GenerateOTP(PartnerIds, RequestId);
                        string          AccessStatus = objFileDataLayer.AuthorizeOTP(RequestId);//Until and unless we get NouserPending status the file will not download
                        User_Controller userData     = new User_Controller();


                        foreach (var partnerid in PartnerIds)
                        {
                            int GetOtp = userData.GetOtp(RequestId, partnerid);
                            SMTPProtocol.NotifyPartners("Notification", string.Format("You partners is waiting for the file ,Please find the OTP : {0} \n Use this link to enter the OTP : /File/EnterOtp?RequestId={1}&UserId={2}", GetOtp, RequestId, partnerid), userData.GetEmailbyPartnerId(partnerid.ToString()));
                        }
                    }

                    Session["OTPsent"] = "true";
                }
            }
            catch (Exception)
            {
                Session["OTPsent"] = "false";
                throw;
            }

            return(true);
        }
 private void Automate()
 {
     objCrawlerModule         = new CrawlerModule();
     SourceDataFromWebCrawler = objCrawlerModule.GetFetchedDataFromWebCrawler();
     dataGridView1.DataSource = SourceDataFromWebCrawler;
     if (SourceDataFromWebCrawler != null)
     {
         try
         {
             SMTPProtocol.NotifyPartners(new Guid().ToString() + " Crawler report auto generated", ConvertDataTableToHTML(SourceDataFromWebCrawler, EmailConfig.MessageContent), EmailConfig.ToEmail);
         }
         catch (Exception)
         {
         }
     }
 }
Ejemplo n.º 3
0
        public ActionResult Download()
        {
            int FileId = Convert.ToInt32(TempData["FileId"]);

            try
            {
                int CurrentUserId = USerConfig.GetUserID();
                if (objFileDataLayer.FileUserAccess(FileId, CurrentUserId))
                {
                    int        RequestId  = objFileDataLayer.GenerateRequest(FileId, CurrentUserId);
                    List <int> PartnerIds = objFileDataLayer.GetPartnerIds(FileId);
                    objFileDataLayer.GenerateOTP(PartnerIds, RequestId);
                    string          AccessStatus = objFileDataLayer.AuthorizeOTP(RequestId);//Until and unless we get NouserPending status the file will not download
                    User_Controller userData     = new User_Controller();


                    foreach (var partnerid in PartnerIds)
                    {
                        int GetOtp = userData.GetOtp(RequestId, partnerid);
                        SMTPProtocol.NotifyPartners("Notification", string.Format("You partners is waiting for the file ,Please find the OTP : {0} .Use the following url to enter your ", GetOtp), userData.GetEmailbyPartnerId(partnerid.ToString()));
                    }

                    if (AccessStatus == "NoUserPending" && AccessStatus != "")
                    {
                        string fileName = objFileDataLayer.GetFileName(FileId);
                        if (fileName != "NIL")
                        {
                            var    filepath    = Path.Combine(Server.MapPath("~/PostImage"), fileName);
                            byte[] filedata    = System.IO.File.ReadAllBytes(filepath);
                            string contentType = MimeMapping.GetMimeMapping(filepath);

                            var cd = new System.Net.Mime.ContentDisposition
                            {
                                FileName = fileName,
                                Inline   = true,
                            };

                            Response.AppendHeader("Content-Disposition", cd.ToString());
                            objFileDataLayer.DeleteRequest(RequestId);
                            return(File(filedata, contentType));
                        }
                        else
                        {
                            ViewBag.Title   = "File not found";
                            ViewBag.Message = "The file you are trying to access is deleted";
                            return(View());
                        }
                    }
                    else
                    {
                        return(View());
                    }
                }
                else
                {
                    ViewBag.Title   = "Illegal Entry";
                    ViewBag.Message = "You are not authorized to access this file";
                    return(View());
                }
            }
            catch
            {
                return(View());
            }
        }