public async Task TrackEvent(string eventName, uint userId, string parameters, bool isTest = false) { eventName.Check(s => !string.IsNullOrWhiteSpace(s), "eventName"); var payload = new PayloadEntity { At = DateTime.UtcNow.GetEpochUtc(), Event = eventName, Nr = IncrementSerial(ref this._sessionSerial), UserId = userId, Parameters = parameters, IsTesting = isTest }; payload.Ip = await GetIp(); var ce = this.CreateCollectionEntity(new List <PayloadEntity> { payload }); await this._persistentStorage.Add(new SessionCollection { SessionId = this._sessionId, Collection = ce }); // Trigger publish mechanism await this.SendItemsToCollector(); }
public static async Task <DataTableEntity> MapPayloadToTableEntityAsync(string payloadJsonString) { DataTableEntity dataTableEntity = new DataTableEntity(ConfigReader.PartitionKey, Guid.NewGuid()); List <PayloadEntity> payloadList = new List <PayloadEntity>(); PayloadEntity data = await GeneralHelpers.ConvertToObject(payloadJsonString); payloadList.Add(data); foreach (PayloadEntity payload in payloadList) { dataTableEntity.DataFormat = payload.DataFormat; dataTableEntity.Humidity = payload.Humidity; dataTableEntity.Temperature = payload.Temperature; dataTableEntity.Pressure = payload.Pressure; dataTableEntity.Battery = payload.Battery; } return(await Task.FromResult(dataTableEntity)); }
private void Run() { try { progressBar1.Value = 0; GetLastRun(); string restFreight = "freight/dailyUpdate"; string restVegetables = "vegetables/dailyUpdateQuotation/" + collectDateVeg.ToString("yyyy-MM-dd"); if (collectDateFreight == DateTime.MinValue) { restFreight = "freight/historic"; updateStatus("Downloading freight historical data. "); } else { updateStatus("Looking for freight data since: " + strDateFreight); } if (collectDateVeg == DateTime.MinValue) { restVegetables = "vegetables/historicQuotation"; updateStatus("Downloading vegetables historical data. "); } else { updateStatus("Looking for vegetables data since: " + strDateVeg); } //textBox1.Text = ""; button1.Text = "Processing..."; button1.Enabled = false; ScicropEntity se = new ScicropEntity(); PayloadEntity payloadEntity = new PayloadEntity(); Freight freight = new Freight(); freight.Date = strDateFreight; List <Freight> freightList = new List <Freight>(); freightList.Add(freight); payloadEntity.FreightLst = freightList; VegetablesQuotationEntity vegetablesQuotationEntity = new VegetablesQuotationEntity(); vegetablesQuotationEntity.PriceDate = strDateVeg; List <VegetablesQuotationEntity> vegs = new List <VegetablesQuotationEntity>(); vegs.Add(vegetablesQuotationEntity); payloadEntity.VegetablesQuotationEntities = vegs; se.PayloadEntity = payloadEntity; string jsonStr = UrlHelper.Instance.PostScicropEntityJsonBA(restFreight, se, authEntity.UserEntity.Email, authEntity.UserEntity.Hash); se = ScicropEntity.FromJson(jsonStr); freightList = se.PayloadEntity.FreightLst; if (freightList.Count > 0) { int i = 1; updateStatus("Inserting " + freightList.Count + " freight offer(s)."); foreach (var item in freightList) { updateStatus(item.Load.LoadName + ": " + item.SourceCity.Name + " > " + item.DestinationCity.Name); DbConnector dbc = new DbConnector(); try { dbc.InsertFreight(item); } catch (Exception e) { updateStatus(e.Message); } progressBar1.Maximum = freightList.Count; progressBar1.Value = i; i++; } updateStatus("All freight data inserted."); } else { updateStatus("No new freight data was found."); } WriteEventLog("Freight data collected (" + freightList.Count + " | REST: " + restFreight + " | " + isSilent + ")"); GetLastRun(); jsonStr = UrlHelper.Instance.GetScicropEntityJsonBA(restVegetables, authEntity.UserEntity.Email, authEntity.UserEntity.Hash); se = ScicropEntity.FromJson(jsonStr); vegs = se.PayloadEntity.VegetablesQuotationEntities; if (vegs.Count > 0) { int i = 1; updateStatus("Inserting " + vegs.Count + " vegetables quotation(s)."); foreach (var item in vegs) { updateStatus(item.VegName + ": " + item.VegPrice + " from " + item.IbgeUfId); DbConnector dbc = new DbConnector(); try { dbc.InsertVegetableQuotation(item); } catch (Exception e) { updateStatus(e.Message); } progressBar1.Maximum = vegs.Count; progressBar1.Value = i; i++; } updateStatus("All Vegetables data inserted."); } else { updateStatus("No new Vegetables data was found."); } WriteEventLog("Vegetables data collected (" + vegs.Count + " | REST: " + restVegetables + " | " + isSilent + ")"); GetLastRun(); } catch (Exception ex) { updateStatus("Error: " + ex.Message); } finally { button1.Enabled = true; button1.Text = "Run"; if (this.isSilent) { System.Environment.Exit(0); } } }