Exemplo n.º 1
0
        //    /blink1/pattern/add -- Add color pattern to color pattern list
        static string Ublink1PatternAdd(HttpRequest request, Blink1Server blink1Server)
        {
            string pname      = request.Query.Get("pname");
            string patternstr = request.Query.Get("pattern");
            string statusstr  = "pattern add";

            Blink1Pattern pattern = null;

            if (pname != null && patternstr != null)
            {
                pattern = new Blink1Pattern(pname);
                Boolean goodpattern = pattern.parsePatternStr(patternstr);
                if (goodpattern)
                {
                    blink1Server.patterns[pname] = pattern; // NOTE: this replaces pattern if already exists
                }
                else
                {
                    statusstr = "error: pattern badly formatted";
                }
            }
            else
            {
                statusstr = "error: need 'pname' and 'pattern' (e.g. '2,#ff00ff,0.5,#00ff00,0.5') argument";
            }
            blink1Server.saveSettings();

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", statusstr);
            result.Add("pattern", pattern);
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 2
0
        //    /blink1/fadeToRGB -- Send fadeToRGB command to blink(1) with hex color & fade time
        static string Ublink1FadeToRGB(HttpRequest request, Blink1Server blink1Server)
        {
            // FIXME: stop pattern player
            //NameValueCollection query = request.Query;
            string rgbstr  = request.Query.Get("rgb");
            string timestr = request.Query.Get("time");

            Log("rgb: " + rgbstr);
            if (rgbstr == null)
            {
                rgbstr = "#000000";
            }
            if (timestr == null)
            {
                timestr = "0.1";
            }
            Color colr = ColorTranslator.FromHtml(rgbstr);
            float secs = float.Parse(timestr, CultureInfo.InvariantCulture);

            blink1Server.fadeToRGB(secs, colr);

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", "fadeToRGB");
            result.Add("rgb", Blink1.colorToHexCode(colr));
            result.Add("time", secs.ToString("F2", CultureInfo.InvariantCulture));
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 3
0
        // -----------------------------------------------------------------------------------------------
        // color patterns url handling
        //

        //    /blink1/pattern/ -- List saved color patterns
        static string Ublink1Pattern(HttpRequest request, Blink1Server blink1Server)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", "pattern results");
            result.Add("patterns", blink1Server.patterns.Values);
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 4
0
        //    /blink1/lastColor -- Return the last color command sent to blink(1)
        static string Ublink1LastColor(HttpRequest request, Blink1Server blink1Server)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", "lastColor");
            result.Add("lastColor", blink1Server.blink1.lastColorString);
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 5
0
        //    /blink1/pattern/stopall -- Stop all pattern playback
        static string Ublink1PatternStopAll(HttpRequest request, Blink1Server blink1Server)
        {
            blink1Server.stopAllPatterns();
            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", "all patterns stopped");
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 6
0
 public Blink1Input(Blink1Server b1s, string iname, string pname, string type, string arg1, string arg2, string arg3)
 {
     this.blink1Server = b1s;
     this.iname = iname; 
     this.pname = pname;
     this.type = type;
     this.arg1 = arg1; this.arg2 = arg2; this.arg3 = arg3;
     this.lastDateTime = DateTime.Now;  // FIXME: what about UTC?
 }
Exemplo n.º 7
0
        //    /blink1/off -- Stop pattern playback and send fadeToRGB command to blink(1) with #000000 & 0.1 sec fade time
        static string Ublink1Off(HttpRequest request, Blink1Server blink1Server)
        {
            blink1Server.stopAllPatterns();
            blink1Server.fadeToRGB(0.1, Color.Black);

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", "off");
            return(JsonConvert.SerializeObject(result, Formatting.Indented));
        }
Exemplo n.º 8
0
 public Blink1Input(Blink1Server b1s, string iname, string pname, string type, string arg1, string arg2, string arg3)
 {
     this.blink1Server = b1s;
     this.iname        = iname;
     this.pname        = pname;
     this.type         = type;
     this.arg1         = arg1; this.arg2 = arg2; this.arg3 = arg3;
     this.lastDateTime = DateTime.Now.ToUniversalTime();  // FIXME: what about UTC?
     this.possibleVals = new List <string>();
 }
Exemplo n.º 9
0
 public Blink1JSONFile(string name, IDirectory parent, Blink1Server aBlink1Server)
 {
     this.name         = name;
     this.parent       = parent;
     this.blink1Server = aBlink1Server;
     GetStringResponse = delegate(HttpRequest input, Blink1Server bs)
     {
         return(input.ToString()); //placeholder
     };
 }
Exemplo n.º 10
0
        //    /blink1/input/delall -- Remove all configured inputs
        static string Ublink1InputDelAll(HttpRequest request, Blink1Server blink1Server)
        {
            foreach (KeyValuePair <string, Blink1Input> kvp in blink1Server.inputs)
            {
                kvp.Value.stop();
            }
            blink1Server.inputs.Clear();
            blink1Server.saveSettings();

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", "all patterns removed");
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 11
0
 /// <summary>
 /// Get contents of file into string
 /// </summary>
 /// <param name="filepath">full filepath of file to read</param>
 /// <returns>contents of file or null</returns>
 public static string getContentsOfFile(string filepath)
 {
     try {
         using (StreamReader sr = new StreamReader(filepath)) {
             String contents = sr.ReadToEnd();
             Blink1Server.Log("file contents:" + contents);
             return(contents);
         }
     }
     catch (Exception e) {
         Blink1Server.Log("The file could not be read:");
         Blink1Server.Log(e.Message);
     }
     return(null);
 }
Exemplo n.º 12
0
        // ---------------------------------------------------------------------------
        // inputs
        //

        //    /blink1/input/ -- List configured inputs, enable or disable input watching
        static string Ublink1Input(HttpRequest request, Blink1Server blink1Server)
        {
            string enabled = request.Query.Get("enabled");

            if (enabled != null)
            {
                blink1Server.inputsEnable = (enabled.Equals("on") || enabled.Equals("true"));
            }
            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", "input results");
            result.Add("enabled", blink1Server.inputsEnable);
            result.Add("inputs", blink1Server.inputs.Values);
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 13
0
        //
        // direct blink(1) control url handling
        //

        //    /blink1/id -- Display blink1_id and blink1 serial numbers (if any)
        static string Ublink1Id(HttpRequest request, Blink1Server blink1Server)
        {
            Blink1 blink1 = blink1Server.blink1;
            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("blink1_id", blink1.blink1Id);
            List <string> serialnums = new List <string>();

            for (int i = 0; i < blink1.getCachedCount(); i++)    // FIXME: surely a smarter way to do this
            {
                serialnums.Add(blink1.getCachedSerial(i));
            }
            result.Add("blink1_serialnums", serialnums);
            result.Add("status", "blink1 id");
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 14
0
 private void notifyIcon1_Click(object sender, EventArgs e)
 {
     Blink1Server.Log("notifyIcon1 SingleClick! " + e);
     stripMenuBlink1Status.Text = "blink1 status: hello";
     if (blink1Server.blink1.getCachedCount() > 0)
     {
         stripMenuBlink1Status.Text = "blink(1) found";
         stripMenuBlink1Id.Text     = "serial: " + blink1Server.blink1.getCachedSerial(0);
         stripMenuKey.Text          = "key: " + blink1Server.blink1.blink1Id;
     }
     else
     {
         stripMenuBlink1Status.Text = "blink(1) not found";
         stripMenuBlink1Id.Text     = "serial: -none-";
         stripMenuKey.Text          = "key: " + blink1Server.blink1.blink1Id;
     }
 }
Exemplo n.º 15
0
        /// <summary>
        /// periodically fetch events from IFTTT gateway
        /// </summary>
        /// <returns>true if pattern was played from input match</returns>
        public Boolean updateIftttInput()
        {
            if (iftttLastContent == null)
            {
                lastVal      = "[couldn't connect]";
                lastDateTime = DateTime.Now.ToUniversalTime();
                return(false);
            }

            string rulename = arg1;

            IftttResponse iftttResponse = JsonConvert.DeserializeObject <IftttResponse>(iftttLastContent);

            if (iftttResponse.event_count > 0)
            {
                long lastsecs = (long)ConvertToUnixTimestamp(lastDateTime);
                //long lastsecs = epochSecs(lastDateTime);
                possibleVals.Clear();
                foreach (IftttEvent ev in iftttResponse.events)    // FIXME: loop overwrites per-obj props
                {
                    long evdate = long.Parse(ev.date);
                    //Blink1Server.Log("evdate: " + evdate + ", lastsecs:" + lastsecs);
                    lastDateTime = ConvertFromUnixTimestamp(evdate);
                    string evname = ev.name;
                    possibleVals.Add(ev.name);
                    lastVal = ev.source;
                    if (rulename.Equals(evname))
                    {
                        Blink1Server.Log("---ifttt match: evdate:" + evdate + ", lastsecs:" + lastsecs + ", dt:" + (evdate - lastsecs));
                        if (evdate > lastsecs)
                        {
                            blink1Server.playPattern(pname);
                            return(true);
                        }
                    }
                }
            }
            else
            {
                lastVal      = "[no events]";
                lastDateTime = DateTime.Now.ToUniversalTime();
            }
            return(false);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Execute a script
        /// </summary>
        /// <param name="scriptpath"></param>
        /// <returns></returns>
        public static string execScript(string scriptpath)
        {
            //stolen from: http://stackoverflow.com/questions/878632/best-way-to-call-external-program-in-c-sharp-and-parse-output
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName               = "cmd.exe";
            p.StartInfo.Arguments              = "/c " + scriptpath; // dir *.cs";
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.CreateNoWindow         = true;
            p.StartInfo.RedirectStandardError  = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.Start();

            string output = p.StandardOutput.ReadToEnd();

            p.WaitForExit();
            Blink1Server.Log("Output:" + output);

            return(output);
        }
Exemplo n.º 17
0
        //    /blink1/logging -- Set logging level (or turn it off)
        static string Ublink1Logging(HttpRequest request, Blink1Server blink1Server)
        {
            string loglevelstr = request.Query.Get("loglevel");
            int    loglevel    = (logToScreen) ? 1 : 0;

            if (loglevelstr != null)
            {
                loglevel    = int.Parse(loglevelstr, CultureInfo.InvariantCulture);
                logToScreen = (loglevel >= 1);
                blink1Server.saveSettings();
            }
            Log("loglevel: " + loglevel);

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", "logging");
            result.Add("loglevel", loglevel);
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 18
0
        //    /blink1/pattern/stop -- Stop a pattern playback for a given pattern
        static string Ublink1PatternStop(HttpRequest request, Blink1Server blink1Server)
        {
            string pname     = request.Query.Get("pname");
            string statusstr = "no pattern by that name";

            if (pname != null)
            {
                Blink1Pattern patt = null;
                if (blink1Server.patterns.TryGetValue(pname, out patt))
                {
                    patt.stop();
                    statusstr = "pattern '" + pname + "' stopped";
                }
            }
            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", statusstr);
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 19
0
        //    /blink1/pattern/del -- Remove color pattern from color pattern list
        static string Ublink1PatternDel(HttpRequest request, Blink1Server blink1Server)
        {
            string        pname     = request.Query.Get("pname");
            string        statusstr = "no pattern by that name";
            Blink1Pattern patt      = null;

            if (pname != null)
            {
                patt = blink1Server.patterns[pname];
                patt.stop();
                blink1Server.patterns.Remove(pname);
                statusstr = "pattern '" + pname + "' removed";
            }
            blink1Server.saveSettings();

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", statusstr);
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 20
0
        //    /blink1/input/ifttt -- Add and Start watching messages from IFTTT webservice
        static string Ublink1InputIfttt(HttpRequest request, Blink1Server blink1Server)
        {
            string pname    = request.Query.Get("pname");
            string iname    = request.Query.Get("iname");
            string rulename = request.Query.Get("arg1");
            string test     = request.Query.Get("test");

            if (pname == null)
            {
                pname = iname;
            }
            Boolean testmode = (test == null) ? false : (test.Equals("on") || test.Equals("true"));

            string statusstr = "must specifiy 'iname' and 'arg1' (rulename)";

            Blink1Input input = null;

            if (rulename != null && iname != null)
            {
                statusstr = "input ifttt";
                rulename  = rulename.Trim();
                input     = new Blink1Input(blink1Server, iname, pname, "ifttt", rulename);

                if (testmode)   // override periodic fetch for immediate fetch
                {
                    Blink1Input.getIftttResponse(false);
                }
                input.updateIftttInput();
                if (!testmode)
                {
                    blink1Server.inputs[iname] = input; // NOTE: this replaces input if already exists
                }
            }
            blink1Server.saveSettings();

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", statusstr);
            result.Add("input", input);
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 21
0
        //    /blink1/input/del -- Remove a configured input
        static string Ublink1InputDel(HttpRequest request, Blink1Server blink1Server)
        {
            string      iname     = request.Query.Get("iname");
            string      statusstr = "no input by that name";
            Blink1Input input     = null;

            if (iname != null)
            {
                input = blink1Server.inputs[iname];
                input.stop();
                blink1Server.inputs.Remove(iname);
                statusstr = "input '" + iname + "' removed";
            }

            blink1Server.saveSettings();

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", statusstr);
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 22
0
        /// <summary>
        /// Called whenever a new color needs to be played, via timer
        /// </summary>
        public void update(Object stateInfo)
        {
            if (!playing)
            {
                return;
            }
            Blink1Server.Log("update! " + name);

            Boolean scheduleNext = true;

            playpos++;
            if (playpos == times.Count())
            {
                playpos = 0;
                if (repeats != 0)     // infinite
                {
                    playcount++;
                    if (playcount == repeats)
                    {
                        scheduleNext = false;
                    }
                }
            }

            if (scheduleNext)
            {
                float nextTime = times[playpos];
                Color color    = colors[playpos];
                Blink1Server.Log("update: scheduleNext: " + nextTime);
                //DLog(@"%@ updt p:%d c:%d %@ nextTime:%f",name,playpos,playcount,[Blink1 hexStringFromColor:color],nextTime);
                blink1Server.fadeToRGB(nextTime / 2, color);
                timer = new Timer(update, null, (int)(nextTime * 1000), 0);
            }
            else
            {
                playing = false;
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Get the contents of a URL into string
        /// </summary>
        /// <param name="url">the url to fetch</param>
        /// <returns>contents of url or null</returns>
        public static string getContentsOfUrl(string url)
        {
            // stolen from: http://stackoverflow.com/questions/9961220/webclient-read-content-of-error-page
            Blink1Server.Log("getContentsOfUrl:" + url);  // FIXME: how to do debug logging better?
            string content = null;

            if (url == null)
            {
                return(null);
            }
            WebClient webclient = new WebClient();

            try {
                content = webclient.DownloadString(url);
            }
            catch (WebException we) {
                // WebException.Status holds useful information
                Blink1Server.Log("webex:" + we.Message); // + "\n" + we.Status.ToString());  // FIXME:

                /*
                 * Stream receiveStream = we.Response.GetResponseStream();
                 * Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
                 * StreamReader readStream = new StreamReader(receiveStream, encode);
                 * content = readStream.ReadToEnd();
                 * Blink1Server.Log("content: " + content);
                 */
                content = "{\"lastVal\":\"url not found\"}";
            }
            catch (System.ArgumentException sae) {
                Blink1Server.Log("sae:" + sae.Message);
            }
            catch (NotSupportedException ne) {
                Blink1Server.Log("ne:" + ne.Message);   // other errors
            }
            return(content);
        }
Exemplo n.º 24
0
        //    /blink1/input/script -- Add and Start command-line script executer
        static string Ublink1InputScript(HttpRequest request, Blink1Server blink1Server)
        {
            string pname = request.Query.Get("pname");
            string iname = request.Query.Get("iname");
            string fpath = request.Query.Get("arg1").Trim();
            string test  = request.Query.Get("test");

            if (pname == null)
            {
                pname = iname;
            }
            Boolean testmode = (test == null) ? false : (test.Equals("on") || test.Equals("true"));

            string statusstr = "must specifiy 'iname' and 'arg1' (script filepath)";

            Blink1Input input = null;

            if (fpath != null && iname != null)
            {
                statusstr = "input script";
                input     = new Blink1Input(blink1Server, iname, pname, "script", fpath);

                input.updateScriptInput();
                if (!testmode)
                {
                    blink1Server.inputs[iname] = input; // NOTE: this replaces input if already exists
                }
            }
            blink1Server.saveSettings();

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", statusstr);
            result.Add("input", input);
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Exemplo n.º 25
0
 public Blink1Input(Blink1Server b1s, string iname, string pname, string type, string arg1)
     : this(b1s, iname, pname, type, arg1, null, null)
 {
 }
Exemplo n.º 26
0
        //    /blink1/pattern/del -- Remove color pattern from color pattern list
        static string Ublink1PatternDel(HttpRequest request, Blink1Server blink1Server)
        {
            string pname = request.Query.Get("pname");
            string statusstr = "no pattern by that name";
            Blink1Pattern patt = null;
            if (pname != null) {
                patt = blink1Server.patterns[pname];
                patt.stop();
                blink1Server.patterns.Remove(pname);
                statusstr = "pattern '" + pname + "' removed";
            }
            blink1Server.saveSettings();

            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("status", statusstr);
            return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
        }
Exemplo n.º 27
0
        //    /blink1/regenerateblinkid -- Generate, save, and return new blink1_id
        static string Ublink1RegenerateBlink1Id(HttpRequest request, Blink1Server blink1Server)
        {
            Blink1 blink1 = blink1Server.blink1;
            string blink1Id_old = blink1.blink1Id;

            blink1.hostId = null;
            blink1.enumerate();
            blink1.regenerateBlink1Id();

            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("blink1_id_old", blink1Id_old);
            result.Add("blink1_id", blink1.blink1Id);
            List<string> serialnums = new List<string>();
            for (int i = 0; i < blink1.getCachedCount(); i++) {  // FIXME: surely a smarter way to do this
                serialnums.Add(blink1.getCachedSerial(i));
            }
            result.Add("blink1_serialnums", serialnums);
            result.Add("status", "regenrateblink1id");
            return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
        }
Exemplo n.º 28
0
 // TESTING
 static string Ufoobar(HttpRequest request, Blink1Server blink1Server)//example
 {
     return "\n\n{ yup this works }\n\n";
 }
Exemplo n.º 29
0
        //    /blink1/input/script -- Add and Start command-line script executer
        static string Ublink1InputScript(HttpRequest request, Blink1Server blink1Server)
        {
            string pname = request.Query.Get("pname");
            string iname = request.Query.Get("iname");
            string fpath = request.Query.Get("arg1").Trim();
            string test = request.Query.Get("test");
            if (pname == null) pname = iname;
            Boolean testmode = (test == null) ? false : (test.Equals("on") || test.Equals("true"));

            string statusstr = "must specifiy 'iname' and 'arg1' (script filepath)";

            Blink1Input input = null;
            if (fpath != null && iname != null) {
                statusstr = "input script";
                input = new Blink1Input(blink1Server, iname, pname, "script", fpath);

                input.updateScriptInput();
                if (!testmode) {
                    blink1Server.inputs[iname] = input; // NOTE: this replaces input if already exists
                }
            }
            blink1Server.saveSettings();

            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("status", statusstr);
            result.Add("input", input);
            return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
        }
Exemplo n.º 30
0
        //    /blink1/fadeToRGB -- Send fadeToRGB command to blink(1) with hex color & fade time
        static string Ublink1FadeToRGB(HttpRequest request, Blink1Server blink1Server)
        {
            // FIXME: stop pattern player
            //NameValueCollection query = request.Query;
            string rgbstr = request.Query.Get("rgb");
            string timestr = request.Query.Get("time");
            Log("rgb: " + rgbstr);
            if (rgbstr == null) rgbstr = "#000000";
            if (timestr == null) timestr = "0.1";
            Color colr = ColorTranslator.FromHtml(rgbstr);
            float secs = float.Parse(timestr, CultureInfo.InvariantCulture);

            blink1Server.fadeToRGB(secs, colr);

            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("status", "fadeToRGB");
            result.Add("rgb", Blink1.colorToHexCode(colr));
            result.Add("time", secs.ToString("F2", CultureInfo.InvariantCulture));
            return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
        }
Exemplo n.º 31
0
        //    /blink1/logging -- Set logging level (or turn it off)
        static string Ublink1Logging(HttpRequest request, Blink1Server blink1Server)
        {
            string loglevelstr = request.Query.Get("loglevel");
            int loglevel = (logToScreen) ? 1 : 0;
            if (loglevelstr != null) {
                loglevel = int.Parse(loglevelstr, CultureInfo.InvariantCulture);
                logToScreen = (loglevel >= 1);
                blink1Server.saveSettings();
            }
            Log("loglevel: " + loglevel);

            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("status", "logging");
            result.Add("loglevel", loglevel);
            return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
        }
Exemplo n.º 32
0
 // TESTING
 static string Ufoobar(HttpRequest request, Blink1Server blink1Server)//example
 {
     //Properties.Settings.Default["blink1Id"] = blink1Server.blink1Id;
     //Properties.Settings.Default.Save();
     //Settings.Default["blink1Id"] = blink1.getBlink1Id();
     //Settings.Default.Save(); // Saves settings in application configuration file
     return "\n\n{ suck it whitey }\n\n";
 }
Exemplo n.º 33
0
 // TESTING
 static string Ufoobar(HttpRequest request, Blink1Server blink1Server)//example
 {
     return("\n\n{ yup this works }\n\n");
 }
Exemplo n.º 34
0
        // -----------------------------------------------------------------------------------------------
        // color patterns url handling
        //

        //    /blink1/pattern/ -- List saved color patterns
        static string Ublink1Pattern(HttpRequest request, Blink1Server blink1Server)
        {
            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("status", "pattern results");
            result.Add("patterns", blink1Server.patterns.Values);
            return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
        }
Exemplo n.º 35
0
        //    /blink1/pattern/add -- Add color pattern to color pattern list
        static string Ublink1PatternAdd(HttpRequest request, Blink1Server blink1Server)
        {
            string pname = request.Query.Get("pname");
            string patternstr = request.Query.Get("pattern");
            string statusstr = "pattern add";

            Blink1Pattern pattern = null;
            if (pname != null && patternstr != null) {
                pattern = new Blink1Pattern(pname);
                Boolean goodpattern = pattern.parsePatternStr(patternstr);
                if (goodpattern) {
                    blink1Server.patterns[pname] = pattern; // NOTE: this replaces pattern if already exists
                }
                else {
                    statusstr = "error: pattern badly formatted";
                }
            }
            else {
                statusstr = "error: need 'pname' and 'pattern' (e.g. '2,#ff00ff,0.5,#00ff00,0.5') argument";
            }
            blink1Server.saveSettings();

            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("status", statusstr);
            result.Add("pattern", pattern);
            return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
        }
Exemplo n.º 36
0
 public Blink1JSONFile(string name, IDirectory parent, Blink1Server aBlink1Server)
 {
     this.name = name;
     this.parent = parent;
     this.blink1Server = aBlink1Server;
     GetStringResponse = delegate(HttpRequest input, Blink1Server bs)
     {
         return input.ToString(); //placeholder
     };
 }
Exemplo n.º 37
0
        //    /blink1/input/ifttt -- Add and Start watching messages from IFTTT webservice
        static string Ublink1InputIfttt(HttpRequest request, Blink1Server blink1Server)
        {
            string pname = request.Query.Get("pname");
            string iname = request.Query.Get("iname");
            string rulename = request.Query.Get("arg1");
            string test = request.Query.Get("test");
            if (pname == null) pname = iname;
            Boolean testmode = (test == null) ? false : (test.Equals("on") || test.Equals("true"));

            string statusstr = "must specifiy 'iname' and 'arg1' (rulename)";

            Blink1Input input = null;
            if (rulename != null && iname != null) {
                statusstr = "input ifttt";
                rulename = rulename.Trim();
                input = new Blink1Input(blink1Server, iname, pname, "ifttt", rulename);

                if (testmode) { // override periodic fetch for immediate fetch
                    Blink1Input.getIftttResponse(false);
                }
                input.updateIftttInput();
                if (!testmode) {
                    blink1Server.inputs[iname] = input; // NOTE: this replaces input if already exists
                }
            }
            blink1Server.saveSettings();

            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("status", statusstr);
            result.Add("input", input);
            return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
        }
Exemplo n.º 38
0
        //    /blink1/input/url -- Add and Start URL watcher on given URL
        static string Ublink1InputUrl(HttpRequest request, Blink1Server blink1Server)
        {
            string pname = request.Query.Get("pname");
            string iname = request.Query.Get("iname");
            string url = request.Query.Get("arg1");
            string test = request.Query.Get("test");
            if (pname == null) pname = iname;
            Boolean testmode = (test == null) ? false : (test.Equals("on") || test.Equals("true"));

            string statusstr = "must specifiy 'iname' and 'arg1' (url)";

            Blink1Input input = null;
            if (url != null && iname != null) {
                statusstr = "input url";
                input = new Blink1Input(iname, "url", url, null, null);
                input.blink1Server = blink1Server;
                input.pname = pname;

                input.updateUrlInput();
                if (!testmode) {
                    blink1Server.inputs[iname] = input; // NOTE: this replaces input if already exists
                }
            }

            blink1Server.saveSettings();

            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("status", statusstr);
            result.Add("input", input);
            return JsonConvert.SerializeObject(result, Formatting.Indented,jsonSerializerSettings);
        }
Exemplo n.º 39
0
 //    /blink1/lastColor -- Return the last color command sent to blink(1)
 static string Ublink1LastColor(HttpRequest request, Blink1Server blink1Server)
 {
     Dictionary<string, object> result = new Dictionary<string, object>();
     result.Add("status", "lastColor");
     result.Add("lastColor", blink1Server.blink1.lastColorString);
     return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
 }
Exemplo n.º 40
0
        //    /blink1/on -- Stop pattern playback and send fadeToRGB command to blink(1) with #FFFFFF & 0.1 sec fade time
        static string Ublink1On(HttpRequest request, Blink1Server blink1Server)
        {
            blink1Server.fadeToRGB(0.1, Color.White);

            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("status", "on");
            return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
        }
Exemplo n.º 41
0
        //    /blink1/off -- Stop pattern playback and send fadeToRGB command to blink(1) with #000000 & 0.1 sec fade time
        static string Ublink1Off(HttpRequest request, Blink1Server blink1Server)
        {
            blink1Server.stopAllPatterns();
            blink1Server.fadeToRGB(0.1, Color.Black);

            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("status", "off");
            return JsonConvert.SerializeObject(result, Formatting.Indented);
        }
Exemplo n.º 42
0
 //    /blink1/pattern/stopall -- Stop all pattern playback
 static string Ublink1PatternStopAll(HttpRequest request, Blink1Server blink1Server)
 {
     blink1Server.stopAllPatterns();
     Dictionary<string, object> result = new Dictionary<string, object>();
     result.Add("status", "all patterns stopped");
     return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
 }
Exemplo n.º 43
0
 //    /blink1/pattern/stop -- Stop a pattern playback for a given pattern
 static string Ublink1PatternStop(HttpRequest request, Blink1Server blink1Server)
 {
     string pname = request.Query.Get("pname");
     string statusstr = "no pattern by that name";
     if (pname != null) {
         Blink1Pattern patt = null;
         if (blink1Server.patterns.TryGetValue(pname, out patt)) {
             patt.stop();
             statusstr = "pattern '" + pname + "' stopped";
         }
     }
     Dictionary<string, object> result = new Dictionary<string, object>();
     result.Add("status", statusstr);
     return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
 }
Exemplo n.º 44
0
        // ---------------------------------------------------------------------------
        // inputs
        //

        //    /blink1/input/ -- List configured inputs, enable or disable input watching
        static string Ublink1Input(HttpRequest request, Blink1Server blink1Server)
        {
            string enabled = request.Query.Get("enabled");
            if (enabled != null) {
                blink1Server.inputsEnable = (enabled.Equals("on") || enabled.Equals("true"));
            }
            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("status", "input results");
            result.Add("enabled", blink1Server.inputsEnable);
            result.Add("inputs", blink1Server.inputs.Values);
            return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
        }
Exemplo n.º 45
0
        //    /blink1/input/del -- Remove a configured input
        static string Ublink1InputDel(HttpRequest request, Blink1Server blink1Server)
        {
            string iname = request.Query.Get("iname");
            string statusstr = "no input by that name";
            Blink1Input input = null;
            if (iname != null) {
                if (blink1Server.inputs.TryGetValue(iname, out input)) {
                    input.stop();
                    blink1Server.inputs.Remove(iname);
                    statusstr = "input '" + iname + "' removed";
                }
            }

            blink1Server.saveSettings();

            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("status", statusstr);
            return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
        }
Exemplo n.º 46
0
 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 {
     Blink1Server.Log("FormClosed!");
     doExit();
 }
Exemplo n.º 47
0
        //    /blink1/input/delall -- Remove all configured inputs
        static string Ublink1InputDelAll(HttpRequest request, Blink1Server blink1Server)
        {
            foreach (KeyValuePair<string, Blink1Input> kvp in blink1Server.inputs) {
                kvp.Value.stop();
            }
            blink1Server.inputs.Clear();
            blink1Server.saveSettings();

            Dictionary<string, object> result = new Dictionary<string, object>();
            result.Add("status", "all patterns removed");
            return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
        }
Exemplo n.º 48
0
 public Blink1Input(Blink1Server b1s, string iname, string pname, string type, string arg1)
     : this(b1s, iname, pname, type, arg1, null, null)
 {
 }
Exemplo n.º 49
0
 public Blink1Input(Blink1Server b1s, string iname, string pname, string type, string arg1, string arg2, string arg3)
 {
     this.blink1Server = b1s;
     this.iname = iname; 
     this.pname = pname;
     this.type = type;
     this.arg1 = arg1; this.arg2 = arg2; this.arg3 = arg3;
     this.lastDateTime = DateTime.Now.ToUniversalTime();  // FIXME: what about UTC?
     this.possibleVals = new List<string>();
 }