/// <summary> /// Get's The Binary Data From A Received UDP Message /// </summary> /// <param name="ar">Gets the received message</param> private void EndUDPRecieve(IAsyncResult ar) { EDXLDE temp; if (this.udpRecieveClient.Client != null) { try { byte[] recieveBytes = this.udpRecieveClient.EndReceive(ar, ref this.udpSubscribeEndPoint); this.udpRecieveClient.BeginReceive(this.udpRecieveCallback, this.udpRecieveClient); string recieveString = Encoding.ASCII.GetString(recieveBytes); // We Have An EDXL Terminator if (recieveString.Contains("</EDXLDistribution>")) { temp = new EDXLDE(recieveString); this.recvQ.EnQueue(new NameObject <string, EDXLDE>(this.udpString, temp)); this.messageReceived.Invoke(); } } catch (ObjectDisposedException e) { //// throw e; e.Message.ToString(); } catch (NullReferenceException e) { throw e; } catch (Exception e) { throw e; } } }
private void FederateDE(EDXLDE de, string[] fedUris) { //TODO:figure out how to federate all DE //TODO:build unique list of endpoints in case more than one match to same destination foreach (string uri in fedUris) { DoPost(new Uri(uri), de); } }
/// <summary> /// Thread Operation for the Receive Queue /// </summary> private void RecvQThr() { EDXLDE temp; while (this.recvEnabled) { temp = new EDXLDE(this.tcpReciever.TCPRecieveQ.DeQueue()); this.recvQ.EnQueue(new NameObject <string, EDXLDE>(this.tcpString, temp)); this.messageReceived.Invoke(); } }
/// <summary> /// Forwards the DE to another webserver. /// </summary> /// <param name="requesturi">The location to where the DE should be forwarded.</param> /// <param name="distributionElement">The DE to be forwarded</param> private void DoPost(Uri requesturi, EDXLDE distributionElement) { try { HttpWebRequest request; HttpWebResponse resp; string s = distributionElement.WriteToXML(); s = s.Replace("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"no\"?>\r\n", String.Empty); request = (HttpWebRequest)WebRequest.Create(requesturi); request.KeepAlive = true; request.Method = "POST"; request.ContentType = "text/xml"; request.AllowAutoRedirect = true; request.ContentLength = Encoding.UTF8.GetByteCount(s); this.SetBody(request, s); resp = null; resp = (HttpWebResponse)request.GetResponse(); resp.Close(); }catch (Exception e) { Log.Error("Error POSTing to " + requesturi + ": " + e.Message); } }
/// <summary> /// Thread worker method /// </summary> private void PollSQS() { Log.Info("InThreadSQS"); while (true) { Log.Info("SQSLoop"); ReceiveMessageRequest req = new ReceiveMessageRequest(); req.QueueUrl = AWSConstants.FederationProcessingQueueUrl; Log.Info("Federation URL: " + req.QueueUrl); req.WaitTimeSeconds = AWSConstants.FederationProcessing.PollIntervalInSeconds; ReceiveMessageResponse resp = this.amazonSQSClient.ReceiveMessage(req); Log.Info("Got " + resp.Messages.Count + " messages from SQS"); foreach (Message m in resp.Messages) { try { Log.Info(m.Body); string queueBody = m.Body; int hash = -1; JObject json = JObject.Parse(queueBody); // Get the deHash from the JSON hash = Int32.Parse(json.GetValue("DEHash").ToString()); Log.Info(hash); EDXLDE de = dbDal.ReadDE(hash); Log.Info(de.WriteToXML()); // Get the URIs from the JSON string[] fedUris = json.GetValue("FederationURIs").ToObject <string[]>(); Log.Info(fedUris); switch (de.DistributionType) { case TypeValue.Report: case TypeValue.Update: FederateDE(de, fedUris); break; case TypeValue.Cancel: break; default: Log.Error("Got unexpected distributiontype"); break; } DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest(); deleteMessageRequest.QueueUrl = req.QueueUrl; deleteMessageRequest.ReceiptHandle = m.ReceiptHandle; try { DeleteMessageResponse sqsdelresp = this.amazonSQSClient.DeleteMessage(deleteMessageRequest); if (sqsdelresp.HttpStatusCode == System.Net.HttpStatusCode.OK) { Log.Info("Message removed from queue"); } else { Log.Error("SQS Delete error: " + sqsdelresp.HttpStatusCode.ToString()); } } catch (Exception e) { Log.Error("Error deleting from SQS", e); } } catch (Exception e) { Log.Error(e); } } } }
/// <summary> /// Populate EDXLViewerForm with the specified message /// </summary> /// <param name="mNO">EDXL Message to be displayed in the form</param> private void MShowEDXLDE(NameObject <string, EDXLDE> mNO) { if (mNO != null) { EDXLDE deobj = (EDXLDE)mNO.Value; this.mLabelDistibutionID.Text = deobj.DistributionID; this.mLabelSenderID.Text = deobj.SenderID; this.mLabelDateTimeSent.Text = deobj.DateTimeSent.ToString(); if (deobj.DistributionStatus.HasValue) { this.mLabelDistributionStatus.Text = deobj.DistributionStatus.Value.ToString(); } if (deobj.DistributionType.HasValue) { this.mLabelDistributionType.Text = deobj.DistributionType.Value.ToString(); } this.mLabelLanguage.Text = deobj.Language; // setup Explicit Address if (deobj.ExplicitAddress.Count > 0) { this.mComboBoxExplicitAddress.Items.Clear(); this.mLabelExplicitAddressCount.Text = deobj.ExplicitAddress.Count.ToString(); foreach (object obj in deobj.ExplicitAddress) { this.mComboBoxExplicitAddress.Items.Add(((ValueScheme)obj).ExplicitAddressScheme); } this.mComboBoxExplicitAddress.SelectedIndex = 0; } else { this.mComboBoxTargetArea.Items.Clear(); this.mLabelExplicitAddressCount.Text = "0"; } // setup Target Area if (deobj.TargetArea.Count > 0) { this.mComboBoxTargetArea.Items.Clear(); this.mLabelTargetAreaCount.Text = deobj.TargetArea.Count.ToString(); foreach (object obj in deobj.TargetArea) { this.mComboBoxTargetArea.Items.Add(((TargetAreaType)obj).ToString()); } this.mComboBoxTargetArea.SelectedIndex = 0; } else { this.mComboBoxTargetArea.Items.Clear(); this.mLabelTargetAreaCount.Text = "0"; } // setup Content Object if (deobj.ContentObjects.Count > 0) { this.mComboBoxContentObject.Items.Clear(); this.mLabelContentObjectCount.Text = deobj.ContentObjects.Count.ToString(); foreach (object obj in deobj.ContentObjects) { this.mComboBoxContentObject.Items.Add(((ContentObject)obj).IncidentID); } this.mComboBoxContentObject.SelectedIndex = 0; } else { this.mComboBoxContentObject.Items.Clear(); this.mLabelContentObjectCount.Text = "0"; } // Routing Options // Sender Role if (deobj.SenderRole != null && deobj.SenderRole.Count > 0) { this.mComboBoxSenderRole.Items.Clear(); this.mLabelSenderRoleCount.Text = deobj.SenderRole.Count.ToString(); foreach (object obj in deobj.SenderRole) { this.mComboBoxSenderRole.Items.Add(((ValueList)obj).ValueListURN); } this.mComboBoxSenderRole.SelectedIndex = 0; } else { this.mComboBoxSenderRole.Items.Clear(); this.mLabelSenderRoleCount.Text = "0"; } // Recipient Role if (deobj.RecipientRole != null && deobj.RecipientRole.Count > 0) { this.mComboRecipientRole.Items.Clear(); this.mLabelRecipientRoleCount.Text = deobj.RecipientRole.Count.ToString(); foreach (object obj in deobj.RecipientRole) { this.mComboRecipientRole.Items.Add(((ValueList)obj).ValueListURN); } this.mComboRecipientRole.SelectedIndex = 0; } else { this.mComboRecipientRole.Items.Clear(); this.mLabelRecipientRoleCount.Text = "0"; } // Keyword if (deobj.Keyword != null && deobj.Keyword.Count > 0) { this.mComboBoxKeyword.Items.Clear(); this.mLabelKeywordCount.Text = deobj.Keyword.Count.ToString(); foreach (object obj in deobj.Keyword) { this.mComboBoxKeyword.Items.Add(((ValueList)obj).ValueListURN); } this.mComboBoxKeyword.SelectedIndex = 0; } else { this.mComboBoxKeyword.Items.Clear(); this.mLabelKeywordCount.Text = "0"; } // Distribution Reference if (deobj.DistributionReference != null && deobj.DistributionReference.Count > 0) { this.mComboBoxDistributionReference.Items.Clear(); this.mLabelDistributionRefCount.Text = deobj.DistributionReference.Count.ToString(); foreach (object obj in deobj.DistributionReference) { this.mComboBoxDistributionReference.Items.Add((string)obj); } this.mComboBoxDistributionReference.SelectedIndex = 0; } else { this.mComboBoxDistributionReference.Items.Clear(); this.mLabelDistributionRefCount.Text = "0"; } // show the xml message string xmltemp = null; try { xmltemp = deobj.WriteToXML(); this.mTextBoxXML.Text = xmltemp; this.mTextBoxXML.BackColor = Color.LightGray; } catch (Exception e) { string[] temp = new string[2]; temp[0] = "Sent non-valid xml. Reported error(s) below:"; temp[1] = e.Message; this.mTextBoxXML.Lines = temp; this.mTextBoxXML.BackColor = Color.LightPink; } string protocolMessage = mNO.Name; if (protocolMessage != null && protocolMessage.Length > 0) { this.mLabelProtocol.Text = "Carrier = " + protocolMessage; this.mLabelProtocol.Show(); } else { this.mLabelProtocol.Text = string.Empty; this.mLabelProtocol.Hide(); } } }
/// <summary> /// Places an EDXL-DE Message In Queue To Be Sent /// </summary> /// <param name="message">EDXL Message To Send</param> public void Send(EDXLDE message) { this.sendQ.EnQueue(message); }