示例#1
0
        private async Task <IDictionary <string, string> > ProcessLoginAsync()
        {
            try
            {
                if (!string.IsNullOrEmpty(KioskConfigurationHepler.GetValueFromSecurity("UserEncrypted")))
                {
                    var user = GetUserInfos();

                    var result = await EnsureApiTokenAsync(user[0], user[1]);

                    if (result.ContainsKey("error"))
                    {
                        _log.Error("ProxyService" + result["error"]);

                        throw new Exception("ProxyService ==> ProcessLogin got Exception please check log" + result["error"]);
                    }

                    KioskConfigurationHepler.UpdateValueForElement("Token", result["access_token"]);

                    KioskConfigurationHepler.UpdateValueForElement("RefreshToken", result["refresh_token"]);

                    return(result);
                }

                return(null);
            }
            catch (Exception ex)
            {
                _log.Error("ProxyService" + ex);
                throw new Exception("ProxyService ==> ProcessLogin got Exception please check log", ex);
            }
        }
        private async Task <KioskDto> CreateKioskAsync(CountryDto countryDto, GroupDto groupDto)
        {
            _log.Debug("Begin ProcessKioskAsync Create");

            var defaultValue = await _collectDeviceService.CollectDeviceInfoAsync();

            _log.Debug("defaultValue: " + defaultValue);

            var kiosk = await _apiService.CreateKioskAsync(new KioskDto
            {
                MachineId    = KioskConfigurationHepler.GetValueFromSecurity(MACHINE_ID),
                Name         = SettingsConfigurationCommon.MACHINE_NAME,
                GroupId      = groupDto.Id,
                CountryId    = countryDto.Id,
                IpAddress    = UnitHelper.GetLocalIPAddress(),
                Address      = GeoLocaltion.GetCountryName(),
                DefaultValue = defaultValue,
                Status       = KioskStatus.online,
                Long         = GeoLocaltion.GetLongitude(),
                Lat          = GeoLocaltion.GetLatitude()
            });

            _log.Debug("UnitHelper.GetMacAddress() " + UnitHelper.GetMacAddress());

            await _apiService.UpdateKioskSecurityByKeyAsync(KioskConfigurationHepler.GetValueFromSecurity(LICENSE_KEY), new KioskSecurityDto
            {
                MacAddress = UnitHelper.GetMacAddress(),
                IsActive   = true
            });

            return(kiosk);
        }
        private async Task <KioskDto> ProcessKioskAsync()
        {
            try
            {
                _log.Debug("Begin ProcessKioskAsync");

                var kiosk = await _apiService.FindKioskByMachineIdAsync(KioskConfigurationHepler.GetValueFromSecurity(MACHINE_ID));

                if (kiosk == null)
                {
                    CountryDto countryDto = await _apiService.FindCountryByNameAsync(GeoLocaltion.GetCountryName());

                    GroupDto groupDto = await _apiService.FindGroupByNameAsync("Unknow");

                    return(await CreateKioskAsync(countryDto, groupDto));
                }
                else
                {
                    return(await UpdateKioskAsync(kiosk, kiosk.GroupId, kiosk.CountryId));
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                throw new Exception("Please check log with error from SignalRClientProvider ==> ProcessKioskAsync: " + ex.Message, ex);
            }
        }
示例#4
0
        private string[] GetUserInfos()
        {
            string userEncrypted = KioskConfigurationHepler.GetValueFromSecurity("UserEncrypted");
            string saltKey       = KioskConfigurationHepler.GetValueFromSecurity("SaltKey");
            string viKey         = KioskConfigurationHepler.GetValueFromSecurity("VIKey");
            string passwordHash  = KioskConfigurationHepler.GetValueFromSecurity("PasswordHash");

            return(UnitHelper.Decrypt(userEncrypted, passwordHash, saltKey, viKey).Split('&'));
        }
示例#5
0
 private void BindBearer()
 {
     Bearer = KioskConfigurationHepler.GetValueFromSecurity("Token");
     if (string.IsNullOrEmpty(Bearer))
     {
         var result = ProcessLoginAsync().Result;
         if (result != null)
         {
             Bearer = result["access_token"];
         }
     }
 }
        public void OnSuccess(IHubProxy hubProxy)
        {
            _log.Debug("Connected signalr OnSuccess");
            do
            {
                if (!_isStartCollectData)
                {
                    _apiService.UpdateConnectionIdAsync(KioskConfigurationHepler.GetValueFromSecurity(MACHINE_ID), _signalR.ConnectionId);
                    _isStartCollectData = true;
                }

                AsyncHelper.RunSync(() => DoWork(null));
            } while (_isStartCollectData);
        }
示例#7
0
        private void ProcessPanelLiscense()
        {
            var licenseKey = KioskConfigurationHepler.GetValueFromSecurity("LicenseKey");

            if (!string.IsNullOrEmpty(licenseKey))
            {
                BindSetting();
                txt_license_key.Text   = licenseKey;
                panel_liscense.Enabled = false;
            }
            else
            {
                panel_liscense.Enabled = true;
            }
        }
示例#8
0
 private void UpdateKioskSecurity(KioskSecurityDto kioskSecurityDto)
 {
     if (kioskSecurityDto != null)
     {
         var item = kioskSecurityDto.EncryptionUser;
         KioskConfigurationHepler.UpdateValueForElement("LicenseKey", txt_license_key.Text);
         KioskConfigurationHepler.UpdateValueForElement("UserEncrypted", item.UserEncrypted);
         KioskConfigurationHepler.UpdateValueForElement("SaltKey", item.SaltKey);
         KioskConfigurationHepler.UpdateValueForElement("VIKey", item.VIKey);
         KioskConfigurationHepler.UpdateValueForElement("PasswordHash", item.PasswordHash);
         KioskConfigurationHepler.UpdateValueForElement("MachineId", kioskSecurityDto.MachineId);
         KioskConfigurationHepler.UpdateValueForElement("ClientId", kioskSecurityDto.ClientId);
         BindSetting();
     }
     else
     {
         MessageBox.Show("License key is invalid");
         panel_liscense.Enabled = true;
     }
 }
        public virtual void Run(ObjectState objectState)
        {
            _objectState = objectState;
            var querystringData = new Dictionary <string, string>();

            querystringData.Add("access_token", KioskConfigurationHepler.GetValueFromSecurity("Token"));
            querystringData.Add("refresh_token", KioskConfigurationHepler.GetValueFromSecurity("RefreshToken"));
            querystringData.Add("clientId", objectState.ClientId);
            querystringData.Add("groupName", objectState.GroupName);
            querystringData.Add("systemName", objectState.MachineName);
            querystringData.Add("machineId", objectState.MachineId);
            querystringData.Add("role", "");

            _connection = new HubConnection(_objectState.SignalrUrl, querystringData);
            _hubProxy   = _connection.CreateHubProxy(SettingsConfigurationKiosks.HUB_NAME);
            _connection.Reconnecting   += () => OnReconnecting(_hubProxy);
            _connection.Reconnected    += () => OnReconnect(_hubProxy);
            _connection.ConnectionSlow += () => OnConnectionSlow(_hubProxy);

            _connection.Start().ContinueWith(OnComplete);
        }
示例#10
0
        private void RefreshToken()
        {
            string refreshToken = KioskConfigurationHepler.GetValueFromSecurity("RefreshToken");

            try
            {
                if (!string.IsNullOrEmpty(refreshToken))
                {
                    var result = RefreshApiTokenAsync(refreshToken).Result;
                    KioskConfigurationHepler.UpdateValueForElement("Token", result["access_token"]);
                    KioskConfigurationHepler.UpdateValueForElement("RefreshToken", result["refresh_token"]);
                    Bearer = result["access_token"];
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                KioskConfigurationHepler.UpdateValueForElement("Token", "");
                BindBearer();
                throw new Exception("There is an exception that was happening at server when refreshing token. Please check the error log: " + ex.Message);
            }
        }
示例#11
0
        protected override void OnStart(string[] args)
        {
            try
            {
                _log.Debug("Begin OnStart");
                if (KioskConfigurationHepler.GetValueFromSecurity("LicenseKey") == null && KioskConfigurationHepler.GetValueFromSecurity("LicenseKey") == "")
                {
                    _log.Error("Can't start service with LicenseKey is empty please input LicenseKey before start service thanks");
                    throw new Exception("Can't start service with LicenseKey is empty please input LicenseKey before start service thanks");
                }

                _log.Debug("OnStart Client");
                _process = ResolverFactory.GetService <Process>();
                _process.Start();
                _log.Debug("OnStarted");
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                OnStop();
            }
        }
示例#12
0
        public virtual void Start()
        {
            _log.Debug("Begin Start");

            _log.Debug("ProcessKioskAsync");

            _kioskDto = AsyncHelper.RunSync(() => ProcessKioskAsync());

            _log.Debug("GetClientByClientId");

            _clientDto = AsyncHelper.RunSync(() => _apiService.GetClientByClientId(KioskConfigurationHepler.GetValueFromSecurity(CLIENT_ID)));

            _log.Debug("Begin connect signalR server");

            _signalR.OnSuccess        += OnSuccess;
            _signalR.OnReconnect      += OnReconnect;
            _signalR.OnConnectionSlow += OnConnectionSlow;
            _signalR.OnReconnecting   += OnReconnecting;
            _signalR.OnBeforeStop     += OnBeforeStop;

            _signalR.Run(new ObjectState(_kioskDto, _clientDto));

            _log.Debug("End Start");
        }