/// <summary>
        /// Called when we have determined that we have 1 or more USB / Mobile Device files which need
        /// to be uploaded.
        /// </summary>
        /// <param name="notifications"></param>
        protected void UploadLyncAudits(LyncAuditFileList lyncAuditFiles, string uploadFolder)
        {
            LogFile ourLog = LogFile.Instance;

            try
            {
                AuditUploader auditLoader = new AuditUploader(uploadFolder, this._service.LicenseCount);
                foreach (LyncAuditFile lyncFile in lyncAuditFiles.LyncAuditFiles)
                {
                    AuditDataFile convertedFile = lyncFile.ConvertedFile();

                    try
                    {
                        auditLoader.UploadAuditDataFile(convertedFile);
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            catch (Exception ex)
            {
                ourLog.Write("Exception occurred in [UploadLyncAudits], Exception Text is is " + ex.Message, true);
            }
        }
Example #2
0
        /// <summary>
        /// Handle a message coming in from an audited client - this should be an ADF file streamed
        /// </summary>
        /// <param name="message">Message received from the TCP server</param>
        private void HandleClientMessage(TcpConnection sender, string message)
        {
            // ...and try and upload this as an audit file
            LogFile ourLog = LogFile.Instance;

            ourLog.Write("Uploading Audit File received as an incoming TCP Stream from " + sender.HostName, true);

            // clean up the message, so it can be parsed by XmlDocument.LoadXml
            message = message.Trim();
            message = message.Remove(message.LastIndexOf('>') + 1, message.Length - message.LastIndexOf('>') - 1);

            // Create an XmlTextReader and populate it with the string which should be the XML text
            XmlTextReader xmlTextReader = new XmlTextReader(new System.IO.StringReader(message));

            // Create an AuditDataFile from the stream
            AuditDataFile auditDataFile = new AuditDataFile();

            auditDataFile.Read(xmlTextReader);

            // Create an uploader
            AuditUploader auditUploader = new AuditUploader("", _service.LicenseCount);

            // ...and upload the file
            auditUploader.UploadAuditDataFile(auditDataFile);
        }
Example #3
0
        /// <summary>
        /// This is the main processing loop for the worker thread
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundWorkerUpload_DoWork(object sender, DoWorkEventArgs e)
        {
            e.Result       = 0;                         // Assume success
            _uploadedFiles = new List <AuditDataFile>();

            // We can work on the '_listToUpload' data member as nothing will happen to it
            // in the main UI thread as that thread is stalled waiting for the background thread
            // to complete
            int uploading = 1;

            foreach (AuditDataFile dataFile in _listToUpload)
            {
                // If we have been requested to close then do so
                if (this.backgroundWorkerUpload.CancellationPending)
                {
                    break;
                }

                // Use the report progress facility to communicate to this control's UI thread to indicate another
                // audit file uploaded
                string statusText = String.Format("Uploading {0} of {1} Audits...", uploading, _listToUpload.Count);
                this.backgroundWorkerUpload.ReportProgress(0, statusText);

                // Now perform the upload of this data file
                try
                {
                    AuditUploader uploader = new AuditUploader(_uploadFolder, _licenseCount);
                    uploader.UploadAuditDataFile(dataFile);
                    _uploadedFiles.Add(dataFile);
                }

                // Any exceptions from the upload should be caught and reported - the exception will abort the
                // upload process.
                catch (Exception ex)
                {
                    RefreshList();
                    statusText = "Upload failed: " + ex.Message;
                    this.backgroundWorkerUpload.ReportProgress(0, statusText);
                    e.Result = -1;
                    //break;
                }

                uploading++;
            }
        }
        /// <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);
            }
        }
Example #5
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();
        }