Ejemplo n.º 1
0
        private void ProcessGPRSRecord(WmDevice wmDevice, object data, GPRSData gprsData)
        {
            Record record     = this.CastRecord(wmDevice, data);
            string recordType = record.Recordtype.ToString();

            gprsData.Database = Hacks.AdjustDatabase(gprsData.Database);

            // GPS enabled recorders
            if (wmDevice.Devicetype == DeviceType.WM5000P5)
            {
                this.StoreGPSData(data, recordType);
            }
            else
            {
                this.StoreNonGPSData(gprsData, record);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method checks for copies of the file passed to it in the history and
        /// exception directories inside the database host directory. If it does not
        /// find copies of those files it will determine which decrypt process to run
        /// the file through and call the appropriate method.
        /// </summary>
        /// <param name="file">The FileInfo object of the file to be decrypted</param>
        public FileDecrypt(FileInfo file)
        {
            // Set the file locally
            this.file = file;

            // History and Exception paths
            string histPath = this.file.DirectoryName + @"\History\";
            string excpPath = this.file.DirectoryName + @"\Exceptions\";

            // Set default response
            int decryptResponse = 4;

            // Set database name: Ensure to use hacks utility to rename databases which require it
            this.databaseName = Hacks.AdjustDatabase(this.file.Directory.Name);

            // Before we attempt to decrypt the file, check for identical files in History and Exceptions
            FileInfo histFile = new FileInfo(histPath + this.file.Name);
            FileInfo excpFile = new FileInfo(excpPath + this.file.Name);

            // If a copy of the file exists in history, put it into Exceptions, unless it exists there too
            if (histFile.Exists)
            {
                if (excpFile.Exists)
                {
                    // If it exists in both, just delete it.
                    try
                    {
                        this.file.Delete();
                        Log.Warning("Deleted " + this.file.FullName + ", it was already present in History and Exceptions.");
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Could not delete the file " + this.file.FullName + "\r\n" + ex.Message);
                    }
                    return;
                }
                else
                {
                    this.file.MoveTo(excpPath + this.file.Name);
                    Log.Warning("Moved " + this.file.FullName + " to Exceptions as it was already present in History.");
                    return;
                }
            }

            // Decrypt the file depending on its extension
            try
            {
                // If the file is an export file, run DecryptExport()
                if (file.Extension == ".export")
                {
                    decryptResponse = this.DecryptExport();
                }

                // If it is a uef DecryptUEF()
                if (file.Extension == ".uef")
                {
                    decryptResponse = this.DecryptUEF();
                }

                // If its an import file, it's already decrypted
                if (file.Extension == ".uif" || file.Extension == ".plain")
                {
                    decryptResponse = this.DecryptUIF();
                }
            }
            catch (Exception ex)
            {
                Log.Error("Decrypt error." + ex.Message);
            }

            // Let's force a wait here...
            Thread.Sleep(500);

            // Determine the appropriate action to take once the file is decrypted
            switch (decryptResponse)
            {
            case 0:
                // Success, therefore we move the file to it's History directory
                try
                {
                    this.file.MoveTo(histPath + this.file.Name);
                }
                catch (Exception ex)
                {
                    Log.Error(String.Format("Could not move file during decryption. {0}, {1}", this.file.FullName, ex.Message));
                }
                break;

            case 1:
                Log.Warning("Insufficient arguments when decrypting " + file.Name);
                break;

            case 2:
                Log.Warning("Source file does not exist: " + file.Name);
                break;

            case 3:
                Log.Warning("Problem saving " + file.Name + " to target destination.");
                break;

            case 4:
                Log.Warning("Error decrypting file: " + file.Name);
                break;

            case 5:
                Thread.Sleep(1000);
                break;
            }
        }