Beispiel #1
0
        public static void sendAlarm(string userName, string title, string content)
        {
            DecodedMessge msg = new DecodedMessge();

            msg.type       = msgType.ALARM;
            msg.name       = title;
            msg.param_list = new string[] { content };

            lock (SubscriberLock)
            {
                foreach (var item in subscribers)
                {
                    if (item.Item1.Invoke().Equals(userName))
                    {
                        item.Item2.Invoke(msg);
                        return;
                    }
                }

                if (!alarmList.ContainsKey(userName))
                {
                    alarmList.Add(userName, new List <DecodedMessge>());
                }
                alarmList[userName].Add(msg);
            }
        }
        public string[] Login(string username, string password)
        {
            /*
             * TradingSystem.ServiceLayer.DecodedMessge msg = new TradingSystem.ServiceLayer.DecodedMessge();
             * msg.type = TradingSystem.ServiceLayer.msgType.FUNC;
             * msg.name = "login";
             * msg.param_list = new string[] { username, password };
             *
             * TradingSystem.ServiceLayer.DecodedMessge ans_d = TradingSystem.ServiceLayer.ServerMessageManager.act(msg);
             *
             * if (ans_d.type == TradingSystem.ServiceLayer.msgType.OBJ && ans_d.name == "string[]")
             * {
             *  return ans_d.param_list;
             * }
             * return null;
             */

            DecodedMessge msg = new DecodedMessge();

            msg.type       = msgType.FUNC;
            msg.name       = "login";
            msg.param_list = new string[] { username, password };
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();

            if (ans_d.type == msgType.OBJ && ans_d.name == "login response")
            {
                return(ans_d.param_list);
            }
            return(null);
        }
Beispiel #3
0
        public string test()
        {
            DecodedMessge msg = new DecodedMessge();

            msg.type       = msgType.FUNC;
            msg.name       = "register";
            msg.param_list = new string[] { "username", "Password1" };

            byte[] enc = Connection.Encoder.encode(msg);

            Connection.ConnectionManager.sendMessage(enc);
            return("blup");
        }
        public string test()
        {
            DecodedMessge msg = new DecodedMessge();

            msg.type       = msgType.FUNC;
            msg.name       = "fail";
            msg.param_list = new string[] { "zzz" };

            byte[] enc = Connection.Encoder.encode(msg);

            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();

            return("blup");
        }
        public string[] Register(string username, string password, string age, string gender, string address)
        {
            DecodedMessge msg = new DecodedMessge();

            msg.type       = msgType.FUNC;
            msg.name       = "register";
            msg.param_list = new string[] { username, password, age, gender, address };
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();

            if (ans_d.type == msgType.OBJ && ans_d.name == "string[]")
            {
                return(ans_d.param_list);
            }
            return(null);
        }
        public string GetStore(string username, string storename)
        {
            DecodedMessge msg = new DecodedMessge();

            msg.type       = msgType.FUNC;
            msg.name       = "browse store";
            msg.param_list = new string[] { username, storename };
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();
            string        ans   = "";

            if (ans_d.type == msgType.OBJ && ans_d.name == "string")
            {
                ans = ans_d.param_list[0];
            }
            return(ans);
        }
        } // delete product

        public bool RemoveProductStore(string username, string storeName, string productName, string manufacturer)
        {
            DecodedMessge msg = new DecodedMessge();

            msg.type       = msgType.FUNC;
            msg.name       = "delete product";
            msg.param_list = new string[] { username, storeName, productName, manufacturer };
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();
            bool          ans   = false;

            if (ans_d.type == msgType.OBJ && ans_d.name == "bool")
            {
                ans = ans_d.param_list[0] == "true";
            }
            return(ans);
        }
        public string getUserName()
        {
            DecodedMessge msg = new DecodedMessge();

            msg.type       = msgType.FUNC;
            msg.name       = "get online user name";
            msg.param_list = new string[] { };
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();
            string        ans   = "guest";

            if (ans_d.type == msgType.OBJ && ans_d.name == "string")
            {
                ans = ans_d.param_list[0];
            }
            return(ans);
        }
        public bool LeaveFeedback(string username, string storeName, string productName, string manufacturer, string comment)
        {
            DecodedMessge msg = new DecodedMessge();

            msg.type       = msgType.FUNC;
            msg.name       = "leave feedback";
            msg.param_list = new string[] { username, storeName, productName, manufacturer, comment };
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();
            bool          ans   = false;

            if (ans_d.type == msgType.OBJ && ans_d.name == "bool")
            {
                ans = ans_d.param_list[0] == "true";
            }
            return(ans);
        }
Beispiel #10
0
        public bool Logoutfunc()
        {
            DecodedMessge msg = new DecodedMessge();

            msg.type       = msgType.FUNC;
            msg.name       = "logout";
            msg.param_list = new string[] { };
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();
            bool          ans   = false;

            if (ans_d.type == msgType.OBJ && ans_d.name == "bool")
            {
                ans = ans_d.param_list[0] == "true";
            }
            return(ans);
        }
Beispiel #11
0
        public bool EditProduct(string username, string storename, string productname, string price, string manu)
        {
            DecodedMessge msg = new DecodedMessge();

            msg.type       = msgType.FUNC;
            msg.name       = "edit product from store";
            msg.param_list = new string[] { username, storename, productname, price, manu };
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();
            bool          ans   = false;

            if (ans_d.type == msgType.OBJ && ans_d.name == "bool")
            {
                ans = ans_d.param_list[0] == "true";
            }
            return(ans);
        }
Beispiel #12
0
        public bool RemoveManager(string username, string storeName, string userToHire)
        {
            DecodedMessge msg = new DecodedMessge();

            msg.type       = msgType.FUNC;
            msg.name       = "remove manager";
            msg.param_list = new string[] { username, storeName, userToHire };
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();
            bool          ans   = false;

            if (ans_d.type == msgType.OBJ && ans_d.name == "bool")
            {
                ans = ans_d.param_list[0] == "true";
            }
            return(ans);
        }
Beispiel #13
0
        public string[] GetUserMessages(string username)
        {
            DecodedMessge msg = new DecodedMessge();

            // init message fields
            msg.type       = msgType.FUNC;
            msg.name       = "get my message";
            msg.param_list = new string[] { username };
            // encode and send message
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();

            if (ans_d.type == msgType.OBJ && ans_d.name == "string[]")
            {
                return(ans_d.param_list);
            }
            return(null);
        }
Beispiel #14
0
        public string[] GetInfoEmployees(string username, string storename)
        { // products -> product$product$product -> name&amount
            DecodedMessge msg = new DecodedMessge();

            // init message fields
            msg.type       = msgType.FUNC;
            msg.name       = "get my employees";
            msg.param_list = new string[] { username, storename };
            // encode and send message
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();

            if (ans_d.type == msgType.OBJ && ans_d.name == "users")
            {
                return(ans_d.param_list);
            }
            return(null);
        }
Beispiel #15
0
        public string[] BrowseProducts(string username, string productname, string manu)
        { // products -> product$product$product -> name&amount
            DecodedMessge msg = new DecodedMessge();

            // init message fields
            msg.type       = msgType.FUNC;
            msg.name       = "browse products";
            msg.param_list = new string[] { username, productname, manu };
            // encode and send message
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();

            if (ans_d.type == msgType.OBJ && ans_d.name == "dictionary product")
            {
                return(ans_d.param_list);
            }
            return(null);
        }
Beispiel #16
0
        public string[] Purchase(string username, string paymant)
        { // products -> product$product$product -> name&amount
            DecodedMessge msg = new DecodedMessge();

            // init message fields
            msg.type       = msgType.FUNC;
            msg.name       = "purchase";
            msg.param_list = new string[] { username, paymant };
            // encode and send message
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();

            if (ans_d.type == msgType.OBJ && ans_d.name == "receipts")
            {
                return(ans_d.param_list);
            }
            return(null);
        }
Beispiel #17
0
        public string CheckPrice(string username)
        { // products -> product$product$product -> name&amount
            DecodedMessge msg = new DecodedMessge();

            // init message fields
            msg.type       = msgType.FUNC;
            msg.name       = "check price";
            msg.param_list = new string[] { username };
            // encode and send message
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();
            string        ans   = "";

            if (ans_d.type == msgType.OBJ && ans_d.name == "double")
            {
                ans = ans_d.param_list[0];
            }
            return(ans);
        }
Beispiel #18
0
        public string SearchStore(string storeName)
        {
            DecodedMessge msg = new DecodedMessge();

            // init message fields
            msg.type       = msgType.FUNC;
            msg.name       = "search store";
            msg.param_list = new string[] { storeName };
            // encode and send message
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();
            string        ans   = "";

            if (ans_d.type == msgType.OBJ && ans_d.name == "string")
            {
                ans = ans_d.param_list[0];
            }
            return(ans);
        }
Beispiel #19
0
        public string getAllFeedbacks(string storeName, string productName, string manufacturer)
        { // products -> product$product$product -> name&amount
            DecodedMessge msg = new DecodedMessge();

            // init message fields
            msg.type       = msgType.FUNC;
            msg.name       = "get all feedbacks";
            msg.param_list = new string[] { storeName, productName, manufacturer };
            // encode and send message
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();
            string        ans   = "";

            if (ans_d.type == msgType.OBJ && ans_d.name == "feedbacks")
            {
                ans = ans_d.param_list[0];
            }
            return(ans);
        }
Beispiel #20
0
        public bool RemoveProducts(string username, string storeName, string manu, string products)
        { // products -> product$product$product -> name&amount
            DecodedMessge msg = new DecodedMessge();

            // init message fields
            msg.type       = msgType.FUNC;
            msg.name       = "remove product";
            msg.param_list = new string[] { username, storeName, manu, products };
            // encode and send message
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge ans_d = readMessage();
            bool          ans   = false;

            if (ans_d.type == msgType.OBJ && ans_d.name == "bool")
            {
                ans = ans_d.param_list[0] == "true";
            }
            return(ans);
        }
Beispiel #21
0
        public ICollection <string> SearchStores(string storeName)
        {
            DecodedMessge msg = new DecodedMessge();

            // init message fields
            msg.type       = msgType.FUNC;
            msg.name       = "search stores";
            msg.param_list = new string[] { storeName };
            // encode and send message
            byte[] enc = Connection.Encoder.encode(msg);
            Connection.ConnectionManager.sendMessage(enc);

            DecodedMessge        ans_d  = readMessage();
            bool                 ans    = false;
            ICollection <string> stores = new LinkedList <string>();

            if (ans_d.type == msgType.OBJ && ans_d.name == "bool")
            {
                ans = ans_d.param_list[0] == "true";
            }
            return(stores);
        }