Ejemplo n.º 1
0
        public static string SendMessage(MessageFormat msg,string SharedKey)
        {
            try
            {
                string connectionString = string.Format("Endpoint=sb://myflow-ns.servicebus.windows.net/;SharedAccessKeyName={0};SharedAccessKey={1}", msg.PolicyName, SharedKey);
                string JsonMessage = JsonConvert.SerializeObject(msg);
                var jsonObjStream = new MemoryStream(Encoding.UTF8.GetBytes(JsonMessage));
                MessagingFactory factory = MessagingFactory.CreateFromConnectionString(connectionString);
                MessageSender MessageSender = factory.CreateMessageSender("flowspec");
                BrokeredMessage Message = new BrokeredMessage(jsonObjStream);
                MessageSender.Send(Message);
                if (msg.Action == "Add")
                {
                    return "The Filter is added";
                }
                else
                {
                    return "The Filter is removed";
                }

            }
            catch (MessagingCommunicationException)
            {

                return "Client is not able to establish a connection to Service Bus.";
            }

            catch (UnauthorizedAccessException)
            {
                return "PolicyName or SharedAccessKey is incorrect";
            }
        }
Ejemplo n.º 2
0
 public static string Remove(string Action,string Ticket, string Hash, string PolicyName,string SharedAccessKey)
 {
     MessageFormat msg = new MessageFormat();
     msg.Hash = Hash;
     msg.PolicyName = PolicyName;
     msg.Ticket = Ticket;
     msg.Action = Action;
     string SharedKey = SharedAccessKey;
     string op1 = servicebusMessage.SendMessage(msg, SharedKey);
     return op1;
 }
Ejemplo n.º 3
0
        public static string Add(string DestinationPrefix, string SourcePrefix, string DestinationPort, string SourcePort, 
            string PolicyName, string Protocol, string Comment, string Treatment, string Action,
            string lookups, string Ticket, string Hash, string SharedAccessKey, string ttl)
        {
            MessageFormat msg = new MessageFormat();
            if (lookups == "no")
            {
                //IpWhoIs.IpLookup IpSrc = null;
                //IpWhoIs.IpLookup IpDest = null;
                msg.DestinationGEO = null;
                msg.SourceGEO = null;
                msg.DestinationWHOIS = null;
                msg.SourceWHOIS = null;

            }
            else
            {
                string DestIP = (DestinationPrefix).Split('/')[0];
                IpWhoIs.IpLookup IpDest = IpWhoIs.WhoIs(DestIP);
                string SrcIP = (SourcePrefix).Split('/')[0];
                IpWhoIs.IpLookup IpSrc = IpWhoIs.WhoIs(SrcIP);
                msg.DestinationGEO = IpDest.regionName;
                msg.SourceGEO = IpSrc.regionName;
                msg.DestinationWHOIS = IpDest.org;
                msg.SourceWHOIS = IpSrc.org;
            }

            if ( Action == "Add")
            {

                msg.DestinationPrefix = (DestinationPrefix == "") ? msg.DestinationPrefix = "0.0.0.0/0" : msg.DestinationPrefix = DestinationPrefix;
                msg.DestinationPort = (DestinationPort == "") ? msg.DestinationPort = 0 : msg.DestinationPort = Int32.Parse(DestinationPort);
                msg.SourcePrefix = (SourcePrefix == "") ? msg.SourcePrefix = "0.0.0.0/0" : msg.SourcePrefix = SourcePrefix;
                msg.SourcePort = (SourcePort == "") ? msg.SourcePort = 0 : msg.SourcePort = Int32.Parse(SourcePort);
                msg.TTL = (ttl == "") ? msg.TTL = 86400 : msg.TTL = Int32.Parse(ttl);
                msg.PolicyName = PolicyName;
                msg.Protocol = (Protocol == "") ? msg.Protocol = 0 : msg.Protocol = Int32.Parse(Protocol);
                msg.Comment = Comment;
                msg.Treatment = Treatment;
                msg.Action = Action;
                msg.lookups = lookups;
                msg.DestinationDNS = null;
                msg.SourceDNS = null;
                msg.Ticket = Ticket;
                msg.Hash = Hash;
                string SharedKey = SharedAccessKey;
                string op = servicebusMessage.SendMessage(msg, SharedKey);
                return op;
            }
            else
            {
                msg.Hash = Hash;
                msg.PolicyName = PolicyName;
                msg.Ticket = Ticket;
                msg.Action = Action;
                string SharedKey = SharedAccessKey;
                string op1=   servicebusMessage.SendMessage(msg, SharedKey);
                return op1;

            }
        }