Exemplo n.º 1
0
 public AssistantResponse Play(string url, Platform targetPlatform = Platform.All)
 {
     OutputObjects.Add(new OutputObject {
         TargetPlatform = targetPlatform, Type = OutputType.Url, Value = url
     });
     return(this);
 }
Exemplo n.º 2
0
 public AssistantResponse Speak(string text, Platform targetPlatform = Platform.All)
 {
     OutputObjects.Add(new OutputObject {
         TargetPlatform = targetPlatform, Type = OutputType.Text, Value = text
     });
     return(this);
 }
Exemplo n.º 3
0
        public void PushObject(object instance)
        {
            lock (stackSyncObject) {
                OutputObjects.Push(instance);
            }

            if (OutputNotificationType == NotificationType.Auto)
            {
                OnOutputAvailable();
            }
        }
Exemplo n.º 4
0
        public AssistantResponse Break(int second, Platform targetPlatform = Platform.All)
        {
            if (second == 0 || second > 10)
            {
                throw new Exception("Break time must be set between 1 and 10 seconds.");
            }

            OutputObjects.Add(new OutputObject {
                TargetPlatform = targetPlatform, Type = OutputType.Break, BreakTime = second
            });
            return(this);
        }
Exemplo n.º 5
0
 private string GetSsmlResponse(Platform targetPlatform)
 {
     return($@"<speak>{
         string.Concat(OutputObjects
             .Where(output => output.TargetPlatform == Platform.All || output.TargetPlatform == targetPlatform)
             .Select(output =>
                 output.Type switch
                 {
                     OutputType.Text => output.Value,
                     OutputType.Url => $"<audio src=\"{output.Value}\" />",
                     OutputType.Break => $"<break time=\"{output.BreakTime}s\" />",
                     _ => string.Empty
                 }))
Exemplo n.º 6
0
        public void PushMultiObjects(IList <object> instances)
        {
            lock (stackSyncObject) {
                foreach (object instance in instances)
                {
                    OutputObjects.Push(instance);
                }
            }

            if (OutputNotificationType == NotificationType.Auto)
            {
                OnOutputAvailable();
            }
        }
Exemplo n.º 7
0
 public IEnumerable <object> ConsumeOutput()
 {
     lock (stackSyncObject) {
         while (OutputObjects.Count > 0)
         {
             object input = OutputObjects.Pop();
             if (OutputObjects.Count == 0)
             {
                 yield break;
             }
             else
             {
                 yield return(input);
             }
         }
     }
 }
        /// <summary>
        ///		Ejecuta un script de PowerShell
        /// </summary>
        internal void Process()
        {
            // Ejecuta el script
            try
            {
                using (PowerShell instance = PowerShell.Create())
                {
                    Collection <PSObject> outputItems;

                    // Añade el script a PowerShell
                    instance.AddScript(Script);
                    // Añade los parámetros de entrada
                    if (InputParameters != null)
                    {
                        foreach (KeyValuePair <string, object> parameter in InputParameters)
                        {
                            instance.AddParameter(parameter.Key, parameter.Value);
                        }
                    }
                    // Llama a la ejecución de PowerShell
                    outputItems = instance.Invoke();
                    // Guarda los valores de salida
                    foreach (PSObject outputItem in outputItems)
                    {
                        OutputObjects.Add(outputItem.BaseObject);
                    }
                    // Guarda los errores
                    if (instance.Streams.Error.Count > 0)
                    {
                        foreach (ErrorRecord error in instance.Streams.Error)
                        {
                            Errors.Add(error.ToString());
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Errors.Add(exception.Message);
            }
            // Llama al evento de fin de proceso
            EndExecute?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 9
0
        public CEKResponse ToClovaResponse()
        {
            var response = new CEKResponse();

            // normal
            foreach (var output in OutputObjects
                     .Where(output => output.TargetPlatform == Platform.All || output.TargetPlatform == Platform.Clova))
            {
                if (output.Type == OutputType.Text)
                {
                    response.AddText(output.Value);
                }
                else if (output.Type == OutputType.Url)
                {
                    response.AddUrl(output.Value);
                }
                else if (output.Type == OutputType.Break)
                {
                    if (output.BreakTime <= 5)
                    {
                        response.AddUrl($"https://himanago.github.io/silent-mp3/silent_{output.BreakTime}s.mp3");
                    }
                    else
                    {
                        response.AddUrl($"https://himanago.github.io/silent-mp3/silent_5s.mp3");
                        response.AddUrl($"https://himanago.github.io/silent-mp3/silent_{output.BreakTime - 5}s.mp3");
                    }
                }
            }

            // AudioPlayer
            foreach (var audio in AudioItemObjects
                     .Where(audio => audio.TargetPlatform == Platform.All || audio.TargetPlatform == Platform.Clova))
            {
                response.Response.Directives.Add(new Directive()
                {
                    Header = new DirectiveHeader()
                    {
                        Namespace = DirectiveHeaderNamespace.AudioPlayer,
                        Name      = DirectiveHeaderName.Play
                    },
                    Payload = new AudioPlayPayload
                    {
                        AudioItem = new LineDC.CEK.Models.AudioItem
                        {
                            AudioItemId   = audio.AudioItemId,
                            HeaderText    = audio.Title,
                            TitleText     = audio.Title,
                            TitleSubText1 = audio.SubTitle,
                            ArtImageUrl   = audio.ImageUrl,
                            Stream        = new AudioStreamInfoObject
                            {
                                BeginAtInMilliseconds = 0,
                                Url         = audio.Url,
                                UrlPlayable = true
                            }
                        },
                        PlayBehavior = audio.AudioPlayBehavior == AudioPlayBehavior.Enqueue
                            ? LineDC.CEK.Models.AudioPlayBehavior.ENQUEUE
                            : LineDC.CEK.Models.AudioPlayBehavior.REPLACE_ALL,

                        Source = new Source {
                            Name = audio.Title
                        }
                    }
                });
            }

            if (!ShouldEndSession)
            {
                response.KeepListening();
            }

            return(response);
        }
Exemplo n.º 10
0
        public SkillResponse ToAlexaResponse()
        {
            if (AudioItemObjects.Any(obj => obj.TargetPlatform == Platform.All || obj.TargetPlatform == Platform.Alexa))
            {
                // AudioPlayer
                var response = new SkillResponse
                {
                    Response = new ResponseBody
                    {
                        ShouldEndSession = ShouldEndSession,
                        Directives       = new List <IDirective>()
                    },
                    Version = "1.0"
                };

                if (OutputObjects.Any(obj => obj.TargetPlatform == Platform.All || obj.TargetPlatform == Platform.Alexa))
                {
                    response.Response.OutputSpeech = new SsmlOutputSpeech
                    {
                        Ssml = GetSsmlResponse(Platform.Alexa)
                    };
                    response.Response.Reprompt = !string.IsNullOrEmpty(RepromptText)
                        ? new Alexa.NET.Response.Reprompt(RepromptText)
                        : null;
                }

                foreach (var audio in AudioItemObjects
                         .Where(audio => audio.TargetPlatform == Platform.All || audio.TargetPlatform == Platform.Alexa))
                {
                    response.Response.Directives.Add(new AudioPlayerPlayDirective
                    {
                        PlayBehavior = audio.AudioPlayBehavior == AudioPlayBehavior.Enqueue
                            ? PlayBehavior.Enqueue
                            : PlayBehavior.ReplaceAll,
                        AudioItem = new Alexa.NET.Response.Directive.AudioItem
                        {
                            Stream = new AudioItemStream
                            {
                                Url   = audio.Url,
                                Token = audio.AudioItemId,
                                ExpectedPreviousToken = audio.PreviousAudioItemId
                            },
                            Metadata = new AudioItemMetadata
                            {
                                Title    = audio.Title,
                                Subtitle = audio.SubTitle
                            }
                        }
                    });
                }
                return(response);
            }
            else if (OutputObjects.Any(obj => obj.TargetPlatform == Platform.All || obj.TargetPlatform == Platform.Alexa))
            {
                // normal
                return(new SkillResponse
                {
                    Response = new ResponseBody
                    {
                        OutputSpeech = new SsmlOutputSpeech
                        {
                            Ssml = GetSsmlResponse(Platform.Alexa)
                        },
                        Reprompt = !string.IsNullOrEmpty(RepromptText)
                            ? new Alexa.NET.Response.Reprompt(RepromptText)
                            : null,
                        ShouldEndSession = ShouldEndSession
                    },
                    Version = "1.0"
                });
            }
            else
            {
                // nothing
                return(null);
            }
        }