Exemplo n.º 1
0
        public async Task <IActionResult> PutEventDictionaryItem(long id, EventDictionaryItem EventDictionaryItem)
        {
            if (id != EventDictionaryItem.PackageId)
            {
                return(BadRequest());
            }

            _context.Entry(EventDictionaryItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventDictionaryItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <EventDictionaryItem> > PostEventDictionaryItem(EventDictionaryItem eventDictionaryItem)
        {
            Stopwatch processingStopwatch = Stopwatch.StartNew();

            // _context.EventDictionaryItems.Add(EventDictionaryItem);
            // await _context.SaveChangesAsync();

            processingStopwatch.Stop();

            // Set return values
            eventDictionaryItem.ProcessingDateTime = DateTime.UtcNow;
            eventDictionaryItem.Count            = 1;
            eventDictionaryItem.ProcessingServer = Environment.MachineName;

            return(CreatedAtAction("GetEventDictionaryItem", new EventDictionaryItem {
                PackageId = eventDictionaryItem.PackageId
            }, eventDictionaryItem));
        }
Exemplo n.º 3
0
        private static async Task SendEventDictionary(IDictionary <string, object> eventDictionary)
        {
            bool uploadSuccessful;

            try
            {
                // Get a random server name from the configured list
                string receiverServer = "localhost";
                string receiverPort   = "5000";

                Stopwatch uploadStopWatch = Stopwatch.StartNew();

                // Create a client, and add the authentication cert
                var        _clientHandler = new HttpClientHandler();
                HttpClient Client         = new HttpClient(_clientHandler);

                var eventDictionaryItem = new EventDictionaryItem
                {
                    PackageId       = 0,
                    EventDictionary = eventDictionary,
                    UploadServer    = Environment.MachineName,
                    UploadDateTime  = DateTime.UtcNow
                };

                // Build the client data for the file metrics
                try
                {
                    string uri = $"http://{receiverServer}:{receiverPort}/api/EventDictionary";

                    var parameters = Newtonsoft.Json.JsonConvert.SerializeObject(eventDictionaryItem);

                    var req = WebRequest.Create(uri);

                    req.Method      = "POST";
                    req.ContentType = "application/json";

                    byte[] bytes = Encoding.ASCII.GetBytes(parameters);

                    req.ContentLength = bytes.Length;

                    using (var os = req.GetRequestStream())
                    {
                        os.Write(bytes, 0, bytes.Length);

                        os.Close();
                    }

                    var stream = req.GetResponse().GetResponseStream();

                    if (stream != null)
                    {
                        using (stream)
                            using (var sr = new StreamReader(stream))
                            {
                                string streamResult = sr.ReadToEnd().Trim();

                                var returnEventDictionaryItem = JsonConvert.DeserializeObject <EventDictionaryItem>(streamResult);

                                PrintToConsole(
                                    $"Processed {returnEventDictionaryItem.Count} record(s) in {(returnEventDictionaryItem.ProcessingDateTime - returnEventDictionaryItem.UploadDateTime).TotalMilliseconds:N2} milliseconds.");
                            }
                    }
                }
                catch (Exception e)
                {
                    uploadSuccessful = false;
                }

                Client.Dispose();

                uploadStopWatch.Stop();
            }
            catch (Exception ex)
            {
                ExceptionHandler(ex);
            }
        }