/// <summary>
 ///     Initializes a new instance of the <see cref="XmppClient" /> class
 /// </summary>
 internal XmppClient()
 {
     _logger = Log.Get <XmppClient>();
     _logger.Log(LogLevel.Debug, $"{typeof(XmppClient)} created");
     ClientSocket = new AsyncClientSocket(this);
     Parser       = new Parser(this);
     Parser.Tag  += Parser_Tag;
 }
Example #2
0
        private void startClientSocket()
        {
            AsyncClientSocket client = new AsyncClientSocket();

            client.createSocketConnect("127.0.0.1", AsyncServerSocket.localPort,
                                       delegate(int port) {
                int index = cboClient.Items.Add(port);
                cboClient.SelectedIndex = index;

                clientMap.Add(port, client);
            });
        }
        public object Index([FromForm] string url)
        {
            // Create object to return
            APIResult result = new APIResult()
            {
                Status     = (int)APIStatus.Failure,
                Message    = "",
                URL        = url,
                Shortcut   = string.Empty,
                Popularity = 0
            };

            // Get the URL's SHA512 & SHA256 hash
            string sha512 = SHA512Hash.GetSHA512Hash(url);
            string sha256 = SHA256Hash.GetSHA256Hash(url);

            // Open up a connection to Cassandra
            CassandraConnection csConnection = new CassandraConnection();

            // Get connection session
            ISession csSession = csConnection.GetSession();

            // Lookup database and return the URL's signature if it exists
            SignatureLookup signatureLookup = new SignatureLookup(csSession);

            if (signatureLookup.LookupSignature(sha512, sha256, out string signature, out long hits))
            {
                result.Shortcut   = this.MakeShortcut(signature);
                result.Popularity = hits;
                result.Status     = (int)APIStatus.Success;
                return(Json(result));
            }

            // Get total URL count from the running service
            long id = 0;

            try
            {
                const string BOT           = "<~BOT~>";
                const string EOT           = "<~EOT~>";
                const string COMMAND_COUNT = "COUNT";

                string message = string.Format("{0}{1}{2}", BOT, COMMAND_COUNT, EOT);
                string ip      = "127.0.0.1";
                int    port    = 7079;

                AsyncClientSocket asyncClientSocket = new AsyncClientSocket();
                asyncClientSocket.Transmit(ip, port, message, out string response);
                //SyncClientSocket.Transmit(ip, port, message, out string response);

                if (response == string.Empty)
                {
                    result.Message = "Service Unavailable!";
                    return(Json(result));
                }

                id = long.Parse(response);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            // Prepare dictionary
            char[] dictionary =
            {
                'A', 'B', 'C', 'D', 'E', 'F',
                'G', 'H', 'I', 'J', 'K', 'L',
                'M', 'N', 'O', 'P', 'Q', 'R',
                'S', 'T', 'U', 'V', 'W', 'X',
                'Y', 'Z',

                'a', 'b', 'c', 'd', 'e', 'f',
                'g', 'h', 'i', 'j', 'k', 'l',
                'm', 'n', 'o', 'p', 'q', 'r',
                's', 't', 'u', 'v', 'w', 'x',
                'y', 'z',

                '0', '1', '2', '3', '4', '5',
                '6', '7', '8', '9'
            };

            // Get signature
            signature = BaseN.ChangeBase(id, dictionary);

            // Unique signature is now set
            result.Shortcut = this.MakeShortcut(signature);

            // Insert the new URL into the database
            URLInsertion urlInsertion = new URLInsertion(csSession);

            if (urlInsertion.InsertURL(url, signature, sha512, sha256))
            {
                result.Popularity = 1;
                result.Status     = (int)APIStatus.Success;
            }

            return(Json(result));
        }
 public TcpConnectModule(AsyncClientSocket client)
 {
     clientHost = client;
 }