/// <summary>
        /// Calculates unique HashCode based on the values of members
        /// </summary>
        /// <returns>int</returns>
        public override int GetHashCode()
        {
            int hashLetterID       = LetterID.GetHashCode();
            int hashName           = Name.GetHashCode();
            int hashRemoteFileName = RemoteFileName.GetHashCode();
            int hashCategory       = Category.GetHashCode();

            return(hashLetterID ^ hashName ^ hashRemoteFileName ^ hashCategory);
        }
Example #2
0
        public bool Download()
        {
            if (Device != null && Device.IsLogin && !IsDownloading)
            {
                mProgress = -1;

                string remoteFileName = RemoteFileName.Trim();
                if (!remoteFileName.Equals(""))
                {
                    if (DoDownloadFromFile(remoteFileName))
                    {
                        mDrive        = GetDriveInfo(LocalFileName);
                        mCurSkipCount = 0;

                        IsDownloadFromFile = true;
                        IsDownloading      = true;
                        mTimer.Enabled     = true;
                        return(true);
                    }
                }
                else
                {
                    if (DoDownloadFromTime(StartTime, StopTime))
                    {
                        mDrive        = GetDriveInfo(LocalFileName);
                        mCurSkipCount = 0;

                        IsDownloadFromFile = false;
                        IsDownloading      = true;
                        mTimer.Enabled     = true;
                        return(true);
                    }
                }
            }
            return(false);
        }
        protected void PostFromDisk(string LocalFileName, Destination Destination)
        {
            FileInfo LocalFileInfo;
            string   LocalFileFullPath = "";
            string   RemoteFileName    = "";
            string   RemoteDirectory   = "";
            string   PartialPath       = "";
            long     LocalFileSize;

            //Parse the local file's name.
            LocalFileName = TextParser.Parse(LocalFileName, DrivingData, SharedData, ModuleCommands);

            //Set the local file's base path as the processes temporary directory.
            //If required strip the base path from the LocalFileName.
            if (!LocalFileName.Contains(TextParser.Parse(SharedData.TempFileDirectory, DrivingData, SharedData, ModuleCommands)))
            {
                //If only the file name was provided, add the processes temporary directory to create the full path.
                LocalFileFullPath = TextParser.Parse(SharedData.TempFileDirectory + LocalFileName, DrivingData, SharedData, ModuleCommands);
            }
            else
            {
                LocalFileFullPath = LocalFileName;
                LocalFileName     = LocalFileName.Replace(TextParser.Parse(SharedData.TempFileDirectory, DrivingData, SharedData, ModuleCommands), "");
            }

            //Get the local file's information and store it in the modules commands.
            LocalFileInfo = new System.IO.FileInfo(LocalFileFullPath);
            AddOriginalModuleVariables(LocalFileInfo);

            //Check the LocalFileName for a partial path.
            if (LocalFileName.Contains(@"\"))
            {
                PartialPath   = LocalFileName.Substring(0, LocalFileName.LastIndexOf(@"\") + 1);
                LocalFileName = LocalFileName.Replace(PartialPath, "");
            }

            //Concat the destination url and the partial path
            RemoteDirectory = (TextParser.Parse(Destination.URL, DrivingData, SharedData, ModuleCommands) + PartialPath).Replace("/", @"\");
            System.IO.Directory.CreateDirectory(RemoteDirectory);

            //Check to see if the local file will be renamed when it is posted.
            if (!string.IsNullOrEmpty(Destination.NewFileName))
            {
                //Get the new name of the file.
                RemoteFileName = TextParser.Parse(Destination.NewFileName, DrivingData, SharedData, ModuleCommands);
                Logger.WriteLine("LanPoster.PostFromDisk", "        RENAMED FILE: " + RemoteFileName, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory);
            }
            else
            {
                RemoteFileName = LocalFileName;
            }

            //Get the size of the current file.
            LocalFileSize = LocalFileInfo.Length;

            if (ZipFile && MinFileSizeToZip <= 0 || (LocalFileSize >= (MinFileSizeToZip * 1000) && MinFileSizeToZip > 0))
            {
                Logger.WriteLine("LanPoster.PostFromDisk", "    COMPRESSING FILE: " + RemoteFileName, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory);

                //Change the remote filename extension.
                RemoteFileName = RemoteFileName.Substring(0, RemoteFileName.LastIndexOf(".")) + ".zip";

                //Compress the local file.
                EnterpriseLibrary.Utilities.Zip.Compress(LocalFileFullPath, TextParser.Parse(SharedData.TempFileDirectory + RemoteFileName, DrivingData, SharedData, ModuleCommands));

                //Since the original local file was compressed, its name and path must be updated
                //to reflect the new compressed file's information.
                LocalFileFullPath = TextParser.Parse(SharedData.TempFileDirectory + RemoteFileName, DrivingData, SharedData, ModuleCommands);
                LocalFileName     = RemoteFileName;
            }

            try
            {
                //Upload the file to the LAN directory.
                Logger.WriteLine("LanPoster.PostFromDisk", "      UPLOADING FILE: " + RemoteFileName, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory);
                System.IO.File.Copy(LocalFileFullPath, RemoteDirectory + RemoteFileName, OverWrite);
                Logger.WriteLine("LanPoster.PostFromDisk", "       UPLOAD STATUS: SUCCESSFULL", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory);

                //Get the posted file's information and store it in the module's commands.
                LocalFileInfo = new System.IO.FileInfo(RemoteDirectory + RemoteFileName);
                AddPostedModuleVariables(LocalFileInfo);

                //Add the current file to the results table.
                AddResults();
            }
            catch (Exception ex)
            {
                Logger.WriteLine("LanPoster.PostFromDisk", "       UPLOAD STATUS: FAILED", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory);
                throw ex;
            }
        }
        protected void PostFromMemory(string LocalFileName, Byte[] ReportBuffer, Destination Destination)
        {
            long   ReportFileSize = 0;
            string RemoteDirectory;
            string PartialPath    = "";
            string RemoteFileName = "";

            System.IO.FileInfo LocalFileInfo;

            try
            {
                //Get the size of the current file.
                ReportFileSize = ReportBuffer.LongLength;

                //Check to see if the file will be renamed.
                if (!string.IsNullOrEmpty(Destination.NewFileName))
                {
                    //Get the new name of the file.
                    RemoteFileName = TextParser.Parse(Destination.NewFileName, DrivingData, SharedData, ModuleCommands);
                    Logger.WriteLine("LanPoster.PostFromMemory", "        RENAMED FILE: " + RemoteFileName, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory);
                }
                else
                {
                    RemoteFileName = LocalFileName;
                }

                //Remove the partial path from the file name if exists.
                if (RemoteFileName.Contains(@"\"))
                {
                    PartialPath    = RemoteFileName.Substring(0, RemoteFileName.LastIndexOf(@"\") + 1);
                    RemoteFileName = RemoteFileName.Replace(PartialPath, "");
                }

                RemoteDirectory = TextParser.Parse(Destination.URL, DrivingData, SharedData, ModuleCommands) + PartialPath;

                //Ensure the target directory exist.
                if (!System.IO.Directory.Exists(RemoteDirectory))
                {
                    //Creates directory and all subdirectories needed.
                    System.IO.Directory.CreateDirectory(RemoteDirectory);
                }

                //Check to see if the file is suppose to be zipped, and if it meets the minimum file size to be zipped.
                if (ZipFile && (MinFileSizeToZip <= 0 || ReportFileSize >= (MinFileSizeToZip * 1000)))
                {
                    Logger.WriteLine("LanPoster.PostFromMemory", "    COMPRESSING FILE: " + RemoteFileName, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory);

                    //Zip the file buffer.
                    ReportBuffer = EnterpriseLibrary.Utilities.Zip.Compress(ReportBuffer, RemoteFileName);

                    //Change the files extension.
                    RemoteFileName = RemoteFileName.Substring(0, RemoteFileName.LastIndexOf(".")) + ".zip";
                }

                //Upload the file to the LAN directory.
                Logger.WriteLine("LanPoster.PostFromMemory", "      UPLOADING FILE: " + RemoteFileName, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory);

                try
                {
                    System.IO.File.WriteAllBytes(RemoteDirectory + RemoteFileName, ReportBuffer);
                    Logger.WriteLine("LanPoster.PostFromMemory", "       UPLOAD STATUS: SUCCESSFULL", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory);

                    //Update the variable values for the current file.
                    LocalFileInfo = new System.IO.FileInfo(RemoteDirectory + RemoteFileName);
                    AddPostedModuleVariables(LocalFileInfo);

                    //Add the current file to the results table.
                    AddResults();
                }
                catch (Exception ex)
                {
                    Logger.WriteLine("LanPoster.PostFromMemory", "       UPLOAD STATUS: FAILED", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory);
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }