Example #1
0
        private void ProcessReduceLevels(Dictionary<string, List<ReduceLevel>> aggregatedReduceLevels, IDbConnection conn)
        {
            //Basically resoving the foreign key reference
            var allReduceLevels = _storageCommands.SelectListAllReduceLevels(conn);
            foreach (var level in allReduceLevels)
            {
                level.AggregationClass = _settings.ReduceMethodProvider.Retrieve(level.AggregationClassName);

                //TODO This is a problem... this really doesn't work!
                var reduceLevelList = aggregatedReduceLevels.SetDefault(level.MonitorConfigName, new List<ReduceLevel>());
                reduceLevelList.Add(level);
            }

            //Validate that the reduce level resolutions are all integral multiples of one another
            foreach (var reduceLevels in aggregatedReduceLevels.Values)
            {
                long lastResolution = 0;
                foreach (var reduceLevel in reduceLevels)
                {
                    if (reduceLevel.Resolution < Constant.MinResolutionForDbWrites)
                        throw new DataException("Will not write to DB at a resolution higher than " + Constant.MinResolutionForDbWrites + " ms; make sure your first reduce table has at least this resolution.  Monitor Config \"" + reduceLevel.MonitorConfigName + "\"");

                    if (Constant.MsPerDay % reduceLevel.Resolution != 0)
                        throw new DataException("Only resolutions that divide evenly into a day are supported");

                    if (lastResolution == 0)
                    {
                        lastResolution = reduceLevel.Resolution;
                        continue;
                    }

                    //if the resolutions are devisable by each other then we have a problem
                    if (((double)reduceLevel.Resolution / (double)lastResolution) != (long)(reduceLevel.Resolution / lastResolution))
                        throw new DataException("Reduce level resolutions must be integral multiples of each other.  Failed for \"" + reduceLevel.MonitorConfigName + "\" levels " + lastResolution + " and " + reduceLevel.Resolution);

                    lastResolution = reduceLevel.Resolution;
                }
            }
        }
Example #2
0
        private int PruneDuplicates()
        {
            var byPath = new Dictionary<string, List<LaunchEntry>>();
            foreach (var launchEntry in foundFiles) {
                byPath.SetDefault(launchEntry.FullPath).Add(launchEntry);
                if(!string.IsNullOrEmpty(launchEntry.LinkTarget)) byPath.SetDefault(launchEntry.LinkTarget).Add(launchEntry);
            }
            int dropped = 0;
            foreach (var byPathPair in byPath) {
                if(byPathPair.Value.Count <= 1) continue;
                foreach(var elToDrop in byPathPair.Value.OrderBy(entry => entry.NamePath.Length).Skip(1)) {
                    foundFiles.Remove(elToDrop);
                    dropped++;
                }

            }
            return dropped;
        }
Example #3
0
        private void Checker()
        {
            var conditionStates = new Dictionary<Space, Dictionary<BaseCondition, bool>>();

            while (true)
            {
                foreach (var space in Config.Spaces)
                    foreach (var condition in Conditions)
                    {
                        var oldState = conditionStates.SetDefault(space, new Dictionary<BaseCondition, bool>()).SetDefault(condition, false);
                        var newState = condition.Check(space);

                        if (newState && !oldState)
                        {
                            ActivateSpace(space);
                        }

                        conditionStates[space][condition] = newState;
                    }

                Thread.Sleep(5000);
            }
        }