Example #1
0
        public virtual void SaveSettings()
        {
            if (Settings == null)
            {
                throw new System.Exception("Settings not initialized, cannot save");
            }

            // validate
            Settings.Validate();

            // encrypt
            _dataSaver.SaveDataAsync(Settings, _config.SettingsPath).GetAwaiter().GetResult();
        }
Example #2
0
        public async Task <string> SaveResponseAndSetDeleteTimeout(object response, string identifier = null)
        {
            // save data
            var guid = identifier ?? Guid.NewGuid().ToString();
            await _dataSaver.SaveDataAsync(response, guid);

            // mark calc. as not active
            var propsImportant = new List <string> {
                "Log", "IsSuccess"
            };
            var objProps = response.GetType().GetProperties().Where(x => propsImportant.Contains(x.Name));

            var logProp   = objProps.FirstOrDefault(x => x.Name == "Log");
            var logValues = logProp != null?logProp.GetValue(response) as IList <string> : null;

            var isSuccessProp  = objProps.FirstOrDefault(x => x.Name == "IsSuccess");
            var isSuccessValue = isSuccessProp != null?isSuccessProp.GetValue(response) as bool? : null;

            var log       = logValues;
            var isSuccess = isSuccessValue ?? false;

            StopCalculation(guid, false, log, isSuccess);


            // set up timer
            _activeTimersLock.EnterWriteLock();
            try
            {
                if (_activeTimers == null)
                {
                    _activeTimers = new Dictionary <string, Chronos <string, Task <bool> > >();
                }

                var timer = new Chronos <string, Task <bool> >();
                timer.SetTimeout(DeleteAssociatedData, TimeSpan.FromHours(_hoursToKeepData), guid);
                _activeTimers.Add(guid, timer);
            }
            finally
            {
                _activeTimersLock.ExitWriteLock();
            }

            // clean used data
            GC.Collect();

            return(guid);
        }