Example #1
0
        public void FTPEligFile(string _file)
        {
            string        _uri;
            int           contentLen, buffLength;
            Impersonation _imp = new Impersonation();
            Page          page = HttpContext.Current.Handler as Page;
            FtpWebRequest reqFTP;
            FileInfo      fileInf;
            FileStream    fs;
            Stream        strm;


            if (_imp.impersonateValidUser(HttpContext.Current.Session["uid"].ToString(), "CORP", EncryptDecrypt.Decrypt(HttpContext.Current.Session["pwd"].ToString())))
            {
                if (!File.Exists(_file))
                {
                    throw new Exception("Problem in PGP of file");
                }

                fileInf = new FileInfo(_file);
                _uri    = "ftp://ftp.datamgmt.mercerhrs.com/fa00760.in.pgp";

                reqFTP               = (FtpWebRequest)FtpWebRequest.Create(new Uri(_uri));
                reqFTP.Credentials   = new NetworkCredential("Blackftp", "N0v2oo4");
                reqFTP.Proxy         = null;
                reqFTP.KeepAlive     = false;
                reqFTP.Method        = WebRequestMethods.Ftp.UploadFile;
                reqFTP.UseBinary     = true;
                reqFTP.ContentLength = fileInf.Length;

                buffLength = 2048;
                byte[] buff = new byte[buffLength];
                fs         = fileInf.OpenRead();
                strm       = reqFTP.GetRequestStream();
                contentLen = fs.Read(buff, 0, buffLength);

                while (contentLen != 0)
                {
                    strm.Write(buff, 0, contentLen);
                    contentLen = fs.Read(buff, 0, buffLength);
                }
                strm.Close();
                fs.Close();

                _imp.undoImpersonation();

                if (!page.ClientScript.IsClientScriptBlockRegistered("OpenWindow"))
                {
                    page.ClientScript.RegisterClientScriptBlock(typeof(Page), "OpenWindow", "window.open('ftp://*****:*****@ftp.datamgmt.mercerhrs.com/');", true);
                }
            }
            else
            {
                throw new Exception("Error in accessing network location");
            }
        }
Example #2
0
 public string Get(string endpoint)
 {
     if (!Impersonation.impersonateValidUser(UserId, UserDirectory, UserPassword))
     {
         throw new ArgumentException("L'utilisateur indiqué n'est pas valide.\n Vérifier user/mdp.\n", "Utilisateur - mot de passe");
     }
     else
     {
         //System.Windows.Forms.MessageBox.Show("10- GET\n_userDirectory = " + _userDirectory + "\n_userId=" + _userId + "\nEnvironment.UserDomainName=" + Environment.UserDomainName + "\nEnvironment.UserName=" + Environment.UserName);
         ValidateConfiguration();
         Encoding = Encoding.UTF8;
         var retour = DownloadString(new Uri(Uri, endpoint));
         Impersonation.undoImpersonation();
         return(retour);
     }
 }
Example #3
0
 public string Put(string endpoint, string body)
 {
     if (!Impersonation.impersonateValidUser(UserId, UserDirectory, UserPassword))
     {
         throw new ArgumentException("L'utilisateur indiqué n'est pas valide.\n Vérifier user/mdp.\n", "Utilisateur - mot de passe");
     }
     else
     {
         ValidateConfiguration();
         if (_cookieJar.Count == 0)
         {
             CollectCookie();
         }
         var retour = UploadString(new Uri(Uri, endpoint), "PUT", body);
         Impersonation.undoImpersonation();
         return(retour);
     }
 }
Example #4
0
 public string Delete(string endpoint)
 {
     if (!Impersonation.impersonateValidUser(UserId, UserDirectory, UserPassword))
     {
         throw new ArgumentException("L'utilisateur indiqué n'est pas valide.\n Vérifier user/mdp.\n", "Utilisateur - mot de passe");
     }
     else
     {
         ValidateConfiguration();
         if (_cookieJar.Count == 0) // && !endpoint.ToUpper().Contains("QPS"))
         {
             CollectCookie();
         }
         var retour = UploadString(new Uri(Uri, endpoint), "DELETE", "");
         Impersonation.undoImpersonation();
         return(retour);
     }
 }
Example #5
0
 public void Test2()
 {
     if (Impersonation.impersonateValidUser(UserId, UserDirectory, UserPassword))
     {
         var client = new WebClient();
         //client.UseDefaultCredentials = false;
         var urlBuilder = new UriBuilder(Uri.OriginalString);
         urlBuilder.Scheme = Uri.UriSchemeHttp;
         urlBuilder.Port   = -1;
         var url = new Uri(urlBuilder.Uri.OriginalString);
         client.UseDefaultCredentials = true;
         client.Credentials           = new System.Net.NetworkCredential(UserId, UserPassword, UserDirectory);
         client.Headers.Add("User-Agent", "Windows");
         var dummyResponse = client.DownloadString(url + "/hub"); // Used to collect cookie
         client.Headers.Add("Cookie", client.ResponseHeaders[HttpResponseHeader.SetCookie]);
         var theUser = client.DownloadString(url + "/qps/user");
         Console.WriteLine(theUser);
     }
     Impersonation.undoImpersonation();
 }
    protected void btn_autoImport_Click(object sender, EventArgs e)
    {
        HRASofoDAL    robj = new HRASofoDAL();
        Impersonation _imp = new Impersonation();
        string        yrmo = ddlYrmo1.SelectedItem.Text;
        string        clientfilename, clientfile, serverPath;
        string        serverfile = "";

        div1_error.Visible = false;
        div1_alert.Visible = false;

        if (Page.IsValid)
        {
            if (txtPrevYRMO1.Visible)
            {
                lbl_error1.Text = "Enter YRMO in format 'yyyymm'";
                return;
            }

            try
            {
                serverPath     = Server.MapPath("~/uploads/");
                clientfilename = HRA.GetInputFileName(yrmo, source);
                serverfile     = serverPath + clientfilename;

                if (_imp.impersonateValidUser(Session["uid"].ToString(), "CORP", EncryptDecrypt.Decrypt(Session["pwd"].ToString())))
                {
                    clientfile = HRAImportDAL.GetClientFilePath(_category, source) + "\\" + clientfilename;
                    File.Copy(clientfile, serverfile);
                    _imp.undoImpersonation();
                }
                else
                {
                    throw new Exception("Error in accessing network location");
                }

                if (!(File.Exists(serverfile)))
                {
                    throw new Exception("Unable to import file from specified location.<br/>Please check if file exists and you are logged in to the network.");
                }

                AutoReconcile(serverfile);
                HRA_Results.SavePrintFiles(_category, yrmo);
                viewresult1(yrmo);
                Session["taskId"] = Convert.ToInt32(Session["taskId"]) + 1;
                Audit.auditUserTaskR(Session.SessionID, Session["mid"].ToString(), Session["taskId"].ToString(), "HRA", "Reconciliation", "SOFO Reconciliation", yrmo);
            }
            catch (Exception ex)
            {
                MultiView3.SetActiveView(view_main1);
                robj.ReconDelete(yrmo);
                div1_error.Visible = true;
                lbl_error1.Text    = "Error - " + ex.Message;
            }
            finally
            {
                if (File.Exists(serverfile))
                {
                    File.Delete(serverfile);
                }
            }
        }
    }
Example #7
0
    protected void btn_autoImport_Click(object sender, EventArgs e)
    {
        HRAImportDAL  iobj = new HRAImportDAL();
        Impersonation _imp = new Impersonation();
        string        yrmo = ddlYrmo.SelectedItem.Text;
        string        clientfilename, clientfile, serverPath;
        string        serverfile = "";

        lbl_error.Text = "";
        string logFilePath = Server.MapPath("~/uploads/") + "Exceptions_PutnamAdj_" + yrmo + ".txt";

        if (Page.IsValid)
        {
            if (txtPrevYRMO.Visible)
            {
                lbl_error.Text = "Enter YRMO in format 'yyyymm'";
                return;
            }

            try
            {
                serverPath     = FilePaths.getFilePath("Uploads").Replace("\\\\", "\\");
                clientfilename = HRA.GetInputFileName(yrmo, source);
                serverfile     = serverPath + clientfilename;

                if (_imp.impersonateValidUser(Session["uid"].ToString(), "CORP", EncryptDecrypt.Decrypt(Session["pwd"].ToString())))
                {
                    clientfile = HRAImportDAL.GetClientFilePath(_category, source) + "\\" + clientfilename;
                    if (!File.Exists(clientfile))
                    {
                        clientfile = clientfile.Replace(".xls", ".txt");
                        serverfile = serverfile.Replace(".xls", ".txt");
                    }
                    File.Copy(clientfile, serverfile);
                    _imp.undoImpersonation();
                }
                else
                {
                    throw new Exception("Error in accessing network location");
                }

                if (!(File.Exists(serverfile)))
                {
                    throw new Exception("Unable to import file from specified location.<br/>Please check if file exists and you are logged in to the network.");
                }

                if (ImportFile(serverfile))
                {
                    MultiView1.SetActiveView(view_result);
                    lbl_result.Text = "Import completed successfully -- " + _counter + " records imported";
                }
                else
                {
                    throw new Exception("Unable to parse file.<br/>Please check file type and format.");
                }
            }
            catch (Exception ex)
            {
                if (File.Exists(logFilePath))
                {
                    File.Delete(logFilePath);
                }
                resultDiv.Visible = false;
                iobj.Rollback(source, yrmo);
                lbl_error.Text = "Error - " + ex.Message;
            }
            finally
            {
                if (File.Exists(serverfile))
                {
                    File.Delete(serverfile);
                }
            }
        }
    }
Example #8
0
        public static bool CopyFolder(string from, string to, DateTime logTime, string name ,EnumsBackupType backuptype,   long Schedule_DetailId ,string SourceUserId , string sourceUserPassword, string sourceuserdomain, string TargetUserid, string TargetUserPassword, string targetuserdomain)
        {
            var imporsonate = new Impersonation(targetuserdomain, TargetUserid, TargetUserPassword.Trim());

            try
            {
                using (imporsonate)

                {
                    Log.Begin(name + ": Backup started ...", Schedule_DetailId);

                    if (!Directory.Exists(from))
                    {
                        imporsonate.undoImpersonation();
                        Log.Error(name + ": Source Folder does not exist or access denied to " + from, Schedule_DetailId);
                        throw new Exception("Source Folder does not exist or access denied to " + from);
                    }

                    if ((backuptype == EnumsBackupType.Incremental_Backup))
                    {
                        if (!Directory.Exists(to))
                            Directory.CreateDirectory(to);

                        to = to + "\\" + name + "-" + logTime.ToString("MM-dd-yyyy");

                        Directory.CreateDirectory(to);

                    }
                    else if (!Directory.Exists(to))
                    {
                        Directory.CreateDirectory(to);
                    }

                    string[] directories = Directory.GetDirectories(from, "*.*", SearchOption.AllDirectories);

                    Parallel.ForEach(directories, dirPath =>
                    {
                        try
                        {
                            Directory.CreateDirectory(dirPath.Replace(from, to));
                        }
                        catch (Exception ex)
                        {

                            Log.Error(name + ": " + ex.Message, Schedule_DetailId);
                        }
                    });

                    string[] files = Directory.GetFiles(from, "*.*", SearchOption.AllDirectories);

                    Parallel.ForEach(files, filePath =>
                    {
                        try
                        {
                            //Replace File.Copy to FileStream to prevent source file lock
                            //File.Copy(filePath, filePath.Replace(from, to));

                            using (FileStream source = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                            {
                                using (FileStream dest = new FileStream(filePath.Replace(from, to), FileMode.Create, FileAccess.ReadWrite))
                                {
                                    source.CopyTo(dest);
                                }
                            }
                        }
                        catch (Exception ex)
                        {

                            Log.Error(name + ": " + ex.Message, Schedule_DetailId);

                        }
                    });

                    Log.End(name + ":  Backup completed successfully", Schedule_DetailId);
                    imporsonate.undoImpersonation();
                    return true;
                }
                //else
                //{
                //    Log.Error(name + ": Target User not authenticated " ,  Schedule_DetailId);
                //    return false; }

            }
            catch (Exception ex)
            {
                Log.Error(name + ": " + ex.Message, Schedule_DetailId);
                Log.End  (name + ":  Backup completed with errors", Schedule_DetailId);
                imporsonate.undoImpersonation();
                return false;
            }
        }
Example #9
0
    protected void btn_autoImport_Click(object sender, EventArgs e)
    {
        HRAAdminBill  hobj = new HRAAdminBill();
        Impersonation _imp = new Impersonation();
        HRAImportDAL  iobj = new HRAImportDAL();
        string        yrmo = ddlYrmo.SelectedItem.Text;
        string        clientfilename, clientfile, serverPath;
        string        serverfile = "";

        lbl_error.Text = "";
        string logFilePath = Server.MapPath("~/uploads/") + "Exceptions_WageworksInvoice_" + yrmo + ".txt";

        if (Page.IsValid)
        {
            if (txtPrevYRMO.Visible)
            {
                lbl_error.Text = "Enter YRMO in format 'yyyymm'";
                return;
            }

            try
            {
                serverPath     = FilePaths.getFilePath("Uploads").Replace("\\\\", "\\");
                clientfilename = HRA.GetInputFileName(yrmo, source);
                serverfile     = serverPath + clientfilename;

                if (_imp.impersonateValidUser(Session["uid"].ToString(), "CORP", EncryptDecrypt.Decrypt(Session["pwd"].ToString())))
                {
                    clientfile = HRAImportDAL.GetClientFilePath(_category, source) + "\\" + clientfilename;
                    File.Copy(clientfile, serverfile);
                    _imp.undoImpersonation();
                }
                else
                {
                    throw new Exception("Error in accessing network location");
                }

                if (!(File.Exists(serverfile)))
                {
                    throw new Exception("Unable to copy file from specified location.<br/>Please check if file exists and you are logged in to the network.");
                }

                if (File.Exists(logFilePath))
                {
                    File.Delete(logFilePath);
                }

                iobj.Rollback(source, yrmo);
                _counter = hobj.ImportWgwkInvoice(serverfile, source, yrmo);

                if (File.Exists(logFilePath))
                {
                    resultDiv.Visible = true;
                }

                Session["taskId"] = Convert.ToInt32(Session["taskId"]) + 1;
                Audit.auditUserTaskI(Session.SessionID, Session["mid"].ToString(), Session["taskId"].ToString(), "HRA", "Administrative Bill Validation", "hra_PartDataInvoice", "Wageworks Invoice Import", yrmo, _counter);
                MultiView1.SetActiveView(view_result);
                lbl_result.Text = "Import completed successfully -- " + _counter + " records imported";
            }
            catch (Exception ex)
            {
                if (File.Exists(logFilePath))
                {
                    File.Delete(logFilePath);
                }
                resultDiv.Visible = false;
                iobj.Rollback(source, yrmo);
                lbl_error.Text = "Error - " + ex.Message;
            }
            finally
            {
                if (File.Exists(serverfile))
                {
                    File.Delete(serverfile);
                }
            }
        }
    }
    protected void btn_autoImport_Click(object sender, EventArgs e)
    {
        Impersonation _imp = new Impersonation();
        string        yrmo = ddlYrmo.SelectedItem.Text;
        string        clientfilename1, clientfilename2, clientfilename3, clientfilename4, clientfilename5;
        string        clientfile1, clientfile2, clientfile3, clientfile4, clientfile5;
        string        serverfile1, serverfile2, serverfile3, serverfile4, serverfile5;
        List <string> filepaths = new List <string>();
        List <string> sources   = new List <string>();
        string        wiredt    = tbx_autoWiredt.Text;

        ErrMsgDiv1.Visible = false;
        ErrMsgDiv2.Visible = false;

        if (Page.IsValid)
        {
            if (txtPrevYRMO.Visible)
            {
                lbl_error1.Text = "Enter YRMO in format 'yyyymm'";
                return;
            }

            serverfile1 = "";
            serverfile2 = "";
            serverfile3 = "";
            serverfile4 = "";
            serverfile5 = "";

            try
            {
                clientfilename1 = VWA.GetInputFileName(yrmo, source_OC);
                clientfilename2 = VWA.GetInputFileName(yrmo, source_Cigna);
                clientfilename3 = VWA.GetInputFileName(yrmo, source_UHC);
                clientfilename4 = VWA.GetInputFileName(yrmo, source_Disab);
                clientfilename5 = VWA.GetInputFileName(yrmo, source_Anth);

                serverfile1 = Server.MapPath("~/uploads/") + clientfilename1;
                serverfile2 = Server.MapPath("~/uploads/") + clientfilename2;
                serverfile3 = Server.MapPath("~/uploads/") + clientfilename3;
                serverfile4 = Server.MapPath("~/uploads/") + clientfilename4;
                serverfile5 = Server.MapPath("~/uploads/") + clientfilename5;

                if (_imp.impersonateValidUser(Session["uid"].ToString(), "CORP", EncryptDecrypt.Decrypt(Session["pwd"].ToString())))
                {
                    clientfile1 = VWAImportDAL.GetClientFilePath(_category, source) + "\\" + clientfilename1;
                    clientfile2 = VWAImportDAL.GetClientFilePath(_category, source) + "\\" + clientfilename2;
                    clientfile3 = VWAImportDAL.GetClientFilePath(_category, source) + "\\" + clientfilename3;
                    clientfile4 = VWAImportDAL.GetClientFilePath(_category, source) + "\\" + clientfilename4;
                    clientfile5 = VWAImportDAL.GetClientFilePath(_category, source) + "\\" + clientfilename5;

                    if (File.Exists(clientfile1) || File.Exists(clientfile2) || File.Exists(clientfile3) || File.Exists(clientfile4) || File.Exists(clientfile5) || wiredt != String.Empty)
                    {
                        if (File.Exists(clientfile1))
                        {
                            File.Copy(clientfile1, serverfile1);
                            filepaths.Add(serverfile1);
                            sources.Add(source_OC);
                        }
                        if (File.Exists(clientfile2))
                        {
                            File.Copy(clientfile2, serverfile2);
                            filepaths.Add(serverfile2);
                            sources.Add(source_Cigna);
                        }
                        if (File.Exists(clientfile3))
                        {
                            File.Copy(clientfile3, serverfile3);
                            filepaths.Add(serverfile3);
                            sources.Add(source_UHC);
                        }
                        if (File.Exists(clientfile4))
                        {
                            File.Copy(clientfile4, serverfile4);
                            filepaths.Add(serverfile4);
                            sources.Add(source_Disab);
                        }
                        if (File.Exists(clientfile5))
                        {
                            File.Copy(clientfile5, serverfile5);
                            filepaths.Add(serverfile5);
                            sources.Add(source_Anth);
                        }

                        _imp.undoImpersonation();
                    }
                    else
                    {
                        throw new Exception("Error in accessing network location");
                    }

                    if (ImportFile(filepaths, sources, wiredt))
                    {
                        View_Result();
                    }
                    else
                    {
                        throw new Exception("Unable to parse reports.<br/>Please check reports type and format.");
                    }
                }
            }
            catch (Exception ex)
            {
                resultdiv.Visible = false;
                VWAImportDAL.DeleteRemit(yrmo);
                ErrMsgDiv1.Visible = true;
                lbl_error1.Text    = "Error - " + ex.Message;
            }
            finally
            {
                if (File.Exists(serverfile1))
                {
                    File.Delete(serverfile1);
                }
                ;
                if (File.Exists(serverfile2))
                {
                    File.Delete(serverfile2);
                }
                ;
                if (File.Exists(serverfile3))
                {
                    File.Delete(serverfile3);
                }
                ;
                if (File.Exists(serverfile4))
                {
                    File.Delete(serverfile4);
                }
                ;
                if (File.Exists(serverfile5))
                {
                    File.Delete(serverfile5);
                }
                ;
            }
        }
    }