Ejemplo n.º 1
0
 public static void AddRequest(MessageCorrelator mc, int hash)
 {
     messageTable.Add(hash, mc);
 }
Ejemplo n.º 2
0
 public static void AddRequest(int hash, DateTime time, string message, string url, NameValueCollection headers)
 {
     MessageCorrelator x = new MessageCorrelator();
     x.RequestMessage = message;
     x.RecievedAt = time;
     x.originalUrl = x.URL = url;
     x.MessageID = Guid.NewGuid().ToString();
     x.identity = new List<string>();
     messageTable.Add(hash, x);
 }
Ejemplo n.º 3
0
        private void ProcessRequest(SoapMessage message, Boolean isclient)
        {
            if (Trace.CorrelationManager.ActivityId == Guid.Empty)
            {
                Guid newGuid = Guid.NewGuid();
                Trace.CorrelationManager.ActivityId = newGuid;
            }
            MessageProcessor ctx = MessageProcessor.Instance;
            MessageCorrelator mc = new MessageCorrelator();

            mc.MessageID = Guid.NewGuid().ToString();
            if (isclient)
            {
                mc.threadid = MessageProcessor.GetTransactionThreadId(Thread.CurrentContext.ContextID.ToString() + Thread.CurrentThread.ManagedThreadId.ToString() + ":" + Thread.GetDomainID().ToString() + Thread.CurrentThread.Name);
                if (String.IsNullOrEmpty(mc.threadid))
                {
                    mc.threadid = Guid.NewGuid().ToString();
                }
                if (MessageProcessor.GetConfig.DependencyInjectionEnabled)
                {
                    message.Headers.Add(new FGSMSSoapHeaderRelatedMessageASPNET(mc.MessageID));
                    message.Headers.Add(new FGSMSSoapHeaderTransactionThreadIdASPNET(mc.threadid));
                }
            }
            else //service processing a request
            {
                IEnumerator it = message.Headers.GetEnumerator();
                while (it.MoveNext())
                {
                    SoapUnknownHeader e = it.Current as SoapUnknownHeader;
                    if (e != null)
                    {

                        //if (e.Element.Name.Equals(FGSMSSoapHeaderTransactionThreadIdWCF.Name2) && e.Element.NamespaceURI.Equals(FGSMSSoapHeaderTransactionThreadIdWCF.Namespace2))
                        //{
                        //    mc.threadid = e.Element.InnerText;
                        //}
                        if (e.Element.Name.Equals(FGSMSSoapHeaderRelatedMessageIdWCF.Name2) && e.Element.NamespaceURI.Equals(FGSMSSoapHeaderRelatedMessageIdWCF.Namespace2))
                        {
                            mc.relatedtransactionid = e.Element.InnerText;
                        }
                        if (e.Element.Name.Equals(FGSMSSoapHeaderTransactionThreadIdWCF.Name2) && e.Element.NamespaceURI.Equals(FGSMSSoapHeaderTransactionThreadIdWCF.Namespace2))
                        {
                            mc.threadid = e.Element.InnerText;
                        }
                    }

                  
                }

             
            }
            if (String.IsNullOrEmpty(mc.threadid))
                mc.threadid = Guid.NewGuid().ToString();
            MessageProcessor.SetTransactionThreadId(Thread.CurrentContext.ContextID.ToString() + Thread.CurrentThread.ManagedThreadId.ToString() + ":" + Thread.GetDomainID().ToString() + Thread.CurrentThread.Name, mc.threadid);



            try
            {
                Uri url = new Uri("urn:undeterminable");
                if (!isclient && System.Web.HttpContext.Current != null)
                    url = System.Web.HttpContext.Current.Request.Url;
                else url = new Uri(message.Url);
                AgentMessageTable hashtable = AgentMessageTable.Instance;
                if (isclient)
                    localhashcode = message.GetHashCode();
                else if (HttpContext.Current != null)
                {
                    localhashcode = HttpContext.Current.Request.GetHashCode();
                }
                else
                {
                    //uh oh, http context is null and this is a server side request, unexpected.
                }
                if (HttpContext.Current == null)
                {
                    mc.RecievedAt = DateTime.Now;
                    mc.RequestMessage = StreamtoString(message.Stream);
                    mc.requestsize = mc.RequestMessage.Length;
                    mc.originalUrl = mc.URL = url.ToString();
                    mc.RequestHeaders = new System.Collections.Specialized.NameValueCollection();
                    //   mc.RequestHeaders.Add("Content-Type", message.ContentType);
                    //  mc.RequestHeaders.Add("Content-Encoding", message.ContentEncoding);
                    mc.RequestHeaders.Add("SOAPAction", message.Action);
                    mc.soapAction = message.Action;
                    AgentMessageTable.AddRequest(mc, localhashcode);
                    /* AgentMessageTable.AddRequest(localhashcode,
                         DateTime.Now,
                         StreamtoString(message.Stream),
                         //InputMessageToString(message),
                         url.ToString()
                         // message.ToString()
                     );*/
                }
                else
                {
                    mc.RecievedAt = DateTime.Now;

                    mc.RequestMessage = StreamtoString(message.Stream);
                    mc.requestsize = mc.RequestMessage.Length;
                    mc.originalUrl = mc.URL = url.ToString();
                    mc.RequestHeaders = new System.Collections.Specialized.NameValueCollection();
                    mc.RequestHeaders = HttpContext.Current.Request.Headers;
                    mc.userp = HttpContext.Current.User;
                    try
                    {
                        mc.soapAction = message.Action;
                    }
                    catch { }
                    if (String.IsNullOrEmpty(mc.soapAction))
                    {
                        mc.soapAction = mc.RequestHeaders["SOAPAction"];
                    }
                    if (HttpContext.Current.Request.ClientCertificate != null)
                        mc.ClientCertificate = new X509Certificate2(HttpContext.Current.Request.ClientCertificate.Certificate);

                    AgentMessageTable.AddRequest(mc, localhashcode);
                    /*
                    AgentMessageTable.AddRequest(localhashcode,
                   DateTime.Now,
                   StreamtoString(message.Stream),
                        //OutputMessageToString(message),
                   url.ToString());
                    // message.ToString()*/
                }

            }
            catch (Exception ex)
            {
                Logger.error(ex, this.GetType().FullName + " error caught processing a request ");
                
            }
            // PurgeOldMessages();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a message to the processor queue
        /// </summary>
        /// <param name="requestUrl"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="soapAction"></param>
        /// <param name="requestMessage"></param>
        /// <param name="responseMessage"></param>
        /// <param name="messageID"></param>
        /// <param name="IsFault">true if faulting message</param>
        /// <param name="context">HttpContext for things running inside IIS, nullable</param>
        /// <param name="ipaddress">IP of the requestor</param>
        /// <param name="classname">classname of the monitoring agent</param>
        /// <param name="user">Username of the person requesting the service</param>
        /// <param name="memo"></param>
        /// <param name="threadid"></param>
        /// <param name="relatedtransactionid"></param>
        /// <param name="requestheaders"></param>
        /// <param name="responseheaders"></param>
        public static void ProcessMessage(string requestUrl,
            DateTime start,
            DateTime end,
            string soapAction,
            string requestMessage,
            string responseMessage,
            string messageID,
            bool IsFault,
            HttpContext context,
            string ipaddress,
            string classname,
            string user, string memo,
            string threadid,
            string relatedtransactionid,
            NameValueCollection requestheaders,
            NameValueCollection responseheaders)
        {
            MessageProcessor i = MessageProcessor.Instance;
            Logger.debug(DateTime.Now.ToString("o") + " Process Message " + messageID + requestUrl);

            if (Trace.CorrelationManager.ActivityId == Guid.Empty)
            {
                Guid newGuid = Guid.NewGuid();
                Trace.CorrelationManager.ActivityId = newGuid;
            }
            soapAction = soapAction.Replace("\"", "");
            soapAction = soapAction.Replace("\'", "");
            soapAction = soapAction.Replace("{", "");
            soapAction = soapAction.Replace("}", "");
            //special case

            if (soapAction.Equals("urn:org:miloss:FGSMS:services:interfaces:dataCollector/dataCollectorService/AddData", StringComparison.CurrentCultureIgnoreCase))
                return;     //prevent recursive loops
            if (soapAction.Equals("AddData", StringComparison.CurrentCultureIgnoreCase))
                return;     //prevent recursive loops
            if (soapAction.Equals("AddMoreData", StringComparison.CurrentCultureIgnoreCase))
                return;     //prevent recursive loops
            if (soapAction.Equals("urn:org:miloss:FGSMS:services:interfaces:policyConfiguration/policyConfigurationService/GetServicePolicy", StringComparison.CurrentCultureIgnoreCase))
                return;     //prevent recursive loops
            if (soapAction.Equals("urn:org:miloss:FGSMS:services:interfaces:dataCollector/dataCollectorService/AddMoreData", StringComparison.CurrentCultureIgnoreCase))
                return;
            if (soapAction.Equals(FGSMSConstants.DCSaction, StringComparison.CurrentCultureIgnoreCase))
                return;
            if (soapAction.Equals(FGSMSConstants.DCSaction2, StringComparison.CurrentCultureIgnoreCase))
                return;
            if (soapAction.Equals(FGSMSConstants.DCSaction3, StringComparison.CurrentCultureIgnoreCase))
                return;
            if (soapAction.Equals(FGSMSConstants.DCSaction4, StringComparison.CurrentCultureIgnoreCase))
                return;
            if (soapAction.Equals(FGSMSConstants.PCSaction, StringComparison.CurrentCultureIgnoreCase))
                return;
            if (soapAction.Equals(FGSMSConstants.PCSaction2, StringComparison.CurrentCultureIgnoreCase))
                return;
            if (ErrorState) return;
            MessageCorrelator Event = new MessageCorrelator();
            if (requestUrl.ToString().Equals("urn:undeterminable"))
            {
                //TODO maybe we should log this? The only time i've seen this happen is during a strange concurrency issue.
                Logger.warn(DateTime.Now.ToString("o") + " Could not process a message identified as " + requestUrl + soapAction + " because the url is marked as undeterminable");
                Event = null;
                return;
            }
            if (IsOnIgnoreList(requestUrl))
            {
                Logger.debug(DateTime.Now.ToString("o") + requestUrl + " is on the ignore list");
                return;
            }
            Logger.debug(DateTime.Now.ToString("o") + " process ignore list exit");
            Event.originalUrl = Event.URL = requestUrl.ToString();
            Event.agenttype = classname;
            Event.ipaddress = ipaddress;
            Event.RecievedAt = start;
            if (requestMessage == null)
                Event.requestsize = 0;
            else
                Event.requestsize = requestMessage.Length;
            if (responseMessage == null)
                Event.responsesize = 0;
            else
                Event.responsesize = responseMessage.Length;
            //memory reduction optimization, we really don't know how long this data will hang around in the queue,
            //if the policy is available we can reduce memory usage by not hanging on to the message content
            TransactionalWebServicePolicy tp = MessageProcessor.GetPolicyIfAvailable(Event.originalUrl, classname.ToLower().EndsWith("client"));
            if (tp != null)
            {
                if (tp.RecordRequestMessage || (tp.RecordFaultsOnly && IsFault) || ContainsSLAXpathOrUserIdentXpath(tp))
                {
                    if (MessageProcessor.MAXCAP < requestMessage.Length)
                        Event.RequestMessage = requestMessage.Substring(0, MessageProcessor.MAXCAP);
                    else Event.RequestMessage = requestMessage;
                }
                if (tp.RecordResponseMessage || (tp.RecordFaultsOnly && IsFault))
                {
                    if (MessageProcessor.MAXCAP < requestMessage.Length)
                        Event.ResponseMessage = responseMessage.Substring(0, MessageProcessor.MAXCAP);
                    else Event.ResponseMessage = responseMessage;
                }
            }
            else
            {
                if (requestMessage != null)
                {
                    //policy is not available, save the content just in case
                    if (MessageProcessor.MAXCAP < requestMessage.Length)
                        Event.RequestMessage = requestMessage.Substring(0, MessageProcessor.MAXCAP);
                    else Event.RequestMessage = requestMessage;
                }
                if (responseMessage != null)
                {
                    if (MessageProcessor.MAXCAP < responseMessage.Length)
                        Event.ResponseMessage = responseMessage.Substring(0, MessageProcessor.MAXCAP);
                    else Event.ResponseMessage = responseMessage;
                }
            }
            //Event.RequestMessage = requestMessage;
            Event.soapAction = soapAction;
            Event.MessageID = messageID;
            Event.CompletedAt = end;
            //Event.ResponseMessage = responseMessage;
            Event.identity = new List<string>();
            Event.relatedtransactionid = relatedtransactionid;
            Event.memo = memo;
            Event.threadid = threadid;
            Event.RequestHeaders = requestheaders;
            Event.ResponseHeaders = responseheaders;
            if (!String.IsNullOrEmpty(user))
                Event.identity.Add(user);
            if (!String.IsNullOrEmpty(ipaddress))
                Event.identity.Add(ipaddress);
            if (context != null)
            {
                if (context.Request.ClientCertificate != null)
                    Event.ClientCertificate = new X509Certificate2(context.Request.ClientCertificate.Certificate);
                //Event.RequestHeaders = context.Request.Headers;
                Event.userp = context.User;
                if (!Event.identity.Contains(context.User.Identity.Name))
                    Event.identity.Add(context.User.Identity.Name);
            }
            Logger.debug(DateTime.Now.ToString("o") + " Process Message enq " + messageID);

            the_queue.Enqueue(Event);
            lock (publishingThread)
            {
                if (publishingThread == null || publishingThread.Count == 0)
                {
                    Thread t = new Thread(new ThreadStart(SendBulkPerformanceData));
                    t.Name = "FGSMS DataPusher from thread " + Thread.CurrentThread.ManagedThreadId;
                    t.Start();
                    publishingThread.Add(t);
                    Logger.debug(DateTime.Now.ToString("o") + " Process Message thread start " + Thread.CurrentThread.ManagedThreadId + " " + messageID);
                }
                lock (publishingThread)
                {
                    //        int a = the_queue.Count / Environment.ProcessorCount;   //logical processors != cores;
                    if (the_queue.Count > 1000)// && !Event.agenttype.EndsWith("client", StringComparison.CurrentCultureIgnoreCase))
                    {

                        if (publishingThread.Count < 2)
                        {
                            //Shutdown = false;
                            // ThreadStart ts = new ThreadStart(SendPerformanceData);

                            Thread t = new Thread(new ThreadStart(SendBulkPerformanceData));
                            t.Name = "FGSMS Data Pusher from thread " + Thread.CurrentThread.Name;
                            t.IsBackground = true;
                            t.Start();
                            publishingThread.Add(t);
                            Logger.debug(DateTime.Now.ToString("o") + " Process Message thread start " + Thread.CurrentThread.ManagedThreadId + " " + messageID);
                        }
                        else
                        {
                            for (int k = 0; k < publishingThread.Count; k++)
                            {
                                if (publishingThread[k] == null || !publishingThread[k].IsAlive)
                                {
                                    publishingThread[k] = new Thread(new ThreadStart(SendBulkPerformanceData));
                                    publishingThread[k].Name = "FGSMS Data Pusher from thread " + Thread.CurrentThread.Name;
                                    publishingThread[k].IsBackground = true;
                                    publishingThread[k].Start();
                                    Logger.debug(DateTime.Now.ToString("o") + " Process Message thread start " + Thread.CurrentThread.ManagedThreadId + " " + messageID);
                                }
                            }

                        }

                    }
                }
            }

            Logger.debug(DateTime.Now.ToString("o") + " Process Message exit " + " " + messageID);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// this assumes that the message corrleator object is populated as required.
        /// minimum settings, url, classification and a unique message id
        /// </summary>
        /// <param name="mc"></param>
        public static void ProcessMessage(MessageCorrelator mc)
        {
            MessageProcessor mp = MessageProcessor.Instance;
            if (mc == null)
                return;

            if (mc.soapAction.Equals("urn:org:miloss:FGSMS:services:interfaces:dataCollector/dataCollectorService/AddData", StringComparison.CurrentCultureIgnoreCase))
                return;     //prevent recursive loops
            if (mc.soapAction.Equals("AddData", StringComparison.CurrentCultureIgnoreCase))
                return;     //prevent recursive loops
            if (mc.soapAction.Equals("AddMoreData", StringComparison.CurrentCultureIgnoreCase))
                return;     //prevent recursive loops
            if (mc.soapAction.Equals("urn:org:miloss:FGSMS:services:interfaces:policyConfiguration/policyConfigurationService/GetServicePolicy", StringComparison.CurrentCultureIgnoreCase))
                return;     //prevent recursive loops
            if (mc.soapAction.Equals("urn:org:miloss:FGSMS:services:interfaces:dataCollector/dataCollectorService/AddMoreData", StringComparison.CurrentCultureIgnoreCase))
                return;
            if (mc.soapAction.Equals(FGSMSConstants.DCSaction, StringComparison.CurrentCultureIgnoreCase))
                return;
            if (mc.soapAction.Equals(FGSMSConstants.DCSaction2, StringComparison.CurrentCultureIgnoreCase))
                return;
            if (mc.soapAction.Equals(FGSMSConstants.DCSaction3, StringComparison.CurrentCultureIgnoreCase))
                return;
            if (mc.soapAction.Equals(FGSMSConstants.DCSaction4, StringComparison.CurrentCultureIgnoreCase))
                return;
            if (mc.soapAction.Equals(FGSMSConstants.PCSaction, StringComparison.CurrentCultureIgnoreCase))
                return;
            if (mc.soapAction.Equals(FGSMSConstants.PCSaction2, StringComparison.CurrentCultureIgnoreCase))
                return;
            Logger.debug(DateTime.Now.ToString("o") + " Process Message " + mc.MessageID);

            the_queue.Enqueue(mc);
            lock (publishingThread)
            {
                if (publishingThread == null || publishingThread.Count == 0)
                {
                    Thread t = new Thread(new ThreadStart(SendBulkPerformanceData));
                    t.Name = "FGSMS DataPusher from thread " + Thread.CurrentThread.ManagedThreadId;
                    t.Start();
                    publishingThread.Add(t);

                }
                if (the_queue.Count > 1000)// && !Event.agenttype.EndsWith("client", StringComparison.CurrentCultureIgnoreCase))
                {
                    lock (publishingThread)
                    {
                        if (publishingThread.Count < 2)
                        {
                            //Shutdown = false;
                            // ThreadStart ts = new ThreadStart(SendPerformanceData);

                            Thread t = new Thread(new ThreadStart(SendBulkPerformanceData));
                            t.Name = "FGSMS Data Pusher from thread " + Thread.CurrentThread.Name;
                            t.IsBackground = true;
                            t.Start();
                            publishingThread.Add(t);
                        }
                        else
                        {
                            for (int k = 0; k < publishingThread.Count; k++)
                            {
                                if (publishingThread[k] == null || !publishingThread[k].IsAlive)
                                {
                                    publishingThread[k] = new Thread(new ThreadStart(SendBulkPerformanceData));
                                    publishingThread[k].Name = "FGSMS Data Pusher from thread " + Thread.CurrentThread.Name;
                                    publishingThread[k].IsBackground = true;
                                    publishingThread[k].Start();
                                }
                            }

                        }
                    }
                }
            }
            Logger.debug(DateTime.Now.ToString("o") + " Process Message Exit " + mc.MessageID);
        }
Ejemplo n.º 6
0
        private static AddDataRequestMsg PrepMessage(MessageCorrelator message)
        {
            Logger.debug(DateTime.Now.ToString("o") + " Prepmessage enter " + message.MessageID);

            MessageProcessor i = MessageProcessor.Instance;

            Logger.info("SendPerformanceData, Data acquistion successful, sending data to the data collector." + message.URL + " at " + message.RecievedAt + " recording agent " + message.agenttype);
            //if (FGSMSConstants.log) log.TraceEvent(TraceEventType.Information, 0, ());

            AddDataRequestMsg request = new AddDataRequestMsg();
            request = new AddDataRequestMsg();
            request.Action = message.soapAction;

            if (String.IsNullOrEmpty(message.URL))
            {
                Logger.warn("FGSMS.MessageProcessor Send Peformance Data, the url on this message is null, skipping");
                message = null;
                return null;
            }
            if (message.agenttype.ToLower().Contains(".client"))
                message.URL = ModifyURL(message.URL, true);
            else message.URL = ModifyURL(message.URL, false);
            Logger.debug(

                 DateTime.Now.ToString("o") + " Prepmessage after url mod " + message.MessageID);

            //This double check is required due to adjusted urls do not remove
            if (IsOnIgnoreList(message.URL))
            {
                message = null;
                try
                {
                    //if (FGSMSConstants.log) EventLog.WriteEntry("FGSMS.MessageProcessor", "Message ignored due to ignore list " + message.originalUrl + " translated " + message.URL, EventLogEntryType.Information);
                }
                catch { }
                return null;
            }

            PolicyHelper myPolicy = FetchPolicy(message.URL);
            Logger.debug(

                 DateTime.Now.ToString("o") + " Prepmessage after pol fetch" + message.MessageID);

            if (myPolicy == null)
                return null;
            //record the request
            if (!String.IsNullOrEmpty(message.RequestMessage))
                if (myPolicy.policy.RecordRequestMessage)
                {
                    request.XmlRequest =
                        message.RequestMessage;
                    //truncate the request
                    if (myPolicy.policy.RecordedMessageCap < request.XmlRequest.Length)
                        request.XmlRequest = request.XmlRequest.Substring(0, myPolicy.policy.RecordedMessageCap);
                }

            //record response
            if (!String.IsNullOrEmpty(message.ResponseMessage))
                if (myPolicy.policy.RecordResponseMessage)
                {
                    request.XmlResponse =
                        message.ResponseMessage;
                    //truncate the response
                    if (myPolicy.policy.RecordedMessageCap < request.XmlResponse.Length)
                        request.XmlResponse = request.XmlResponse.Substring(0, myPolicy.policy.RecordedMessageCap);
                }

            request.requestSize = (int)message.requestsize;
            request.responseSize = (int)message.responsesize;
            if (myPolicy.policy.RecordFaultsOnly && message.IsFault)
            {
                request.XmlRequest =
                 message.RequestMessage;
                request.XmlResponse =
                   message.ResponseMessage;
                //truncate the request
                if (myPolicy.policy.RecordedMessageCap < request.XmlRequest.Length)
                    request.XmlRequest = request.XmlRequest.Substring(0, myPolicy.policy.RecordedMessageCap);
                //truncate the response
                if (myPolicy.policy.RecordedMessageCap < request.XmlResponse.Length)
                    request.XmlResponse = request.XmlResponse.Substring(0, myPolicy.policy.RecordedMessageCap);

            }
            if (myPolicy.policy.RecordHeaders)
            {
                if (message.RequestHeaders != null && message.RequestHeaders.Count > 0)
                {
                    List<header> l = new List<header>();
                    for (int b = 0; b < message.RequestHeaders.AllKeys.Length; b++)
                    {
                        header h = new header();
                        h.name = message.RequestHeaders.AllKeys[b];
                        h.value = new string[] { message.RequestHeaders[message.RequestHeaders.AllKeys[b]] };
                        l.Add(h);
                    }
                    request.headersRequest = l.ToArray();
                    l = null;
                }
                if (message.ResponseHeaders != null && message.ResponseHeaders.Count > 0)
                {
                    List<header> l = new List<header>();
                    for (int b = 0; b < message.ResponseHeaders.Count; b++)
                    {
                        header h = new header();
                        h.name = message.ResponseHeaders.AllKeys[b];
                        h.value = new string[] { message.ResponseHeaders[message.ResponseHeaders.AllKeys[b]] };
                        l.Add(h);
                    }
                    request.headersResponse = l.ToArray();
                    l = null;
                }
            }
            request.Identity = GetUserIdentity(myPolicy.policy.UserIdentification, ref message);
            long ticks = message.CompletedAt.Ticks - message.RecievedAt.Ticks;
            request.recordedat = message.RecievedAt;
            TimeSpan ts = new TimeSpan(ticks);
            request.responseTime = (ts.Hours * 60 * 60 * 1000) + (ts.Minutes * 60 * 1000) + (ts.Seconds * 1000) + (ts.Milliseconds);
            request.ServiceHost = System.Environment.MachineName.ToLower();
            request.Success = !message.IsFault;
            request.URI = message.URL;
            request.TransactionID = message.MessageID;
            request.TransactionThreadID = message.threadid;
            request.RelatedTransactionID = message.relatedtransactionid;

            request.agentType = message.agenttype;
            request.RequestURI = message.originalUrl;

            request.Action = message.soapAction;
            request.Action = request.Action.Replace("\"", string.Empty);
            request.Action = request.Action.Replace("'", string.Empty);
            long memused = System.GC.GetTotalMemory(false);

            ulong installedMemory = 0;
            ulong freememroy = 0;

            MEMORYSTATUSEX memStatus = new MEMORYSTATUSEX();
            if (GlobalMemoryStatusEx(memStatus))
            {
                installedMemory = memStatus.ullTotalPhys;
                freememroy = memStatus.ullAvailPhys;
            }

            request.Message += "Agent Outbound queue: " + the_queue.Count + " Outbound Threads " + ThreadPoolSize() + " Thread " + Thread.CurrentThread.Name;
            request.Message += " mem stat " + freememroy + "/" + installedMemory;
            /*if (String.IsNullOrEmpty(message.RequestMessage))
                request.requestSize = 0;
            else request.requestSize = message.RequestMessage.Length;
            if (String.IsNullOrEmpty(message.ResponseMessage))
                request.responseSize = 0;
            else request.responseSize = message.ResponseMessage.Length;*/
            request.classification = currentlevel;
            Logger.debug(

                 DateTime.Now.ToString("o") + " Prepmessage exit " + message.MessageID);

            message = null;

            return request;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// GetUserIdentity
        /// </summary>
        /// <param name="userIdentity">policy items related to identifying a user</param>
        /// <param name="msg">reference to the current correlation object</param>
        /// <returns>A string array representing all user identities found using the given service policy</returns>
        private static string[] GetUserIdentity(UserIdentity[] userIdentity, ref MessageCorrelator msg)
        {
            if (msg == null)
            {
                return null;
            }

            if (userIdentity != null && userIdentity.Length > 0)
            {
                StringReader sr = new StringReader(msg.RequestMessage);
                XPathDocument doc = new XPathDocument(sr);
                sr.Dispose();
                foreach (UserIdentity ui in userIdentity)
                {
                    if (ui.UseHttpCredential)
                    {
                        if (msg.identity == null)
                        {
                            //log warning
                        }
                        else
                        {
                            if (msg.ClientCertificate != null)
                                msg.identity.Add(msg.ClientCertificate.Subject);
                        }

                    }
                    if (ui.UseHttpHeader && !String.IsNullOrEmpty(ui.HttpHeaderName))
                    {
                        if (!String.IsNullOrEmpty(msg.RequestHeaders[ui.HttpHeaderName]))
                            msg.identity.Add(msg.RequestHeaders[ui.HttpHeaderName]);
                    }
                    XPathNavigator navi = doc.CreateNavigator();
                    XmlNamespaceManager mgr = new XmlNamespaceManager(navi.NameTable);

                    foreach (XMLNamespacePrefixies ns in ui.Namespaces)
                    {
                        mgr.AddNamespace(ns.Prefix, System.Web.HttpUtility.HtmlDecode(ns.Namespace));
                    }
                    foreach (XPathExpressionType xpath in ui.XPaths)
                    {

                        System.Xml.XPath.XPathExpression x = System.Xml.XPath.XPathExpression.Compile(xpath.XPath, mgr);
                        XPathNodeIterator valueIT = navi.Select(x);
                        if (valueIT.Count > 0)
                        {
                            while (valueIT.MoveNext())
                            {
                                try
                                {
                                    if (xpath.IsCertificate)
                                    {
                                        byte[] certb = System.Text.Encoding.UTF8.GetBytes(valueIT.Current.Value);
                                        X509Certificate2 xcert = new X509Certificate2(certb);
                                        if (xcert != null)
                                            msg.identity.Add(System.Web.HttpUtility.HtmlEncode(xcert.Subject));
                                    }
                                    else
                                        msg.identity.Add(System.Web.HttpUtility.HtmlEncode(valueIT.Current.Value));
                                }
                                catch (Exception ex)
                                {
                                    Logger.error(ex, "FGSMS.MessageProcessor" + @"GetUserIdentity, error obtaining user identity. This means that the
                                xpath query worked but something went haywire when parsing the results. XPATH=" + xpath.XPath + "error ");

                                }
                            }
                        }
                    }
                }
            }
            if (msg.identity.Count == 0)
                return null;
            List<string> myusers = new List<string>();
            for (int i = 0; i < msg.identity.Count; i++)
            {
                if (!String.IsNullOrEmpty(msg.identity[i]))
                    myusers.Add(msg.identity[i]);
            }
            return myusers.ToArray();
        }