Ejemplo n.º 1
0
        /// <summary>
        /// UploadNow
        /// =========
        ///
        /// Called when the file system watcher has determined that a .ADF file has appeared in one of the
        /// watched audit data folders.
        ///
        /// Actually this is now called every 60 seconds as the file system watchers appeared to be very unreliable
        /// and could easily fail to initialize depending on system resources
        ///
        /// We need to check for various types of files
        ///
        ///		ADF - Audit Data Files created by v8 Scanners
        ///		ANF	- Alert Notification File created by Alert Monitor
        ///		AUD/SWA - Audit Files created by the USB/Mobile Device Scanners
        ///
        /// </summary>
        protected void UploadNow(string uploadFolder)
        {
            LogFile ourLog = LogFile.Instance;

            try
            {
                ourLog.Write("Uploading any new audit data files from [" + uploadFolder + "]", true);

                // Find all of the upload files in the specified folder
                List <AuditFileInfo> listAuditFiles = new List <AuditFileInfo>();
                AuditUploader        auditLoader    = new AuditUploader(uploadFolder, this._service.LicenseCount);
                auditLoader.EnumerateFiles(listAuditFiles);
                ourLog.Write("There are " + listAuditFiles.Count.ToString() + " new audit data files available", true);

                // sort the list by audit scan date
                listAuditFiles.Sort();

                // then upload each in turn
                int index = 0;
                foreach (AuditFileInfo thisAuditFile in listAuditFiles)
                {
                    try
                    {
                        ourLog.Write("Uploading audit data file [" + Path.GetFileName(thisAuditFile.Filename) + "]  Index : " + index.ToString(), true);
                        auditLoader.UploadAuditDataFile(thisAuditFile.AuditFile);
                    }
                    catch (Exception ex)
                    {
                        ourLog.Write("An exception occurred while uploading the audit file [" + thisAuditFile.Filename + "].  The error was [" + ex.Message + "]", true);
                        string backupFile = thisAuditFile.AuditFile.FileName.Replace(Path.GetExtension(thisAuditFile.Filename), ".ADF.ERROR");

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

                        File.Move(thisAuditFile.AuditFile.FileName, backupFile);

                        ourLog.Write("Erroneous audit file renamed to [" + backupFile + "]", true);
                    }
                }

                // OK Do we have any Alert Notification files that need uploading?
                ourLog.Write("Uploading any new alert notification files from [" + uploadFolder + "]", true);
                AlertNotificationFileList notifications = new AlertNotificationFileList();
                if (notifications.Populate(uploadFolder) != 0)
                {
                    UploadNotifications(notifications);
                }

                // Do we have any USB/Mobile Device audits to upload
                LyncAuditFileList listLyncAudits = new LyncAuditFileList();
                if (listLyncAudits.Populate(uploadFolder) != 0)
                {
                    UploadLyncAudits(listLyncAudits, uploadFolder);
                }

                ourLog.Write("...done", true);
            }

            catch (Exception ex)
            {
                ourLog.Write("Exception occurred in [UploadNow], Exception Text is " + ex.Message, true);
            }
        }