Exemple #1
0
        public void Start()
        {
            try
            {
                Logger.WriteDebug(MethodBase.GetCurrentMethod(), "Starting");
                var stopWatch = new Stopwatch();
                stopWatch.Start();

                IsRunning   = false;
                _apiService = null;

                if (string.IsNullOrEmpty(Settings.Default.Alarmapp_ApiToken))
                {
                    Logger.WriteDebug(MethodBase.GetCurrentMethod(), "AuthToken not set");
                    return;
                }

                _apiService = new AlarmappApiService(Settings.Default.Alarmapp_ApiToken);
                timerAlarmEnd_Elapsed(this, null); // reset pagerlist & alarmId
                registerEvents();
                IsRunning = true;

                stopWatch.Stop();
                Logger.WriteDebug(MethodBase.GetCurrentMethod(), $"Started -> {stopWatch.Elapsed}");
            }
            catch (Exception ex)
            {
                ExceptionOccured.RaiseEvent(this, new ExceptionEventArgs
                {
                    Methode = MethodBase.GetCurrentMethod(),
                    Error   = ex
                });
            }
        }
Exemple #2
0
        public bool Refresh(string apiToken, string organisationId)
        {
            try
            {
                if (string.IsNullOrEmpty(apiToken))
                {
                    Logger.WriteDebug(MethodBase.GetCurrentMethod(), "apiToken not set");
                    return(false);
                }

                if (string.IsNullOrEmpty(organisationId))
                {
                    Logger.WriteDebug(MethodBase.GetCurrentMethod(), "organisationId not set");
                    return(false);
                }

                _apiService = new AlarmappApiService(apiToken);

                //Check departments and alarmgroups
                var _alarmgroupsResult = _apiService.GetAlarmgroups(organisationId);
                if (_alarmgroupsResult == null)
                {
                    Logger.WriteDebug(MethodBase.GetCurrentMethod(), "GetAlarmgroups -> fail");
                    return(false);
                }

                //Check alarmgroups
                var dbDepartment = _business.GetAlarmappDepartmentById(organisationId);
                if (dbDepartment == null)
                {
                    Logger.WriteDebug(MethodBase.GetCurrentMethod(), $"add new department -> {organisationId}");
                    dbDepartment = new AlarmappDepartment();
                    dbDepartment.DepartmentId   = organisationId;
                    dbDepartment.DepartmentName = organisationId; //we dont get a name at the moment
                    dbDepartment = _business.AddOrUpdateAlarmappDepartment(dbDepartment);
                }

                //dbDepartment.DepartmentName = department.name;
                _business.AddOrUpdateAlarmappDepartment(dbDepartment);

                foreach (var alarmgroup in _alarmgroupsResult)
                {
                    var dbGroup = _business.GetAlarmappGroupByGroupId(alarmgroup.id);
                    if (dbGroup == null)
                    {
                        Logger.WriteDebug(MethodBase.GetCurrentMethod(), $"add new alarmgroup -> {alarmgroup.name}");
                        dbGroup            = new AlarmappGroup();
                        dbGroup.Department = dbDepartment;
                        dbGroup.GroupId    = alarmgroup.id;
                        dbGroup.GroupName  = alarmgroup.name;
                        dbGroup            = _business.AddOrUpdateAlarmappGroup(dbGroup);
                    }

                    dbGroup.GroupName = alarmgroup.name;
                    _business.AddOrUpdateAlarmappGroup(dbGroup);
                }

                Settings.Default.Alarmapp_ApiToken       = apiToken;
                Settings.Default.Alarmapp_OrganisationId = organisationId;
                Settings.Default.Save();

                Logger.WriteDebug(MethodBase.GetCurrentMethod(), "Refresh -> OK");
                return(true);
            }
            catch (Exception ex)
            {
                ExceptionOccured.RaiseEvent(this, new ExceptionEventArgs
                {
                    Methode = MethodBase.GetCurrentMethod(),
                    Error   = ex
                });
                return(false);
            }
        }