Ejemplo n.º 1
0
        private bool IsDeviceOnline(long queueCommandID)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            InitSqlPath();
            bool online = false;

            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");
                MyCom.setCommand("bCheckDeviceOnline");
                MyCom.AddParam(queueCommandID);

                dic = MyCom.GetResultD();
                if (dic != null && dic.Count != 0)
                {
                    bool.TryParse(dic["online"].ToString(), out online);
                }
            }
            catch (Exception ex)
            {
                SaveErrorLog(queueCommandID, "IsDeviceOnline(): " + ex.Message);
            }
            return(online);
        }
Ejemplo n.º 2
0
        private bool RestoreMaster(string hash, long masterID)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();
            string result = string.Empty;
            var    res    = new List <Master>();

            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");

                MyCom.setCommand("sRestorePair");
                MyCom.AddParam(hash);
                MyCom.AddParam(masterID);
                dic = MyCom.GetResultD();

                if (dic == null || dic.Count == 0)
                {
                    return(false);
                }
                result = dic["ok"].ToString();
            }
            catch (Exception ex)
            {
                var err = ex.Message;
                return(false);
            }
            return(result.Equals("0"));
        }
Ejemplo n.º 3
0
        public MLContextMenu(Dictionary <string, object> par)
        {
            InitializeComponent();
            Menus = new DataTable();

            conStr = par["conStr"].ToString();

            com = new SQLCom(conStr, "mGetRepRarts");

            DataTable t;

            com.AddParam(14); com.AddParam(0);
            try
            {
                t = com.GetResult();
                comboBox2.DataSource = t;

                com.setCommand("getAnalityc");
                com.AddParam(26); com.AddParam(1);
                comboBox3.DataSource = com.GetResult();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            GetMenu();
        }
Ejemplo n.º 4
0
        private async void SendAutoInfoToMaster(string guidnew, string androidIDmacHash)
        {
            int                 chatID = 0;//NEED GET FROM SQL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            DataTable           table  = new DataTable();
            StringBuilder       sb     = new StringBuilder();
            WebHookPwController whc    = new WebHookPwController();

            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");
                MyCom.setCommand("bAutoSendPowerPCToMasterBot");
                MyCom.AddParam(androidIDmacHash);
                MyCom.AddParam((int)TypeDevicePW.TelegramBotMaster);
                MyCom.AddParam(guidnew);
                table = MyCom.GetResult();

                if (table == null || table.Rows.Count == 0)
                {
                    return;
                }
                //for all master paired with slave sending message with info powerON
                foreach (DataRow row in table.Rows)
                {
                    sb.Append(row["name"]);
                    sb.Append(" (");
                    sb.Append(row["type"]);
                    sb.Append(")");
                    sb.Append(Environment.NewLine);
                    sb.Append(Environment.NewLine);
                    sb.Append("power ON: ");
                    sb.Append(string.Format("{0: hh:mm tt (d MMM)} ", Convert.ToDateTime(row["on"])));
                    sb.Append(Environment.NewLine);
                    sb.Append("-----------------------------");
                    sb.Append(Environment.NewLine);
                    sb.Append(string.Format("sync: {0: hh:mm:ss tt (d MMM)} ", Convert.ToDateTime(row["sync"])));
                    sb.Append(Environment.NewLine);
                    sb.Append(Environment.NewLine);
                    sb.Append("/menu");
                    chatID = 0;
                    int.TryParse(row["chatID"].ToString(), out chatID);
                    if (chatID != 0 && sb.Length != 0)
                    {
                        MyCom.clearParams();
                        MyCom.setCommand("sCreateMessForSending");
                        MyCom.AddParam(chatID);
                        MyCom.AddParam(sb.ToString());
                        MyCom.ExecuteCommand();
                    }
                    sb.Clear();
                }
                //Send To Bot Command Sending Message from [bMessForSending]             !!!!!!!!!!!!!!!
                whc.Get(777);
            }
            catch (Exception ex)
            {
                whc.SaveErrorLog(chatID, "SendAutoInfoToMaster():" + ex.Message);
            }
        }
Ejemplo n.º 5
0
        private async Task <string> GetStatusMessage(long queueCommandID)
        {
            DataTable     table = new DataTable();
            StringBuilder sb    = new StringBuilder();

            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");
                MyCom.setCommand("bGetSlavePCStatus");
                MyCom.AddParam(queueCommandID);
                table = MyCom.GetResult();

                if (table == null || table.Rows.Count == 0)
                {
                    return("No Information");
                }

                foreach (DataRow row in table.Rows)
                {
                    sb.Append(row["name"]);
                    sb.Append(" (");
                    sb.Append(row["type"]);
                    sb.Append(")");
                    sb.Append(Environment.NewLine);
                    sb.Append(Environment.NewLine);

                    bool online = Convert.ToBoolean(row["online"]);
                    if (online)
                    {
                        sb.Append("Device is Online");
                    }
                    else
                    {
                        sb.Append("Device is Offline");
                    }
                    sb.Append(Environment.NewLine);
                    sb.Append("Last Power ON: ");
                    sb.Append(string.Format("{0: hh:mm tt (d MMM)} ", Convert.ToDateTime(row["on"])));
                    sb.Append(Environment.NewLine);
                    if (!online)
                    {
                        sb.Append("Last Power OFF: ");
                        sb.Append(string.Format("{0: hh:mm tt (d MMM)} ", Convert.ToDateTime(row["off"])));
                        sb.Append(Environment.NewLine);
                    }
                    sb.Append("-----------------------------");
                    sb.Append(Environment.NewLine);
                }

                sb.Append(Environment.NewLine);
                sb.Append("/menu");
            }
            catch (Exception ex)
            {
                SaveErrorLog(queueCommandID, "GetStartUpTimeToday(queueCommandID): " + ex.Message);
            }
            return(await Complete(sb.ToString()));
        }
Ejemplo n.º 6
0
        private async Task <int> SavePowerPC(Device device, List <PowerPC> powerpcs)
        {
            connectionString = Utils.InitSqlPath(connectionString);
            int result = 0;
            Dictionary <string, object> dic = new Dictionary <string, object>();

            MyCom = new MLDBUtils.SQLCom(connectionString, "");
            int count      = 0;
            int newrecords = 0;

            try
            {
                string guidnew = string.Empty;
                foreach (var ppc in powerpcs)
                {
                    MyCom.clearParams();
                    MyCom.setCommand("sSetpowerTime");
                    MyCom.AddParam(device.AndroidIDmacHash);
                    MyCom.AddParam(device.TypeDeviceID);
                    MyCom.AddParam(ppc.GUID);
                    MyCom.AddParam(ppc.dateTimeOnPC);
                    MyCom.AddParam(ppc.dateTimeOffPC);
                    dic = MyCom.GetResultD();
                    if (dic == null || dic.Count == 0)
                    {
                        result = 0;
                        break;
                    }
                    int.TryParse(dic["c"].ToString(), out count);
                    int.TryParse(dic["n"].ToString(), out newrecords);
                    if (newrecords == 1)
                    {
                        guidnew = ppc.GUID;
                    }
                    if (count == NOT_FOUND_DEVICEID || count == NotActive)
                    {
                        result = count;
                        break;
                    }
                    else
                    {
                        result += count;
                    }
                }
                if (newrecords == 1 && !string.IsNullOrEmpty(guidnew))
                {
                    SendAutoInfoToMaster(guidnew, device.AndroidIDmacHash);
                }
            }

            catch (Exception ex)
            {
                var err = ex.Message;
                result = SQL_ERROR;
            }
            return(result);
        }
Ejemplo n.º 7
0
        public List <Command> getCommand(string hash)
        {
            if (string.IsNullOrEmpty(hash))
            {
                return(null);
            }
            DataTable table  = new DataTable();
            string    result = string.Empty;
            var       res    = new List <Command>();

            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");

                MyCom.setCommand("sGetCommand");
                MyCom.AddParam(hash);
                table = MyCom.GetResult();

                if (table == null || table.Rows.Count == 0)
                {
                    return(null);
                }

                foreach (DataRow row in table.Rows)
                {
                    res.Add(new Command
                    {
                        commandID      = Convert.ToInt32(row["commandID"]),
                        QueueCommandID = Convert.ToInt64(row["QueueCommandID"]),
                        dateCreate     = Convert.ToDateTime(row["dataCreate"])
                    });
                }
            }
            catch (Exception ex)
            {
                var err = ex.Message;
                res.Add(new Command {
                    commandID = -1
                });
                return(res);
            }

            return(res);
        }
Ejemplo n.º 8
0
        private async void SendCommand(long chatid, string commandID)
        {
            int command = 0;

            int.TryParse(commandID, out command);
            Dictionary <string, object> dic = new Dictionary <string, object>();

            InitSqlPath();
            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");
                MyCom.setCommand("bSendCommand");
                MyCom.AddParam(chatid);
                MyCom.AddParam(command);

                dic = MyCom.GetResultD();
                if (dic == null || dic.Count == 0)
                {
                    SendMessage(chatid, "Error sending command");
                }
                else
                {
                    long QueueCommandID = 0;
                    long.TryParse(dic["i"].ToString(), out QueueCommandID);
                    if (QueueCommandID != 0)
                    {
                        string responce = await ExecuteCommand(command, QueueCommandID);

                        SendMessage(chatid, responce);
                    }
                    else
                    {
                        SendMessage(chatid, "Error SendCommand()");
                    }
                }
                //CurrentStatus status = GetStatus(new CurrentStatus { ChatID = chatid, Name = string.Empty, Data = string.Empty, StatusID = 0 });
                //Task.Delay(300);
                //DeviceMenuShow(chatid, status.Data, status.Name);
            }
            catch (Exception ex)
            {
                SaveErrorLog(chatid, "SendCommand(): " + ex.Message);
            }
        }
Ejemplo n.º 9
0
        public List <ScreenShot> getScreenShotPC(string hash, string GUID)
        {
            DataTable table  = new DataTable();
            string    result = string.Empty;
            var       res    = new List <ScreenShot>();

            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");

                MyCom.setCommand("bGetScreenShotByDevice");
                MyCom.AddParam(GUID);
                MyCom.AddParam(hash);
                table = MyCom.GetResult();

                if (table == null || table.Rows.Count == 0)
                {
                    return(null);
                }

                foreach (DataRow row in table.Rows)
                {
                    res.Add(new ScreenShot
                    {
                        GUID            = row["GUID"].ToString(),
                        ImageScreen     = (byte[])row["ImageScreen"], //Utils.ObjectToByteArray(row["ImageScreen"]),//Encoding.UTF8.GetBytes(row["ImageScreen"].ToString()),//Utils.ObjectToByteArray(row["ImageScreen"]),
                        dateCreate      = Convert.ToDateTime(row["dateCreate"]),
                        synchronizeTime = Convert.ToDateTime(row["synchronizeTime"])
                    });
                }
            }
            catch (Exception ex)
            {
                var err = ex.Message;
                res.Add(new ScreenShot {
                    GUID = "SQL error " + err
                });
                return(res);
            }

            return(res);
        }
Ejemplo n.º 10
0
        private List <Master> getMasters(string hash)
        {
            DataTable table  = new DataTable();
            string    result = string.Empty;
            var       res    = new List <Master>();

            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");

                MyCom.setCommand("sGetMasters");
                MyCom.AddParam(hash);
                table = MyCom.GetResult();

                if (table == null || table.Rows.Count == 0)
                {
                    return(null);
                }

                foreach (DataRow row in table.Rows)
                {
                    res.Add(new Master {
                        MasterId     = Convert.ToInt32(row["MasterID"]),
                        codeB        = Convert.ToInt32(row["codeB"]),
                        Name         = row["name"].ToString(),
                        TypeDeviceID = Convert.ToInt32(row["typedeviceID"]),
                        TypeName     = row["typedevice"].ToString(),
                        IsActive     = Convert.ToBoolean(row["isActive"])
                    });
                }
            }
            catch (Exception ex)
            {
                var err = ex.Message;
                res = new List <Master>();
                res.Add(new Master {
                    codeB = 0, MasterId = 0, Name = err, TypeDeviceID = 0, TypeName = "ERROR SQL"
                });
                return(res);
            }
            return(res);
        }
Ejemplo n.º 11
0
        private List <PowerPC> getPowerPC(string hash)
        {
            DataTable table  = new DataTable();
            string    result = string.Empty;
            var       res    = new List <PowerPC>();

            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");

                MyCom.setCommand("bGetPowerPCByDevice");
                MyCom.AddParam(DateTime.Now.Date); //only for today power on
                MyCom.AddParam(hash);
                table = MyCom.GetResult();

                if (table == null || table.Rows.Count == 0)
                {
                    return(null);
                }

                foreach (DataRow row in table.Rows)
                {
                    res.Add(new PowerPC
                    {
                        GUID            = row["GUID"].ToString(),
                        dateTimeOnPC    = Convert.ToDateTime(row["dateTimeOnPC"]),
                        dateTimeOffPC   = Convert.ToDateTime(row["dateTimeOffPC"]),
                        synchronizeTime = Convert.ToDateTime(row["synchronizeTime"])
                    });
                }
            }
            catch (Exception ex)
            {
                var err = ex.Message;
                res.Add(new PowerPC {
                    GUID = "SQL error " + err
                });
                return(res);
            }
            return(res);
        }
Ejemplo n.º 12
0
        private string GetCodeA(Device device)
        {
            //-3 exception sql
            //-2 return random not uniq
            //-1 data return empty
            connectionString = Utils.InitSqlPath(connectionString);
            Dictionary <string, object> dic = new Dictionary <string, object>();
            string result = string.Empty;

            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");

                MyCom.setCommand("sGETcodeA");
                MyCom.AddParam(Utils.getRandom());
                MyCom.AddParam(device.AndroidIDmacHash); //hash
                MyCom.AddParam(device.TypeDeviceID);

                dic = MyCom.GetResultD();

                if (dic == null || dic.Count == 0)
                {
                    return(EMPTY_SQL);
                }
                result = dic["a"].ToString();
            }
            catch (Exception ex)
            {
                var err = ex.Message;
                return(SQL_ERROR);
            }
            if (!result.Equals(NOT_UNIQUE))
            {
                return(result);
            }
            return(GetCodeA(device));
        }
Ejemplo n.º 13
0
        private string GetCodeB(int codeA, Master master)
        {
            //-11 not valid code A
            //-12 code A is Expired 2min
            //-22 for code A pair EXIST before!!!
            //-4 unexpected error
            //-3 exception sql
            //-1 data return empty
            connectionString = Utils.InitSqlPath(connectionString);
            Dictionary <string, object> dic = new Dictionary <string, object>();
            string result = string.Empty;

            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");
                MyCom.setCommand("bGETcodeB");
                MyCom.AddParam(Utils.getRandom());
                MyCom.AddParam(codeA);
                MyCom.AddParam(master.ChatId);
                MyCom.AddParam(master.TypeDeviceID);
                MyCom.AddParam(master.Name);

                dic = MyCom.GetResultD();
                if (dic == null || dic.Count == 0)
                {
                    return(EMPTY_SQL);
                }
                result = dic["b"].ToString();
            }
            catch (Exception ex)
            {
                var err = ex.Message;
                result = SQL_ERROR;
            }
            return(result);
        }
Ejemplo n.º 14
0
        //get list startup - powertime from slave pc to master telegram bot
        private async Task <string> GetStartUpTimeMessage(long queueCommandID, int days)
        {
            DataTable     table = new DataTable();
            StringBuilder sb    = new StringBuilder();

            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");
                if (days == 0)
                {
                    MyCom.setCommand("bGetStartUpTimeToday");
                }
                else if (days == 3)
                {
                    MyCom.setCommand("bGetStartUpTime");
                }
                MyCom.AddParam(queueCommandID);
                if (days == 3)
                {
                    MyCom.AddParam(DateTime.Now.Date.AddDays(-2));
                    MyCom.AddParam(DateTime.Now.Date);
                }
                table = MyCom.GetResult();

                if (table == null || table.Rows.Count == 0)
                {
                    return("Today is no information");
                }
                int    r        = 0;
                string synctime = string.Empty;
                foreach (DataRow row in table.Rows)
                {
                    if (r == 0)
                    {
                        sb.Append(row["name"]);
                        sb.Append(" (");
                        sb.Append(row["type"]);
                        sb.Append(")");
                        sb.Append(Environment.NewLine);
                        sb.Append(Environment.NewLine);
                    }
                    sb.Append("power ON: ");
                    sb.Append(string.Format("{0: hh:mm tt (d MMM)} ", Convert.ToDateTime(row["on"])));
                    sb.Append(Environment.NewLine);
                    if (r == (table.Rows.Count - 1)) //last row
                    {
                        synctime = string.Format("sync: {0: hh:mm tt (d MMM)} ", Convert.ToDateTime(row["sync"]));
                        if (IsDeviceOnline(queueCommandID))
                        {
                            sb.Append("Device Online");
                        }
                        else
                        {
                            sb.Append("power OFF: ");
                            sb.Append(string.Format("{0: hh:mm tt (d MMM)} ", Convert.ToDateTime(row["off"])));
                        }
                    }
                    else
                    {
                        sb.Append("power OFF: ");
                        sb.Append(string.Format("{0: hh:mm tt (d MMM)} ", Convert.ToDateTime(row["off"])));
                    }
                    sb.Append(Environment.NewLine);
                    sb.Append("-----------------------------");
                    sb.Append(Environment.NewLine);
                    r++;
                }
                sb.Append(synctime);
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("/menu");
            }
            catch (Exception ex)
            {
                SaveErrorLog(queueCommandID, "GetStartUpTimeToday(queueCommandID): " + ex.Message);
            }
            return(await Complete(sb.ToString()));
        }
Ejemplo n.º 15
0
        private Device Registration(List<string> data)
        {
            //@email NVARCHAR(50),
            //@pwd NVARCHAR(50),
            //@TypeDeviceID INT,
            //@Token NVARCHAR(300),
            //@AndroidIDMacaddress NVARCHAR(100),
            //@Name NVARCHAR(50)
            Device dev = new Device();

            int typeDevice = Convert.ToInt32(data[TypeDeviceIDX]);
            if (typeDevice < 1)
            {
                dev.Name = "type device not define";
                return dev;
            }
            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");
                Dictionary<string, object> dic = new Dictionary<string, object>();
                MyCom.setCommand("aRegistration");

                MyCom.AddParam(Utils.TruncateLongString(data[EMAILIDX], 50));
                MyCom.AddParam(Utils.TruncateLongString(data[PWDIDX], 50));
                MyCom.AddParam(typeDevice);
                MyCom.AddParam(Utils.TruncateLongString(data[TokenIDX], 500));
                MyCom.AddParam(Utils.TruncateLongString(data[AndroidIDMacAddressIDX], 100));
                MyCom.AddParam(Utils.TruncateLongString(data[NameIDX], 50));
                MyCom.AddParam(Utils.TruncateLongString(data[VersionIDX], 10));

                dic = MyCom.GetResultD();

                if (dic == null || dic.Count == 0)
                {
                    dev.Name = "dic is null or empty";
                    return dev;
                }

                dev.UserID = Convert.ToInt64(dic["userID"].ToString());

                 if (dev.UserID == EXISTUSER)
                {
                    dev.Name = "User Exist";
                    return dev;
                }
                if (dev.UserID == ERRORSQL)
                {
                    dev.Name = "Error SQL";
                    return dev;
                }

                dev.DeviceID = Convert.ToInt64(dic["deviceID"]);
                //dev.TypeDeviceID = Convert.ToInt32(dic["TypeDeviceID"]);
                //dev.Token = dic["Token"].ToString();
                //dev.AndroidIDMacaddress = dic["AndroidIDMacaddress"].ToString();
                dev.Name = dic["Name"].ToString();
                //dev.DateCreate = Convert.ToDateTime(dic["dateCreate"]);

            }
            catch (Exception ex)
            {
                dev.UserID = ERRORDB;
                dev.Name = "Sql Exept. - ";
                if (ex.Message != null)
                {
                    dev.Name += ex.Message;
                }
                return dev;
            }
            return dev;
        }
Ejemplo n.º 16
0
        private string GetB(List<string> data)
        {
            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");
                Dictionary<string, object> dic = new Dictionary<string, object>();
                MyCom.setCommand("addDeviceB");

                int typedevice = 0;
                if(!Int32.TryParse((data[TypeDeviceIDX]), out typedevice))
                {
                    return String.Empty;
                }

                MyCom.AddParam(typedevice);
                MyCom.AddParam(Utils.TruncateLongString(data[TokenIDX], 500));

                MyCom.AddParam(Utils.TruncateLongString(data[AndroidIDMacAddressIDX], 100));//AndroidID
                MyCom.AddParam(Utils.TruncateLongString(data[AndroidIDMacAddressIDX], 20)); //MacAdress
                MyCom.AddParam(Convert.ToInt32(data[CodeAIDX]));
                MyCom.AddParam(Utils.TruncateLongString(data[IpIDX], 50));

                dic = MyCom.GetResultD();

                if (dic == null || dic.Count == 0)
                {

                    return "-2";
                }

              return  dic["codeB"].ToString();

            }
            catch (Exception ex)
            {
                return "-2";
            }
        }
Ejemplo n.º 17
0
        private string getA(List<string> listdata)
        {
            string deviceID = String.Empty;
            try
            {
                deviceID = listdata[DeviceIdIDX];
            }
            catch (Exception ex)
            {
                return String.Empty;
                //return ex.Message;
            }

            char first = deviceID[deviceID.Length - 1];
            char second = first;
            if (deviceID.Length > 2)
            {
                second = deviceID[deviceID.Length - 2];
            }

            string codeA = String.Format("{0}{1}{2}{3}{4}{5}",
                GetRandomNumberNotZero(),
                GetRandomNumber(),
                GetRandomNumber(),
                GetRandomNumber(),
                first,
                second
                );

            string codeB = String.Format("{0}{1}{2}{3}{4}{5}",
                GetRandomNumberNotZero(),
                GetRandomNumber(),
                GetRandomNumber(),
                GetRandomNumber(),
                GetRandomNumber(),
                GetRandomNumber()
                );

            string namedevice;
            if (String.IsNullOrEmpty(listdata[NameIDX]))
            {
                namedevice = "host new";
            }
            else
            {
                namedevice = listdata[NameIDX];
            }

            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");
                Dictionary<string, object> dic = new Dictionary<string, object>();
                MyCom.setCommand("addDeviceA");
                /*
                 * 	@deviceID BIGINT,
            @codeA INT,
            @codeB INT
                 * SELECT @@IDENTITY AS ID
                 */
                MyCom.AddParam(Convert.ToInt64(deviceID));
                MyCom.AddParam(Convert.ToInt32(codeA));
                MyCom.AddParam(Convert.ToInt32(codeB));
                MyCom.AddParam(Utils.TruncateLongString(namedevice, 50));
                dic = MyCom.GetResultD();

                if (dic == null || dic.Count == 0)
                {
                    return string.Empty;
                }

                long id = 0;
                if (!Int64.TryParse(dic["ID"].ToString(), out id))
                {
                    return String.Empty;
                }
                if (id == 0)
                {
                    return String.Empty;
                }
            }
            catch (Exception ex)
            {
                return String.Empty;
            }

            return codeA;
        }
Ejemplo n.º 18
0
        private string FinishAddHostDevice(List<string> data)
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            string result = String.Empty;
            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");

                MyCom.setCommand("acheckABfinish");

                long deviceID = 0;
                if (!Int64.TryParse(data[DeviceIdIDX], out deviceID))
                {
                    return String.Empty;
                }

                MyCom.AddParam(deviceID);
                MyCom.AddParam(Convert.ToInt32(data[CodeAIDX]));
                MyCom.AddParam(Convert.ToInt32(data[CodeBIDX]));
                MyCom.AddParam(Utils.TruncateLongString(data[IpIDX], 50));

                dic = MyCom.GetResultD();

                if (dic == null || dic.Count == 0)
                {
                    return "-1";
                }
                result = dic["DeviceID"].ToString();
            }
            catch (Exception ex)
            {
                return "-3";
            }

            try
            {
                //for send push after and active deviceID
                long newDeviceId = 0;
                if (Int64.TryParse(dic["DeviceID"].ToString(), out newDeviceId))
                {
                    if (newDeviceId > 0)
                    {
                        if (dic["token"] != null)
                        {
                            string mess = newDeviceId.ToString();
                            string url = "http:\\tut.by";
                            string title = "title";
                            Utils.responseGCM responcegsm = Utils.SendGCM(mess, url, title, dic["token"].ToString());
                            string err = responcegsm.Warningmess;
                            if (String.IsNullOrEmpty(err))
                            {
                                err = "OK";
                            }
                            var responce = responcegsm.ResponseLine;
                            if (String.IsNullOrEmpty(responce))
                            {
                                responce = "EMPTY";
                            }
                            string request = String.Format("{0};{1};{2}", mess, url, title);
                            MyCom = new MLDBUtils.SQLCom(connectionString, "");
                            MyCom.setCommand("aGCMlog");

                            MyCom.AddParam(Utils.TruncateLongString(request, 50));
                            MyCom.AddParam(Utils.TruncateLongString(responce, 255));
                            MyCom.AddParam(newDeviceId);
                            MyCom.AddParam(Utils.TruncateLongString(err, 50));
                            MyCom.AddParam(Utils.TruncateLongString("ADDdevice", 20));

                            MyCom.ExecuteCommand();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return "-5|" + dic["DeviceID"].ToString();
            }

            return result;
        }
Ejemplo n.º 19
0
        private Device Authentication(List<string> data)
        {
            Device dev = new Device();

            int typeDevice = Convert.ToInt32(data[TypeDeviceIDX]);
            if (typeDevice < 1)
            {
                dev.Name = "type device not define";
                return dev;
            }
            try
            {
                MyCom = new MLDBUtils.SQLCom(connectionString, "");
                Dictionary<string, object> dic = new Dictionary<string, object>();
                MyCom.setCommand("aAuthentication");

                MyCom.AddParam(Utils.TruncateLongString(data[EMAILIDX], 50));
                MyCom.AddParam(Utils.TruncateLongString(data[PWDIDX], 50));
                MyCom.AddParam(typeDevice);
                MyCom.AddParam(Utils.TruncateLongString(data[TokenIDX], 500));
                MyCom.AddParam(Utils.TruncateLongString(data[AndroidIDMacAddressIDX], 100));
                MyCom.AddParam(Utils.TruncateLongString(data[IpIDX], 50));
                MyCom.AddParam(Utils.TruncateLongString(data[VersionIDX], 10));

                dic = MyCom.GetResultD();

                if (dic == null || dic.Count == 0)
                {
                    dev.Name = "dic is null or empty";
                    return dev;
                }

                //SELECT @OK AS 'returncode', @deviceID AS 'deviceID', @DeviceName AS 'DeviceName', '0' AS 'PGP'

                dev.Code = Convert.ToInt32(dic["returncode"]);
                dev.DeviceID = Convert.ToInt64(dic["deviceID"]);
                dev.Name = dic["DeviceName"].ToString();

            }
            catch (Exception ex)
            {
                dev.Code = ERRORDB;
                dev.Name = "Sql Exept. - ";
                if (ex.Message != null)
                {
                    dev.Name += ex.Message;
                }
                return dev;
            }
            return dev;
        }
Ejemplo n.º 20
0
        private string Activation(List<string> data)
        {
            long deviceID = 0;
                string result = String.Empty;
                if (!Int64.TryParse(data[host_deviceID_idx], out deviceID))
                {
                    return String.Empty;
                }
                Dictionary<string, object> dic = new Dictionary<string, object>();
                try
                {
                    MyCom = new MLDBUtils.SQLCom(connectionString, "");
                    MyCom.setCommand("aActivationDevice");

                    MyCom.AddParam(deviceID);
                    MyCom.AddParam(Convert.ToInt32(data[host_TypeDeviceID_idx]));
                    MyCom.AddParam(Utils.TruncateLongString(data[host_Token_idx], 512));
                    MyCom.AddParam(Utils.TruncateLongString(data[host_AndroidID_idx], 50));
                    MyCom.AddParam(Utils.TruncateLongString(data[host_MacAddress_idx], 50));
                    MyCom.AddParam(Utils.TruncateLongString(data[host_ip_idx], 50));
                    MyCom.AddParam(Utils.TruncateLongString(data[host_Version_idx], 10));

                    dic = MyCom.GetResultD();

                    if (dic == null || dic.Count == 0)
                    {
                        return "-4";
                    }
                    result = dic["result"].ToString();
                }
            catch (Exception ex)
            {
                return ex.Message;
            }
                return result;
        }