Пример #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);
            }
        }
Пример #2
0
        /// <summary>
        /// Refresh the list of files in the specified folder
        /// </summary>
        private void RefreshList()
        {
            // Clear the list view initially
            lvAudits.BeginUpdate();
            lvAudits.Items.Clear();

            // If we have no data folder then we may as well just exit
            _uploadFolder = tbAuditFolder.Text;
            if (_uploadFolder != "")
            {
                // build a temporary list of matching files
                List <AuditFileInfo> listAuditFiles = new List <AuditFileInfo>();
                AuditUploader        auditLoader    = new AuditUploader(_uploadFolder, _licenseCount);
                auditLoader.EnumerateFiles(listAuditFiles);

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

                UltraListViewItem[] items = new UltraListViewItem[listAuditFiles.Count];

                for (int i = 0; i < listAuditFiles.Count; i++)
                {
                    AuditFileInfo thisAuditFile = listAuditFiles[i];

                    UltraListViewSubItem[] subItemArray = new UltraListViewSubItem[3];
                    subItemArray[0]       = new UltraListViewSubItem();
                    subItemArray[0].Value = thisAuditFile.Assetname;
                    subItemArray[1]       = new UltraListViewSubItem();
                    subItemArray[1].Value = thisAuditFile.AuditDate.ToString();
                    subItemArray[2]       = new UltraListViewSubItem();
                    subItemArray[2].Value = thisAuditFile.StatusAsText;
                    //
                    UltraListViewItem item = new UltraListViewItem(thisAuditFile.Filename, subItemArray);
                    item.Tag = thisAuditFile;
                    item.Key = thisAuditFile.AuditFile.FileName;

                    items[i] = item;
                }

                lvAudits.Items.AddRange(items);

                // Also build a list of LYNC audit files which should be uploaded
                LyncAuditFileList listLyncAudits = new LyncAuditFileList();
                listLyncAudits.Populate(_uploadFolder);

                // then add to the file list control
                foreach (LyncAuditFile lyncAuditFile in listLyncAudits.LyncAuditFiles)
                {
                    AuditDataFile thisAuditFile = lyncAuditFile.ConvertedFile();
                    if (thisAuditFile == null)
                    {
                        continue;
                    }

                    // We need an AuditFileInfo object for this file
                    AuditFileInfo auditFileInfo = new AuditFileInfo();
                    auditFileInfo.Assetname = thisAuditFile.AssetName;
                    auditFileInfo.AuditDate = thisAuditFile.AuditDate;
                    auditFileInfo.AuditFile = thisAuditFile;
                    auditFileInfo.Filename  = lyncAuditFile.FileName;

                    UltraListViewSubItem[] subItemArray = new UltraListViewSubItem[3];
                    subItemArray[0]       = new UltraListViewSubItem();
                    subItemArray[0].Value = auditFileInfo.Assetname;
                    subItemArray[1]       = new UltraListViewSubItem();
                    subItemArray[1].Value = auditFileInfo.AuditDate.ToString();
                    subItemArray[2]       = new UltraListViewSubItem();
                    subItemArray[2].Value = auditFileInfo.StatusAsText;
                    //
                    UltraListViewItem item = new UltraListViewItem(auditFileInfo.Filename, subItemArray);
                    item.Tag = auditFileInfo;
                    item.Key = auditFileInfo.Filename;
                    lvAudits.Items.Add(item);
                }
            }

            lvAudits.EndUpdate();
        }