/// <summary>
        /// Asynchronously stores a log in the data store.
        /// </summary>
        /// <param name="timestamp">timestamp of the log (string)</param>
        /// <param name="operation">operation of the log (string)</param>
        /// <param name="identifier">identifier of the performer of the operation (string)</param>
        /// <param name="ipAddress">ip address of the performer of the operation (string)</param>
        /// <param name="errorType">the error type that occurred during the operation (string)</param>
        /// <returns>Task (bool) whether the log creation was successful</returns>
        public async Task <bool> LogToDataStoreAsync(string timestamp, string operation, string identifier,
                                                     string ipAddress, string errorType)
        {
            try
            {
                // Currently the timestamp is expected to be in the following format: "HH:mm:ss:ff UTC yyyyMMdd".
                string[] splitResult = timestamp.Split(' ');

                if (splitResult.Length != 3)
                {
                    throw new ArgumentException(Constants.TimestampFormatIncorrect);
                }


                // Create the log record to be stored, mostly just the parameters to this function apart from the timestamp.
                LogRecord logRecord = new LogRecord(splitResult[0] + " " + splitResult[1], operation, identifier, ipAddress, errorType);
                //TODO
                //LogRecord resultRecord = await _maskingService.MaskAsync(logRecord, false).ConfigureAwait(false) as LogRecord; ;

                // The name of the collection/table should be a derivative of the "yyyyMMdd" part of the timestamp.
                // Asynchronously call the Log DAO's function to create the log record in the collection denoted by the name (second parameter).
                return(await _dsLoggingDAO.CreateAsync(logRecord, splitResult[2]).ConfigureAwait(false));
            }
            catch
            {
                // Any exception results in a failed creation.
                return(false);
            }
        }
示例#2
0
        public async Task LogDAO_CreateAsync_SuccessfulCreation(string timestamp, string operation, string identifier, string ipAddress, string errorType, string date)
        {
            // Arrange:
            LogRecord record = new LogRecord(timestamp, operation, identifier, ipAddress, errorType);

            // Act:
            bool result = await logDAO.CreateAsync(record, date).ConfigureAwait(false);

            Assert.IsTrue(result);

            // Cleanup: find the Id of the log we created and delete it.
            string id = await logDAO.FindIdFieldAsync(record, date).ConfigureAwait(false);

            //bool deleteResult = await logDAO.DeleteAsync(id, date).ConfigureAwait(false);
            //Assert.IsTrue(deleteResult);
        }