Ejemplo n.º 1
0
        protected void Application_BeginRequest(object sender, EventArgs e)
        {

            HttpContext context = HttpContext.Current;
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;


            ELSLogs esLog = new ELSLogs();
            esLog.ElsUser = new ElsUserInfromation();
            esLog.ElsResponse = response.StatusCode;
            esLog.ElsIpaddress = request.UserHostAddress;
            esLog.ElsUser.UserId = "Tz";
            esLog.ElsRequest =
                "[" + DateTime.Now.ToString("dd/MMM/yyyy:HH:mm:ss.FFF zz") + "]" + " \"" + request.HttpMethod + " "
                + request.Path + "\" " + response.StatusCode + " " + request.TotalBytes + " \"" +
                request.UrlReferrer + "\" " + "\"" + request.UserAgent + "\"" + " " + request.Form;

            if (string.IsNullOrEmpty(request.Form.ToString()))
            {
                esLog.ElsRequest += "null";}
            QueryInfo i = new QueryInfo {Type = "logs", Size = 10,SearchText = "Beijing",Start =DateTime.Now.AddDays(-33),End=DateTime.Now};
           

             //Task.Run(() => ss(esLog));
           // sp(i);


            // _logHandler.CallMessageApi(request,response);

            // IRequestHandler ireRequestHandler=new RequestHandler();
            //IRequestHandler ireRequestHandler=new RequestHandler();
            // ireRequestHandler.CallMessageApi(request,response);

        }
Ejemplo n.º 2
0
 /// <param name='operations'>
 /// Reference to the WebApi.ILogMessage.
 /// </param>
 /// <param name='esLog'>
 /// Required.
 /// </param>
 public static object Post(this ILogMessage operations, ELSLogs esLog)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((ILogMessage)s).PostAsync(esLog);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Ejemplo n.º 3
0
        public void SendQueueAsyncAll(int num)
        {
            _queueError = false;
            HttpContext context = HttpContext.Current;
            ELSLogs esLog = new ELSLogs();
            esLog = (ELSLogs)context.Items[Userlog];

            if (_queue == null)
            {
                _queue = GetQueue();
                if (_queue == null)
                {
                    if (_connection == null)
                    {
                        _connection =
                            ConnectionMultiplexer.Connect(ConfigurationManager.ConnectionStrings["AzureRedis"].ToString());
                        if (_cache == null)
                        {
                            _cache = _connection.GetDatabase();
                        }
                    }
                    _queueError = true;
                }
            }

            //get Userlog object and fill with response information
            // String message = "";
            //  message += esLog.ElsIpaddress + " - - " + esLog.ElsRequest + " " + esLog.ElsResponse + " none";

            // string message = "115.88.32.21 luffy priate [" + DateTime.Now.ToString("dd/MMM/yyyy:HH:mm:ss.FFF zz") + "] \"PATCH /api/grade/3\" 206 172 \"http://elswebapi.azurewebsites.net/\" \"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36\" 2shift 204 none";
            //create multiple async task to send message to queue5
            var username = new ArrayList { "BingLi", "HuoYong", "Sherry", "Shot", "Tzkwizard", "Luffy", "Ace", "Fuji","Keith" };

            var auth = new ArrayList { "JianShi", "JiShi", "Godness", "Guarder", "Master", "Priate", "King", "Genius", "Detective" };

            var load = new ArrayList { "miejianxuelong", "yujiafengjie", "shengguang", "miejihaijian", "yazhi", "baqi", "fire", "qifan","icestop" };
            var api = new ArrayList
            {
                "GET /api/ElasticMapping/LogstashMap/",
                "POST /api/ElasticSearch/",
                "DELETE /api/cleangrade/",
                "PUT /api/grade/",
                "PATCH /api/grade/"
            };

            for (var i = 0; i < num; i++)
            {
                Random x = new Random();
                int p1 = x.Next(1, 256);
                int p2 = x.Next(1, 256);
                int p3 = x.Next(1, 256);
                int p4 = x.Next(1, 256);
                int r1 = x.Next(200, 208);
                int r2 = x.Next(300, 308);
                int b = x.Next(1, 1024);
                int m = x.Next(1, 22);
                int ap = x.Next(0, 5);
                int us = x.Next(0, 9);

                string message = p1 + "." + p2 + "." + p3 + "." + p4 + " " + username[us] + " " + auth[us] + " [" +
                    DateTime.Now.ToString("dd/MMM/yyyy:HH:mm:ss.FFF zz") + "]" + " \"" +
                    api[ap] + m + "\" " + +r1 + " " + b + " \"" + "http://LogSearch.azurewebsites.net/" +
                    "\" " + "\"" + "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36"
                    + "\"" + " " + load[us] + " " + r2 + " none";
                Thread.Sleep(10);
                var i1 = i;
                //Thread.Sleep(10);
                Task.Run(() => SendQueueAsync(i1, esLog, _queue, message));

            }






        }
Ejemplo n.º 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="i"></param>
        /// <param name="esLog"></param>
        /// <param name="queue"></param>
        /// <param name="message"></param>
        /// <returns></returns>

        private async Task SendQueueAsync(int i, ELSLogs esLog, CloudQueue queue, string message)
        {
            if (!_queueError)
            //create, fufill and send message
            {

                await queue.AddMessageAsync(new CloudQueueMessage(message));
            }
            else
            {

                _cache.ListLeftPush("s", message);
            }

        }
Ejemplo n.º 5
0
 /// <param name='operations'>
 /// Reference to the WebApi.ILogMessage.
 /// </param>
 /// <param name='esLog'>
 /// Required.
 /// </param>
 /// <param name='cancellationToken'>
 /// Cancellation token.
 /// </param>
 public static async Task<object> PostAsync(this ILogMessage operations, ELSLogs esLog, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     Microsoft.Rest.HttpOperationResponse<object> result = await operations.PostWithOperationResponseAsync(esLog, cancellationToken).ConfigureAwait(false);
     return result.Body;
 }
Ejemplo n.º 6
0
        private async Task ss(ELSLogs esLog)
        {
            HttpClient httpClient = new HttpClient();
            //string dd = JsonConvert.SerializeObject(esLog);
            string uri = "https://microsoft-apiapp463245e7d2084cb79dbc3d162e7b94cb.azurewebsites.net/api/LogMessage";
            var javaScriptSerializer = new
              System.Web.Script.Serialization.JavaScriptSerializer();
            string jsonString = javaScriptSerializer.Serialize(esLog);
            //Console.WriteLine(jsonString);
            // httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            // await httpClient.PostAsJsonAsync(uri, jsonString);

            await httpClient.PostAsync(uri, new StringContent(jsonString, Encoding.UTF8, "application/json"));
        }