public void GetHashCode_Matches(string username, IPEndPoint endpoint) { var a = new ConnectionKey(username, endpoint); var b = new ConnectionKey(username, endpoint); Assert.Equal(a.GetHashCode(), b.GetHashCode()); }
public void Equals_Handles_Null_And_Null_IPEndPoint() { var a = new ConnectionKey(null, new IPEndPoint(new IPAddress(0x0), 1)); ConnectionKey b = null; Assert.False(a.Equals(b)); }
/*=========================*/ #endregion #region Delete Methods /*=========================*/ /// <summary> /// Activate stored procedure Sp_Delete_Table_Days that delete /// all the data in the DB for the required Day. /// </summary> protected void DeleteDayChannel(int dayCode, string tableName, int channelID, int accountID) { using (ConnectionKey key = DataManager.Current.OpenConnection()) { // Initalize stored procedure Sp_Delete_Table_Days. SqlCommand deleteDayStoredProcedureCmd = DataManager.CreateCommand("Sp_Delete_Table_Days(@Table_Name:NVarChar, @Account_ID:NVarChar,@Day:NVarChar, @Channel_ID:NVarChar)", CommandType.StoredProcedure); deleteDayStoredProcedureCmd.CommandTimeout = 30000; // Init Paramters deleteDayStoredProcedureCmd.Parameters["@Table_Name"].Value = tableName; deleteDayStoredProcedureCmd.Parameters["@Account_ID"].Value = accountID; deleteDayStoredProcedureCmd.Parameters["@Day"].Value = dayCode.ToString(); deleteDayStoredProcedureCmd.Parameters["@Channel_ID"].Value = channelID; try { // Activate stored procedure. deleteDayStoredProcedureCmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Error activate stored procedure Delete Table Days.", ex); } } }
public UDPFixedPort(ConnectionKey parKey, IPAddress parAdapterIP, UInt16 parPort) : base(parKey, parAdapterIP) { port = parPort; client = new UdpClient(new IPEndPoint(adapterIP, port)); client.EnableBroadcast = true; }
public void GetHashCode_Matches(string username, IPAddress ipAddress, int port) { var a = new ConnectionKey(username, ipAddress, port); var b = new ConnectionKey(username, ipAddress, port); Assert.Equal(a.GetHashCode(), b.GetHashCode()); }
public void GetHashCode_Does_Not_Match_If_Key_Differs() { var a = new ConnectionKey("a", new IPAddress(0x0), 1); var b = new ConnectionKey("b", new IPAddress(0x0), 1); Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); }
public void Equals_Handles_Null_And_Null_Username() { var a = new ConnectionKey("a", null); ConnectionKey b = null; Assert.False(a.Equals(b)); }
/// <summary> /// Activate stored procedure SP_Content_Add_Total_Imps_Measure. /// This SP deletes the relevant "content total imps" records by the accout_id, Channel_id & day_code /// and recalculates the missing imps between creative (search) data and content data, /// Then adds the diff imps as new record in content table /// </summary> public void ActivateContentSP() { using (ConnectionKey key = DataManager.Current.OpenConnection()) { // Initalize stored procedure Sp_Delete_Table_Days. SqlCommand contentSPCmd = DataManager.CreateCommand("SP_Content_Add_Total_Imps_Measure(@Account_ID:NVarChar,@Day_Code:NVarChar, @Channel_ID:NVarChar)", CommandType.StoredProcedure); contentSPCmd.CommandTimeout = 30000; // Init Paramters contentSPCmd.Parameters["@Account_ID"].Value = _accountID; contentSPCmd.Parameters["@Day_Code"].Value = GetDayCode(_requiredDay); contentSPCmd.Parameters["@Channel_ID"].Value = _channelID; try { // Activate stored procedure. contentSPCmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Error activate content stored procedure.", ex); } } }
public void Equals_Handles_Null_Username_And_IPEndPoint() { var a = new ConnectionKey(null, new IPEndPoint(new IPAddress(0x0), 1)); var b = new ConnectionKey("a", null); Assert.False(a.Equals(b)); Assert.False(b.Equals(a)); }
public void Equals_Handles_Both_Null_Usernames() { var a = new ConnectionKey(null, new IPEndPoint(new IPAddress(0x0), 1)); var b = new ConnectionKey(null, new IPEndPoint(new IPAddress(0x0), 1)); Assert.True(a.Equals(b)); Assert.True(b.Equals(a)); }
public void Equals_Handles_Both_Null_IPEndPoints() { var a = new ConnectionKey("a", null); var b = new ConnectionKey("a", null); Assert.True(a.Equals(b)); Assert.True(b.Equals(a)); }
public void Equals_Returns_False_When_Port_Differs() { var a = new ConnectionKey("a", new IPEndPoint(new IPAddress(0x0), 1)); var b = new ConnectionKey("a", new IPEndPoint(new IPAddress(0x0), 2)); Assert.False(a.Equals(b)); Assert.False(b.Equals(a)); }
public void Equals_Returns_True_When_Equal() { var a = new ConnectionKey("a", new IPEndPoint(new IPAddress(0x0), 1)); var b = new ConnectionKey("a", new IPEndPoint(new IPAddress(0x0), 1)); Assert.True(a.Equals(b)); Assert.True(b.Equals(a)); }
public void Equals_Returns_False_When_Not_Equal() { var a = new ConnectionKey("a", new IPAddress(0x0), 1); var b = new ConnectionKey("a", new IPAddress(0x1), 1); Assert.False(a.Equals(b)); Assert.False(b.Equals(a)); }
public void Equals_Returns_False_When_Different_Type() { var a = new ConnectionKey("a", new IPAddress(0x0), 1); var b = "foo"; Assert.False(a.Equals(b)); Assert.False(b.Equals(a)); }
public void Equals_Returns_True_When_Equal() { var a = new ConnectionKey("a", new IPAddress(0x0), 1, MessageConnectionType.Default); var b = new ConnectionKey("a", new IPAddress(0x0), 1, MessageConnectionType.Default); Assert.True(a.Equals(b)); Assert.True(b.Equals(a)); }
const double MAX_IDLE = 120; //See RFC 4787 Section 4.3 public UDPSession(ConnectionKey parKey, IPAddress parAdapterIP) : base(parKey, parAdapterIP) { lock (deathClock) { deathClock.Start(); } }
internal void Get_Returns_Null_Given_Null_Or_Missing_Key(ConnectionKey key) { var c = new ConnectionManager <IConnection>(); var conn = c.Get(key); Assert.Null(conn); }
public void Equals_Handles_Boxed_Instances() { var a = new ConnectionKey("a", new IPAddress(0x0), 1); var b = new ConnectionKey("a", new IPAddress(0x0), 1); Assert.True(a.Equals((object)b)); Assert.True(b.Equals((object)a)); }
void IConnectable.SetConnectionKey(ConnectionKey connectionKey) { if (Node == null) { TrySetNode(); } Node.Mapper.GetRoot().ConnectionKey = connectionKey; }
internal void GetOrAdd_Queues_Connections( string username, IPAddress ipAddress, int port, string username2, IPAddress ipAddress2, int port2, EventHandler <Message> messageHandler, ConnectionOptions options, int token) { var key1 = new ConnectionKey(username, ipAddress, port, MessageConnectionType.Peer); var key2 = new ConnectionKey(username2, ipAddress2, port2, MessageConnectionType.Peer); var tokenFactory = new Mock <ITokenFactory>(); tokenFactory.Setup(m => m.GetToken()) .Returns(token); var conn = new Mock <IMessageConnection>(); conn.Setup(m => m.Key) .Returns(key1); conn.Setup(m => m.WriteAsync(It.IsAny <byte[]>(), It.IsAny <CancellationToken>())) .Returns(() => Task.CompletedTask); var conn2 = new Mock <IMessageConnection>(); conn2.Setup(m => m.Key) .Returns(key2); conn2.Setup(m => m.WriteAsync(It.IsAny <byte[]>(), It.IsAny <CancellationToken>())) .Returns(() => Task.CompletedTask); var connFactory = new Mock <IConnectionFactory>(); connFactory.Setup(m => m.GetMessageConnection(MessageConnectionType.Peer, username, ipAddress, port, options)) .Returns(conn.Object); connFactory.Setup(m => m.GetMessageConnection(MessageConnectionType.Peer, username2, ipAddress2, port2, options)) .Returns(conn2.Object); var c = new ConnectionManager(1, tokenFactory.Object, connFactory.Object); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed c.GetOrAddUnsolicitedConnectionAsync(key1, username, messageHandler, options, CancellationToken.None); c.GetOrAddUnsolicitedConnectionAsync(key2, username, messageHandler, options, CancellationToken.None); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Assert.Equal(1, c.ActivePeerConnections); Assert.Equal(1, c.WaitingPeerConnections); var firstConn = c.GetProperty <ConcurrentDictionary <ConnectionKey, (SemaphoreSlim Semaphore, IMessageConnection Connection)> >("PeerConnections").First(); c.InvokeMethod("RemoveMessageConnection", firstConn.Value.Connection); Thread.Sleep(100); Assert.Equal(1, c.ActivePeerConnections); Assert.Equal(0, c.WaitingPeerConnections); firstConn = c.GetProperty <ConcurrentDictionary <ConnectionKey, (SemaphoreSlim Semaphore, IMessageConnection Connection)> >("PeerConnections").First(); c.InvokeMethod("RemoveMessageConnection", firstConn.Value.Connection); Thread.Sleep(100); Assert.Equal(0, c.ActivePeerConnections); Assert.Equal(0, c.WaitingPeerConnections); }
public UDPSession(ConnectionKey parKey, IPAddress parAdapterIP, byte[] parBroadcastIP) : base(parKey, parAdapterIP) { broadcastAddr = parBroadcastIP; lock (deathClock) { deathClock.Start(); } }
public UDP_DHCPSession(ConnectionKey parKey, NetworkInterface parAdapter, byte[] parIP, byte[] parNetmask, byte[] parGateway, byte[] parDNS1, byte[] parDNS2) : base(parKey, IPAddress.Any) { //DirectAdapter PS2IP = parIP; HandleNetMask(parAdapter, parNetmask); HandleGateway(parAdapter, parGateway); HandleDNS(parAdapter, parDNS1, parDNS2); HandleBroadcast(PS2IP, NetMask); #region ICS //Special case for ICS if (Gateway == null & PSE.CLR_PSE_Utils.IsWindows()) { //Retrieve ICS IP from Regs byte[] icsIP; try { using (Microsoft.Win32.RegistryKey localKey = Microsoft.Win32.RegistryKey.OpenBaseKey( Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64)) { using (Microsoft.Win32.RegistryKey icsKey = localKey.OpenSubKey("System\\CurrentControlSet\\Services\\SharedAccess\\Parameters")) { icsIP = IPAddress.Parse((string)icsKey.GetValue("ScopeAddress")).GetAddressBytes(); } } } catch { icsIP = new byte[] { 192, 168, 137, 1 }; } //Check if adapter has ICS IP //If so, then adapter is being shared to via ICS IPInterfaceProperties properties = parAdapter.GetIPProperties(); UnicastIPAddressInformationCollection IPInfoCollection = properties.UnicastAddresses; foreach (UnicastIPAddressInformation IPInfo in IPInfoCollection) { if (IPInfo.Address.AddressFamily == AddressFamily.InterNetwork) { byte[] addrB = IPInfo.Address.GetAddressBytes(); if (Utils.memcmp(addrB, 0, icsIP, 0, 4)) { Gateway = icsIP; if (parDNS1 == null) { DNS1 = icsIP; } } } } } #endregion }
// mapped bulk insert internal static Result <T> ExecuteBulkInsert <T>(Assembly client, IEnumerable <T> rows, ConnectBy connectBy) where T : DbRow { if (rows == null) { throw new QueryTalkException("Importer.ExecuteBulkInsert<T>", QueryTalkExceptionType.ArgumentNull, "rows = null", Text.Method.BulkInsertGo); } if (rows.Count() == 0) { return(new Result <T>(false, 0)); } Crud.CheckTable(rows.First(), Text.Method.BulkInsertGo); var first = rows.First(); var nodeID = ((DbRow)first).NodeID; var nodeMap = DbMapping.GetNodeMap(nodeID); var table = nodeMap.Name.ToString(); var data = rows.ToDataTable(); try { ConnectionKey connKey = null; if (connectBy != null) { connKey = ((IConnectable)connectBy).ConnectionKey; } var connectionString = ConnectionManager.InvokeConnectionFunc(client, connKey).ConnectionString; using (SqlConnection cn = new SqlConnection(connectionString)) { cn.Open(); using (SqlBulkCopy bulkCopy = new SqlBulkCopy(cn)) { bulkCopy.DestinationTableName = table; foreach (var column in nodeMap.GetInsertableColumns(false)) { bulkCopy.ColumnMappings.Add(column.Name.Part1, column.Name.Part1); } bulkCopy.WriteToServer(data); } } return(new Result <T>(true, rows.Count())); } catch (QueryTalkException ex) { ex.Method = Text.Method.BulkInsertGo; throw; } }
public UDPFixedPort(ConnectionKey parKey, IPAddress parAdapterIP, UInt16 parPort) : base(parKey, parAdapterIP) { Port = parPort; client = new UdpClient(); client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); client.Client.Bind(new IPEndPoint(adapterIP, Port)); client.EnableBroadcast = true; }
public UDPSession NewClientSession(ConnectionKey parNewKey, bool parIsBrodcast) { UDPSession udp = new UDPSession(parNewKey, adapterIP, parIsBrodcast, client); udp.ConnectionClosedEvent += HandleChildConnectionClosed; lock (connectionSentry) { connections.Add(udp); } return(udp); }
public UDPServerSession NewListenSession(ConnectionKey parNewKey) { UDPServerSession udp = new UDPServerSession(parNewKey, adapterIP, client); udp.ConnectionClosedEvent += HandleChildConnectionClosed; lock (connectionSentry) { connections.Add(udp); } return(udp); }
public void Instantiates_With_IP_EndPoint() { var ip = new IPEndPoint(new IPAddress(0x0), 1); ConnectionKey k = null; var ex = Record.Exception(() => k = new ConnectionKey(ip)); Assert.Null(ex); Assert.NotNull(k); Assert.Equal(ip.Address, k.IPEndPoint.Address); Assert.Equal(1, k.IPEndPoint.Port); }
public void Instantiates_With_IP_And_Port() { var ip = new IPAddress(0x0); ConnectionKey k = null; var ex = Record.Exception(() => k = new ConnectionKey(ip, 0)); Assert.Null(ex); Assert.NotNull(k); Assert.Equal(ip, k.IPAddress); Assert.Equal(0, k.Port); }
/// <summary> /// Gets the current query parameters a dictionary. /// </summary> /// <returns>dictionary of query parameters.</returns> public Dictionary <string, string> GetParams() { var result = new Dictionary <string, string>(); if (AuthMethod == AuthMethod.Basic) { result["key"] = AuthValue; } else { result["accessToken"] = AuthValue; } result["v"] = Defaults.ProtocolVersion; result["lib"] = Defaults.LibraryVersion; // Url encode all the params at the time of creating the query string result["format"] = UseBinaryProtocol ? "msgpack" : "json"; result["echo"] = EchoMessages.ToString().ToLower(); if (ConnectionKey.IsNotEmpty()) { result["resume"] = ConnectionKey; if (ConnectionSerial.HasValue) { result["connection_serial"] = ConnectionSerial.Value.ToString(); } } else if (RecoverValue.IsNotEmpty()) { var match = RecoveryKeyRegex.Match(RecoverValue); if (match.Success) { result["recover"] = match.Groups[1].Value; result["connection_serial"] = match.Groups[2].Value; } } if (ClientId.IsNotEmpty()) { result["clientId"] = ClientId; } if (AdditionalParameters?.Any() ?? false) { return(AdditionalParameters.Merge(result)); } return(result); }
public async Task <IActionResult> Key(ConnectionKey connectionKey) { if (db.Keys.Count() != 0) { foreach (var element in db.Keys) { db.Keys.Remove(element); } } db.Keys.Add(connectionKey); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public ICMPSession(ConnectionKey parKey, ConcurrentDictionary<ConnectionKey, Session> parConnections) : base(parKey, IPAddress.Any) { connections = parConnections; }
public override bool Send(IPPayload payload) { ICMP icmp = (ICMP)payload; switch (icmp.Type) { case 8: //Echo //Code == zero Log_Verb("Send Ping"); lock (sentry) { open += 1; } PingData pd; pd.Data = icmp.Data; pd.HeaderData = icmp.HeaderData; Ping nPing = new Ping(); nPing.PingCompleted += PingCompleate; lock (sentry) { pings.Add(nPing); } nPing.SendAsync(new IPAddress(DestIP), pd); System.Threading.Thread.Sleep(1); //Hack Fix break; case 3: // switch (icmp.Code) { case 3: Log_Error("Recived Packet Rejected, Port Closed"); IPPacket retPkt = new IPPacket(icmp); byte[] srvIP = retPkt.SourceIP; byte prot = retPkt.Protocol; UInt16 srvPort = 0; UInt16 ps2Port = 0; switch (prot) { case (byte)IPType.TCP: TCP tcp = (TCP)retPkt.Payload; srvPort = tcp.SourcePort; ps2Port = tcp.DestinationPort; break; case (byte)IPType.UDP: UDP udp = (UDP)retPkt.Payload; srvPort = udp.SourcePort; ps2Port = udp.DestinationPort; break; } ConnectionKey Key = new ConnectionKey(); Key.IP0 = srvIP[0]; Key.IP1 = srvIP[1]; Key.IP2 = srvIP[2]; Key.IP3 = srvIP[3]; Key.Protocol = prot; Key.PS2Port = ps2Port; Key.SRVPort = srvPort; Session s; connections.TryGetValue(Key, out s); if (s != null) { s.Reset(); Log_Info("Reset Rejected Connection"); } else { Log_Error("Failed To Reset Rejected Connection"); } break; default: throw new NotImplementedException("Unsupported ICMP Code For Destination Unreachable" + icmp.Code); } break; default: throw new NotImplementedException("Unsupported ICMP Type" + icmp.Type); } return true; }
public TCPSession(ConnectionKey parKey, IPAddress parAdapterIP) : base(parKey, parAdapterIP) { }
public Session(ConnectionKey parKey, IPAddress parAdapterIP) { adapterIP = parAdapterIP; Key = parKey; }