コード例 #1
0
        public bool RequestUserAppData(OSDMap json, ref JsonRpcResponse response)
        {
            if (!json.ContainsKey("params"))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "no parameters supplied";
                m_log.DebugFormat("User Application Service URL Request: No Parameters!");
                return(false);
            }

            string      result = string.Empty;
            UserAppData props  = new UserAppData();
            object      Props  = (object)props;

            OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
            if (Service.RequestUserAppData(ref props, ref result))
            {
                OSDMap res = new OSDMap();
                res["result"]   = OSD.FromString("success");
                res["token"]    = OSD.FromString(result);
                response.Result = res;

                return(true);
            }

            response.Error.Code    = ErrorCode.InternalError;
            response.Error.Message = string.Format("{0}", result);
            return(false);
        }
コード例 #2
0
        public bool UpdateUserAppData(OSDMap json, ref JsonRpcResponse response)
        {
            if (!json.ContainsKey("params"))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "no parameters supplied";
                m_log.DebugFormat("User App Data Update Request");
                return(false);
            }

            string      result = string.Empty;
            UserAppData props  = new UserAppData();
            object      Props  = (object)props;

            OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
            if (Service.SetUserAppData(props, ref result))
            {
                response.Result = OSD.SerializeMembers(props);
                return(true);
            }

            response.Error.Code    = ErrorCode.InternalError;
            response.Error.Message = string.Format("{0}", result);
            return(false);
        }
コード例 #3
0
        public bool SetUserAppData(UserAppData props, ref string result)
        {         
            string query = string.Empty;
            
            query += "UPDATE userdata SET ";
            query += "TagId = ?TagId, ";
            query += "DataKey = ?DataKey, ";
            query += "DataVal = ?DataVal WHERE ";
            query += "UserId = ?UserId AND ";
            query += "TagId = ?TagId";
            
            try
            {
                using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
                    {
                        cmd.Parameters.AddWithValue("?UserId", props.UserId.ToString());
                        cmd.Parameters.AddWithValue("?TagId", props.TagId.ToString());
                        cmd.Parameters.AddWithValue("?DataKey", props.DataKey.ToString());
                        cmd.Parameters.AddWithValue("?DataVal", props.DataKey.ToString());

                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[PROFILES_DATA]" +
                                 ": SetUserData exception {0}", e.Message);
                return false;
            }
            return true;
        }
コード例 #4
0
        public bool GetUserAppData(ref UserAppData props, ref string result)
        {
            string query = string.Empty;

            query += "SELECT * FROM `userdata` WHERE ";
            query += "UserId = ?Id AND ";
            query += "TagId = ?TagId";

            try
            {
                using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
                    {
                        cmd.Parameters.AddWithValue("?Id", props.UserId.ToString());
                        cmd.Parameters.AddWithValue("?TagId", props.TagId.ToString());

                        using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                        {
                            if (reader.HasRows)
                            {
                                reader.Read();
                                props.DataKey = (string)reader["DataKey"];
                                props.DataVal = (string)reader["DataVal"];
                            }
                            else
                            {
                                query += "INSERT INTO userdata VALUES ( ";
                                query += "?UserId,";
                                query += "?TagId,";
                                query += "?DataKey,";
                                query += "?DataVal) ";

                                using (MySqlCommand put = new MySqlCommand(query, dbcon))
                                {
                                    put.Parameters.AddWithValue("?Id", props.UserId.ToString());
                                    put.Parameters.AddWithValue("?TagId", props.TagId.ToString());
                                    put.Parameters.AddWithValue("?DataKey", props.DataKey.ToString());
                                    put.Parameters.AddWithValue("?DataVal", props.DataVal.ToString());

                                    lock (Lock)
                                    {
                                        put.ExecuteNonQuery();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[PROFILES_DATA]" +
                                  ": Requst application data exception {0}", e.Message);
                result = e.Message;
                return(false);
            }
            return(true);
        }
コード例 #5
0
        public bool SetUserAppData(UserAppData props, ref string result)
        {
            string query = string.Empty;

            query += "UPDATE userdata SET ";
            query += "TagId = :TagId, ";
            query += "DataKey = :DataKey, ";
            query += "DataVal = :DataVal WHERE ";
            query += "UserId = :UserId AND ";
            query += "TagId = :TagId";

            try
            {
                using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
                {
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue(":UserId", props.UserId.ToString());
                    cmd.Parameters.AddWithValue(":TagId", props.TagId.ToString());
                    cmd.Parameters.AddWithValue(":DataKey", props.DataKey.ToString());
                    cmd.Parameters.AddWithValue(":DataVal", props.DataKey.ToString());

                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[PROFILES_DATA]" +
                                  ": SetUserData exception {0}", e.Message);
                return(false);
            }
            return(true);
        }
コード例 #6
0
        public bool SetUserAppData(UserAppData props, ref string result)
        {
            const string query = "UPDATE userdata SET TagId = ?TagId, DataKey = ?DataKey, DataVal = ?DataVal WHERE UserId = ?UserId AND TagId = ?TagId";

            try
            {
                using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
                    {
                        cmd.Parameters.AddWithValue("?UserId", props.UserId.ToString());
                        cmd.Parameters.AddWithValue("?TagId", props.TagId.ToString());
                        cmd.Parameters.AddWithValue("?DataKey", props.DataKey.ToString());
                        cmd.Parameters.AddWithValue("?DataVal", props.DataKey.ToString());

                        cmd.ExecuteNonQuery();
                    }
                    dbcon.Close();
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[PROFILES_DATA]: SetUserAppData exception {0}", e.Message);
                return(false);
            }
            return(true);
        }
コード例 #7
0
        public bool SetUserAppData(UserAppData props, ref string result)
        {
            string query = string.Empty;

            query += "UPDATE userdata SET ";
            query += "\"TagId\" = :TagId, ";
            query += "\"DataKey\" = :DataKey, ";
            query += "\"DataVal\" = :DataVal WHERE ";
            query += "\"UserId\" = :UserId AND ";
            query += "\"TagId\" = :TagId";

            try
            {
                using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
                    {
                        cmd.Parameters.Add(m_database.CreateParameter("UserId", props.UserId.ToString()));
                        cmd.Parameters.Add(m_database.CreateParameter("TagId", props.TagId.ToString()));
                        cmd.Parameters.Add(m_database.CreateParameter("DataKey", props.DataKey.ToString()));
                        cmd.Parameters.Add(m_database.CreateParameter("DataVal", props.DataKey.ToString()));

                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                m_log.Error("[PROFILES_DATA]: SetUserData exception ", e);
                return(false);
            }

            return(true);
        }
コード例 #8
0
        public bool GetUserAppData(ref UserAppData props, ref string result)
        {
            string query = string.Empty;

            query += "SELECT * FROM userdata WHERE ";
            query += "\"UserId\" = :Id AND ";
            query += "\"TagId\" = :TagId";

            try
            {
                using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
                    {
                        cmd.Parameters.Add(m_database.CreateParameter("Id", props.UserId));
                        cmd.Parameters.Add(m_database.CreateParameter("TagId", props.TagId));

                        using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                        {
                            if (reader.HasRows)
                            {
                                reader.Read();
                                props.DataKey = (string)reader["DataKey"];
                                props.DataVal = (string)reader["DataVal"];
                            }
                            else
                            {
                                query += "INSERT INTO userdata VALUES ( ";
                                query += ":UserId,";
                                query += ":TagId,";
                                query += ":DataKey,";
                                query += ":DataVal) ";

                                using (NpgsqlCommand put = new NpgsqlCommand(query, dbcon))
                                {
                                    put.Parameters.Add(m_database.CreateParameter("UserId", props.UserId));
                                    put.Parameters.Add(m_database.CreateParameter("TagId", props.TagId));
                                    put.Parameters.Add(m_database.CreateParameter("DataKey", props.DataKey.ToString()));
                                    put.Parameters.Add(m_database.CreateParameter("DataVal", props.DataVal.ToString()));

                                    put.ExecuteNonQuery();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                m_log.Error("[PROFILES_DATA]: GetUserAppData exception ", e);
                result = e.Message;
                return(false);
            }

            return(true);
        }
コード例 #9
0
        public bool GetUserAppData(ref UserAppData props, ref string result)
        {
            IDataReader reader = null;
            string      query  = string.Empty;

            query += "SELECT * FROM `userdata` WHERE ";
            query += "UserId = :Id AND ";
            query += "TagId = :TagId";

            try
            {
                using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
                {
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue(":Id", props.UserId.ToString());
                    cmd.Parameters.AddWithValue(":TagId", props.TagId.ToString());

                    using (reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                    {
                        if (reader.Read())
                        {
                            props.DataKey = (string)reader["DataKey"];
                            props.DataVal = (string)reader["DataVal"];
                        }
                        else
                        {
                            query += "INSERT INTO userdata VALUES ( ";
                            query += ":UserId,";
                            query += ":TagId,";
                            query += ":DataKey,";
                            query += ":DataVal) ";

                            using (SqliteCommand put = (SqliteCommand)m_connection.CreateCommand())
                            {
                                put.Parameters.AddWithValue(":Id", props.UserId.ToString());
                                put.Parameters.AddWithValue(":TagId", props.TagId.ToString());
                                put.Parameters.AddWithValue(":DataKey", props.DataKey.ToString());
                                put.Parameters.AddWithValue(":DataVal", props.DataVal.ToString());

                                put.ExecuteNonQuery();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[PROFILES_DATA]" +
                                  ": Requst application data exception {0}", e.Message);
                result = e.Message;
                return(false);
            }
            return(true);
        }
コード例 #10
0
ファイル: DBSeed.cs プロジェクト: ninamarkoff/OneBitTask
        private static void SeedUsers(UserAppData data)
        {
            for (int i = 0; i < 20; i++)
            {
                data.Users.Add(new User
                {
                    FirstName   = "Pesho" + i,
                    LastName    = "Goshev" + i,
                    PhoneNumber = "087" + i,
                    PhotoUrl    = "http://gosho.com" + i,
                    GenderId    = i % 3,
                    StatusId    = (i + 1) % 3
                });
            }

            data.SaveChanges();
        }
コード例 #11
0
ファイル: DBSeed.cs プロジェクト: ninamarkoff/OneBitTask
        private static void SeedUsers(UserAppData data)
        {
            for (int i = 0; i < 20; i++)
            {
                data.Users.Add(new User
                {
                    FirstName = "Pesho" + i,
                    LastName = "Goshev" + i,
                    PhoneNumber = "087" + i,
                    PhotoUrl = "http://gosho.com" + i,
                    GenderId = i % 3,
                    StatusId = (i + 1) % 3
                });

            }

               data.SaveChanges();
        }
コード例 #12
0
        /// <summary>
        /// Loads the user's application settings.
        /// </summary>
        private void LoadSettings()
        {
            Stream stream = null;

            try
            {
                Cursor = Cursors.WaitCursor;

                // open configuration file.
                stream = new FileStream(ConfigFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);

                // deserialize the server object.
                UserAppData settings = (UserAppData) new BinaryFormatter().Deserialize(stream);

                // overrided the current settings.
                if (settings != null)
                {
                    // known urls.
                    selectServerCtrl_.Initialize(settings.KnownUrls, settings.SelectedUrl, OpcSpecification.OPC_DA_30);

                    // proxy server.
                    if (settings.ProxyServer != null)
                    {
                        mProxy_ = new WebProxy(settings.ProxyServer);
                    }
                }
            }
            catch
            {
                // ignore errors.
            }
            finally
            {
                // close the stream.
                if (stream != null)
                {
                    stream.Close();
                }
                Cursor = Cursors.Default;
            }
        }
コード例 #13
0
        /// <summary>
        /// Saves the user's application settings.
        /// </summary>
        private void SaveSettings()
        {
            Stream stream = null;

            try
            {
                Cursor = Cursors.WaitCursor;

                // create the configuartion file.
                stream = new FileStream(ConfigFilePath, FileMode.Create, FileAccess.Write, FileShare.None);

                // populate the user settings object.
                UserAppData settings = new UserAppData();

                settings.KnownUrls = selectServerCtrl_.GetKnownURLs(out settings.SelectedUrl);

                if (mProxy_ != null)
                {
                    settings.ProxyServer = mProxy_.Address.ToString();
                }

                // serialize the user settings object.
                new BinaryFormatter().Serialize(stream, settings);
            }
            catch
            {
                // ignore errors.
            }
            finally
            {
                // close the stream.
                if (stream != null)
                {
                    stream.Close();
                }
                Cursor = Cursors.Default;
            }
        }
コード例 #14
0
 public bool SetUserAppData(UserAppData prop, ref string result)
 {
     return(true);
 }
コード例 #15
0
 public bool RequestUserAppData(ref UserAppData prop, ref string result)
 {
     return(ProfilesData.GetUserAppData(ref prop, ref result));
 }