예제 #1
0
        private void CheckDefaultBrowser()
        {
            var defaults = Configuration.Defaults.ToList();

            if (defaults.Count <= 0)
            {
                return;
            }

            var url  = new Uri(App.UnderlyingTargetURL);
            var auto = defaults
                       .Select(rule => new { rule, matchLength = rule.MatchLength(url) })
                       .Where(o => o.matchLength > 0)
                       .ToList();

            if (auto.Count <= 0)
            {
                return;
            }

            var browser = auto.OrderByDescending(o => o.matchLength).First().rule.Browser;
            var start   = Choices.FirstOrDefault(c => c.Name == browser);

            if (start == null || Configuration.DefaultsWhenRunning && !start.IsRunning)
            {
                return;
            }

            start.Select.Execute(null);
        }
예제 #2
0
        internal void Vote(ChatUser user, Guid choiceID)
        {
            PollChoice choice = Choices.FirstOrDefault(c => c.ID == choiceID);

            if (choice == null)
            {
                throw new Exception("Choice must be present");
            }

            if (!IsOpen)
            {
                throw new Exception("Poll is closed");
            }

            foreach (PollChoice thisChoice in Choices)
            {
                if (thisChoice.Votes.Contains(user))
                {
                    thisChoice.Votes.Remove(user);
                }
            }

            choice.Votes.Add(user);
            OnPropertyChanged(nameof(TotalVotes));
        }
예제 #3
0
        private void CheckDefaultBrowser()
        {
            var defaults = Configuration.Defaults.ToList();

            if (defaults.Count <= 0)
            {
                return;
            }

            var url  = new Uri(App.TargetURL);
            var auto = defaults.Where(d => url.Host.EndsWith(d.Fragment)).ToList();

            if (auto.Count <= 0)
            {
                return;
            }

            var browser = auto.OrderByDescending(d => d.Fragment.Length).First().Browser;
            var start   = Choices.FirstOrDefault(c => c.Name == browser);

            if (start == null || Configuration.DefaultsWhenRunning && !start.IsRunning)
            {
                return;
            }

            start.Select.Execute(null);
        }
예제 #4
0
파일: ChoiceLine.cs 프로젝트: fxMem/Plot
        public void Select(EntityId choiceId, LineContext context)
        {
            var selectedChoice = Choices.FirstOrDefault(c => c.Id == choiceId);

            if (selectedChoice == null)
            {
                throw new ArgumentException($"Choice with id = {choiceId} not found in line {Id}");
            }

            if (VariableId != null && selectedChoice.VariableValue != null)
            {
                context.Progress.Variables[VariableId].Value = selectedChoice.VariableValue;
            }

            if (selectedChoice.TargetGoto != null)
            {
                context.MoveTo(selectedChoice.TargetGoto.Target);
            }
            else
            {
                context.MoveToNextLine();
            }
        }
예제 #5
0
        /// <summary>
        ///     This method returns the name for the given ChoiceValue in the parameter. The choice must exist in the Choices
        ///     property to return the expected name.
        /// </summary>
        /// <param name="choiceVal">The value of the choice to find the name of.</param>
        /// <returns>If the choice exists, the respective name will be returned. Otherwise, an empty string will be returned.</returns>
        public string GetChoiceName(long choiceVal)
        {
            var choice = Choices.FirstOrDefault(c => c.Id == choiceVal);

            return(choice != null ? choice.ChoiceName : string.Empty);
        }
예제 #6
0
        /// <summary>
        ///     This method returns the value for the given ChoiceName in the parameter. The choice must exist in the Choices
        ///     property to return the expected value.
        /// </summary>
        /// <param name="choiceName">The name of the choice to find a value for.</param>
        /// <returns>If the choice exists, the respective value will be returned. Otherwise, an empty string will be returned.</returns>
        public string GetChoiceValue(string choiceName)
        {
            var choice = Choices.FirstOrDefault(c => c.ChoiceName == choiceName);

            return(choice != null?choice.Id.ToString() : string.Empty);
        }
예제 #7
0
 /// <summary>
 /// Resets ChoiceValues to default settings.
 /// </summary>
 public void Reset(bool useDefaultValue)
 {
     SelectedChoice = Choices != null && Choices.Any() ? Choices.FirstOrDefault() : null;
     CurrentValue   = useDefaultValue ? new FieldValue(DefaultValue) : new FieldValue(SelectedChoice);
 }