Exemplo n.º 1
0
 public ButtonInput(StateLookup lookup, int timeframe, int delay, int period)
 {
     Lookup    = lookup;
     Timeframe = timeframe;
     Delay     = delay;
     Period    = period;
 }
Exemplo n.º 2
0
        double MaxQ(string stateName)
        {
            const double defaultValue = 0;

            if (!StateLookup.ContainsKey(stateName))
            {
                return(defaultValue);
            }

            QState state            = StateLookup[stateName];
            var    actionsFromState = state.Actions;
            double?maxValue         = null;

            foreach (var nextState in actionsFromState)
            {
                foreach (var actionResult in nextState.ActionsResult)
                {
                    double value = actionResult.QEstimated;
                    if (value > maxValue || !maxValue.HasValue)
                    {
                        maxValue = value;
                    }
                }
            }

            // no update
            if (!maxValue.HasValue && ShowWarning)
            {
                QMethod.Log(string.Format("Warning: No MaxQ value for stateName {0}",
                                          stateName));
            }

            return(maxValue.HasValue ? maxValue.Value : defaultValue);
        }
        // convert ANY incoming type that has city field and a state abbreviation to "City, State"
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            try
            {
                // use a dynamic to allow any type in
                dynamic address = value;
                String  city    = (address.City ?? String.Empty).Trim();
                String  state   = (address.State ?? String.Empty).Trim();

                // look up the state/provincial abbreviation
                if (StateLookup.ContainsKey(state))
                {
                    state = StateLookup[state];
                }

                // return a formatted value
                if (String.IsNullOrEmpty(city))
                {
                    return(state);
                }
                else
                {
                    return(String.Format("{0}, {1}", city, state));
                }
            }
            catch
            {
                // eat the exception (probably from non-existing property on dynamic type) and just return the original value
            }

            return(value);
        }
Exemplo n.º 4
0
        public void Match_NonExistingKey_ReturnNewValue()
        {
            var stateLookup = new StateLookup();

            stateLookup.Load();
            var country = stateLookup.Match("Waiting");

            Assert.That(country, Is.GreaterThan(2));
        }
Exemplo n.º 5
0
        public void Match_ExistingKey_ReturnValue()
        {
            var stateLookup = new StateLookup();

            stateLookup.Load();
            var state = stateLookup.Match("Started");

            Assert.That(state, Is.EqualTo(1));
        }
Exemplo n.º 6
0
        public void Match_InitiatlyNonExistingKey_ReturnNewValue()
        {
            var stateLookup = new StateLookup();

            stateLookup.Load();
            var stateFirst  = stateLookup.Match("Paused");
            var stateSecond = stateLookup.Match("Paused");

            Assert.That(stateFirst, Is.EqualTo(stateSecond));
        }
Exemplo n.º 7
0
        private void Download()
        {
            WebClient client = new WebClient();

            client.DownloadStringCompleted += client_DownloadStringCompleted;

            string[] loc = _location.Split(',');

            client.DownloadStringAsync(new Uri("http://api.openweathermap.org/data/2.5/weather?q="
                                               + loc[0].Trim() + "," + StateLookup.GetAbbreviation(loc[1].Trim()) + "&mode=xml&APPID="
                                               + GlobalData.OpenWeatherMapAppID));
        }
Exemplo n.º 8
0
        private void DownloadForecast(string location)
        {
            WebClient forecastClient = new WebClient();

            forecastClient.DownloadStringCompleted += forecastClient_DownloadStringCompleted;

            string[] loc = location.Split(',');

            forecastClient.DownloadStringAsync(new Uri("http://api.openweathermap.org/data/2.5/forecast/daily?q="
                                                       + loc[0].Trim() + "," + StateLookup.GetAbbreviation(loc[1].Trim()) + "&mode=xml&cnt=2&APPID="
                                                       + GlobalData.OpenWeatherMapAppID));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Creates a state
 /// </summary>
 /// <param name="stateModel"></param>
 /// <returns></returns>
 public int Create(StateModel stateModel)
 {
     using (var scope = new TransactionScope())
     {
         var state = new StateLookup()
         {
             StateName         = stateModel.StateName,
             StateAbbreviation = stateModel.StateAbbreviation,
             Archived          = stateModel.Archived
         };
         _dbActions.StateRepository.Insert(state);
         _dbActions.Save();
         scope.Complete();
         return(state.Id);
     }
 }
Exemplo n.º 10
0
        private void DownloadCurrent(string location)
        {
            RaiseUpdateStatusEvent("DOWNLOADING WEATHER DATA...");

            if (currentClient != null)
            {
                currentClient.DownloadStringCompleted -= currentClient_DownloadStringCompleted;
                currentClient.CancelAsync();
            }

            currentClient = new WebClient();
            currentClient.DownloadStringCompleted += currentClient_DownloadStringCompleted;

            string[] loc = location.Split(',');

            currentClient.DownloadStringAsync(new Uri("http://api.openweathermap.org/data/2.5/weather?q="
                                                      + loc[0].Trim() + "," + StateLookup.GetAbbreviation(loc[1].Trim()) + "&mode=xml&APPID="
                                                      + GlobalData.OpenWeatherMapAppID));
        }
Exemplo n.º 11
0
 public ButtonInput(StateLookup lookup) : this(lookup, 5, 15, 3)
 {
 }
 /// <summary>
 /// This method is called by the underlying driver of the fixpoint computation. It provides delegates for future lookup
 /// of the abstract state at given pcs.
 /// </summary>
 /// <returns>Return true only if you want the fixpoint computation to eagerly cache each pc state.</returns>
 public bool CacheStates(StateLookup <Label, Domain> preState, StateLookup <Label, Domain> postState)
 {
     this.preStateLookup  = preState;
     this.postStateLookup = postState;
     return(false);
 }