示例#1
0
        public override void HandleMessage(BrokeredMessage msg)
        {
            UserServiceWorker worker = new UserServiceWorker();

            // cast the message's body to our payload
            this.payload = msg.GetBody <UpdateUsersForStoreMessage>();
            // Symmetric difference craziness
            Dictionary <int, User> userDictionary = worker.GetDictionaryOfUsersByStoreCode(this.payload.storeid);
            // Make the JSON call to get the list of users for the store.
            List <User> userlist = FLJsonAdapter.getInstance().GetUsersByStore(this.payload.storeid);

            // update the DB with the list of users
            foreach (User user in userlist)
            {
                if (user.id == 0)
                {
                    // This means the user wasn't found in the DB, we have to add it.
                    worker.AddUser(user);
                }
                else
                {
                    // Already in the DB, update
                    worker.UpdateUser(user);
                    // remove from dictionary to create difference
                    userDictionary.Remove(user.id);
                }
            }
            // delete all users left in the dictionary
            foreach (KeyValuePair <int, User> kvp in userDictionary)
            {
                worker.DeleteUser(kvp.Value);
            }
            // complete the message
            msg.Complete();
        }
示例#2
0
        private void StartQueues()
        {
            DebugLog.Log(String.Format("*********************************\nTrying to start queues at {0}", DateTime.Now.ToString()));
            DebugLog.Log(String.Format("Is josh? {0}", Environment.GetEnvironmentVariable("ISJOSH")));
            String connectionString = null;
            String queueName        = null;
            String protectedQueueConnectionString = null;
            String protectedQueueName             = null;

            if (String.Compare(Environment.GetEnvironmentVariable("ISJOSH"), "Ayup") == 0)
            {
                connectionString = RoleEnvironment.GetConfigurationSettingValue("DevQueueConnectionString");
                queueName        = RoleEnvironment.GetConfigurationSettingValue("DevQueueName");
                protectedQueueConnectionString = RoleEnvironment.GetConfigurationSettingValue("DevProtectedQueueConnectionString");
                protectedQueueName             = RoleEnvironment.GetConfigurationSettingValue("DevProtectedQueueName");
            }
            else
            {
                connectionString = RoleEnvironment.GetConfigurationSettingValue(this.connectionStringKey);
                queueName        = RoleEnvironment.GetConfigurationSettingValue(this.queueNameKey);
                protectedQueueConnectionString = RoleEnvironment.GetConfigurationSettingValue(this.protectedQueueConnectionString);
                protectedQueueName             = RoleEnvironment.GetConfigurationSettingValue(this.protectedQueueName);
            }
            privateQueue = new QueueHandler(connectionString, queueName);
            privateQueue.StartQueue();
            privateQueue.StartListening();
            protectedQueue = new QueueHandler(protectedQueueConnectionString, protectedQueueName);
            protectedQueue.StartQueue();
            protectedQueue.StartListening();
            DebugLog.Log(String.Format("*********************************\nFinished starting queues at {0}", DateTime.Now.ToString()));
            // set us up some delegates
            UpdateUserMessage.Del += (UpdateUserMessage msg) => {
                DebugLog.Log(String.Format("Got update user message from protected queue, guid: {0}", msg.guid));
            };
            UpdateUsersForStoreMessage.Del += (UpdateUsersForStoreMessage msg) => {
                UserServiceWorker worker = new UserServiceWorker();
                if (worker.IsStoreCodeValid(msg.storeid))
                {
                    UpdateUsersForStoreHandler handler = new UpdateUsersForStoreHandler();
                    handler.storeid = msg.storeid;
                    handler.EnqueueSelfAsMessage(privateQueue);
                }
            };
        }
示例#3
0
        // API stuff

        /// <summary>
        /// Gets a list of users by store ID
        /// </summary>
        /// <param name="storeId"></param>
        /// <returns></returns>
        public List <User> GetUsersByStore(String storeId)
        {
            String endpoint = this.ConstructEndpointUrl(ENDPOINT_LIST_USERS);
            String data     = this.GetJsonStringFromEndpoint(String.Format(endpoint, storeId));
            Dictionary <String, dynamic> response = this.ParseJson(data);
            // We shuld do something with roles at some point
            ArrayList   roles    = response["roles"];
            ArrayList   titles   = response["titles"];
            ArrayList   users    = response["value"];
            List <User> userlist = new List <User>();
            //
            UserServiceWorker worker = new UserServiceWorker();

            foreach (Dictionary <String, dynamic> userdata in users)
            {
                userlist.Add(this.ParseUser(userdata, titles, storeId, worker));
            }
            //
            return(userlist);
        }
示例#4
0
        private User ParseUser(Dictionary <String, dynamic> userData, ArrayList titles, String storecode, UserServiceWorker worker)
        {
            String[] usernameParts = ((String)userData["domainname"]).Split('\\');
            String   username      = usernameParts[usernameParts.Length - 1];
            String   guid          = userData["systemuserid"];
            User     user          = worker.GetUserByGuid(guid);

            if (user == null)
            {
                user = new User();
            }
            user.userguid     = guid;
            user.userName     = username;
            user.firstName    = userData["firstname"];
            user.lastName     = userData["lastname"];
            user.storeCode    = storecode;
            user.imagePath    = userData["portraitpath"];
            user.title        = (String)titles[(int)userData["fix_title"]];
            user.primaryphone = userData["primaryphone"];
            user.email        = userData["internalemailaddress"];
            //
            return(user);
        }