Ejemplo n.º 1
0
        public void handleHBEmail(AppTimeEvent timeEvent)
        {
            if (lastHBEmailTime.Equals(AppConstant.INVALID_TIME) || lastHBEmailTime.AddMinutes(AppConstant.HB_EMAIL_ELPASED_TIME) <= timeEvent.eventTime)
            {
                UserPref pref        = stgManager.ParentUI.getUserPref();
                Boolean  isSendEmail = pref.sendEmail;
                Boolean  isPlaySound = pref.playSound;
                if (!isSendEmail)
                {
                    return;
                }
                lastHBEmailTime = Utils.convertToNearestTime(timeEvent.eventTime, lastHBEmailTime, AppConstant.HB_EMAIL_ELPASED_TIME);
                ISendMailManager manager = SendMailManager.getManager();

                List <String[]> summary   = stgManager.getPositionSummary();
                String          emailBody = "";
                foreach (String[] row in summary)
                {
                    String template = "Name:[0], Position=[1], Unrealized PnL=[2], Total PnL=[3]\n";
                    emailBody += template.Replace("[0]", row[0]).Replace("[1]", row[1]).Replace("[2]", row[2]).Replace("[3]", row[3]);
                }

                if (emailBody.Equals(""))
                {
                    emailBody = "[No Content]";
                }

                manager.SendEmail("<AlgoEdge Alert> [HeartBeat] : from " + System.Environment.MachineName + " " + lastHBEmailTime, emailBody);
            }
        }
Ejemplo n.º 2
0
 public void AddNewRating(UserPref user, int productID, float rating)
 {
     Console.WriteLine("Adding rating {0}, for product {1} from user {2}", rating, productID, user.userID);
     allProducts.Add(productID);
     user.productRatings.Add(productID, rating);
     UpdateDeviations(user.productRatings, productID, rating);
 }
Ejemplo n.º 3
0
        // PUT api/UserPref/5
        public IHttpActionResult PutUserPref(int id, UserPref userpref)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userpref.UserPrefId)
            {
                return(BadRequest());
            }

            db.Entry(userpref).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserPrefExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        private void retrieveUserPrefs()
        {
            //bcUserPref up = new bcUserPref();
            UserPref up = new UserPref();

            propertyGrid1.SelectedObject = up;
        }
Ejemplo n.º 5
0
    public Dictionary<int, UserPref> GetData()
    {
        Dictionary <int,UserPref> userData = new Dictionary<int, UserPref>();
        foreach (string line in System.IO.File.ReadLines(FilePath))
        {
            string[] dataArray = line.Split('\t');

            int userID = Int32.Parse(dataArray[0]);
            if (!userData.ContainsKey(userID))
                userData[userID] = new UserPref(userID);

            int productID = Int32.Parse(dataArray[1]);

            float productRating = 0f;
            try
            {
                productRating = float.Parse(dataArray[2], System.Globalization.CultureInfo.InvariantCulture);
            }
            catch (FormatException e)
            {
                Console.WriteLine("Incorrect rating format, replaced with a rating of zero.");
            }
            userData[userID].productRatings[productID] = productRating;

            if ((int)productRating == 0)
                badRatings += 1;
            allProducts.Add(productID);
            totalRatings += 1;
        }
        return userData;
    }
Ejemplo n.º 6
0
        public UserPref getUserPref()
        {
            UserPref pref = new UserPref();

            pref.sendEmail = chk_Send_AEmail.Checked;
            pref.playSound = chk_play_sound.Checked;
            return(pref);
        }
Ejemplo n.º 7
0
		public int Add(UserPref value) 
		{
			if (value.DataType != UserPrefDataType.HiddenType)
				this._visibleItemCount++;
			if (value.Required)
				this._showRequired = true;
			

			return this.List.Add(value);
		}
Ejemplo n.º 8
0
        public ActionResult <UserPref> Post([FromBody] UserPref followed)
        {
            var db     = new GPCalAPIContext();
            var userId = User.Claims.First(f => f.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value;

            followed.UserId = userId;
            db.UserPref.Add(followed);
            db.SaveChanges();
            return(Ok(followed));
        }
Ejemplo n.º 9
0
		/// <summary>
		/// Copies the elements of the specified <see cref="UserPref">UserPref</see> array to the end of the collection.
		/// </summary>
		/// <param name="value">An array of type <see cref="UserPref">UserPref</see> containing the Components to add to the collection.</param>
		public void AddRange(UserPref[] value) 
		{
			for (int i = 0;	(i < value.Length); i = (i + 1)) 
			{
				if (value[i].DataType != UserPrefDataType.HiddenType)
					this._visibleItemCount++;
				if (value[i].Required)
					this._showRequired = true;
				this.Add(value[i]);
			}
		}
Ejemplo n.º 10
0
        public IHttpActionResult GetUserPref(int id)
        {
            UserPref userpref = db.UserPrefs.Find(id);

            if (userpref == null)
            {
                return(NotFound());
            }

            return(Ok(userpref));
        }
Ejemplo n.º 11
0
    // Use this for initialization
    void Start()
    {
        // Disable screen dimming
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        //get preferences
        PrefFunction = gameObject.GetComponent <UserPref>();
        PrefFunction.LoadPref();

        setGreenActive();
    }
Ejemplo n.º 12
0
        public IHttpActionResult PostUserPref(UserPref userpref)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.UserPrefs.Add(userpref);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = userpref.UserPrefId }, userpref));
        }
Ejemplo n.º 13
0
        public void Insert(int index, UserPref value)
        {
            if (value.DataType != UserPrefDataType.HiddenType)
            {
                this._visibleItemCount++;
            }
            if (value.Required)
            {
                this._showRequired = true;
            }

            List.Insert(index, value);
        }
Ejemplo n.º 14
0
        public dynamic CreatePref(dynamic userAccount, double?weight, string weightUnits)
        {
            var userPref  = new UserPref();
            var userPrefs = userPref.All("UserAccountId=@0 and ValidTo is null", args: new object[] { userAccount.Id }).ToArray();

            foreach (var p in userPrefs)
            {
                p.ValidTo = DateTime.UtcNow;
            }
            userPref.Save(userPrefs.ToArray());

            return(userPref.Insert(new { UserAccountId = userAccount.Id, Weight = weight, WeightUnits = weightUnits }));
        }
Ejemplo n.º 15
0
        private List <JsonObject> getOrderedEnums(UserPref pref)
        {
            List <UserPref.EnumValuePair> orderedEnums = pref.getOrderedEnumValues();
            List <JsonObject>             jsonEnums    = new List <JsonObject>();

            foreach (UserPref.EnumValuePair evp in orderedEnums)
            {
                JsonObject curEnum = new JsonObject();
                curEnum.Put("value", evp.getValue());
                curEnum.Put("displayValue", evp.getDisplayValue());
                jsonEnums.Add(curEnum);
            }
            return(jsonEnums);
        }
Ejemplo n.º 16
0
 public float PredictRating(UserPref user, int productID)
 {
     float numerator = 0;
     int denominator = 0;
     foreach (var product in user.productRatings)
     {
         Tuple<int, int> productTuple = new Tuple<int, int>(productID, product.Key);
         numerator += (product.Value + productDevs[productTuple].dev)*productDevs[productTuple].userCount;
         denominator += productDevs[productTuple].userCount;
     }
     float predictedRating = numerator/denominator;
     // Console.WriteLine("Predicted rating of user {0} for product {1}: {2}", user.userID, productID, predictedRating);
     return predictedRating;
 }
Ejemplo n.º 17
0
        public IHttpActionResult DeleteUserPref(int id)
        {
            UserPref userpref = db.UserPrefs.Find(id);

            if (userpref == null)
            {
                return(NotFound());
            }

            db.UserPrefs.Remove(userpref);
            db.SaveChanges();

            return(Ok(userpref));
        }
Ejemplo n.º 18
0
        public int Add(UserPref value)
        {
            if (value.DataType != UserPrefDataType.HiddenType)
            {
                this._visibleItemCount++;
            }
            if (value.Required)
            {
                this._showRequired = true;
            }


            return(this.List.Add(value));
        }
Ejemplo n.º 19
0
 public List<KeyValuePair<int, float>> PredictTopRatings(UserPref user, int topRatings)
 {
     List<KeyValuePair<int, float>> predictedRatings = new List<KeyValuePair<int, float>>();
     foreach (int productID in allProducts.Where(x => !user.productRatings.ContainsKey(x)))
     {
         var productPair = new KeyValuePair<int, float>(productID, PredictRating(user, productID));
         predictedRatings.Add(productPair);
     }
     predictedRatings = predictedRatings.OrderByDescending(n => n.Value).Take(topRatings).ToList();
     foreach (var pair in predictedRatings)
     {
         Console.WriteLine("The predicted rating of product {0}\t = {1}", pair.Key, pair.Value);
     }
     return predictedRatings;
 }
Ejemplo n.º 20
0
        public void Remove(UserPref value)
        {
            if (value.DataType != UserPrefDataType.HiddenType)
            {
                this._visibleItemCount--;
            }
            List.Remove(value);

            this._showRequired = false;
            foreach (UserPref up in this)
            {
                if (up.Required)
                {
                    this._showRequired = true;
                    break;
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 返回指定文件中的UserPref集合
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <returns></returns>
        public static UserPrefCollection <UserPref> LoadUserPrefs(string filename)
        {
            XmlDocument xmlfile = LoadXmlFile(filename);

            if (xmlfile == null)
            {
                return(null);
            }
            XmlNodeList xmlnodelist = xmlfile.SelectNodes("/Module/UserPref");

            if (xmlnodelist == null)
            {
                return(null);
            }

            UserPrefCollection <UserPref> upc = new UserPrefCollection <UserPref>();

            foreach (XmlNode xmlnode in xmlnodelist)
            {
                UserPref up = new UserPref();
                up.Name        = xmlnode.Attributes["name"] == null ? "" : xmlnode.Attributes["name"].Value;
                up.DisplayName = xmlnode.Attributes["display_name"] == null ? "" : xmlnode.Attributes["display_name"].Value;
                up.UrlParam    = xmlnode.Attributes["urlparam"] == null ? "" : xmlnode.Attributes["urlparam"].Value;
                up.DataType    = xmlnode.Attributes["datatype"] == null ? UserPrefDataType.StringType : ParseUserPrefDataType(xmlnode.Attributes["datatype"].Value);

                if (up.DataType == UserPrefDataType.EnumType)
                {
                    up.EnumValues = new Discuz.Common.Generic.List <EnumValue>();
                    XmlNodeList enumlist = xmlnode.SelectNodes("EnumValue");
                    foreach (XmlNode enumnode in enumlist)
                    {
                        EnumValue ev = new EnumValue();
                        ev.Value        = enumnode.Attributes["value"] == null ? "" : enumnode.Attributes["value"].Value;
                        ev.DisplayValue = enumnode.Attributes["display_value"] == null ? "" : enumnode.Attributes["display_value"].Value;
                        up.EnumValues.Add(ev);
                    }
                }

                up.Required     = xmlnode.Attributes["required"] == null ? false : Utils.StrToBool(xmlnode.Attributes["required"].Value, false);
                up.DefaultValue = xmlnode.Attributes["default_value"] == null ? "" : xmlnode.Attributes["default_value"].Value;
                upc.Add(up);
            }
            return(upc);
        }
Ejemplo n.º 22
0
        public void handOrderExeEvent(AppOrderExecutedEvent exeEvent)
        {
            UserPref pref        = stgManager.ParentUI.getUserPref();
            Boolean  isSendEmail = pref.sendEmail;
            Boolean  isPlaySound = pref.playSound;

            if (!isSendEmail)
            {
                return;
            }
            ISendMailManager manager   = SendMailManager.getManager();
            String           emailBody = "";
            String           template  = "Ticker Name:[0], BQty=[1], SQty=[2], Price=[3], Time=[4], Status=[5], SNo=[6]\n";

            emailBody += template.Replace("[0]", exeEvent.TickerName).Replace("[1]", exeEvent.BQty).Replace("[2]", exeEvent.SQty).Replace("[3]", exeEvent.Price)
                         .Replace("[4]", exeEvent.Time).Replace("[5]", exeEvent.Status).Replace("[6]", exeEvent.SNo);
            manager.SendEmail("<AlgoEdge Alert> ***Execution*** : from " + System.Environment.MachineName + " " + exeEvent.Time, emailBody);
            if (isPlaySound)
            {
                playTradeAlertSound();
            }
        }
Ejemplo n.º 23
0
		public void Remove(UserPref value) 
		{
			if (value.DataType != UserPrefDataType.HiddenType)
				this._visibleItemCount--;
			List.Remove(value);

			this._showRequired = false;
			foreach (UserPref up in this)
			{
				if (up.Required)
				{
					this._showRequired = true;
					break;
				}
			}
		}
Ejemplo n.º 24
0
 public void Remove(UserPref i_Elem)
 {
     List.Remove(i_Elem);
 }
Ejemplo n.º 25
0
 public void Insert(int i_iIndex, UserPref i_Elem)
 {
     List.Insert(i_iIndex, i_Elem);
 }
Ejemplo n.º 26
0
		/// <summary>
		/// 返回指定文件中的UserPref集合
		/// </summary>
		/// <param name="filename">文件名</param>
		/// <returns></returns>
        public static UserPrefCollection<UserPref> LoadUserPrefs(string filename)
    	{
			XmlDocument xmlfile = LoadXmlFile(filename);

			if (xmlfile == null)
				return null;
			XmlNodeList xmlnodelist = xmlfile.SelectNodes("/Module/UserPref");

			if (xmlnodelist == null)
				return null;

            UserPrefCollection<UserPref> upc = new UserPrefCollection<UserPref>();

			foreach (XmlNode xmlnode in xmlnodelist)
			{
				UserPref up = new UserPref();
				up.Name = xmlnode.Attributes["name"] == null ? "" : xmlnode.Attributes["name"].Value;
				up.DisplayName = xmlnode.Attributes["display_name"] == null ? "" : xmlnode.Attributes["display_name"].Value;
				up.UrlParam = xmlnode.Attributes["urlparam"] == null ? "" : xmlnode.Attributes["urlparam"].Value;
				up.DataType = xmlnode.Attributes["datatype"] == null ? UserPrefDataType.StringType : ParseUserPrefDataType(xmlnode.Attributes["datatype"].Value);

				if (up.DataType == UserPrefDataType.EnumType)
				{
                    up.EnumValues = new Discuz.Common.Generic.List<EnumValue>();
					XmlNodeList enumlist = xmlnode.SelectNodes("EnumValue");
					foreach(XmlNode enumnode in enumlist)
					{
						EnumValue ev = new EnumValue();
						ev.Value = enumnode.Attributes["value"] == null ? "" : enumnode.Attributes["value"].Value;
						ev.DisplayValue = enumnode.Attributes["display_value"] == null ? "" : enumnode.Attributes["display_value"].Value;
						up.EnumValues.Add(ev);
					}
				}

				up.Required = xmlnode.Attributes["required"] == null ? false : Utils.StrToBool(xmlnode.Attributes["required"].Value, false);
				up.DefaultValue = xmlnode.Attributes["default_value"] == null ? "" : xmlnode.Attributes["default_value"].Value;
				upc.Add(up);
			}
			return upc;
		}
Ejemplo n.º 27
0
        public bool LoadFromTableByUserid(string i_sUserid)
        {
            bool          bRet        = true;
            string        sCmd        = "";
            IDbConnection sqlConn     = null;
            IDbCommand    sqlCmd      = null;
            IDataReader   sqlReader   = null;
            UserPref      userprefTmp = null;

            try
            {
                if (RunningSystem.RunningDatabase == Database.MsSql)
                {
                    if (m_sSqlConn.Length <= 0)
                    {
                        sqlConn = new SqlConnection(ConfigurationManager.AppSettings["SqlConnStr"]);
                    }
                    else
                    {
                        sqlConn = new SqlConnection(m_sSqlConn);
                    }
                }
                else if (RunningSystem.RunningDatabase == Database.PostgreSql)
                {
                    if (m_sSqlConn.Length <= 0)
                    {
                        sqlConn = new NpgsqlConnection(ConfigurationManager.AppSettings["NpgsqlConnStr"]);
                    }
                    else
                    {
                        sqlConn = new NpgsqlConnection(m_sSqlConn);
                    }
                }
                sCmd = "select uParamKey, uUserID, iParamType, sParamName, sParamValue from tblUserParams where uUserID='" + i_sUserid + "'";

                sqlCmd             = sqlConn.CreateCommand();
                sqlCmd.CommandText = sCmd;
                sqlConn.Open();
                sqlReader = sqlCmd.ExecuteReader();

                try
                {
                    while (sqlReader.Read())
                    {
                        userprefTmp = new UserPref();

                        //sqlReader.GetString(0);	// Fast way, but not maintainable
                        userprefTmp.ParamKey   = sqlReader[m_csParamKeyColumn].ToString();
                        userprefTmp.Userid     = sqlReader[m_csUserIDColumn].ToString();
                        userprefTmp.ParamType  = GetParamType((int)sqlReader[m_csParamTypeColumn]);
                        userprefTmp.ParamName  = sqlReader[m_csParamNameColumn].ToString();
                        userprefTmp.ParamValue = sqlReader[m_csParamValueColumn].ToString();

                        Add(userprefTmp);
                    }
                }
                catch (Exception exc)
                {
                    Console.Error.WriteLine(DateTime.Now.ToString() + " SBConfigStore.UserPrefs.LoadFromTableByUserid exception: " + exc.ToString());
                    bRet = false;
                }
                finally
                {
                    sqlReader.Close();
                    sqlReader = null;
                    sqlCmd.Dispose();
                    sqlCmd = null;
                    sqlConn.Close();
                    sqlConn = null;
                }
            }
            catch (Exception exc)
            {
                Console.Error.WriteLine(DateTime.Now.ToString() + " SBConfigStore.UserPrefs.LoadFromTableByUserid exception: " + exc.ToString());
                // FIX - log error
                string sErr = exc.ToString();
                bRet = false;
            }

            return(bRet);
        }         // LoadFromTableByUserid
Ejemplo n.º 28
0
        }         // LoadFromTableByUserid

        public bool LoadFromTableByTypeValue(eParamType i_eType, string i_sValue)
        {
            bool bRet = true;

            try
            {
                IDbConnection sqlConn = null;

                if (RunningSystem.RunningDatabase == Database.MsSql)
                {
                    if (m_sSqlConn.Length <= 0)
                    {
                        sqlConn = new SqlConnection(ConfigurationManager.AppSettings["SqlConnStr"]);
                    }
                    else
                    {
                        sqlConn = new SqlConnection(m_sSqlConn);
                    }
                }
                else if (RunningSystem.RunningDatabase == Database.PostgreSql)
                {
                    if (m_sSqlConn.Length <= 0)
                    {
                        sqlConn = new NpgsqlConnection(ConfigurationManager.AppSettings["NpgsqlConnStr"]);
                    }
                    else
                    {
                        sqlConn = new NpgsqlConnection(m_sSqlConn);
                    }
                }

                using (sqlConn)
                    using (IDbCommand sqlCmd = sqlConn.CreateCommand())
                    {
                        sqlCmd.CommandText = "SELECT uParamKey, uUserID, sParamName FROM tblUserParams WHERE iParamType = @ParamType AND sParamValue = @ParamValue";

                        if (RunningSystem.RunningDatabase == Database.MsSql)
                        {
                            sqlCmd.Parameters.Add(new SqlParameter("@ParamType", ((int)i_eType).ToString()));
                            sqlCmd.Parameters.Add(new SqlParameter("@ParamValue", i_sValue));
                        }
                        else if (RunningSystem.RunningDatabase == Database.PostgreSql)
                        {
                            sqlCmd.Parameters.Add(new NpgsqlParameter("@ParamType", ((int)i_eType).ToString()));
                            sqlCmd.Parameters.Add(new NpgsqlParameter("@ParamValue", i_sValue));
                        }

                        sqlConn.Open();

                        using (IDataReader sqlReader = sqlCmd.ExecuteReader())
                        {
                            while (sqlReader.Read())
                            {
                                UserPref userprefTmp = new UserPref();

                                userprefTmp.ParamKey   = sqlReader[m_csParamKeyColumn].ToString();
                                userprefTmp.Userid     = sqlReader[m_csUserIDColumn].ToString();
                                userprefTmp.ParamType  = i_eType;
                                userprefTmp.ParamName  = sqlReader[m_csParamNameColumn].ToString();
                                userprefTmp.ParamValue = i_sValue;

                                Add(userprefTmp);
                            }
                        }

                        sqlConn.Close();
                    }
            }
            catch (Exception exc)
            {
                Console.Error.WriteLine(String.Format("{0} SBConfigStore.UserPrefs.LoadFromTableByTypeValue exception: {1}", DateTime.Now, exc.ToString()));
                // FIX - log error
                string sErr = exc.ToString();
                bRet = false;
            }

            return(bRet);
        }         // LoadFromTableByTypeValue
Ejemplo n.º 29
0
		/// <summary>
		/// Gets a value indicating whether the collection contains the specified <see cref="UserPrefCollection">UserPrefCollection</see>.
		/// </summary>
		/// <param name="value">The <see cref="UserPrefCollection">UserPrefCollection</see> to search for in the collection.</param>
		/// <returns><b>true</b> if the collection contains the specified object; otherwise, <b>false</b>.</returns>
		public bool Contains(UserPref value) 
		{
			return this.List.Contains(value);
		}
Ejemplo n.º 30
0
 /// <summary>
 /// Gets the index in the collection of the specified <see cref="UserPrefCollection">UserPrefCollection</see>, if it exists in the collection.
 /// </summary>
 /// <param name="value">The <see cref="UserPrefCollection">UserPrefCollection</see> to locate in the collection.</param>
 /// <returns>The index in the collection of the specified object, if found; otherwise, -1.</returns>
 public int IndexOf(UserPref value)
 {
     return(this.List.IndexOf(value));
 }
Ejemplo n.º 31
0
 public int IndexOf(UserPref i_Elem)
 {
     return(List.IndexOf(i_Elem));
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Gets a value indicating whether the collection contains the specified <see cref="UserPrefCollection">UserPrefCollection</see>.
 /// </summary>
 /// <param name="value">The <see cref="UserPrefCollection">UserPrefCollection</see> to search for in the collection.</param>
 /// <returns><b>true</b> if the collection contains the specified object; otherwise, <b>false</b>.</returns>
 public bool Contains(UserPref value)
 {
     return(this.List.Contains(value));
 }
Ejemplo n.º 33
0
		public void Insert(int index, UserPref value)	
		{
			if (value.DataType != UserPrefDataType.HiddenType)
				this._visibleItemCount++;
			if (value.Required)
				this._showRequired = true;

			List.Insert(index, value);
		}
Ejemplo n.º 34
0
		/// <summary>
		/// Gets the index in the collection of the specified <see cref="UserPrefCollection">UserPrefCollection</see>, if it exists in the collection.
		/// </summary>
		/// <param name="value">The <see cref="UserPrefCollection">UserPrefCollection</see> to locate in the collection.</param>
		/// <returns>The index in the collection of the specified object, if found; otherwise, -1.</returns>
		public int IndexOf(UserPref value) 
		{
			return this.List.IndexOf(value);
		}
Ejemplo n.º 35
0
		/// <summary>
		/// Copies the collection Components to a one-dimensional <see cref="T:System.Array">Array</see> instance beginning at the specified index.
		/// </summary>
		/// <param name="array">The one-dimensional <see cref="T:System.Array">Array</see> that is the destination of the values copied from the collection.</param>
		/// <param name="index">The index of the array at which to begin inserting.</param>
		public void CopyTo(UserPref[] array, int index) 
		{
			this.List.CopyTo(array, index);
		}
Ejemplo n.º 36
0
 public int Add(UserPref i_Elem)
 {
     return(List.Add(i_Elem));
 }
Ejemplo n.º 37
0
		/// <summary>
		/// Initializes a new instance of the <see cref="UserPrefCollection">UserPrefCollection</see> class containing the specified array of <see cref="UserPref">UserPref</see> Components.
		/// </summary>
		/// <param name="value">An array of <see cref="UserPref">UserPref</see> Components with which to initialize the collection. </param>
		public UserPrefCollection(UserPref[] value)
		{
			this.AddRange(value);
		}
Ejemplo n.º 38
0
 private List<JsonObject> getOrderedEnums(UserPref pref) 
 {
     List<UserPref.EnumValuePair> orderedEnums = pref.getOrderedEnumValues();
     List<JsonObject> jsonEnums = new List<JsonObject>();
     foreach(UserPref.EnumValuePair evp in orderedEnums) 
     {
         JsonObject curEnum = new JsonObject();
         curEnum.Put("value", evp.getValue());
         curEnum.Put("displayValue", evp.getDisplayValue());
         jsonEnums.Add(curEnum);
     }
     return jsonEnums;
 }
Ejemplo n.º 39
0
        /**
        * Creates a new Module from the given xml input.
        *
        * @param url
        * @param xml
        * @throws SpecParserException
        */
        public GadgetSpec(Uri url, String xml)
        {
            XmlElement doc;
            try
            {
                doc = XmlUtil.Parse(xml);
            }
            catch (XmlException e)
            {
                throw new SpecParserException("Malformed XML in file " + url.ToString(), e);
            }
            this.url = url;

            // This might not be good enough; should we take message bundle changes
            // into account?
            this.checksum = HashUtil.checksum(xml);

            XmlNodeList children = doc.ChildNodes;

            ModulePrefs modulePrefs = null;
            List<UserPref> userPrefs = new List<UserPref>();
            Dictionary<String, List<XmlElement>> views = new Dictionary<String, List<XmlElement>>();
            for (int i = 0, j = children.Count; i < j; ++i)
            {
                XmlNode child = children[i];
                if (!(child is XmlElement))
                {
                    continue;
                }
                XmlElement element = (XmlElement)child;
                switch (element.Name)
                {
                    case "ModulePrefs":
                        if (modulePrefs == null)
                        {
                            modulePrefs = new ModulePrefs(element, url);
                        }
                        else
                        {
                            throw new SpecParserException("Only 1 ModulePrefs is allowed.");
                        }
                        break;
                    case "UserPref":
                        UserPref pref = new UserPref(element);
                        userPrefs.Add(pref);
                        break;
                    case "Content":
                        String viewNames = XmlUtil.getAttribute(element, "view", "default");
                        foreach (String _view in viewNames.Split(','))
                        {
                            String view = _view.Trim();
                            List<XmlElement> viewElements;
                            if (!views.TryGetValue(view, out viewElements))
                            {
                                viewElements = new List<XmlElement>();
                                views.Add(view, viewElements);
                            }
                            viewElements.Add(element);
                        }
                        break;
                }
            }

            if (modulePrefs == null)
            {
                throw new SpecParserException("At least 1 ModulePrefs is required.");
            }
            
            this.modulePrefs = modulePrefs;

            if (views.Count == 0)
            {
                throw new SpecParserException("At least 1 Content is required.");
            }
            
            Dictionary<String, View> tmpViews = new Dictionary<String, View>();
            foreach (var view in views)
            {
                View v = new View(view.Key, view.Value, url);
                tmpViews.Add(v.getName(), v);
            }
            this.views = tmpViews;
            

            if (userPrefs.Count != 0)
            {
                this.userPrefs = userPrefs;
            }
            else
            {
                this.userPrefs = new List<UserPref>();
            }
        }
Ejemplo n.º 40
0
 public bool Contains(UserPref i_Elem)
 {
     return(List.Contains(i_Elem));
 }