예제 #1
0
            /// <summary>
            /// Inserts audit log.
            /// </summary>
            /// <param name="request">The <see cref="InsertAuditLogDataRequest"/>log request.</param>
            /// <returns>The <see cref="NullResponse"/>response.</returns>
            private NullResponse InsertAuditLog(InsertAuditLogDataRequest request)
            {
                // Insert
                ChannelConfiguration channelConfiguration = request.RequestContext.GetChannelConfiguration();

                // RetailLog is an AX table, DataAreaId field is mandatory. We need to confirm channelConfiguration is present
                // before inserting data to RetailLog, otherwise P-job will fail due to DataAreaId is missing.
                if (channelConfiguration != null)
                {
                    var parameters = new ParameterSet();
                    parameters["@RETAILLOGID"]        = DateTimeOffset.UtcNow.Ticks;
                    parameters["@DATE"]               = request.RequestContext.GetNowInChannelTimeZone().DateTime;
                    parameters["@CODEUNIT"]           = request.Source;
                    parameters["@LOGSTRING"]          = request.LogEntry;
                    parameters["@LOGLEVEL"]           = request.LogLevel;
                    parameters["@STOREID"]            = request.StoreId;
                    parameters["@TERMINALID"]         = request.TerminalId;
                    parameters["@DURATIONINMILLISEC"] = request.DurationInMilliseconds;
                    parameters["@DATAAREAID"]         = channelConfiguration.InventLocationDataAreaId;

                    using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                    {
                        sqlServerDatabaseContext.ExecuteStoredProcedureNonQuery(AuditLogSqlServerDataService.InsertAuditLogSprocName, parameters);
                    }
                }

                return(new NullResponse());
            }
예제 #2
0
         /// <summary>
         /// Inserts Audit Log.
         /// </summary>
         /// <param name="request">The audit log request.</param>
         /// <returns>The response.</returns>
         private static NullResponse InsertAuditLog(InsertAuditLogServiceRequest request)
         {
             string storeId = string.Empty;
             string terminalId = string.Empty;
             bool auditEnabled = true;
 
             try
             {
                 var context = request.RequestContext;
 
                 if (context.GetPrincipal() != null)
                 {
                     Terminal terminal = context.GetTerminal();
                     if (terminal != null)
                     {
                         terminalId = terminal.TerminalId;
 
                         // Get device information
                         if (!context.GetPrincipal().IsChannelAgnostic)
                         {
                             try
                             {
                                 DeviceConfiguration deviceConfiguration = context.GetDeviceConfiguration();
                                 if (deviceConfiguration != null)
                                 {
                                     auditEnabled = deviceConfiguration.AuditEnabled;
                                 }
 
                                 // Try to get store information
                                 if (request.RequestContext.GetOrgUnit() != null)
                                 {
                                     storeId = request.RequestContext.GetOrgUnit().OrgUnitNumber ?? string.Empty;
                                 }
                             }
                             catch (Exception ex)
                             {
                                 // If anything bad happens, log an event and continue.
                                 RetailLogger.Log.CrtServicesLoggingServiceWriteEntryFailure(ex);
                             }
                         }
                     }
                 }
 
                 if (auditEnabled)
                 {
                     if (string.IsNullOrEmpty(storeId))
                     {
                         storeId = @"<not set>";
                     }
 
                     if (string.IsNullOrEmpty(terminalId))
                     {
                         terminalId = @"<not set>";
                     }
 
                     var dataRequest = new InsertAuditLogDataRequest(
                         request.Source,
                         request.LogEntry,
                         request.LogLevel,
                         storeId,
                         terminalId,
                         request.DurationInMilliseconds);
 
                     context.Execute<NullResponse>(dataRequest);
                 }
             }
             catch (Exception ex)
             {
                 RetailLogger.Log.CrtServicesLoggingServiceWriteEntryFailure(ex);
             }
 
             return new NullResponse();
         }