public async Task SleepTask() { _log.Debug("Starting sleep task"); await Task.Delay(2000); _log.Debug("Finished sleep task"); }
public override void Initialize() { CreatableTypes() .EndingWith("Service") .AsInterfaces() .RegisterAsLazySingleton(); log = Mvx.IoCProvider.Resolve <IMvxLog>(); appSettings = Mvx.IoCProvider.Resolve <IAppSettings>(); TpsSerializer tpsSerializer = new TpsSerializer(log); FcsMessageSerializer fcsMessageSerializer = new FcsMessageSerializer(log); log.Debug("App: Initializing FcsService,TpsService and saleStatus as singleton.."); Mvx.IoCProvider.LazyConstructAndRegisterSingleton <ITpsService>(() => new TpsService(log, appSettings.TpsIpAddress, appSettings.TpsPort, tpsSerializer)); Mvx.IoCProvider.LazyConstructAndRegisterSingleton <IFcsService>(() => new FcsService(log, fcsMessageSerializer)); Mvx.IoCProvider.LazyConstructAndRegisterSingleton <Printer>(() => new Printer(appSettings)); Mvx.IoCProvider.LazyConstructAndRegisterSingleton <IDBAccess>(() => new DBAccess()); Mvx.IoCProvider.ConstructAndRegisterSingleton(typeof(PosManager)); Mvx.IoCProvider.ConstructAndRegisterSingleton(typeof(IPAddressManager)); Mvx.IoCProvider.LazyConstructAndRegisterSingleton <IReceiptGenerator>(() => new ReceiptGenerator( Mvx.IoCProvider.Resolve <PosManager>(), AppLanguage.multi, appSettings.FuelUnitPriceDecimal )); log.Debug("App: Load and configure all the neccessary settings.."); LoadAppSettings(); ConfigurePaymentServer(); ConfigureFcsServer(); RegisterAppStart <MainViewModel>(); }
public async Task <bool> SendCommand(CommandType commandType) { bool success = false; var device = _slot.ConnectedDevice; if (device == null) { _log.Debug($"Tried to send the command <{commandType}> but the device is set to null."); return(success); } if (device.CommandCharacteristic == null) { _log.Debug($"Tried to send the command <{commandType}> but the device does not have a valid characteristic for it."); return(success); } try { byte[] data = { (byte)commandType }; _log.Debug($"Writing to characteristic command <{commandType}>."); success = await device.CommandCharacteristic.WriteAsync(data); _log.Debug($"Writing complete for characteristic command <{commandType}>."); } catch (Exception e) { _log.Debug($"Error: Characteristic write cannot be completed. {e.Message}"); } return(success); }
/// <summary> /// Handles the selection of a device by the user /// </summary> /// <param name="deviceViewModel">Device view model.</param> private async void HandleSelectedDevice() { _log.Info("Attempting to handle selected bluetooth device"); // Check bluetooth status and if not on, exit if (!_bluetoothService.IsOn) { _log.Info("Bluetooth is not on"); _userDialogs.Toast($"\tError: {_bluetoothService.StateText}"); return; } // Device is already connected if (IsConnected) { _log.Info("Device is already connected. Attempting to disconnect."); Task.Run(async() => await TryToDisconnectDevice()); _log.Debug("Disconnection task <TryToDisconnectDevice> has been spawned."); return; } // Device has not connected yet else { _log.Info("Connecting to device."); var slots = _deviceSlotService.GetAvailableSlots(); var buttons = new List <string>(); if (slots.Count > 0) { foreach (var slotIndex in slots) { try { string name = _deviceSlotService.SlotName[slotIndex]; buttons.Add(name); } catch (KeyNotFoundException) { _userDialogs.Alert("Invalid slot index value"); return; } } var result = await _userDialogs.ActionSheetAsync("Which device?", "Cancel", null, null, buttons.ToArray()); if (result == "Cancel") { return; } var selected = _deviceSlotService.SlotName.IndexOf(result); await Task.Run(async() => await TryToConnectDevice(selected)); return; } else { _userDialogs.Alert("Please disconnect from a device before attempt to connect to another one"); } } }
private void ConfirmSomething() { var confirmActionModel = new ConfirmActionModel() { ConfirmActionCallback = async(confirmed) => { await HandleConfirmationResult(confirmed); } }; _log.Debug("Ask the user to confirm."); _confirmInteraction.Raise(confirmActionModel); }
public override async Task Initialize() { log.Debug("GradesViewModel: ViewModel is initializing."); await base.Initialize(); FuelUnitPriceDecimal = appSettings.FuelUnitPriceDecimal; IsDecimalButtonEnabled = true; GetGrades(); log.Debug("HomeViewModel: ViewModel initialization is finished."); return; }
public async Task Open(long epochTime) { if (_objectOpen) { return; } _log.Debug("Logger opened"); await CreateNewLogFile(epochTime); }
/// <inheritdoc /> public string?TryGetDeviceCountryCode() { if (!TryGetSimBasedCountryCode(out string?code)) { _log.Debug("Couldn't receive the country code from sim."); _ = TryGetLocalCountryCode(out code); _log.Debug($"Local country code is: {code}"); } return(string.IsNullOrEmpty(code) ? null : code !.ToUpper(CultureInfo.InvariantCulture)); }
private void LoadAppSettings() { log.Debug("App: Loading app settings..."); var appLangauge = appSettings.DefaultLanguage; Enum.TryParse(appLangauge.ToLower(), out AppLanguage lang); log.Debug("App: Set current culture " + appLangauge); SetLanguage(lang); var posType = appSettings.PosType; log.Debug("App: Set current culture " + posType); SetPosType(posType); }
private DeviceCountryIdentifier(IMvxLogProvider mvxLogProvider) { _log = mvxLogProvider.GetLogFor <DeviceCountryIdentifier>(); _telephonyManager = new CTTelephonyNetworkInfo(); _log.Debug(_telephonyManager == null ? $"{nameof(CTTelephonyNetworkInfo)} is null" : $"{nameof(CTTelephonyNetworkInfo)} is not null"); }
public MainOffersViewModel( IWebpageService webpageService, IBrowserService browserService, IMvxNavigationService navigationService, IUnitOfWork unitOfWork, ISnackbarMessageQueue snackbarMessageQueue, IMvxLog logger ) { _webpageService = webpageService; _browserService = browserService; _navigationService = navigationService; _unitOfWork = unitOfWork; SnackbarMessageQueue = snackbarMessageQueue; _logger = logger; Offers = new MvxObservableCollection <OfferViewModel>(); GetDataFromWebpageCommand = new MvxAsyncCommand(GetDataFromWebpage, CanGetDataFromWebpage); NavigateToOfferViewCommand = new MvxAsyncCommand(NavigateToOfferView); UpdatePricesCommand = new MvxAsyncCommand(UpdatePrices, CanUpdatePrices); DeleteCommand = new MvxAsyncCommand(DeleteOffer, CanDeleteOffer); InfoText = "Uruchomiono"; _logger.Debug("test uruchomiono MainOffersViewModel"); }
public override async void ViewAppeared() { log.Debug("PrintReportViewModel: View is appeared."); base.ViewAppeared(); App.CultureChange += OnCultureChangeAsync; try { log.Debug("PrintReportViewModel: Printing report."); printer.PrintReportReceipt(report); await this.navigationService.Navigate <HomeViewModel>(); } catch (Exception ex) { log.ErrorException(string.Format("PrintReportViewModel: Exception:{0}. ", ex.Message), ex); } }
public TpsService(IMvxLog log, string ipAddress, int port, TpsSerializer tpsSerializer) { this.log = log; IpAddress = ipAddress; Port = port; this.tpsSerializer = tpsSerializer; log.Debug("TpsService: Tps IpAddress:{0}, port:{1}", ipAddress, port); client = new AsyncNetTcpClient(ipAddress, port); log.Debug("TpsService: Suscribing ConnectionEstablished, FrameArrived and Connection closed events."); client.ConnectionEstablished += ConnectionEstablished; client.FrameArrived += FrameArrived; client.ConnectionClosed += ConnectionClosed; log.Debug("TpsService: Creating new instance of awaitaible client"); awaitaibleClient = new AwaitaibleAsyncNetTcpClient(client); }
public override async Task Initialize() { log.Debug("ReprintReceiptDataViewModel: View Model is initializing."); await base.Initialize(); Receipt = ""; await GetReceiptData(); log.Debug("ReprintReceiptDataViewModel: View Model initialization is finished."); }
public string SerializeTpsRequest(TpsRequest tpsRequest, bool appendEndData = true) { log.Debug("TpsSerializer: Serializing tps request."); StringBuilder csvBuilder = new StringBuilder(); using (var writer = new StringWriter(csvBuilder)) using (var csvWriter = new CsvWriter(writer)) { csvWriter.Configuration.HasHeaderRecord = false; csvWriter.WriteRecord(tpsRequest); } if (appendEndData) { csvBuilder.Append(",END-DATA"); } log.Debug("TpsSerializer: Returning serialized data."); return(csvBuilder.ToString()); }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var totalElapsedTime = Stopwatch.StartNew(); _log.Debug(string.Format("Request: {0}", request)); if (request.Content != null) { var content = await request.Content.ReadAsStringAsync().ConfigureAwait(false); _log.Debug(string.Format("Request Content: {0}", content)); } var responseElapsedTime = Stopwatch.StartNew(); var response = await base.SendAsync(request, cancellationToken); _log.Debug(string.Format("Response: {0}", response)); if (response.Content != null) { var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); _log.Debug(string.Format("Response Content: {0}", content)); } responseElapsedTime.Stop(); _log.Debug(string.Format("Response elapsed time: {0} ms", responseElapsedTime.ElapsedMilliseconds)); totalElapsedTime.Stop(); _log.Debug(string.Format("Total elapsed time: {0} ms", totalElapsedTime.ElapsedMilliseconds)); return(response); }
public DataLoggingService(IMvxLog log) { _log = log; FileStreams = new Dictionary <int, FileStream>(); timeStampBlockingCollection = new BlockingCollection <double>(); // Setup stopwatch. _stopWatch = new Stopwatch(); _stopWatch.Start(); //Task.Run(() => ProcessCollectionAsync(0)); //Task.Run(() => ProcessCollectionAsync(1)); Task.Run(() => ProcessTimeSyncCollectionAsync()); _log.Debug("Data logging service loaded."); }
public List <string> GetV4Ips() { try { log.Debug("IPAddressManager: Trying to fetch local ip addresses"); return(Dns.GetHostAddresses(Dns.GetHostName()) .Where(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) .ToList() .Select(ip => ip.ToString()) .ToList()); } catch (Exception ex) { log.ErrorException(string.Format("IPAddressManager: Exception: {0}.", ex.Message), ex); return(null); } }
/// <summary> /// Enqueues the data and starts the data threads to commence write to file. /// </summary> /// <param name="data">Data.</param> public void EnqueueData(Collection <DataProfile> data) { if (!DataWriter1.IsAlive) { foreach (var d in data) { queue1.Enqueue(d); } if (!DataWriter2.IsAlive) { DataWriter1 = new Thread(() => PopAndWrite(queue1)) { IsBackground = true }; DataWriter1.Start(); } } else if (!DataWriter2.IsAlive) { foreach (var d in data) { queue2.Enqueue(d); } if (!DataWriter1.IsAlive) { DataWriter2 = new Thread(() => PopAndWrite(queue2)) { IsBackground = true }; DataWriter2.Start(); } } else { _log.Debug("DATA IS LEAKING"); } }
public override async Task Initialize() { log.Debug("ReprintReceiptViewModel: View Model is initialized."); await base.Initialize(); SelectedDate = DateTime.Now; }
public byte[] Serialize(string xmlCommand) { log.Debug("FcsMessageSerializer: Serializing xml command."); log.Debug("FcsMessageSerializer:Sending xml Message to Fcs: {0}", xmlCommand); byte[] bytes = null; BinaryFormatter binFmt = new BinaryFormatter(); using (MemoryStream memStream = new MemoryStream(xmlCommand.Length + 4)) { BinaryWriter binWriter = new BinaryWriter(memStream, Encoding.UTF8); byte headerStart = 0X01; binWriter.Write(headerStart); binWriter.Write(sequenceNumber++); if (sequenceNumber == 128) { // Maximum sequence number is 127 sequenceNumber = 1; } binWriter.Write(xmlCommand.Length); binWriter.Write(xmlCommand); binWriter.Write(0X04); bytes = memStream.GetBuffer(); } return(bytes); }
public string GetPassword(string U_CODE) { try { log.Debug("DBAccess: Get user password."); string epw = null; var connectionString = appSettings.CSCAdminDBConnectionString; const string queryString = @" select EPW from [USER] where U_CODE=@U_CODE"; ExecuteQuery(connectionString, queryString, (dataReader) => { if (dataReader.Read()) { epw = dataReader[0].ToString(); } }, new List <SqlParameter>() { new SqlParameter("@U_CODE", System.Data.SqlDbType.NVarChar) { Value = U_CODE } }, false); if (epw == null) { return(""); } var pswd = new EncryptionManager(); var decryptedText = pswd.DecryptText(epw); return(decryptedText); } catch (Exception ex) { log.DebugException(string.Format("Error: DBAccess:GetPassword() {0}", ex.Message), ex); return(""); } }
/// <summary> /// Gets the available characteristics. /// </summary> /// <returns>The available characteristics.</returns> /// <param name="sensorDevice">Sensor device.</param> public async Task <List <ICharacteristic> > GetAvailableCharacteristics(SensorDevice sensorDevice) { var discoveredCharacteristics = new List <ICharacteristic>(); // Attempt to get characteristics populated in the adapter device. var services = await sensorDevice.Device.GetServicesAsync(); foreach (var service in services) { var characteristics = await service.GetCharacteristicsAsync(); foreach (var characteristic in characteristics) { _log.Debug(characteristic.Name + " " + characteristic.Uuid); try { // Filter out only the ones we are interested in. if (_validCharacteristicUuids.Contains(characteristic.Uuid)) { // Change from characteristic to internal DataType. discoveredCharacteristics.Add(characteristic); } } catch (Exception e) { _log.Debug(e.Message); } } } return(discoveredCharacteristics); }
public override void Prepare(int parameter) { log.Debug("CardTenderViewModel: Receiving pumpId {0} as parameter.", parameter); pumpId = parameter; }
public override async void ViewAppeared() { log.Debug("PrintReceiptViewModel: View is appeared."); base.ViewAppeared(); App.CultureChange += OnCultureChangeAsync; try { log.Debug("PrintReceiptViewModel: Printing receipt."); Print(); await Navigate(); } catch (Exception ex) { log.ErrorException("PrintReceiptViewModel: ", ex); } }
public override async void ViewAppeared() { log.Debug("RefundStatusViewModel: View is appeared."); App.CultureChange += OnCultureChangeAsync; if (posManager.ActiveSale.RefundStatus == Enums.RefundApprovalStatus.RefundApproved) { this.IsRefundApproved = true; } else { this.IsRefundApproved = false; } if (IsRefundApproved) { log.Debug("RefundStatusViewModel: Refund is approved."); await OnRefundApproved(); } else { log.Debug("RefundStatusViewModel: Refund is not approved."); await OnRefundNotApproved(); } await GoToHome(); base.ViewAppeared(); }
public async Task ConnectAsync() { var connected = false; do { try { log.Debug("TpsService: Trying to re-connect until connection is established."); awaitaiblePeer = await awaitaibleClient.ConnectAsync(); connected = true; } catch { log.Debug("TpsService: Trying to connect but failed and wait for 2s."); await Task.Delay(2000); // Todo: take retry time value from config or use Poly } } while (!connected); }
public override void Prepare(string message) { log.Debug("ConfirmationViewModel: Receiving message:{0} as parameter.", message); Message = message; }
public override void ViewAppearing() { log.Debug("PrepayViewModel: View Appearing"); base.ViewAppearing(); App.CultureChange += OnCultureChangeAsync; }
public override void ViewAppearing() { log.Debug("LogoutViewModel: View is appearing."); base.ViewAppearing(); App.CultureChange += OnCultureChangeAsync; }