protected virtual Choreography AddMainColor()
 {
     var choreography = new Choreography
         {
             Sequences = SwitchOnPin(0, AppSettings.Default.LsGreenPin).Cast<Sequences>().ToList()
         };
     return choreography;
 }
 protected override int RunCommand(string[] remainingArguments)
 {
     var choreography = new Choreography
     {
         Sequences = new List<Sequences>
                         {
                             new SequencesGpIo
                                 {
                                     BeginTime = 0,
                                     Pin = AppSettings.Default.LsBluePin,
                                     IsOn = true
                                 },
                             new SequencesPlaySound {BeginTime = 1, File = "Wtf/lightsaber.mp3"},
                         }
     };
     BuildIndicationApi.Enqueue(choreography);
     return 0;
 }
		public void Post_GivenMultipleItems_ShouldAddAllToStage()
		{
			// arrange
			Setup();
			_mockIStage.Setup(mc => mc.Enqueue(It.IsAny<object>()));
			_mockIStage.Setup(mc => mc.Count).Returns(7);
			_mockIStage.Setup(mc => mc.Play()).Returns(Task.FromResult(true));
			// action
			var choreography = new Choreography();
			choreography.Sequences.Add(new SequencesPlaySound() { BeginTime = 0, File = "Startup" });
			choreography.Sequences.Add(new SequencesText2Speech() { BeginTime = 0, Text = "Mhaha", DisableTransform = false });
			choreography.Sequences.Add(new SequencesGpIo() { BeginTime = 0, IsOn = true, PinName = PinName.MainLightGreen });
			choreography.Sequences.Add(new SequencesInsult() { BeginTime = 0 });
			choreography.Sequences.Add(new SequencesOneLiner() { BeginTime = 0 });
			choreography.Sequences.Add(new SequencesQuotes() { BeginTime = 0 });
			choreography.Sequences.Add(new SequencesTweet() { BeginTime = 0, Text = "Tweeeet" });
			var serializeObject = JsonConvert.SerializeObject(choreography);
			var deserializeObject = JsonConvert.DeserializeObject<EnqueueController.ChoreographyModel>(serializeObject);
			var result = _enqueueController.Post(deserializeObject);
			// assert
			result.Should().NotBeNull();
			_mockIStage.Verify(mc => mc.Enqueue(It.IsAny<object>()), Times.Exactly(7));
		}
        protected virtual void AddProjectStatusSounds(Task<JenkensProjectsResult> allProjects, string projectName, Choreography choreography)
        {
            allProjects.Wait();
            var project = allProjects.Result.Jobs.FirstOrDefault(x => x.Name.ToUpper() == projectName);
            if (project != null)
            {
                var successfulBuildInARow = JenkensTextConverter.SuccessfulBuildInARow(project.Builds);
                System.Console.Out.WriteLine(string.Format("The build has {0} successful builds in a row", successfulBuildInARow));

                if (successfulBuildInARow > 20 && successfulBuildInARow%10 == 0)
                {
                    choreography.Sequences.Add(new SequencesText2Speech()
                        {
                            BeginTime = 300,
                            Text =
                                projectName + " completed with " + successfulBuildInARow +
                                " successful builds in a row. The force is strong with this one"
                        });
                }
                if (successfulBuildInARow == 2)
                {
                    choreography.Sequences.Add(new SequencesText2Speech()
                        {
                            BeginTime = 300,
                            Text = " another successful build"
                        });
                }
                else
                {
                    choreography.Sequences.Add(new SequencesPlaySound {BeginTime = 2000, File = "Success"});
                }
            }
            else
            {
                System.Console.Out.WriteLine("Project could not be found on jenkins");
            }
        }
        protected void AddJenkensStatsToButton()
        {
            var allProjects = AllProjects();
            Log.Info("Downloading jenkins values");
            allProjects.Wait();
            var jenkensTextConverter = new JenkensTextConverter();
            IEnumerable<string> summaryList = jenkensTextConverter.ToSummaryList(allProjects.Result);
            Choreography[] choreography = summaryList.Select(summary => new Choreography
                {
                    Sequences = new List<Sequences>
                        {
                            new SequencesGpIo {BeginTime = 0, Pin = AppSettings.Default.LsBluePin, IsOn = true},
                            new SequencesText2Speech {BeginTime = 0, Text = summary},
                            new SequencesGpIo {BeginTime = 1000, Pin = AppSettings.Default.LsBluePin, IsOn = false},
                        }
                }).ToArray();

            BuildIndicationApi.SetButtonChoreography(choreography).Wait();
            var failed = allProjects.Result.Jobs.Any(x => x.IsFailed());
            var glow = new Choreography()
            {
                Sequences = new List<Sequences>
                        {
                            new SequencesGpIo {BeginTime = 0, Pin = AppSettings.Default.FeetGreenPin, IsOn = !failed},
                            new SequencesGpIo {BeginTime = 0, Pin = AppSettings.Default.FeetRedPin, IsOn = failed},
                        }
            };
            BuildIndicationApi.Enqueue(glow).Wait();
            
        }
        private void SendText(string message)
        {
            Choreography choreography = null;
            choreography = new Choreography
            {
                Sequences = new List<Sequences>
                                {
                                    new SequencesGpIo
                                        {
                                            BeginTime = 0,
                                            Pin = AppSettings.Default.LsBluePin,
                                            IsOn = true
                                        }
                                }
            };
            AddMessage(choreography, message);
			AddSound(choreography, Sound);
            choreography.Sequences.Add(new SequencesGpIo
                                        {
                                            BeginTime = 1000,
                                            Pin = AppSettings.Default.LsBluePin,
                                            IsOn = false
                                        });
            BuildIndicationApi.Enqueue(choreography).Wait();
        }
 private void AddSound(Choreography choreography, string sound)
 {
     if (string.IsNullOrEmpty(sound)) return;
     int max = choreography.Sequences.Select(x => x.BeginTime).Max();
     choreography.Sequences.Add(new SequencesPlaySound() { BeginTime = max + 1000, File = sound });
 }
 private void AddMessage(Choreography choreography, string message)
 {
     if (!string.IsNullOrEmpty(message))
     {
         int max = choreography.Sequences.Select(x => x.BeginTime).Max();
         choreography.Sequences.Add(new SequencesText2Speech { BeginTime = max + 1000, Text = message });
     }
 }
 private void SetLightSaber(string setBuildState, string message)
 {
     Choreography choreography = null;
     choreography = new Choreography
     {
         Sequences = new List<Sequences>
                         {
                             new SequencesGpIo
                                 {
                                     BeginTime = 0,
                                     Pin = AppSettings.Default.LsGreenPin,
                                     IsOn = setBuildState.ToUpper().Contains('G')
                                 },
                             new SequencesGpIo
                                 {
                                     BeginTime = 0,
                                     Pin = AppSettings.Default.LsBluePin,
                                     IsOn = setBuildState.ToUpper().Contains('B')
                                 },
                             new SequencesGpIo
                                 {
                                     BeginTime = 0,
                                     Pin = AppSettings.Default.LsRedPin,
                                     IsOn = setBuildState.ToUpper().Contains('R')
                                 },
                         }
     };
     AddMessage(choreography, message);
     AddSound(choreography, Sound);
     Task<EnqueueResponse> result = BuildIndicationApi.Enqueue(choreography);
     result.Wait();
 }
 private void SetButtonClick(string message)
 {
     var choreography = new Choreography
     {
         Sequences = new List<Sequences>
                 {
                     new SequencesGpIo {BeginTime = 0, Pin = AppSettings.Default.LsBluePin, IsOn = true},
                     new SequencesText2Speech {BeginTime = 0, Text = message},
                     new SequencesGpIo {BeginTime = 1000, Pin = AppSettings.Default.LsBluePin, IsOn = false},
                 }
     };
     Task<SetButtonChoreographyResponse> result = BuildIndicationApi.SetButtonChoreography(choreography);
     result.Wait();
 }
        protected virtual void AddCoreProjectStatus(Choreography choreography, string projectName, bool isSuccess)
        {
            Log.Warn("CommandSuccessfulBuild:AddCoreProjectStatus Sending green pin");
            var coreProjects = GetCoreProjects().ToArray();
            foreach (var coreProject in coreProjects.Where(x => x.Name.ToUpper() == projectName))
            {
                coreProject.Color = isSuccess ? Job.SuccessColor : Job.FailColor;
            }
            Log.Info("Core projects stats for " + string.Join(",",coreProjects.Select(x => x.Name).ToArray()));
            Log.Info("Core projects stats for " + string.Join(",", coreProjects.Select(x => x.Color).ToArray()));
            const int beginTime = 10000;
            if (coreProjects.Any(x => x.IsFailed()))
            {
                Log.Info("Found atleast one core project that failed");
                choreography.Sequences.AddRange(SwitchOnPin(beginTime, AppSettings.Default.LsRedPin));
            }
            else
            {
                Log.Warn("CommandSuccessfulBuild:AddCoreProjectStatus Sending green pin");
                choreography.Sequences.AddRange(SwitchOnPin(beginTime, AppSettings.Default.LsGreenPin));
            }

        }
		public void Enqueue_GivenSoundsThenText_ShouldPlayBoth()
		{
			// arrange
			Setup();
			// action
			var choreography = new Choreography();
			choreography.Sequences.Add(new SequencesPlaySound() { BeginTime = 50, File = "Start" });

			choreography.Sequences.Add(new SequencesGpIo() { BeginTime = 50, PinName = PinName.MainLightBlue, IsOn = true });
			choreography.Sequences.Add(new SequencesText2Speech() { BeginTime = 50, Text = "Main Blue" });
			choreography.Sequences.Add(new SequencesGpIo() { BeginTime = 50, PinName = PinName.MainLightBlue, IsOn = false});

			choreography.Sequences.Add(new SequencesGpIo() { BeginTime = 50, PinName = PinName.MainLightGreen, IsOn = true });
			choreography.Sequences.Add(new SequencesText2Speech() { BeginTime = 50, Text = "Main Green" });
			choreography.Sequences.Add(new SequencesGpIo() { BeginTime = 50, PinName = PinName.MainLightGreen, IsOn = false });

			choreography.Sequences.Add(new SequencesGpIo() { BeginTime = 50, PinName = PinName.MainLightRed, IsOn = true });
			choreography.Sequences.Add(new SequencesText2Speech() { BeginTime = 50, Text = "Main Red" });
			choreography.Sequences.Add(new SequencesGpIo() { BeginTime = 50, PinName = PinName.MainLightRed, IsOn = false });

			choreography.Sequences.Add(new SequencesGpIo() { BeginTime = 50, PinName = PinName.SecondaryLightGreen, IsOn = true });
			choreography.Sequences.Add(new SequencesText2Speech() { BeginTime = 50, Text = "Secondary Green" });
			choreography.Sequences.Add(new SequencesGpIo() { BeginTime = 50, PinName = PinName.SecondaryLightGreen, IsOn = false });

			choreography.Sequences.Add(new SequencesGpIo() { BeginTime = 50, PinName = PinName.SecondaryLightRed, IsOn = true });
			choreography.Sequences.Add(new SequencesText2Speech() { BeginTime = 50, Text = "Secondary Red" });
			choreography.Sequences.Add(new SequencesGpIo() { BeginTime = 50, PinName = PinName.SecondaryLightRed, IsOn = false });

			choreography.Sequences.Add(new SequencesGpIo() { BeginTime = 50, PinName = PinName.MainLightBlue, IsOn = true });
			choreography.Sequences.Add(new SequencesInsult() { BeginTime = 0 });
			choreography.Sequences.Add(new SequencesOneLiner() { BeginTime = 0 });
			choreography.Sequences.Add(new SequencesQuotes() { BeginTime = 0 });
			choreography.Sequences.Add(new SequencesGpIo() { BeginTime = 50, PinName = PinName.MainLightBlue, IsOn = false });
//			choreography.Sequences.Add(new SequencesTweet() { BeginTime = 0, Text = "Tweeeet" });
			var result = BuildIndicatorApi.Enqueue(choreography).Result;
			// assert
			result.Should().NotBeNull();
			var size = result.QueueSize;
			size.Should().Be(choreography.Sequences.Count);
			while (size > 0)
			{
				var queueSize = BuildIndicatorApi.GetQueueSize();
				size = queueSize.Result.QueueSize;
				Thread.Sleep(1000);
			}
		}
 public Task<EnqueueResponse> Enqueue(Choreography choreography)
 {
     var restRequest = GetRestRequest(ApiPaths.Enqueue, Method.POST, choreography);
     return ProcessDefaultRequest<EnqueueResponse>(restRequest);
 }
 private void OnSpeakDarthTap(object sender, GestureEventArgs e)
 {
     var choreography = new Choreography
         {
             Sequences = SequencesText2Speeches(false).ToList()
         };
     _robotApi.Enqueue(choreography);
 }
 private void OnTweetTap(object sender, GestureEventArgs e)
 {
     var choreography = new Choreography
     {
         Sequences = SequencesTweet().ToList()
     };
     _robotApi.Enqueue(choreography);
 }