/// <summary> /// This function will return a proxy to the DCS service using the provided username and password /// OR if FGSMS is configured for PKI auth, the certinfo field will be used to search for a certificate /// </summary> /// <param name="url"></param> /// <param name="Myusername"></param> /// <param name="Mypassword"></param> /// <param name="certinfo"></param> /// <returns></returns> public DCSBinding GetDCSProxy(string url, string Myusername, string Mypassword, string certinfo) { ServicePointManager.Expect100Continue = false; DCSBinding r = new DCSBinding(); r.Url = url; switch (authMode) { case AuthMode.usernamePassword: r.Credentials = new NetworkCredential(Myusername, Mypassword); break; case AuthMode.PKI: r.ClientCertificates.Add(FindCert(certinfo)); break; } return(r); }
public DCSBinding GetDCSProxy(string url) { ServicePointManager.Expect100Continue = false; DCSBinding r = new DCSBinding(); r.Url = url; switch (authMode) { case AuthMode.usernamePassword: r.Credentials = new NetworkCredential(username, util.DE(password)); break; case AuthMode.PKI: r.ClientCertificates.Add(FindCert(pkiinfo)); break; } return r; }
/// <summary> /// Attempts to send a single message sychronously /// this assumes that the prepedMessage object is populated as required. /// minimum settings, url, classification and a unique message id /// </summary> /// <param name="mc"></param> public static bool ProcessSingleMessage(AddDataRequestMsg prepedMessage) { MessageProcessor mp = MessageProcessor.Instance; if (prepedMessage == null) throw new ArgumentNullException(); if (dcsservice != null) try { ((IClientChannel)dcsservice).Dispose(); ((IClientChannel)dcsservice).Close(); } catch { } dcsservice = config.GetDCSProxy(config.dcsurl[0]); AddDataRequestMsg[] req = new AddDataRequestMsg[1]; ; req[0] = prepedMessage; bool success = false; for (int b = 0; b < config.dcsurl.Count; b++) { if (!success) for (int a = 0; a < config.DCSretrycount; a++) { try { AddDataResponseMsg response = dcsservice.AddMoreData(req); if ((response.Status == DataResponseStatus.Failure)) { //this case usually only happens when the same transaction was attempted to be written more than once or there was a problemn on the other end success = true; } else { success = true; break; } } catch (Exception ex) { _lasterror = ex.GetType().FullName + " " + ex.Message; Logger.error(ex, "FGSMS.MessageProcessor" + " ProcessSingleMessage - Data acquistion successful, but there was an error sending the information to the data collector. (incorrect password or URL?) "); } } if (b + 1 < config.dcsurl.Count) { if (dcsservice != null) { try { ((IClientChannel)dcsservice).Close(); ((IClientChannel)dcsservice).Dispose(); } catch (Exception ex) { } } dcsservice = config.GetDCSProxy(config.dcsurl[b + 1]); } } try { ((IClientChannel)dcsservice).Close(); ((IClientChannel)dcsservice).Dispose(); } catch { } return success; }
private static void SendBulkPerformanceData() { MessageProcessor m = MessageProcessor.Instance; Logger.debug( DateTime.Now.ToString("o") + " Sendbulk"); Init(); Logger.debug( DateTime.Now.ToString("o") + " Sendbulk after init"); MessageProcessor i = MessageProcessor.Instance; if (ErrorState) { Logger.error("FGSMS.MessageProcessor Message processor shuting down, the configuration file isn't available or FGSMS is being uninstalled. " + the_queue.Count + " message transactions were orphaned"); //ErrorState = true; publishingThread.Remove(Thread.CurrentThread); return; } if (!Enabled) { //persistence? the_queue.Clear(); } if (!ErrorState) try { //enabled check removed here because once we're disabled, theres no way to reenable things while (!shutdown && (the_queue.Count != 0) && Enabled) // || HasPersistenceFiles())) //remove for architecture change { int count = 0; AddDataRequestMsg[] req = null; List<AddDataRequestMsg> data = new List<AddDataRequestMsg>(); int totalbody = 0; //each enabled check is here because policies will be being updated during this routine, thus its necessary //grab the first 40 transactions or up to a total of MAXCAP while (count < 40 && the_queue.Count != 0 && Enabled && totalbody < 1024000) { Object j = the_queue.Dequeue(); MessageCorrelator message = j as MessageCorrelator; if (message != null) { count++; AddDataRequestMsg r = PrepMessage(message); if (r != null) { if (r.XmlResponse != null) totalbody += r.XmlResponse.Length; if (r.XmlRequest != null) totalbody += r.XmlRequest.Length; data.Add(r); message = null; } else the_queue.Enqueue(message); // PCS is not available! } else { AddDataRequestMsg rr = j as AddDataRequestMsg; if (rr != null) { if (rr.XmlRequest != null) totalbody += rr.XmlRequest.Length; if (rr.XmlResponse != null) totalbody += rr.XmlResponse.Length; data.Add(rr); } rr = null; } j = null; } //get items stored to disk, meaning that we couldn't send it before, so lets try it again //change 1-18-2012 from while to if, only grab the first item form disk //while /* if (HasPersistenceFiles() && count < 40 && totalbody < 1024000) { AddDataRequestMsg rr = ReadItemsFromDisk(); if (rr != null) { if (rr.XmlRequest != null) totalbody += rr.XmlRequest.Length; if (rr.XmlResponse != null) totalbody += rr.XmlResponse.Length; data.Add(rr); } }*/ req = data.ToArray(); Logger.debug( DateTime.Now.ToString("o") + " Sendbulk items " + req.Length + " queue " + the_queue.Count); /* XmlSerializer xs = new XmlSerializer(typeof(AddMoreDataRequest)); StringWriter sw = new StringWriter(); xs.Serialize(sw, req); String temp = sw.ToString();*/ data.Clear(); data = null; if (req.Length == 0) continue; bool success = false; if (config.OperatingMode == ConfigLoader.OperationMode.ONLINE) //ok ready to send switch (config.DCSalgo) { case ConfigLoader.Algorithm.ROUNDROBIN: //dcsservice = config.GetDCSProxy(config.dcsurl[0]); Logger.debug( DateTime.Now.ToString("o") + " build dcs proxy "); if (dcsservice != null) try { ((IClientChannel)dcsservice).Dispose(); ((IClientChannel)dcsservice).Close(); } catch { } dcsservice = config.GetDCSProxy(config.dcsurl[0]); Logger.debug( DateTime.Now.ToString("o") + " build dcs proxy done"); for (int b = 0; b < config.dcsurl.Count; b++) { if (!success) for (int a = 0; a < config.DCSretrycount; a++) { try { AddDataResponseMsg response = dcsservice.AddMoreData(req); if ((response.Status == DataResponseStatus.Failure)) { //this case usually only happens when the same transaction was attempted to be written more than once or there was a problemn on the other end success = true; } else { success = true; Logger.debug( DateTime.Now.ToString("o") + " Sendbulk items " + req.Length + " data sent"); break; } } catch (Exception ex) { _lasterror = ex.GetType().FullName + " " + ex.Message; Logger.warn("FGSMS.MessageProcessor" + "ProcessOutputMessage - Data acquistion successful, but there was an error sending the information to the data collector. " + ex.ToString()); } Logger.debug( DateTime.Now.ToString("o") + " Sendbulk items " + req.Length + " data send fail" + _lasterror); } if (b + 1 < config.dcsurl.Count) { Logger.debug( DateTime.Now.ToString("o") + " rebuild dcs proxy "); if (dcsservice != null) { try { ((IClientChannel)dcsservice).Close(); ((IClientChannel)dcsservice).Dispose(); } catch (Exception ex) { // log.TraceEvent(TraceEventType.Warning, 0, "Uh oh" + ex.Message + ex.StackTrace); } } dcsservice = config.GetDCSProxy(config.dcsurl[b + 1]); Logger.debug( DateTime.Now.ToString("o") + " rebuild dcs proxy done"); } } break; case ConfigLoader.Algorithm.FAILOVER: for (int a = 0; a < config.DCSretrycount; a++) { Logger.debug (DateTime.Now.ToString("o") + " build dcs proxy "); if (dcsservice != null) { try { ((IClientChannel)dcsservice).Close(); ((IClientChannel)dcsservice).Dispose(); } catch (Exception ex) { //log.TraceEvent(TraceEventType.Warning, 0, "Uh oh" + ex.Message + ex.StackTrace); } } dcsservice = config.GetDCSProxy(config.dcsurl[0]); Logger.debug( DateTime.Now.ToString("o") + " build dcs proxy done"); //dcsservice = config.GetDCSProxy(config.dcsurl[0]); if (!success) for (int b = 0; b < config.dcsurl.Count; b++) { try { AddDataResponseMsg response = dcsservice.AddMoreData(req); if ((response.Status == DataResponseStatus.Failure)) { Logger.warn("FGSMS.MessageProcessor" + "ProcessOutputMessage - Data acquistion successful, but there was an error sending the information to the data collector. Check the logs at that service. "); } else { success = true; Logger.debug( DateTime.Now.ToString("o") + " Sendbulk items " + req.Length + " data sent"); break; /*try { if (FGSMSConstants.log) EventLog.WriteEntry("FGSMS.MessageProcessor", "ProcessOutputMessage - Data acquistion successful, message sent to the data collector was successful for " + req.req.Length + " records", EventLogEntryType.Information); } catch { } if (FGSMSConstants.log) log.TraceEvent(TraceEventType.Information, 0, ("ProcessOutputMessage - Data acquistion successful, message sent to the data collector was successful for " + req.req.Length + " records")); */ } } catch (Exception ex) { _lasterror = ex.GetType().FullName + " " + ex.Message; Logger.warn(ex, "FGSMS.MessageProcessor" + "ProcessOutputMessage - Data acquistion successful, but there was an error sending the information to the data collector. " + ex.ToString()); } if (b + 1 < config.dcsurl.Count) { Logger.debug( DateTime.Now.ToString("o") + " rebuild dcs proxy "); if (dcsservice != null) { try { ((IClientChannel)dcsservice).Close(); ((IClientChannel)dcsservice).Dispose(); } catch (Exception ex) { } } dcsservice = config.GetDCSProxy(config.dcsurl[b + 1]); Logger.debug( DateTime.Now.ToString("o") + " rebuild dcs proxy done"); } } } break; } if (!success && config.ServiceUnavailableBehavior == ConfigLoader.UnavailableBehavior.HOLD) { for (int k = 0; k < req.Length; k++) { the_queue.Enqueue(req[k]); } } if (!success && config.ServiceUnavailableBehavior == ConfigLoader.UnavailableBehavior.PURGE) { req = null; } if (!success && config.ServiceUnavailableBehavior == ConfigLoader.UnavailableBehavior.HOLDPERSIST) { Logger.debug( DateTime.Now.ToString("o") + " Sendbulk items " + req.Length + " write to disk"); for (int k = 0; k < req.Length; k++) { WriteToDisk(req[k]); } Logger.debug(DateTime.Now.ToString("o") + " Sendbulk items " + req.Length + " write to disk done"); } } DoCallbacks_EmptyQueue(); if (!Enabled) the_queue.Clear(); if (the_queue.Count == 0) { DoCallbacks_LastMessageSent(); publishingThread.Remove(Thread.CurrentThread); return; } // list = null; } catch (Exception Exception) { _lasterror = Exception.GetType().FullName + " " + Exception.Message; Logger.error(Exception, "FGSMS.MessageProcessor" + " ProcessOutputMessage Data acquistion successful, but there was an error sending the information to the data collector."); } publishingThread.Remove(Thread.CurrentThread); Logger.debug( DateTime.Now.ToString("o") + " Sendbulk Thread exit"); if (dcsservice != null) { try { ((IClientChannel)dcsservice).Close(); ((IClientChannel)dcsservice).Dispose(); } catch (Exception ex) { // log.TraceEvent(TraceEventType.Warning, 0, "Uh oh" + ex.Message + ex.StackTrace); } } if (polservice != null) { try { ((IClientChannel)polservice).Close(); ((IClientChannel)polservice).Dispose(); } catch (Exception ex) { // log.TraceEvent(TraceEventType.Warning, 0, "Uh oh" + ex.Message + ex.StackTrace); } } }