public static StateFlags HandleKingCaptureFlag(this StateFlags flags)
        {
            if (flags.HasFlag(StateFlags.RedKingTaken))
            {
                return(flags | StateFlags.BlueWin);
            }

            if (flags.HasFlag(StateFlags.BlueKingTaken))
            {
                return(flags | StateFlags.RedWin);
            }

            return(flags);
        }
 private static int GetEditorSlot(StateFlags flags)
 {
     if (flags.HasFlag(StateFlags.RedAction2))
     {
         return(0);
     }
     if (flags.HasFlag(StateFlags.BlueAction1))
     {
         return(1);
     }
     if (flags.HasFlag(StateFlags.BlueAction2))
     {
         return(2);
     }
     return(3);
 }
Ejemplo n.º 3
0
        public void IntroOutroTest(StateFlags flags)
        {
            Task.From.Attachments = new List <Attachment>();
            string introArg = null;

            if (flags.HasFlag(StateFlags.Intro))
            {
                introArg = "D:\\temp\\intro.wav";
                Task.From.Attachments.Add(new Attachment
                {
                    Type      = AttachmentType.Intro,
                    Path      = introArg,
                    Arguments = new Dictionary <string, string>()
                    {
                        { "Duration", "10000" }
                    }
                });
                Task.To.Flags |= StateFlags.Intro;
            }
            string outroArg = null;

            if (flags.HasFlag(StateFlags.Outro))
            {
                outroArg = "D:\\temp\\outro.wav";
                Task.From.Attachments.Add(new Attachment
                {
                    Type      = AttachmentType.Outro,
                    Path      = outroArg,
                    Arguments = new Dictionary <string, string>()
                    {
                        { "Duration", "10000" }
                    }
                });
                Task.To.Flags |= StateFlags.Outro;
            }
            Assert.That(sut.CheckAndEstimate(Task));

            mockFFMPegService = new Mock <IFFMpegService>(MockBehavior.Strict);
            var jobGuid = Guid.NewGuid();

            mockFFMPegService.Setup(m => m.PostAudioJob(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <ObservableCollection <AudioDestinationFormat> >(), introArg, outroArg))
            .Returns(jobGuid);

            FfmpegJobModel job = new FfmpegJobModel()
            {
                State = FfmpegJobModelState.Done,
                Tasks = new ObservableCollection <FfmpegTaskModel>()
                {
                    new FfmpegTaskModel()
                    {
                        DestinationFilename = "\\\\sdfsdfsdf\\sdfgsdf\\1_64.mp3"
                    },
                    new FfmpegTaskModel()
                    {
                        DestinationFilename = "\\\\sdfsdfsdf\\sdfgsdf\\1_192.mp3"
                    },
                    new FfmpegTaskModel()
                    {
                        DestinationFilename = "\\\\sdfsdfsdf\\sdfgsdf\\1_64.mp4"
                    }
                }
            };

            mockFFMPegService.Setup(m => m.GetAudioJob(jobGuid)).Returns(job);

            sut          = new FFMpeg.FFMpeg(_pluginUrn, MockTimeProvider.Object, Logging, mockFFMPegService.Object, mockPresetProvider.Object);
            Task.To.Path = "\\\\sdfsdfsdf\\sdfgsdf";

            sut.Assign(Task);
            sut.Pulse(Task);
            Assert.That(Task.To.Files, Is.Not.Empty);
        }
Ejemplo n.º 4
0
        private void ParseToken(StringBuilder buffer, StateFlags state, StateFlags?nextState, StringBuilder executionSql)
        {
            var token = buffer.ToString().Replace("\r", "");

            if (state.HasFlag(StateFlags.Comment))
            {
                if (!state.HasFlag(StateFlags.Multiline))
                {
                    var match = _descriptionRegex.Match(token);

                    if (match.Success)
                    {
                        var name      = match.Groups["name"].Value;
                        var parameter = Parameters.ContainsKey(name) ? Parameters[name] : new QueryParameter();

                        parameter.Label = match.Groups["label"].Value;

                        if (match.Groups["description"].Success)
                        {
                            parameter.Description = match.Groups["description"].Value;
                        }

                        Parameters[name] = parameter;
                    }

                    executionSql.Append('\n');
                }

                _sql.Append(token);
            }
            else
            {
                _sql.Append(token);

                if (!state.HasFlag(StateFlags.String))
                {
                    token = _whitespaceRegex.Replace(token, "${whitespace}");
                    token = _boundarySpacesRegex.Replace(token, "");

                    if (nextState.HasValue && nextState.Value.HasFlag(StateFlags.Comment) && !nextState.Value.HasFlag(StateFlags.Multiline))
                    {
                        token = token.TrimEnd(' ');
                    }
                }

                var matches = _paramsRegex.Matches(token);

                foreach (Match match in matches)
                {
                    var name      = match.Groups["name"].Value;
                    var parameter = Parameters.ContainsKey(name) ? Parameters[name] : new QueryParameter();

                    if (match.Groups["type"].Success)
                    {
                        var type = match.Groups["type"].Value.ToLower();

                        if (CheckIfTypeIsKnown(type))
                        {
                            parameter.Type = type;
                        }
                        else
                        {
                            Errors.Add($"{name} has unknown parameter type {type}!");
                        }
                    }

                    if (match.Groups["default"].Success)
                    {
                        var value = match.Groups["default"].Value;

                        if (!parameter.Type.HasValue() || ValidateType(parameter.Type, value))
                        {
                            parameter.Default = value;
                        }
                        else
                        {
                            Errors.Add($"{name}'s default value of {value} is invalid for the type {parameter.Type}!");
                        }
                    }

                    parameter.Required = parameter.Default == null;

                    Parameters[name] = parameter;
                    token            = token.ReplaceFirst(match.Value, "##" + name + "##");
                }

                if (executionSql.Length > 0 && executionSql[executionSql.Length - 1] == '\n')
                {
                    token = token.TrimStart('\n', ' ');
                }

                executionSql.Append(token);
            }
        }
        private void ParseToken(StringBuilder buffer, StateFlags state, StateFlags? nextState, StringBuilder executionSql)
        {
            var token = buffer.ToString().Replace("\r", "");

            if (state.HasFlag(StateFlags.Comment)) {
                if (!state.HasFlag(StateFlags.Multiline))
                {
                    var match = DescriptionRegex.Match(token);

                    if (match.Success)
                    {
                        var name = match.Groups["name"].Value;
                        var parameter = Parameters.ContainsKey(name) ? Parameters[name] : new QueryParameter();

                        parameter.Label = match.Groups["label"].Value;

                        if (match.Groups["description"].Success)
                        {
                            parameter.Description = match.Groups["description"].Value;
                        }

                        Parameters[name] = parameter;
                    }

                    executionSql.Append('\n');
                }

                sql.Append(token);
            }
            else
            {
                sql.Append(token);

                if (!state.HasFlag(StateFlags.String))
                {
                    token = WhitespaceRegex.Replace(token, "${whitespace}");
                    token = BoundarySpacesRegex.Replace(token, "");

                    if (nextState.HasValue && nextState.Value.HasFlag(StateFlags.Comment) && !nextState.Value.HasFlag(StateFlags.Multiline))
                    {
                        token = token.TrimEnd(' ');
                    }
                }

                var matches = ParamsRegex.Matches(token);

                foreach (Match match in matches)
                {
                    var name = match.Groups["name"].Value;
                    var parameter = Parameters.ContainsKey(name) ? Parameters[name] : new QueryParameter();

                    if (match.Groups["type"].Success)
                    {
                        var type = match.Groups["type"].Value.ToLower();

                        if (CheckIfTypeIsKnown(type))
                        {
                            parameter.Type = type;
                        }
                        else
                        {
                            Errors.Add(string.Format("{0} has unknown parameter type {1}!", name, type));
                        }

                        
                    }

                    if (match.Groups["default"].Success)
                    {
                        var value = match.Groups["default"].Value;

                        if (!parameter.Type.HasValue() || ValidateType(parameter.Type, value))
                        {
                            parameter.Default = value;
                        }
                        else
                        {
                            Errors.Add(string.Format("{0}'s default value of {1} is invalid for the type {2}!", name, value, parameter.Type));
                        }
                    }

                    parameter.Required = parameter.Default == null;

                    Parameters[name] = parameter;
                    token = token.ReplaceFirst(match.Value, "##" + name + "##");
                }

                if (executionSql.Length > 0 && executionSql[executionSql.Length - 1] == '\n')
                {
                    token = token.TrimStart('\n', ' ');
                }

                executionSql.Append(token);
            }
        }
 public static bool GameWon(this StateFlags flags) =>
 flags.HasFlag(StateFlags.RedWin) || flags.HasFlag(StateFlags.BlueWin);
 public static bool IsSecondTurn(this StateFlags flags) =>
 flags.HasFlag(StateFlags.RedAction2) || flags.HasFlag(StateFlags.BlueAction2);
 public static bool IsBlueTurn(this StateFlags flags) =>
 flags.HasFlag(StateFlags.BlueAction1) || flags.HasFlag(StateFlags.BlueAction2);
 public static bool IsRedTurn(this StateFlags flags) =>
 flags.HasFlag(StateFlags.RedAction1) || flags.HasFlag(StateFlags.RedAction2);