示例#1
0
    static void Main(string[] args)
    {
        Console.WriteLine("Пример1");
        CounterAction counter = MakeCounter();

        Console.WriteLine(counter());
        Console.WriteLine(counter());
        Console.WriteLine(counter());

        //разные вызовы функций создают разные счетчики и лексические окружения
        CounterAction counter2 = MakeCounter();

        Console.WriteLine(counter2());
        Console.WriteLine(counter2());
        Console.WriteLine(counter2());
        Console.WriteLine();


        Console.WriteLine("Пример2");
        Console.WriteLine("3 + 6 = {0}", Sum(3)(6));
        Console.WriteLine();

        Console.WriteLine("Пример3");
        //для объекта List (можно использовать и обычные массивы)
        List <int> lst = new List <int> {
            1, 4, 6, 3, 6
        };
        List <float> resLst = ConvertTypes <int, float>(lst, (a) => a + 0.5f);

        Console.WriteLine("Before: {0}\nAfter: {1}", string.Join(" ", lst), string.Join(" ", resLst));

        Console.Read();
    }
示例#2
0
    public static CounterAction MakeCounter()
    {
        int           c         = 0;
        CounterAction increment = () => c++;

        return(increment);
    }
示例#3
0
        public IActionResult Index(CounterAction action, CounterViewModel model)
        {
            this.ValidateCounter(model);
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            switch (action)
            {
            case CounterAction.Increase:
                model.Actions.Add(action);
                model.CurrentCount++;
                this.ModelState.Remove("CurrentCount");
                return(this.View(model));

            case CounterAction.Decrease:
                model.Actions.Add(action);
                model.CurrentCount--;
                this.ModelState.Remove("CurrentCount");
                return(this.View(model));

            case CounterAction.Finish:
                return(this.View("Result", model));

            default:
                throw new ArgumentOutOfRangeException(nameof(action), action, null);
            }
        }
示例#4
0
        public IActionResult Quiz(CounterAction action, QuizModel model)
        {
            this.ValidateCounter(model);
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            switch (action)
            {
            case CounterAction.Submit:
                model.CurrentCount++;
                model.Questions.Add(model.NewQuestion);
                model.NewQuestion = MakeNewQuestion();
                this.ModelState.Remove("CurrentCount");
                this.ModelState.Remove("NewQuestion.FirstNumber");
                this.ModelState.Remove("NewQuestion.SecondNumber");
                this.ModelState.Remove("NewQuestion.Operator");

                return(this.View(model));

            case CounterAction.Finish:

                model.Questions.Add(model.NewQuestion);
                var i = 0;
                foreach (var question in model.Questions)
                {
                    if (
                        this.calculateService.Calculate(
                            question.FirstNumber,
                            question.SecondNumber,
                            question.Operator) == question.Answer
                        )
                    {
                        question.isCorrect = true;
                    }
                    else
                    {
                        question.isCorrect = false;
                    }
                    if (question.isCorrect)
                    {
                        i++;
                    }
                }
                model.RightAnswCount = i;
                return(this.View("QuizResult", model));

            default:
                throw new ArgumentOutOfRangeException(nameof(action), action, null);
            }
        }
        internal static void ChangeCounterActionsToUseSpecialIdentifiers(List <ActionBase> actions)
        {
            for (int i = 0; i < actions.Count; i++)
            {
                ActionBase action = actions[i];
                if (action is CounterAction)
                {
                    CounterAction cAction = (CounterAction)action;
#pragma warning disable CS0612 // Type or member is obsolete
                    cAction.Amount = cAction.CounterAmount.ToString();
#pragma warning restore CS0612 // Type or member is obsolete
                }
            }
        }
        private static async Task Version11Upgrade(int version, string filePath)
        {
            if (version < 11)
            {
                string data = File.ReadAllText(filePath);
                data = data.Replace("MixItUp.Base.Actions.OverlayAction, MixItUp.Base", "MixItUp.Desktop.Services.LegacyOverlayAction, MixItUp.Desktop");
                DesktopChannelSettings legacySettings = SerializerHelper.DeserializeFromString <DesktopChannelSettings>(data);
                await ChannelSession.Services.Settings.Initialize(legacySettings);

                Dictionary <Guid, LegacyOverlayAction> legacyOverlayActions = new Dictionary <Guid, LegacyOverlayAction>();

                List <CommandBase> commands = new List <CommandBase>();
                commands.AddRange(legacySettings.ChatCommands);
                commands.AddRange(legacySettings.EventCommands);
                commands.AddRange(legacySettings.InteractiveCommands);
                commands.AddRange(legacySettings.TimerCommands);
                commands.AddRange(legacySettings.ActionGroupCommands);
                commands.AddRange(legacySettings.GameCommands);
                commands.AddRange(legacySettings.RemoteCommands);
                foreach (CommandBase command in commands)
                {
                    foreach (ActionBase action in command.Actions)
                    {
                        if (action is LegacyOverlayAction)
                        {
                            legacyOverlayActions[action.ID] = (LegacyOverlayAction)action;
                        }
                    }
                }

                DesktopChannelSettings settings = await SerializerHelper.DeserializeFromFile <LegacyDesktopChannelSettings>(filePath);

                await ChannelSession.Services.Settings.Initialize(settings);

                commands.Clear();
                commands.AddRange(settings.ChatCommands);
                commands.AddRange(settings.EventCommands);
                commands.AddRange(settings.InteractiveCommands);
                commands.AddRange(settings.TimerCommands);
                commands.AddRange(settings.ActionGroupCommands);
                commands.AddRange(settings.GameCommands);
                commands.AddRange(settings.RemoteCommands);
                foreach (CommandBase command in commands)
                {
                    foreach (ActionBase action in command.Actions)
                    {
                        if (action is OverlayAction && legacyOverlayActions.ContainsKey(action.ID))
                        {
                            OverlayAction       overlayAction       = (OverlayAction)action;
                            LegacyOverlayAction legacyOverlayAction = legacyOverlayActions[action.ID];

                            OverlayEffectEntranceAnimationTypeEnum entrance = OverlayEffectEntranceAnimationTypeEnum.None;
                            OverlayEffectExitAnimationTypeEnum     exit     = OverlayEffectExitAnimationTypeEnum.None;
                            if (legacyOverlayAction.FadeDuration > 0)
                            {
                                entrance = OverlayEffectEntranceAnimationTypeEnum.FadeIn;
                                exit     = OverlayEffectExitAnimationTypeEnum.FadeOut;
                            }

                            if (!string.IsNullOrEmpty(legacyOverlayAction.ImagePath))
                            {
                                overlayAction.Effect = new OverlayImageEffect(legacyOverlayAction.ImagePath, legacyOverlayAction.ImageWidth, legacyOverlayAction.ImageHeight,
                                                                              entrance, OverlayEffectVisibleAnimationTypeEnum.None, exit, legacyOverlayAction.Duration, legacyOverlayAction.Horizontal, legacyOverlayAction.Vertical);
                            }
                            else if (!string.IsNullOrEmpty(legacyOverlayAction.Text))
                            {
                                overlayAction.Effect = new OverlayTextEffect(legacyOverlayAction.Text, legacyOverlayAction.Color, legacyOverlayAction.FontSize,
                                                                             entrance, OverlayEffectVisibleAnimationTypeEnum.None, exit, legacyOverlayAction.Duration, legacyOverlayAction.Horizontal, legacyOverlayAction.Vertical);
                            }
                            else if (!string.IsNullOrEmpty(legacyOverlayAction.youtubeVideoID))
                            {
                                overlayAction.Effect = new OverlayYoutubeEffect(legacyOverlayAction.youtubeVideoID, legacyOverlayAction.youtubeStartTime, legacyOverlayAction.VideoWidth,
                                                                                legacyOverlayAction.VideoHeight, entrance, OverlayEffectVisibleAnimationTypeEnum.None, exit, legacyOverlayAction.Duration, legacyOverlayAction.Horizontal,
                                                                                legacyOverlayAction.Vertical);
                            }
                            else if (!string.IsNullOrEmpty(legacyOverlayAction.localVideoFilePath))
                            {
                                overlayAction.Effect = new OverlayVideoEffect(legacyOverlayAction.localVideoFilePath, legacyOverlayAction.VideoWidth, legacyOverlayAction.VideoHeight,
                                                                              entrance, OverlayEffectVisibleAnimationTypeEnum.None, exit, legacyOverlayAction.Duration, legacyOverlayAction.Horizontal, legacyOverlayAction.Vertical);
                            }
                            else if (!string.IsNullOrEmpty(legacyOverlayAction.HTMLText))
                            {
                                overlayAction.Effect = new OverlayHTMLEffect(legacyOverlayAction.HTMLText, entrance, OverlayEffectVisibleAnimationTypeEnum.None, exit, legacyOverlayAction.Duration,
                                                                             legacyOverlayAction.Horizontal, legacyOverlayAction.Vertical);
                            }
                        }
                        else if (action is CounterAction)
                        {
                            CounterAction counterAction = (CounterAction)action;
                            if (counterAction.SaveToFile)
                            {
                                counterAction.ResetOnLoad = !counterAction.ResetOnLoad;
                            }
                        }
                    }
                }

                await ChannelSession.Services.Settings.Save(settings);
            }
        }
示例#7
0
 public CounterConditionAction(CounterCondition c, CounterAction a)
 {
     condition = c;
     action = a;
 }
 public CounterActionControl(CounterAction action) : this()
 {
     this.action = action;
 }
 public CounterActionControl(ActionContainerControl containerControl, CounterAction action) : this(containerControl) { this.action = action; }