示例#1
0
文件: Program.cs 项目: Oxigen2/Oxigen
        private static void WriteLogs(bool bFinalWrite)
        {
            if (_bErrorOnStartup)
            {
                _logger.WriteTimestampedMessage("there was an error on startup. Cannot write logs. Exiting.");
                return;
            }

            // method may have been fired by the _logTimer. In this case, if method is also fired
            // as application exists and the timer call hasn't yet finished, wait.
            // the probability of two timer calls come as close together as for the first call not to have
            // finished is practically zero as the _logTimer interval is long enough.
            while (_bAlreadyWritingLogs)
            {
                ;
            }

            _bAlreadyWritingLogs = true;

            // play time in this session
            int playTime = (int)Math.Round((DateTime.Now.Subtract(_startDateTime)).TotalSeconds, 0);

            // write log files
            try
            {
                LogFileWriter.WriteLogs(_advertClickLogsPath1,
                                        _advertClickLogsPath2,
                                        _advertImpressionLogsPath1,
                                        _advertImpressionLogsPath2,
                                        _contentClickLogsPath1,
                                        _contentClickLogsPath2,
                                        _contentImpressionLogsPath1,
                                        _contentImpressionLogsPath2,
                                        _usageCountLogsPath1,
                                        _usageCountLogsPath2,
                                        _user.MachineGUID, // closed networks: this may not be populated until CE or LE run. That's fine as no logs will be written if CE has not run to download content first.
                                        _user.UserGUID,
                                        playTime,
                                        _password,
                                        bFinalWrite,
                                        _bPreviewMode,
                                        _logger);

                _logger.WriteTimestampedMessage("successfully wrote logs.");
            }
            catch (Exception ex)
            {
                _logger.WriteError(ex);
            }

            if (bFinalWrite)
            {
                LogEntriesRawSingleton.Reset();

                _logger.WriteTimestampedMessage("successfully cleared the lgo object.");
            }

            _bAlreadyWritingLogs = false;
        }
示例#2
0
        /// <summary>
        /// Encrypts and writes the accummulated log entries in the LogEntriesRawSingleton to file
        /// </summary>
        /// <param name="adClickLogsPath1">Path of the first advert click log file to try and write to</param>
        /// <param name="adClickLogsPath2">Path of the second advert click log file to try and write to</param>
        /// <param name="adImpressionLogsPath1">Path of the first advert show log file to try and write to</param>
        /// <param name="adImpressionLogsPath2">Path of the second advert show log file to try and write to</param>
        /// <param name="contentClickLogsPath1">Path of the first content click log file to try and write to</param>
        /// <param name="contentClickLogsPath2">Path of the second content click log file to try and write to</param>
        /// <param name="contentImpressionLogsPath1">Path of the first content show log file to try and write to</param>
        /// <param name="contentImpressionLogsPath2">Path of the second content show log file to try and write to</param>
        /// <param name="usagePath1">Path of the first usage file to try and write to</param>
        /// <param name="usagePath2">Path of the second usage file to try and write to</param>
        /// <param name="playTime">play time (in seconds) in this screensaver session</param>
        /// <param name="bEncrypt">true to encrypt files, false if not. Must default to true. Use false only for debuggign purposes.</param>
        /// <param name="machineGUID">the machine's GUID</param>
        /// <param name="userGUID">the user's GUID</param>
        /// <param name="cryptPassword">encryption/decryption password</param>
        /// <param name="maxLines">maximum size of lines in log files. If numbers of lines in the log file exceed this value, trim it.</param>
        /// <param name="bFinalWrite">Is this the log dump that takes place when screen saver exits. If so, write the log file as well.</param>
        /// <exception cref="System.IO.PathTooLongException">The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.</exception>
        /// <exception cref="System.IO.DirectoryNotFoundException">The specified path is invalid, (for example, it is on an unmapped drive).</exception>
        /// <exception cref="System.UnauthorizedAccessException">path specified a file that is read-only and access is not Read. -or- path specified a directory. -or- The caller does not have the required permission.</exception>
        /// <exception cref="System.IO.IOException">If no file has write rights (for example when a user deliberately locks the files, an InvalidOperationException will be thrown.</exception>
        /// <exception cref="InvalidOperationException">thrown by XmlSerializer.Deserialize</exception>
        /// <exception cref="IOException">thrown when there is an error during read</exception>
        /// <exception cref="DirectoryNotFoundException">thrown when the directory is not found</exception>
        /// <exception cref="CryptographicException">thrown when encrypted file is corrupted</exception>
        /// <param name="logger">the Logger object to use when debugging exceptions</param>
        public static void WriteLogs(string adClickLogsPath1, string adClickLogsPath2,
                                     string adImpressionLogsPath1, string adImpressionLogsPath2,
                                     string contentClickLogsPath1, string contentClickLogsPath2,
                                     string contentImpressionLogsPath1, string contentImpressionLogsPath2,
                                     string usagePath1, string usagePath2,
                                     string machineGUID, string userGUID,
                                     int playTime, string cryptPassword, bool bFinalWrite, bool bPreviewMode, Logger logger)
        {
            // logging accumulation must continue when disk operations are conducted. Copy existing logs.
            // moving of list to string arrays is thread safe
            string[] advertClickLogEntries       = LogEntriesRawSingleton.MoveElementsToArray(LogEntriesRawSingleton.Instance.AdvertClickLogEntries);
            string[] advertImpressionLogEntries  = LogEntriesRawSingleton.MoveElementsToArray(LogEntriesRawSingleton.Instance.AdvertImpressionLogEntries);
            string[] contentClickLogEntries      = LogEntriesRawSingleton.MoveElementsToArray(LogEntriesRawSingleton.Instance.ContentClickLogEntries);
            string[] contentImpressionLogEntries = LogEntriesRawSingleton.MoveElementsToArray(LogEntriesRawSingleton.Instance.ContentImpressionLogEntries);

            logger.WriteMessage(DateTime.Now.ToString() + " successfully moved log structures to array.");

            if (bPreviewMode)
            {
                logger.WriteMessage(DateTime.Now.ToString() + " this is preview mode. Will not write logs to disk.");
                return;
            }

            int noNewClicks = advertClickLogEntries.Length + contentClickLogEntries.Length;

            logger.WriteMessage(DateTime.Now.ToString() + " new clicks: " + noNewClicks);

            WriteRawLogs(adClickLogsPath1, adClickLogsPath2, cryptPassword, advertClickLogEntries, logger);

            logger.WriteMessage(DateTime.Now.ToString() + " successfully written ad click logs.");

            WriteRawLogs(adImpressionLogsPath1, adImpressionLogsPath2, cryptPassword, advertImpressionLogEntries, logger);

            logger.WriteMessage(DateTime.Now.ToString() + " successfully written ad impression logs.");

            WriteRawLogs(contentClickLogsPath1, contentClickLogsPath2, cryptPassword, contentClickLogEntries, logger);

            logger.WriteMessage(DateTime.Now.ToString() + " successfully written content click logs.");

            WriteRawLogs(contentImpressionLogsPath1, contentImpressionLogsPath2, cryptPassword, contentImpressionLogEntries, logger);

            logger.WriteMessage(DateTime.Now.ToString() + " successfully written content impression logs.");

            if (bFinalWrite)
            {
                UpdateUsageCounts(usagePath1, usagePath2, cryptPassword, playTime, noNewClicks, machineGUID, userGUID, logger);
                logger.WriteMessage(DateTime.Now.ToString() + " successfully written usage counts.");
            }
        }