sp_add_lamp() public method

public sp_add_lamp ( string username, byte password, string address, string name ) : int
username string
password byte
address string
name string
return int
Ejemplo n.º 1
0
        /// <summary>
        /// PSP 1.1
        /// Lampe in der DB hinzufügen, Hue-Bridge erkennt eine neue Lampe automatisch
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Passwort</param>
        /// <param name="lampAdress">Lampen Adreses</param>
        /// <param name="lampName">Lampen Name</param>
        /// <returns>success -> ob erfolgreich oder nicht</returns>
        public static bool addLamp(string username, string password, string lampAdress, string lampName)
        {
            bool success = false;
            //Übergebenes Passwort hashen und in Var pwhash speichern für Übergabe an DB
            Byte[] pwhash = HelperClass.GetHash(password);

            using (itin18_aktEntities cont = new itin18_aktEntities())
            {
                try
                {
                    cont.sp_add_lamp(username, pwhash, lampAdress, lampName);
                    //Neue Liste lamps von der HUE-Bridge holen
                    HueAccess.getLampList();
                    success = true;
                }
                catch (Exception e)
                {
                    success = false;
                }
            }
            
           
            return success;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// PSP 2.1
        /// Editieren eines Lampennamens anhand des alten Lampennamens
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Passwort</param>
        /// <param name="lampNameOld">alter Lampenname</param>
        /// <param name="lampNameNew">neuer Lampenname</param>
        /// <returns>success -> ob erfolgreich oder nicht</returns>
        internal static bool editLampName(string username, string password, string lampNameOld, string lampNameNew)
        {
            //Übergebenes Passwort hashen und in Var pwhash speichern für Übergabe an DB
            Byte[] pwhash = HelperClass.GetHash(password);
            bool success = false;
            using (itin18_aktEntities cont = new itin18_aktEntities())
            {
                
                List<fn_show_lamp_status_Result> dbLampStatus = null;
                List<fn_show_lamp_control_Result> dbLampsStatus = cont.fn_show_lamp_control(username, pwhash).ToList();
                List<fn_show_lamp_control_Result> dbLampsStatusResult = new List<fn_show_lamp_control_Result>();
                List<fn_show_lampgroups_Result> dbLampGroups = cont.fn_show_lampgroups(username, pwhash).ToList();
                List<fn_show_lampgroup_status_Result> dbLampGroupStatus = null;
                List<fn_show_lamps_Result> dbLampsNew = null;
                //temporäre Variablen
                int? dbLampIdNew = 0;
                int? dblampId = 0;
                string dblampAdr = "";
                string dbLampGroupName = "";

                try
                {
                    foreach (var item in dbLampsStatus)
                    {
                        // Suche des alten Namens zwecks Änderung
                        if (item.lampname == lampNameOld)
                        {
                            dblampId = item.lamp_id;

                            dblampAdr = item.address;

                            dbLampStatus = cont.fn_show_lamp_status(username, pwhash, item.lamp_id).ToList();

                            dbLampsStatusResult.Add(item);

                            dbLampGroupName = item.groupname;
                        }
                    }

                    //Edit gibt es nicht in der DB, Lampe wird gelöscht und wieder neu angelegt
                    cont.sp_delete_lamp(dblampId, username, pwhash);
                    cont.sp_add_lamp(username, pwhash, dblampAdr, lampNameNew);

                    dbLampsNew = cont.fn_show_lamps(username, pwhash).ToList();
                    foreach (var item in dbLampsNew)
                    {
                        if (item.name == lampNameNew)
                        {
                            dbLampIdNew = item.id;
                        }
                    }

                    foreach (var outerItem in dbLampGroups)
                    {
                        dbLampGroupStatus = cont.fn_show_lampgroup_status(username, pwhash, outerItem.id).ToList();
                        foreach (var innerItem in dbLampGroupStatus)
                        {
                            if (innerItem.id == dblampId)
                            {
                                cont.sp_delete_lamp_from_roomgroup(username, pwhash, outerItem.id, dblampId);
                                cont.sp_add_lamp_to_lampgroup(username, pwhash, outerItem.id, dbLampIdNew);
                            }
                        }
                    }

                    cont.sp_lamp_dimm(username, pwhash, dbLampIdNew, dbLampStatus[0].bright);
                    if (dbLampStatus[0].status == true)
                    {
                        cont.sp_lamp_on(username, pwhash, dbLampIdNew);
                    }
                    else
                    {
                        cont.sp_lamp_off(username, pwhash, dbLampIdNew);
                    }
                 //Namen der Lampe in der HUE-Bridge ändern
                 HelperClass.SetLampName(HueAccess.GetLampId(lampNameOld), lampNameNew);
                    success = true;
                }
                catch (Exception e)
                {
                    success = false;
                }
               
            }
            return success;
        }