public void ExecuteRcv(InstructionParameter register)
 {
     switch (register.type)
     {
     case InstructionParameterType.Register:
         _register.SetRegister(register.name, _bus.Receive());
         break;
     }
 }
        public int ExecuteJgz(InstructionParameter register, InstructionParameter value)
        {
            if (_register.GetRegister(register.name) > 0)
            {
                return(value.value);
            }

            return(1);
        }
        public void ExecuteMod(InstructionParameter register, InstructionParameter basis)
        {
            switch (basis.type)
            {
            case InstructionParameterType.Value:
                _register.SetRegister(register.name, _register.GetRegister(register.name) % basis.value);
                break;

            case InstructionParameterType.Register:
                _register.SetRegister(register.name, _register.GetRegister(register.name) % _register.GetRegister(basis.name));
                break;
            }
        }
        public void ExecuteMul(InstructionParameter register, InstructionParameter factor)
        {
            switch (factor.type)
            {
            case InstructionParameterType.Value:
                _register.SetRegister(register.name, _register.GetRegister(register.name) * factor.value);
                break;

            case InstructionParameterType.Register:
                _register.SetRegister(register.name, _register.GetRegister(register.name) * _register.GetRegister(factor.name));
                break;
            }
        }
        public void ExecuteAdd(InstructionParameter register, InstructionParameter addition)
        {
            switch (addition.type)
            {
            case InstructionParameterType.Value:
                _register.SetRegister(register.name, _register.GetRegister(register.name) + addition.value);
                break;

            case InstructionParameterType.Register:
                _register.SetRegister(register.name, _register.GetRegister(register.name) + _register.GetRegister(addition.name));
                break;
            }
        }
        public void ExecuteSet(InstructionParameter register, InstructionParameter value)
        {
            switch (value.type)
            {
            case InstructionParameterType.Value:
                _register.SetRegister(register.name, value.value);
                break;

            case InstructionParameterType.Register:
                _register.SetRegister(register.name, _register.GetRegister(value.name));
                break;
            }
        }
        public void ExecuteSnd(InstructionParameter register)
        {
            switch (register.type)
            {
            case InstructionParameterType.Value:
                _bus.Send(register.value);
                break;

            case InstructionParameterType.Register:
                _bus.Send(_register.GetRegister(register.name));
                break;
            }
        }
示例#8
0
        void GetCurrentlyPlaying()
        {
            if (NextPoll > DateTime.Now)
            {
                return;
            }

            // Create Headers
            Dictionary <string, string> headers = new Dictionary <string, string>
            {
                { "Authorization", "Bearer " + OAuth2.Token }
            };

            // Get Response
            var json = Shared.Web.GetJSON(WebAPI.Responses.CurrentlyPlayingResponse.Endpoint, headers);

            // Process Response
            WebAPI.Responses.CurrentlyPlayingResponse responseObject = null;

            if (!string.IsNullOrEmpty(json) && json != "")
            {
                responseObject = JsonConvert.DeserializeObject <WebAPI.Responses.CurrentlyPlayingResponse>(json);

                if (responseObject != null)
                {
                    if (responseObject.Error != null)
                    {
                        Log.Message("Spotify", "An error (" + responseObject.Error.Code + ") occured while trying to poll the currently playing track. " + responseObject.Error.Description);
                    }
                    else if (responseObject.TrackID != LastTrack.ID)
                    {
                        LastTrack = responseObject.GetTrack();

                        // Call any subscribers
                        NewTrackEvent?.Invoke(this, LastTrack);

                        Dictionary <string, string> parameters = new Dictionary <string, string>
                        {
                            { "filename", "Spotify.txt" },
                            { "content", LastTrack.ToInfoString() }
                        };


                        Socket.SocketService socket = Server.Services.GetService <Socket.SocketService>();
                        socket.SendToAllSessions(Instruction.OpCode.TEXT_FILE, parameters, true, ScopeOutput);

                        parameters["filename"] = "Spotify_Artist.txt";
                        parameters["content"]  = LastTrack.Artist;
                        socket.SendToAllSessions(Instruction.OpCode.TEXT_FILE, parameters, true, ScopeOutput);

                        parameters["filename"] = "Spotify_Track.txt";
                        parameters["content"]  = LastTrack.Track;
                        socket.SendToAllSessions(Instruction.OpCode.TEXT_FILE, parameters, true, ScopeOutput);

                        parameters["filename"] = "Spotify_URL.txt";
                        parameters["content"]  = LastTrack.TrackURL;
                        socket.SendToAllSessions(Instruction.OpCode.TEXT_FILE, parameters, true, ScopeOutput);

                        if (!string.IsNullOrEmpty(LastTrack.ImageURL) && LastTrack.ImageURL != "")
                        {
                            LastTrack.ImageLargeData = Shared.Web.GetBytes(LastTrack.ImageURL);

                            Dictionary <string, InstructionParameter> instructions = new Dictionary <string, InstructionParameter>()
                            {
                                { "filename", new InstructionParameter("Spotify_TrackImage.jpg") },
                                { "content", InstructionParameter.CreateFromUnmarkedBytes(LastTrack.ImageLargeData) }
                            };

                            socket.SendToAllSessions(Instruction.OpCode.BINARY_FILE, instructions, true, ScopeOutput);
                        }

                        // Save track to database
                        LastTrack.SaveToDatabase();

                        // Boo it doesnt work like this currently, no custom alert types.
                        // Server.Services.GetService<Streamlabs.StreamlabsService>().Alert(LastTrack.ToInfoString(), "30000", LastTrack.ImageURL);

                        Log.Message("Spotify", LastTrack.ToString());
                    }
                }
                else
                {
                    Log.Error("Spotify", "Spotify failed to update currently playing. NULL Response Object.");
                }
            }
            else
            {
                Log.Error("Spotify", "Spotify failed to update currently playing. No Response.");
            }

            // Poll every 10 seconds?
            NextPoll = DateTime.Now.AddSeconds(10);
        }