示例#1
0
        //to get the preferences from the card json
        public static SetPreferences SetPreferencesData(string json)
        {
            SetPreferences pref = new SetPreferences();

            pref     = (new JavaScriptSerializer().Deserialize <SetPreferences>(json));
            userName = pref.UserName;
            return(pref);
        }
        public DataBus GetDataBus()
        {
            bool isTimeOut = IsTimeOut;

            if (isTimeOut)
            {
                if (dataBus != null)
                {
                    try
                    {
                        //Send stop mession first
                        StopAction          stopAction = new StopAction(dataBus);
                        HttpResponseMessage response   = stopAction.DoAction();
                        string str = response.GetContent();
                    }
                    catch
                    {
                        //Nothing to do.
                    }
                }
            }
            if (dataBus == null || isTimeOut)
            {
                sessionStart = System.DateTime.Now;

                dataBus = LoadBalanceUtil.GetDataBus(connectionInfo);

                //Start action.
                StartAction         startAction = new StartAction(dataBus);
                HttpResponseMessage response    = startAction.DoAction();

                string str = response.GetContent();

                try
                {
                    Start startEntity = startAction.ResponseData as Start;
                    dataBus.ThreadId = startEntity.Threads[0].ThreadId;
                }
                catch (Exception ex)
                {
                    throw new Exception("Start:" + str);
                }


                ActionUtil.GetFormAndData(dataBus, string.Empty);

                //Login
                LoginAction loginAction = new LoginAction(dataBus);
                loginAction.UserName = dataBus.UserName;
                loginAction.Password = dataBus.EncryptedPassword;
                response             = loginAction.DoAction();
                string loginMessage = response.GetContent();

                GetMessageAction fetchMessageAction = new GetMessageAction(dataBus);

                fetchMessageAction.DoAction();
                Execute execute = fetchMessageAction.ResponseData as Execute;

                while (execute != null && execute.ClientRequestEntity != null)
                {
                    ActionUtil.StoreMessages(execute.ClientRequestEntity);
                    fetchMessageAction = new GetMessageAction(dataBus);
                    fetchMessageAction.DoAction();
                    execute = fetchMessageAction.ResponseData as Execute;
                }

                //fetchMessageAction = new GetMessageAction(dataBus);
                //fetchMessageAction. DoAction();

                ActionUtil.GetFormAndData(dataBus, string.Empty);

                SetPreferencesAction setPreferencesAction = new SetPreferencesAction(dataBus);

                response = setPreferencesAction.DoAction();
                string         setPreferencesMessage = response.GetContent();
                SetPreferences setPreferences        = setPreferencesAction.ResponseData as SetPreferences;
            }
            else
            {
                dataBus.Refresh();
                dataBus.ThreadId++;
            }

            return(dataBus);
        }
示例#3
0
        //Makes a UPrefObject from SetPreferences object
        public static Preference MakeUPrefObject(SetPreferences pref, string uID, string serviceURL, string tenID)
        {
            Preference uPref = new Preference();

            uPref.UserName = pref.UserName;
            UserInfo        uInfo    = new UserInfo();
            NewsPreference  newsPref = new NewsPreference();
            EandtPreference entPref  = new EandtPreference();
            TaskPreference  taskPref = new TaskPreference();

            uInfo.UniqueID   = uID;
            uInfo.ServiceURl = serviceURL;
            uInfo.TenantID   = tenID;
            newsPref.NewsNotificationFlag = true;
            newsPref.NewsNotifyMe         = "True";
            entPref.EandTNotificationFlag = true;
            entPref.EandTNotifyMe         = "True";
            //taskPref.TaskNotificationFlag = true; //this flag is not provided in the front end
            taskPref.TaskNotifyMe = "true";

            //string body = "{'UserName':'******', 'Uni_ID':'likansf3993', 'TenantID':'7454731348764','ServiceURL':'abcghij','SelectedCategories':'a, b, c','NewsNotificationTime':' ','EnTNotifyMe':' ','EnTNotificationTime':' ','TaskNotificationTime':' ','NewsNotificationFlag':' ','EnTNotificationFlag':' ','NewsNotifyMe':' '}";

            string[] time     = { "9:00 AM", "10:00 AM", "11:00 AM", "12:00 PM", "1:00 PM", "2:00 PM", "3:00 PM", "4:00 PM" };
            string[] category = { "Finance", "Media", "Design", "AI", "Data", "Business", "CS", "Technology", "Animation", "IT" };
            switch (pref.SetNewsChoice)
            {
            case "1":
                newsPref.NewsNotificationTime = "8:00 AM";
                break;

            case "2":
                newsPref.NewsNotificationTime = "5:00 PM";
                break;

            case "3":
                newsPref.NewsNotificationTime = time[Int32.Parse(pref.SetNewsPreferredTime) - 1];
                break;

            default:
                break;
            }
            switch (pref.SetENTChoice)
            {
            case "1":
                entPref.EandTNotificationTime = "8:00 AM";
                break;

            case "2":
                entPref.EandTNotificationTime = "5:00 PM";
                break;

            case "3":
                entPref.EandTNotificationTime = time[Int32.Parse(pref.SetENTPreferredTime) - 1];
                break;

            default:
                break;
            }
            switch (pref.SetTaskRemindersChoice)
            {
            case "1":
                taskPref.TaskNotificationTime = "8:00 AM";
                break;

            case "2":
                taskPref.TaskNotificationTime = "5:00 PM";
                break;

            case "3":
                taskPref.TaskNotificationTime = time[Int32.Parse(pref.SetTaskReminderPreferredTime) - 1];
                break;

            default:
                break;
            }
            string newsCategory;

            if (pref.NewsCategory1 == null && pref.NewsCategory2 == null)
            {
                newsPref.SelectedCategories = category;
            }
            else
            {
                if (pref.NewsCategory1 != null && pref.NewsCategory2 == null)
                {
                    newsCategory = pref.NewsCategory1;
                }
                else if (pref.NewsCategory1 == null && pref.NewsCategory2 != null)
                {
                    newsCategory = pref.NewsCategory2;
                }
                else
                {
                    newsCategory = pref.NewsCategory1 + "," + pref.NewsCategory2;
                }

                var arr = newsCategory.Split(',');
                newsPref.SelectedCategories = new string[arr.Count()];
                for (int i = 0; i < arr.Count(); i++)
                {
                    //newsPref.SelectedCategories[i] = category[Int32.Parse(arr[i]) - 1];
                    newsPref.SelectedCategories[i] = arr[i];
                }
            }
            uPref.UserInfo    = new UserInfo[1];
            uPref.News        = new NewsPreference();
            uPref.EandT       = new EandtPreference();
            uPref.Task        = new TaskPreference();
            uPref.UserInfo[0] = uInfo;
            uPref.News        = newsPref;
            uPref.EandT       = entPref;
            uPref.Task        = taskPref;

            return(uPref);
        }