Esempio n. 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="id">The unique ID generated for this request</param>
        /// <param name="apiKey">The API key used to make this request</param>
        /// <param name="servicekey">the key of the service to call</param>
        /// <param name="methodkey">the key of the method in the service to call</param>
        /// <param name="parameterSet">the ParameterSet to pass to the method</param>
        /// <param name="clientIpAddress">The IP address of the client making this request</param>
        /// <param name="hostIpAddress">The IP address of the host making this request</param>
        /// <param name="hostname">The name of the host making this request</param>
        /// <param name="isServiceToService">Is this a service to service request</param>
        internal Request(Guid?id, string apiKey, string servicekey, string methodkey, ParameterSet parameterSet, string clientIpAddress, string hostIpAddress, string hostname, bool isServiceToService)
        {
            if (id == null)
            {
                throw new Exception("Invalid request id specified when creating service-to-service request object");
            }
            else
            {
                Id = (Guid)id;
            }

            APIKey              = new APIKey(apiKey);
            ServiceKey          = servicekey;
            MethodKey           = methodkey;
            _parameterSet       = parameterSet;
            _requestor          = new Requestor(clientIpAddress, hostIpAddress, hostname, parameterSet);
            _isServiceToService = isServiceToService;

            PushRequestToGlobalStack(Id, this);
        }
Esempio n. 2
0
        /// <summary>
        /// Logs the method call to database
        /// </summary>
        /// <param name="calledAt">The DateTime the Requeswas made</param>
        /// <param name="executeStart">The DateTime the Request was passed to the Method</param>
        /// <param name="executeEnd">The DateTime the Method finished processing and control was passed back to the framework</param>
        /// <param name="application">The application calling the method</param>
        /// <param name="serviceKey">The key of the service which was called</param>
        /// <param name="parameters">The parameters which were passed into the method</param>
        /// <param name="hostIPAddress">The IP address of the host calling the method</param>
        /// <param name="userIPAddress">The IP address of the user calling the method</param>
        /// <param name="permanentLog">Should a record of this call be made in the premenant log</param>
        internal void LogCall(DateTime calledAt, DateTime executeStart, DateTime executeEnd, Application application, string serviceKey, ParameterSet parameters, string hostIPAddress, string userIPAddress, bool permanentLog)
        {
            LogMethodParams call = new LogMethodParams()
            {
                MethodId           = (_id == -1 ? null : (int?)_id),
                ExecutionDuration  = (executeEnd - executeStart).TotalMilliseconds,
                CalledAt           = calledAt,
                ApplicationId      = application.Id,
                APIKey             = application.APIKey,
                HandledByIpAddress = ServerDetails.IPv4Addresses.First().ToString(),
                HostIpAddress      = hostIPAddress,
                UserIpAddress      = userIPAddress,
                PermanentLog       = permanentLog,
                ParameterSet       = parameters
            };

            if (Settings.GetBool("CallLogBufferEnabled"))
            {
                _bufferedCallLogQueue.Enqueue(call);
            }
            else
            {
                ParameterizedThreadStart work = new ParameterizedThreadStart(LogMethodCallThread);
                Thread thread = new Thread(work);

                thread.Start(call);
            }

            if (permanentLog)
            {
                string entry = Settings.GetString("LogFormatMethodCall", new Dictionary <string, string>()
                {
                    { "ApplicationId", application.Id.ToString() },
                    { "ApplicationName", application.Name },
                    { "MethodId", _id.ToString() },
                    { "ServiceKey", serviceKey },
                    { "MethodKey", _key },
                    { "Parameters", parameters.ToXml().OuterXml }
                });

                Logging.Module.WriteEvent(new LoggedEvent(EventLevel.Event, string.Format("{0}.{1}", serviceKey, _key), entry)
                {
                    Async           = true,
                    Group           = "ServiceCallAudit",
                    ApplicationType = ApplicationType.Application,
                    ApplicationName = application.Name,
                    ClientIp        = userIPAddress,
                    HostIp          = hostIPAddress
                });
            }
        }