Exemplo n.º 1
0
        private void FinalizeZipFile()
        {
            Log.Debug(string.Format("{0}Zip compression finished.", LOG_LABEL));

            // False stops the Close from also Closing the underlying stream.
            this._zipOutputStream.IsStreamOwner = false;
            // Must finish the ZipOutputStream before using outputMemStream.
            this._zipOutputStream.Close();

            Log.Debug(string.Format("{0}Writing zip file to USB drive.", LOG_LABEL));

            // Write zip file to USB drive
            using (FileStream fileStream = new FileStream(this._zipFilePath, FileMode.Create))
            {
                fileStream.Write(this._zipMemoryStream.GetBuffer(), 0, (int)this._zipMemoryStream.Length);
                fileStream.Flush();
                fileStream.Close();
            }

            Log.Debug(string.Format("{0}Updating zip file timestamp with local time.", LOG_LABEL));

            // File was created with UTC timestamp, because OS's time zone is UTC.
            // We want the timstamp to be the 'local' timezone.
            // Correct zip file timestamp from UTC to local time.
            //FileHelper.SetLastWriteTime( this._zipFilePath, this._zipFileTimeStamp );
            //FileHelper.SetCreationTime( this._zipFilePath, this._zipFileTimeStamp );

            FileInfo fileInfo = new FileInfo(this._zipFilePath);

            LogCompression(this._totalFileBytes, this._totalFileBytes, fileInfo.Length);

            // assume pass if no exception has been thrown
            this._status = TroubleshootStatus.Succeeded;
        }
Exemplo n.º 2
0
        /// <summary>
        /// If a USB drive is attached, the debug log and iNet.db3 database will be zipped up and copied to it.
        /// </summary>
        /// <returns>A TroubleshootEvent is returned.</returns>
        public DockingStationEvent Execute()
        {
            string funcMsg = Name + ".Execute";

            Log.Debug(funcMsg);

            TroubleshootEvent returnEvent = new TroubleshootEvent(this);

            try
            {
                // don't start the operation if the USB drive is not still connected
                if (Controller.IsUsbDriveAttached(LOG_LABEL))
                {
                    Master.Instance.ConsoleService.UpdateAction(ConsoleServiceResources.TROUBLESHOOT_COPYING);

                    // setup streams that will be used to produce the zip file
                    using (this._zipMemoryStream = new MemoryStream())
                    {
                        using (this._zipOutputStream = new ZipOutputStream(this._zipMemoryStream))
                        {
                            // zip file name which uses current time will be set
                            PrepareZipFile();

                            // zip up one file at a time in memory
                            ZipDebugLog();
                            ZipInetDatabase();

                            // write the zip file stream in memory to the usb drive
                            FinalizeZipFile();
                        }
                    }
                }
                else
                {
                    this._status = TroubleshootStatus.NotFound;
                }
            }
            catch (Exception ex)
            {
                // could add exception to return event errors if iNet wanted informed when this happens
                this._status = TroubleshootStatus.Failed;
                Log.Error(string.Format("{0} Caught Exception", funcMsg), ex);
            }

            // display outcome on LCD
            switch (this._status)
            {
            case TroubleshootStatus.NotFound:
                Master.Instance.ConsoleService.UpdateAction(ConsoleServiceResources.TROUBLESHOOT_NOTFOUND);
                break;

            case TroubleshootStatus.Succeeded:
                Master.Instance.ConsoleService.UpdateAction(ConsoleServiceResources.TROUBLESHOOT_SUCCEEDED);
                break;

            default:
                // if the usb drive was initially found, but the operation did not succeeded, assume failure
                Master.Instance.ConsoleService.UpdateAction(ConsoleServiceResources.TROUBLESHOOT_FAILED);
                break;
            }

            // 10 second sleep so user can see the outcome of the troubleshoot operation on the LCD
            System.Threading.Thread.Sleep(10000);

            // this return event should not be reported to iNet
            return(returnEvent);
        }