示例#1
0
        public static Item ToItem(this JsonObject jo)
        {
            var category = jo.GetNamedString("category", "");
            var icon = jo.GetNamedString("icon", "");
            var label = jo.GetNamedString("label", "");

            var type = jo.GetNamedString("type", "");
            var name = jo.GetNamedString("name", "");
            var link = jo.GetNamedString("link", "");
            var state = jo.GetNamedString("state", "");
            var stateDescription = jo.GetNamedObject("stateDescription", null).ToStateDescription();

            var tags = new string[0];
            var groupNames = new string[0];

            if (jo.ContainsKey("tags"))
            {
                tags = jo.GetNamedArray("tags").Select(j => j.GetString()).ToArray();
            }

            if (jo.ContainsKey("groupNames"))
            {
                groupNames = jo.GetNamedArray("groupNames").Select(j => j.GetString()).ToArray();
            }

            return new Item(link, name, state, type)
                .SetStateDescription(stateDescription)
                .SetCategory(category)
                .SetIcon(icon)
                .SetLabel(label)
                .SetGroupNames(groupNames)
                .SetTags(tags);
        }
		public static NSAction a(this JsonObject json, JsonDialogViewController dvc){
			if (json!=null && json.ContainsKey("navigateto") && json.ContainsKey("action")) {
				string file = json["navigateto"];
				string action = json["action"];
				return ()=>{
					dvc.InvokeAction(action, new object[]{file});
				};
			}
			
			if (json.ContainsKey("navigateto")) {
				string file = json["navigateto"];
				return ()=>{
					dvc.NavigateTo(file);
				};
			}
			
			
			if (json.ContainsKey("action")) {
				return ()=>{
					dvc.InvokeAction(json["action"], new Element("adf"));
				};
			}
			
			return null;
			
		}
        public static IDictionary<string, object> MergeAttributes(this IDictionary<string, object> @this,
            IDictionary<string, object> toMerge,
            bool replace = false)
        {
            foreach(var pair in toMerge)
            {
                string key = Convert.ToString(pair.Key, CultureInfo.InvariantCulture);
                string val = Convert.ToString(pair.Value, CultureInfo.InvariantCulture);

                if(string.IsNullOrEmpty(key))
                {
                    throw new ArgumentException("Key cannot be null or empty", "key");
                }

                if(replace || [email protected](key))
                {
                    @this[key] = val;
                }
                else if(@this.ContainsKey(key))
                {
                    // combine - works great for css classes, but can cause issues with data-* and others (like double readonly)
                    @this[key] = @this[key] + " " + val;
                }
            }

            return @this;
        }
示例#4
0
        public static int GetContentLength(this IDictionary<string, string> headers)
        {
            int contentLength = -1;

            // ugly. we need to decide in one spot whether or not we're case-sensitive for all headers.
            if (headers.ContainsKey("Content-Length"))
                int.TryParse(headers["Content-Length"], out contentLength);
            else if (headers.ContainsKey("Content-length"))
                int.TryParse(headers["Content-length"], out contentLength);
            else if (headers.ContainsKey("content-length"))
                int.TryParse(headers["content-length"], out contentLength);

            return contentLength;
        }
示例#5
0
 public static void AddCard(this IDictionary<string, ActivityRepository.ActivityList> lists, string listId, ActivityRepository.ActivityCard card)
 {
     if (lists.ContainsKey(listId))
     {
         lists[listId].AddCard(card);
     }
 }
 public static void AddOrReplace(this RouteValueDictionary dictionary, string key, object value)
 {
     if (dictionary.ContainsKey(key))
         dictionary[key] = value;
     else
         dictionary.Add(key, value);
 }
        public static double? GetDoubleValue(this JsonObject jsonObject, string key)
        {
            IJsonValue value;
            double? returnValue = null;
            double parsedValue;

            if (jsonObject.ContainsKey(key))
            {
                if (jsonObject.TryGetValue(key, out value))
                {
                    if (value.ValueType == JsonValueType.String)
                    {
                        if (double.TryParse(jsonObject.GetNamedString(key), out parsedValue))
                        {
                            returnValue = parsedValue;
                        }
                    }
                    else if (value.ValueType == JsonValueType.Number)
                    {
                        returnValue = jsonObject.GetNamedNumber(key);
                    }
                }
            }

            return returnValue;
        }
	public static object TryGet(this Hashtable hashtable, object key, object notFound){
		if (hashtable == null) return notFound;
		if (hashtable.ContainsKey(key)){
			return hashtable[key];
		}
		return notFound;
	}
 public static void AddHashtable(this Hashtable hash, Hashtable addHash, bool overwriteExistingKeys)
 {
     ICollection keyColl = addHash.Keys;
     foreach(string key in keyColl) {
         if(overwriteExistingKeys || (!hash.ContainsKey(key))) hash[key] = addHash[key];
     }
 }
示例#10
0
 /// <summary>
 /// Merges the specified instance.
 /// </summary>
 /// <param name="instance">The instance.</param>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 /// <param name="replaceExisting">if set to <c>true</c> [replace existing].</param>
 public static void Merge(this IDictionary<string, object> instance, string key, object value, bool replaceExisting)
 {
     if (replaceExisting || !instance.ContainsKey(key))
     {
         instance[key] = value;
     }
 }
示例#11
0
        public static DateTime TimeSent(this IDictionary<string, string> headers)
        {
            if (!headers.ContainsKey(TimeSentHeader))
                return DateTime.MinValue;

            return headers[TimeSentHeader].ToUtcDateTime();
        }
示例#12
0
        public static DateTime ProcessingStarted(this IDictionary<string, string> headers)
        {
            if (!headers.ContainsKey(ProcessingStartedHeader))
                return DateTime.MinValue;

            return headers[ProcessingStartedHeader].ToUtcDateTime();
        }
 public static string GetComponentLinkedValue(this IFieldSet fields, string schemaFieldName, bool isLinkedFieldMetadata, string componentFieldName)
 {
     if (fields.ContainsKey(schemaFieldName))
     {
         if (fields[schemaFieldName].LinkedComponentValues.Count > 0)
         {
             var linkedComponent = fields[schemaFieldName].LinkedComponentValues[0];
             if (isLinkedFieldMetadata)
             {
                 if (linkedComponent.MetadataFields.ContainsKey(componentFieldName))
                 {
                     return linkedComponent.MetadataFields.GetValue(componentFieldName);
                 }
             }
             else
             {
                 if (linkedComponent.Fields.ContainsKey(componentFieldName))
                 {
                     return linkedComponent.Fields.GetValue(componentFieldName);
                 }
             }
         }
     }
     return string.Empty;
 }
示例#14
0
 public static void AddUnique(this Dictionary<string, string> dictionary, string key, string value)
 {
     if (!dictionary.ContainsKey(key))
     {
         dictionary.Add(key, value);
     }
 }
 /// <summary>
 /// Utility extension the deserializes BraintreeProviderSettings from the ExtendedDataCollection
 /// </summary>
 /// <param name="extendedData">
 /// The extended data.
 /// </param>
 /// <returns>
 /// The <see cref="BraintreeProviderSettings"/>.
 /// </returns>
 public static BraintreeProviderSettings GetBrainTreeProviderSettings(this ExtendedDataCollection extendedData)
 {
     return extendedData.ContainsKey(Constants.ExtendedDataKeys.BraintreeProviderSettings)
                ? JsonConvert.DeserializeObject<BraintreeProviderSettings>(
                    extendedData.GetValue(Constants.ExtendedDataKeys.BraintreeProviderSettings))
                : new BraintreeProviderSettings();
 }
示例#16
0
        /// <summary>
        /// Merges two dictionaries holding HTML attribute definitions.
        /// </summary>
        /// <remarks>
        /// If key exists, it overrides it with new value.
        /// In case it's a class, it will add new values to existing.
        /// </remarks>
        public static void MergeHtmlAttributes(this IDictionary<string, object> source, IDictionary<string, object> htmlAttributes)
        {
            if (htmlAttributes == null)
            {
                throw new ArgumentNullException("htmlAttributes");
            }

            foreach (var item in htmlAttributes)
            {
                if (!source.ContainsKey(item.Key))
                {
                    source.Add(item.Key, item.Value);
                }
                else
                {
                    // handle duplicate key issue here
                    if (item.Key.ToLower() == "class")
                    {
                        source[item.Key] = source[item.Key] + " " + item.Value;
                    }
                    else
                    {
                        source[item.Key] = item.Value;
                    }
                }
            }
        }
示例#17
0
 public static void FinishCard(this IDictionary<string, ActivityRepository.ActivityList> lists, string listId, Card card, DateTime endDate)
 {
     if (lists.ContainsKey(listId))
     {
         lists[listId].FinishCard(card.Id, endDate);
     }
 }
示例#18
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="incomingMessageProperties"></param>
		/// <returns></returns>
		public static string GetIP(this MessageProperties incomingMessageProperties)
		{
			string ip = null;

			RemoteEndpointMessageProperty remoteEndpoint = incomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

			if (incomingMessageProperties.ContainsKey(HttpRequestMessageProperty.Name))
			{
				HttpRequestMessageProperty requestMessageProperty = incomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;

				ip = (requestMessageProperty != null && requestMessageProperty.Headers.HasKeys()) ?
					(requestMessageProperty.Headers["Cdn-Src-Ip"] ?? requestMessageProperty.Headers["X-Forwarded-For"] ?? requestMessageProperty.Headers["X-Real-IP"] ?? remoteEndpoint.Address) :
					remoteEndpoint.Address;
			}
			else
			{
				ip = remoteEndpoint.Address;
			}

			string[] segements = XMS.Core.Web.RequestHelper.regIPSplit.Split(ip);
			foreach (string s in segements)
			{
				if (!String.IsNullOrEmpty(s) && !s.ToLower().Equals("unkown"))
				{
					return s;
				}
			}
			return ip;
		}
示例#19
0
 public static void UpdatePoints(this IDictionary<string, ActivityRepository.ActivityList> lists, string listId, Card card)
 {
     if (lists.ContainsKey(listId))
     {
         lists[listId].UpdatePoints(card.Id, card.HasPoints() ? (int?)card.Points() : null);
     }
 }
        public static DateTime GetDateTime(this Hashtable ht, string key, DateTime? defaultValue = null)
        {
            if (string.IsNullOrWhiteSpace(key) || !ht.ContainsKey(key))
                return defaultValue.HasValue ? defaultValue.Value : Utilities.NullDate();

            return Utilities.SafeConvertDateTime(ht[key], defaultValue);
        }
 /// <summary>
 /// 路由扩展
 /// 从路由字典中移除指定的路由参数
 /// </summary>
 /// <param name="dict"></param>
 /// <param name="keysToRemove"></param>
 /// <returns></returns>
 public static RouteValueDictionary ExceptFor(this RouteValueDictionary dict, params string[] keysToRemove)
 {
     foreach (var key in keysToRemove)
         if (dict.ContainsKey(key))
             dict.Remove(key);
     return dict;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="enumerator"></param>
 /// <param name="target">Элемент для записи</param>
 /// <param name="type">Тип: включение или выключение</param>
 public static void AppendTarget(this IDictionary<string, BSharpBuilderTargetType> enumerator, string target, BSharpBuilderTargetType type) {
     if (enumerator.ContainsKey(target)) {
         enumerator[target] = type;
     } else {
         enumerator.Add(target, type);
     }
 }
 internal static void RemoveValue(this IPropertySet self, String key)
 {
     if (self.ContainsKey(key))
     {
         self.Remove(key);
     }
 }
		public static bool Has (this RouteValueDictionary dict, string key)
		{
			if (dict == null)
				return false;
			
			return dict.ContainsKey (key);
		}
        public static IDictionary<string, object> AddIfNotExist(this IDictionary<string, object> data, string key, string value)
        {
            if (!data.ContainsKey(key))
                data.Add(key, value);

            return data;
        }
示例#26
0
 /// <summary>
 /// Deserializes and returns a <see cref="Transaction"/> from the extended data collection
 /// </summary>
 /// <param name="extendedData">
 /// The extended data.
 /// </param>
 /// <returns>
 /// The <see cref="Transaction"/>.
 /// </returns>
 public static TransactionReference GetBraintreeTransaction(this ExtendedDataCollection extendedData)
 {
     return extendedData.ContainsKey(Constants.Braintree.ExtendedDataKeys.BraintreeTransaction)
         ? JsonConvert.DeserializeObject<TransactionReference>(
             extendedData.GetValue(Constants.Braintree.ExtendedDataKeys.BraintreeTransaction))
         : null;
 }
示例#27
0
 public static ViewDataDictionary Merge(this ViewDataDictionary source, ViewDataDictionary dic1)
 {
     if (dic1 != null)
     {
         foreach (KeyValuePair<string, object> pair in dic1)
         {
             if (!source.ContainsKey(pair.Key))
             {
                 source.Add(pair.Key, pair.Value);
             }
         }
         foreach (KeyValuePair<string, ModelState> pair2 in dic1.ModelState)
         {
             if (!source.ModelState.ContainsKey(pair2.Key))
             {
                 source.ModelState.Add(pair2.Key, pair2.Value);
             }
         }
         if (source.Model == null)
         {
             source.Model = dic1.Model;
         }
         if (source.TemplateInfo == null)
         {
             source.TemplateInfo = dic1.TemplateInfo;
         }
         if (source.ModelMetadata == null)
         {
             source.ModelMetadata = dic1.ModelMetadata;
         }
     }
     return source;
 }
示例#28
0
        public static Page ToPage(this JsonObject jo)
        {
            var id = jo.GetNamedString("id", "");
            var link = jo.GetNamedString("link", "");
            var title = jo.GetNamedString("title", "");
            var icon = jo.GetNamedString("icon", "");
            var leaf = jo.ToBooleanSafe("key");
            Page parent = null;

            if (jo.ContainsKey("parent"))
            {
                parent = jo.GetNamedObject("parent").ToPage();
            }

            var page = new Page()
                .SetId(id)
                .SetLink(link)
                .SetTitle(title)
                .SetIcon(icon)
                .SetLeaf(leaf)
                .SetParent(parent);

            var jWidgets = jo.ToWidgetsSafe();
            if (jWidgets != null)
                return page.SetWidgets(jWidgets.ToWidgets());
            return page;
        }
示例#29
0
        public static string GetQueryString(this IDictionary<string, object> dic, string key = null, string val = null)
        {
            if (key != null)
            {
                if (dic.ContainsKey(key))
                {
                    dic[key] = val;
                }
                else
                {
                    dic.Add(key, val);
                }
            }

            List<string> param = new List<string>();

            foreach (var i in dic)
            {
                if (i.Value != null && !string.IsNullOrEmpty(i.Value.ToString()))
                    param.Add(string.Format("{0}={1}", i.Key, i.Value));
            }

            if (param.Count > 0)
            {
                return string.Concat("?", string.Join("&", param.ToArray()));
            }
            else
            {
                return string.Empty;
            }
        }
 public static void AddOrSet(this Dictionary<string, object> dictionary, KeyValuePair<string, object> pair)
 {
     if (dictionary.ContainsKey(pair.Key))
         dictionary[pair.Key] = pair.Value;
     else
         dictionary.Add(pair.Key, pair.Value);
 }