Esempio n. 1
0
        /// <summary>
        /// Returns the
        /// </summary>
        /// <param name="filePathway"></param>
        /// <returns></returns>
        private static byte[] ReturnFileBytes(string filePathway)
        {
            FileStream fs = File.OpenRead(filePathway);

            byte[] data = FileReport.ReadFully(fs, 0);
            fs.Flush();
            fs.Close();

            return(data);
        }
Esempio n. 2
0
        /// <summary>
        /// Actually creates the instance of the object for saving
        /// relevant items to the database and their corresponding files.
        /// </summary>
        public void SubmitReport()
        {
            var IR = new InterfaceRecord();

            IR.WasTest           = this.VendorObject.WasTest;
            IR.PerformedBy       = this.UserID;
            IR.VendorName        = this.VendorObject.VendorName;
            IR.VendorFileName    = Path.GetFileName(this.VendorObject.cleanUpItems.EncryptedFilePath);
            IR.EncryptedFileName = Path.GetFileName(this.VendorObject.cleanUpItems.EncryptedFilePath);
            var bA = new System.Data.Linq.Binary(FileReport.ReturnFileBytes(this.VendorObject.cleanUpItems.EncryptedFilePath));

            IR.EncryptedFile    = bA;
            IR.HrSystemFileName = Path.GetFileName(this.VendorObject.cleanUpItems.TxtWorkingFilePath);
            var bA2 = new System.Data.Linq.Binary(FileReport.ReturnFileBytes(this.VendorObject.cleanUpItems.TxtWorkingFilePath));

            IR.HrSystemFile = bA2;
            IR.Message      = this.VendorObject.TransmissionReport;
            IR.DateOfAction = DateTime.Now;

            //Plop it in!!
            DatabaseHelper.Insert <InterfaceRecord>(IR);
        }
        /// <summary>
        /// Handles the actions for the current working file for encryption and transmission
        /// </summary>
        /// <param name="workingFile"></param>
        private void HandleMovedVendorFile(VendorLite vl, int _count)
        {
            string source = vl.filePath;
                string file = Path.GetFileName(source);
                string dest = String.Format(@"{0}\{1}", Server.MapPath(vl.workingPath), file);
                string PublicKeyFileName = Server.MapPath(vl.publicKeyPath);
                string PrivateKeyFileName = Server.MapPath(appvars.SignPrivateKey);
                VendorType vt = (VendorType)Enum.Parse(typeof(VendorType), vl.VendorName, true);
                string EncryptionFile = String.Format("{0}{1}", dest.Replace(Path.GetFileName(dest), ""), appvars.ReturnNewFileName(vt));

                //Get the user info from their session var...
                SetUserInformation();
                vl.UserID = this.CurrentUser.UserObject.LoginID.ToLower();

                if (!File.Exists(dest))
                {
                    FileStream fs = File.Create(dest);
                    fs.Close();
                }

                File.Copy(source, dest, true);

                PgpEncryptionKeys encryptionKeys = new PgpEncryptionKeys(PublicKeyFileName, PrivateKeyFileName, appvars.SignPassWord);
                PgpEncrypt encrypter = new PgpEncrypt(encryptionKeys);

                using (Stream outputStream = File.Create(EncryptionFile))
                {
                    //build out the encypted file...
                    encrypter.EncryptAndSign(outputStream, new FileInfo(dest));

                    //Our file transfer class requires a fully qualified clean-up set...
                    CleanUpFiles cuf = new CleanUpFiles();
                    cuf.EncryptedFilePath = EncryptionFile;
                    cuf.TxtWorkingFilePath = dest;
                    // we'll put in the script path later.... cuf.ClientScriptFilePath = "";
                    //set the vL item's cleanupItems for the next routine..
                    vl.cleanUpItems = cuf;
                }//end using statement

                //construct the object and run it...
                FileTransfer fT = new FileTransfer(vl);
                fT.RunUpload();

                //File the report and store the files before clean-up...
                FileReport fr = new FileReport(vl);
                fr.SubmitReport();

                //clean up...
                FileCleanUp.CleanUpFileTransfer(vl.cleanUpItems);
        }