Пример #1
0
        public void AsyncIPimpCommand(CommandInfoIPimp command)
        {
            var bw = new BackgroundWorker();

            bw.DoWork += AsyncIPimpCommandWorker;
            bw.RunWorkerAsync(command);
        }
Пример #2
0
        public bool IPimpButton(string button)
        {
            var args = new CommandInfoIPimp
            {
                Action = "button",
                Filter = button,
            };

            var result = IPimpCommand(args);

            return(Convert.ToBoolean(result["result"], CultureInfo.InvariantCulture));
        }
Пример #3
0
        public JsonArray IPimpDBCommand(CommandInfoIPimp cmd, string name)
        {
            if (!_configured)
            {
                return(null);
            }

            var result = IPimpCommand(cmd);

            if (result == null)
            {
                return(null);
            }

            try
            {
                return((JsonArray)result[name]);
            }
            catch (JsonException e)
            {
                Log("ERROR - DBCOMMAND : " + cmd + " - " + e.Message);
            }
            return(null);
        }
Пример #4
0
        public JsonObject IPimpCommand(CommandInfoIPimp command)
        {
            var error = new JsonObject();

            error["result"] = false;

            if (command == null)
            {
                return(error);
            }

            lock (Locker)
            {
                var args = new JsonObject();
                args["action"]   = command.Action;
                args["filter"]   = command.Filter;
                args["value"]    = command.Value;
                args["start"]    = command.Start;
                args["pagesize"] = command.PageSize;
                args["shuffle"]  = command.Shuffle;
                args["enqueue"]  = command.Enqueue;
                args["tracks"]   = command.Tracks;

                if (command.Action != "ping" && command.Action != "nowplaying")
                {
                    Log("COMMAND : " + args);
                }
                else
                {
                    Trace("COMMAND : " + args);
                }

                var myCompleteMessage = "";

                var webRequest = WebRequest.Create(GetApiPath());
                webRequest.Method = "POST";

                var byteArray = Encoding.UTF8.GetBytes(args.ToString());
                webRequest.ContentType   = "application/x-www-form-urlencoded";
                webRequest.ContentLength = byteArray.Length;

                try
                {
                    var datastream = webRequest.GetRequestStream();
                    {
                        datastream.Write(byteArray, 0, byteArray.Length);
                        datastream.Close();

                        var webResponse = webRequest.GetResponse();
                        if (webResponse != null)
                        {
                            using (var datastream2 = webResponse.GetResponseStream())
                            {
                                if (datastream2 != null)
                                {
                                    var reader = new StreamReader(datastream2);
                                    myCompleteMessage = reader.ReadToEnd();
                                }
                            }
                            webResponse.Close();
                        }
                    }
                }
                catch (Exception)
                {
                    if (command.Action != "ping" && command.Action != "nowplaying")
                    {
                        Log("ERROR - COMMAND : " + args);
                    }
                    else
                    {
                        Trace("ERROR - COMMAND : " + args);
                    }
                    myCompleteMessage = error.ToString();
                }

                Trace(myCompleteMessage);
                return((JsonObject)JsonConvert.Import(myCompleteMessage));
            }
        }
Пример #5
0
        public JsonArray IPimpDBCommand(CommandInfoIPimp cmd, string name)
        {
            if (!_configured) return null;

            var result = IPimpCommand(cmd);
            if (result == null)
                return null;

            try
            {
                return (JsonArray)result[name];
            }
            catch (JsonException e)
            {
                Log("ERROR - DBCOMMAND : " + cmd + " - " + e.Message);
            }
            return null;
        }
Пример #6
0
        public JsonObject IPimpCommand(CommandInfoIPimp command)
        {
            var error = new JsonObject();
            error["result"] = false;

            if (command == null)
                return error;

            lock (Locker)
            {
                var args = new JsonObject();
                args["action"] = command.Action;
                args["filter"] = command.Filter;
                args["value"] = command.Value;
                args["start"] = command.Start;
                args["pagesize"] = command.PageSize;
                args["shuffle"] = command.Shuffle;
                args["enqueue"] = command.Enqueue;
                args["tracks"] = command.Tracks;

                if (command.Action != "ping" && command.Action != "nowplaying")
                    Log("COMMAND : " + args);
                else
                    Trace("COMMAND : " + args);

                var myCompleteMessage = "";

                var webRequest = WebRequest.Create(GetApiPath());
                webRequest.Method = "POST";

                var byteArray = Encoding.UTF8.GetBytes(args.ToString());
                webRequest.ContentType = "application/x-www-form-urlencoded";
                webRequest.ContentLength = byteArray.Length;

                try
                {
                    var datastream = webRequest.GetRequestStream();
                    {
                        datastream.Write(byteArray, 0, byteArray.Length);
                        datastream.Close();

                        var webResponse = webRequest.GetResponse();
                        if (webResponse != null)
                        {
                            using (var datastream2 = webResponse.GetResponseStream())
                            {
                                if (datastream2 != null)
                                {
                                    var reader = new StreamReader(datastream2);
                                    myCompleteMessage = reader.ReadToEnd();
                                }
                            }
                            webResponse.Close();
                        }
                    }
                }
                catch (Exception)
                {
                    if (command.Action != "ping" && command.Action != "nowplaying")
                        Log("ERROR - COMMAND : " + args);
                    else
                        Trace("ERROR - COMMAND : " + args);
                    myCompleteMessage = error.ToString();
                }

                Trace(myCompleteMessage);
                return (JsonObject)JsonConvert.Import(myCompleteMessage);
            }
        }
Пример #7
0
        public bool IPimpButton(string button)
        {
            var args = new CommandInfoIPimp
                           {
                               Action = "button",
                               Filter = button,
                           };

            var result = IPimpCommand(args);
            return Convert.ToBoolean(result["result"],CultureInfo.InvariantCulture);
        }
Пример #8
0
 public  void AsyncIPimpCommand(CommandInfoIPimp command)
 {
     var bw = new BackgroundWorker();
     bw.DoWork += AsyncIPimpCommandWorker;
     bw.RunWorkerAsync(command);
 }