Esempio n. 1
0
    public void Admin_GetCategoryAndConnectByCommand()
    {
        UControlAPI api = new UControlAPI();


        string UCommandId = GetParams("UCommandId");
        bool   IsOnline   = true;//GetBoolParams("IsOnline");

        DataSet ds = Dal.ExeDataSetSp("Admin_GetCategoryAndConnectByCommand", UCommandId);

        try
        {
            DataTable dtCommand = ds.Tables[0];
            DataTable dt        = ds.Tables[1];

            if (IsOnline)
            {
                DataTable dtResult  = GetStatusObjFromTELIT(dtCommand, api, "UCommKey", IsOnline);
                string    IsConnect = dtResult.Rows[0]["IsConnect"].ToString();
                if (IsConnect != "True" && IsOnline)
                {
                    HttpContext.Current.Response.Write(ConvertDataTabletoString(dtResult));
                    return;
                }

                dt = GetStatusObjFromTELIT(dt, api, "UConnKey", IsOnline);
            }
            HttpContext.Current.Response.Write(ConvertDataTabletoString(dt));
        }
        catch (Exception ex)
        {
        }
    }
Esempio n. 2
0
    public void User_GetUserEnter()
    {
        //  List<ClassStatus> dd = WebDatesManager.Instance.getDateListClassesStatus(1);
        //  OfekWebManager.Instance.changedClassForceStatus(102,1);
        // OfekWebManager.IP = "192.168.1.20";
        //   OfekWebManager.Instance.changedClassForceStatus(102, 1);


        //ow.sendEliorTest(5100, 5051, false);
        //ow.sendEliorTest(5150, 5101, false);
        //ow.sendEliorTest(5200, 5151, false);
        //   ow.changedClassForceStatus(102, 1);

        string UserName = GetParams("UserName");
        string Password = GetParams("Password");

        UControlAPI api = new UControlAPI();

        //    string sess = api.GetSessionId();

        DataTable dt = Dal.ExeSp("User_GetUserEnter", UserName, Password);


        if (dt.Rows.Count > 0)
        {
            HttpCookie cookie = new HttpCookie("UserData");
            cookie["UserId"] = dt.Rows[0]["UserId"].ToString();
            cookie["RoleId"] = dt.Rows[0]["RoleId"].ToString();
            // cookie["ConfigurationId"] = dt.Rows[0]["ConfigurationId"].ToString();
            cookie["UserName"] = Server.UrlEncode(dt.Rows[0]["UserName"].ToString());

            //School Name
            cookie["SchoolId"] = Server.UrlEncode(dt.Rows[0]["SchoolId"].ToString());
            cookie["Name"]     = Server.UrlEncode(dt.Rows[0]["Name"].ToString());
            // cookie["APISessionId"] = sess;


            // FormsAuthentication.RedirectFromLoginPage(dt.Rows[0]["UserName"].ToString(), true);

            cookie.Expires = DateTime.Now.AddYears(90);
            HttpContext.Current.Response.Cookies.Add(cookie);
        }

        //   dt.Columns.Add("APISessionId");
        //   dt.Rows[0]["APISessionId"] = sess;
        //  SessionOfWebTelit = sess;
        HttpContext.Current.Response.Write(ConvertDataTabletoString(dt));
    }
Esempio n. 3
0
    //id(8) rlyoutcngopen drnplss(10)
    private DataTable GetStatusObjFromTELIT(DataTable dt, UControlAPI api, string ColName, bool IsOnline)
    {
        dt.Columns.Add("IsConnect");
        dt.Columns.Add("Value");


        try
        {
            //JToken token;
            //dynamic Json;
            //string resp = "";


            //Json = new JObject();
            //Json.auth = new JObject(new JProperty("sessionId", HttpContext.Current.Request.Cookies["UserData"]["APISessionId"].ToString()));

            //for (int i = 0; i < dt.Rows.Count; i++)
            //{
            //    Json.Add((i + 1).ToString(), (new JObject(new JProperty("command", "thing.find"),
            //           new JProperty("params", new JObject(new JProperty("key", dt.Rows[i][ColName].ToString()))))));
            //}

            //resp = api.TelitAPI(Json.ToString());
            //token = JObject.Parse(resp);

            for (int i = 1; i <= dt.Rows.Count; i++)
            {
                string Value     = "";
                string IsConnect = "True";//(string)token[i.ToString()].SelectToken("..connected");

                if (IsOnline && ColName != "UCommKey")
                {
                    Value = "36";//(string)token[i.ToString()].SelectToken("params.properties.status.value");
                }

                dt.Rows[i - 1]["Value"]     = (Value == null) ? "" : Value;
                dt.Rows[i - 1]["IsConnect"] = (IsConnect == null) ? "False" : IsConnect;
            }
        }
        catch (Exception ex)
        {
            dt.Rows[0]["IsConnect"] = "sessFalse";
        }

        return(dt);
    }
Esempio n. 4
0
    private DataTable GetStateObjFromTELIT(DataTable dt, UControlAPI api, string ColName)
    {
        dt.Columns.Add("Value");


        try
        {
            JToken  token;
            dynamic Json;
            string  resp = "";


            Json      = new JObject();
            Json.auth = new JObject(new JProperty("sessionId", HttpContext.Current.Request.Cookies["UserData"]["APISessionId"].ToString()));

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Json.Add((i + 1).ToString(), (new JObject(new JProperty("command", "thing.find"),
                                                          new JProperty("params", new JObject(new JProperty("key", dt.Rows[i][ColName].ToString()))))));
            }

            resp  = api.TelitAPI(Json.ToString());
            token = JObject.Parse(resp);
            string Value = "";
            for (int i = 1; i <= token.Count(); i++)
            {
                string connType = dt.Rows[i - 1]["UConnTypeDep"].ToString();

                // אם מדובר בחיישן
                //   if (connType == "4")
                //     Value = (string)token[i.ToString()].SelectToken("params.alarms.alarm.state");

                // אם מדובר בטמפרטורה
                // if (connType == "3")
                Value = (string)token[i.ToString()].SelectToken("params.properties.status.value");

                dt.Rows[i - 1]["Value"] = Value;
            }
        }
        catch (Exception ex)
        {
        }

        return(dt);
    }
Esempio n. 5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        UControlAPI api = new UControlAPI();

        string sess = api.GetSessionId();



        // הדלקה כרגע
        dynamic Json = new JObject();

        Json.auth = new JObject(new JProperty("sessionId", sess));
        Json.Add("1", (new JObject(new JProperty("command", "method.exec"),
                                   new JProperty("params", new JObject(new JProperty("thingKey", "899720203753622046"),
                                                                       new JProperty("method", "ctu"),
                                                                       new JProperty("params",

                                                                                     new JObject(

                                                                                         new JProperty("ctu", "id(8) rlyoutcngopen drnplss(10)")
                                                                                         )
                                                                                     )
                                                                       )))));


        //id(8) rlyoutcngopen drnplss(10)

        //string resp = api.TelitAPI(Json.ToString());


        //// הדלקה כרגע
        //dynamic Json = new JObject();
        //Json.auth = new JObject(new JProperty("sessionId", sess));
        //Json.Add("1", (new JObject(new JProperty("command", "alarm.publish"),
        //    new JProperty("params", new JObject(new JProperty("thingKey", "rly_22"),
        //                                        new JProperty("key", "alarm"),
        //                                          new JProperty("state", "1")
        //                                        )))));

        //string resp = api.TelitAPI(Json.ToString());

        // קריאת מצב נתון

        //dynamic Json = new JObject();
        //Json.auth = new JObject(new JProperty("sessionId", sess));

        //for (int i = 0; i < 3; i++)
        //{
        //    Json.Add(i.ToString(), (new JObject(new JProperty("command", "alarm.current"),
        //    new JProperty("params", new JObject(new JProperty("thingKey", "rly_2" + i.ToString()), new JProperty("key", "alarm"))))));

        //}



        string resp  = api.TelitAPI(Json.ToString());
        JToken token = JObject.Parse(resp);

        foreach (var item in token)
        {
            string res = (string)item.SelectToken("..state");
        }



        //   string json = "{\"auth\":{\"sessionId\":\"584542d93447634334324f45\"},\"1\":{\"command\":\"alarm.current\",\"params\":{\"thingKey\":\"rly_22\",\"key\":\"alarm\"}}}";
    }
Esempio n. 6
0
    public string SetActionTOUControl(DataTable dt, string uStatus, string uStaticOnHour, string FieldNameForAction, string se = "0")
    {
        string Action = "";

        string Pulses = "200";

        switch (uStatus)
        {
        case "1":
            if (string.IsNullOrEmpty(uStaticOnHour) || uStaticOnHour == "0")
            {
                //אם מדובר המזגן העובד לפי פולסים
                if (dt.Rows[0]["UConnType"].ToString() == "2")
                {
                    Action = "rlyoutcngopen drnplsms(" + Pulses + ")";
                }
                else
                {
                    Action = "rlyoutcngopen fixed";
                }
            }
            else
            {
                //אם מדובר המזגן העובד לפי פולסים
                if (dt.Rows[0]["UConnType"].ToString() == "2")
                {
                    Action = "rlyoutcngopen drnplsms(" + Pulses + ")";
                }
                else
                {
                    int SecOpen = Convert.ToInt32(uStaticOnHour) * 3600;
                    Action = "rlyoutcngopen drnplss(" + SecOpen.ToString() + ")";
                }
            }

            break;

        case "0":
            //אם מדובר המזגן העובד לפי פולסים
            if (dt.Rows[0]["UConnType"].ToString() == "2")
            {
                Action = "rlyoutcngopen drnplsms(" + Pulses + ")";
            }
            else
            {
                Action = "rlyoutcngclose fixed";
            }
            break;

        case "2":
            return("0");   //Action = "rlyoutcngclose fixed";
                           // break;
        }

        UControlAPI api = new UControlAPI();


        JToken  token;
        dynamic Json;
        string  resp = "";



        Json = new JObject();

        if (se == "0")
        {
            Json.auth = new JObject(new JProperty("sessionId", HttpContext.Current.Request.Cookies["UserData"]["APISessionId"].ToString()));
        }
        else
        {
            Json.auth = new JObject(new JProperty("sessionId", SessionOfWebTelit));
        }



        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (!string.IsNullOrEmpty(FieldNameForAction))
            {
                Action = dt.Rows[i][FieldNameForAction].ToString();
                if (string.IsNullOrEmpty(Action))
                {
                    break;
                }
            }


            Json.Add((i + 1).ToString(), (new JObject(new JProperty("command", "method.exec"),
                                                      new JProperty("params", new JObject(new JProperty("thingKey", dt.Rows[i]["UCommKey"].ToString()),
                                                                                          new JProperty("method", "ctu"),
                                                                                          new JProperty("params",
                                                                                                        new JObject(
                                                                                                            new JProperty("ctu", "id(" + dt.Rows[i]["UConnId"].ToString() + ")" + Action)
                                                                                                            )
                                                                                                        )
                                                                                          )))));
        }

        resp = api.TelitAPI(Json.ToString());

        return(resp);
    }
Esempio n. 7
0
    public void Control_GetAllUConnectSchedular()
    {
        try
        {
            DataTable dt = Dal.ExeSp("Control_GetAllUConnectSchedular");
            if (dt.Rows.Count > 0)
            {
                UControlAPI api = new UControlAPI();

                DataTable UDepDataTable = new DataTable();
                // בדיקה אם יש תלויים כגון חיישן
                var UDepDataRows = dt.Select("UConnIdDep is not null");
                if (UDepDataRows.Length != 0)
                {
                    UDepDataTable = UDepDataRows.CopyToDataTable();

                    GetStateObjFromTELIT(UDepDataTable, api, "UConnKeyDep"); // כגון dig_226


                    for (int i = 0; i < UDepDataTable.Rows.Count; i++)
                    {
                        string val = UDepDataTable.Rows[i]["Value"].ToString();           //  ערך מהיחידה המקושרת כגון טמפ
                                                                                          // חיישן אקבל כאן 0 או 1
                                                                                          // טמפרטורה אקבל כאן 19.2

                        string status       = UDepDataTable.Rows[i]["status"].ToString(); // המצב המבוקש מדטהבייס
                        string UConnectId   = UDepDataTable.Rows[i]["UConnectId"].ToString();
                        string LastStatus   = UDepDataTable.Rows[i]["LastStatus"].ToString();
                        string UConnType    = UDepDataTable.Rows[i]["UConnType"].ToString();    // סוג יחידה מתח או מזגן פולסים
                        string UConnTypeDep = UDepDataTable.Rows[i]["UConnTypeDep"].ToString(); // חיישן 4 טמפ 3
                        string UtempStart   = UDepDataTable.Rows[i]["UtempStart"].ToString();
                        string UtempEnd     = UDepDataTable.Rows[i]["UtempEnd"].ToString();



                        if (status == "1")// חסר לבדוק מצב מזגן
                        {
                            // במידה ומדובר בחיישן והערך נשאר כמקודם אל תעשה שום פקודה
                            // אם מדובר בטמפרטורה תבדוק אם זה בטווח
                            if (
                                (UConnTypeDep == "4" && val == LastStatus)
                                ||
                                (UConnTypeDep == "3" && IsValTempOutRange(val, UtempStart, UtempEnd))
                                )
                            {
                                var rows = dt.Select("UConnectId = " + UConnectId);
                                rows[0].Delete();
                                dt.AcceptChanges();
                            }
                            else
                            {
                                Dal.ExeSp("Control_UpdateStatus", UConnectId, "1");
                            }
                        }
                        else
                        {
                            Dal.ExeSp("Control_UpdateStatus", UConnectId, "0");
                        }
                    }
                }// end UDepDataTable



                string resp = SetActionTOUControl(dt, "", "", "Action", "1");

                if (resp.Contains("Authentication session is invalid"))
                {
                    SessionOfWebTelit = api.GetSessionId();

                    SetActionTOUControl(dt, "", "", "Action", "1");
                }

                //// את המתאמים שידרתי והערתי את הבקר , עכשיו לעשות עוד פקודה
                //UDepDataRows = UDepDataTable.Select("UConnType=2"); // אך ורק מזגן פולסים
                //if (UDepDataRows.Count() > 0)
                //{
                //    //המתנה 3 שניות אחרי שעוררתי את היחידה
                //    System.Threading.Thread.Sleep(3000);
                //    resp = SetActionTOUControl(UDepDataRows.CopyToDataTable(), "", "", "Action", "1");
                //}
            }
        }
        catch (Exception ex)
        {
        }
    }