public static void AddPaging(this RestRequest request, Paging paging)
		{
			if (paging == null)
				return;

			request.AddParameter("limit", paging.Limit, ParameterType.GetOrPost);
			request.AddParameter("page", paging.Page, ParameterType.GetOrPost);
		}
	public static void AddCommonCardParameters(this RestRequest request)
	{
		request.AddParameter("labels", "true");
		request.AddParameter("badges", "true");
		request.AddParameter("checkItemStates", "true");
		request.AddParameter("attachments", "true");
		request.AddParameter("checklists", "all");
	}
		public static void AddSince(this RestRequest request, ISince since)
		{
			if (since == null) 
				return;

			if (since.LastView)
				request.AddParameter("since", "lastView");
			if (since.Date > DateTime.MinValue)
				request.AddParameter("since", since.Date);
		}
		public static void AddSince(this RestRequest request, ISince since)
		{
			if (since == null) 
				return;

			if (since.LastView)
				request.AddParameter("since", "lastView");
			if (since.Date > DateTime.MinValue)
				request.AddParameter("since", since.Date.ToString("yyyy-MM-ddTHH:mm:ss.fffK"));
		}
Example #5
0
 public static NpgsqlCommand Returns(this NpgsqlCommand command, string name, NpgsqlDbType type)
 {
     var parameter = command.AddParameter(name);
     parameter.NpgsqlDbType = type;
     parameter.Direction = ParameterDirection.ReturnValue;
     return command;
 }
 public static void AddParameters( this IDbCommand dbCommand, IEnumerable<IParameterStub> parameterStubs )
 {
     foreach ( var parameterStub in parameterStubs )
     {
         dbCommand.AddParameter( parameterStub );
     }
 }
 public static void AddParameter(this HttpRequestMessage request, string key, IFormattable value)
 {
     if (value != null)
     {
         request.AddParameter(key, value.ToString(null, CultureInfo.InvariantCulture));
     }
 }
Example #8
0
 public static IRestRequest AddParameterIfNotNull(this RestRequest @this, string name, object value)
 {
     if (value != null)
         return @this.AddParameter(name, value);
     else
         return @this;
 }
Example #9
0
 public static void AddSafeParameter(this IRestRequest request, string parameter, object value)
 {
     if (!string.IsNullOrEmpty(parameter) && value != null)
     {
         request.AddParameter(parameter, value);
     }
 }
Example #10
0
 public static void AddParameterMax(this List<byte> source, int value)
 {
     if (value == Int32.MaxValue)
         source.Add(Constants.EOL);
     else
       source.AddParameter(value);
 }
        public static Query Where(this Query qry, string criterium)
        {
            var keyVal = criterium.SplitLeft('=');
            qry.AddParameter(keyVal.Item1, keyVal.Item2);

            return qry;
        }
Example #12
0
 public static void AddParameterMax(this BinaryWriter source, int value)
 {
     if (value == Int32.MaxValue)
         source.Write(Constants.EOL);
     else
         source.AddParameter(value);
 }
 /// <summary>
 /// Add bool parameter if the vlaue is true, since the default value for bool in powershell is false
 /// </summary>
 /// <param name="ps">PowerShell instance</param>
 /// <param name="parameter">Parameter name</param>
 /// <param name="value">Parameter value</param>
 public static void BindParameter(this PowerShell ps, string parameter, bool value)
 {
     if (value)
     {
         ps.AddParameter(parameter);
     }
 }
 /// <summary>
 /// Add object parameter if the vlaue is not null
 /// </summary>
 /// <param name="ps">PowerShell instance</param>
 /// <param name="parameter">Parameter name</param>
 /// <param name="value">Parameter value</param>
 public static void BindParameter(this PowerShell ps, string parameter, object value)
 {
     if (value != null)
     {
         ps.AddParameter(parameter, value);
     }
 }
 /// <summary>
 /// Add string parameter if the value is not null or empty
 /// </summary>
 /// <param name="ps">PowerShell instance</param>
 /// <param name="parameter">Parameter name</param>
 /// <param name="value">Parameter value</param>
 public static void BindParameter(this PowerShell ps, string parameter, string value)
 {
     if (!string.IsNullOrEmpty(value))
     {
         ps.AddParameter(parameter, value);
     }
 }
		public static void AddTypeFilter(this RestRequest request, IEnumerable<ActionType> filters)
		{
			if (filters == null || !filters.Any())
				return;

			var filterString = string.Join(",", filters.Select(f => f.ToTrelloString()));
			request.AddParameter("filter", filterString, ParameterType.GetOrPost);
		}
Example #17
0
 public static void AddDateTimeParameterToAppender(this log4net.Appender.AdoNetAppender appender, string paramName)
 {
     AdoNetAppenderParameter param = new AdoNetAppenderParameter();
     param.ParameterName = paramName;
     param.DbType = System.Data.DbType.DateTime;
     param.Layout = new RawUtcTimeStampLayout();
     appender.AddParameter(param);
 }
Example #18
0
 public static void AddErrorParameterToAppender(this log4net.Appender.AdoNetAppender appender, string paramName, int size)
 {
     AdoNetAppenderParameter param = new AdoNetAppenderParameter();
     param.ParameterName = paramName;
     param.DbType = System.Data.DbType.String;
     param.Size = size;
     param.Layout = new Layout2RawLayoutAdapter(new ExceptionLayout());
     appender.AddParameter(param);
 }
Example #19
0
 public static void AddStringParameterToAppender(this log4net.Appender.AdoNetAppender appender, string paramName, int size, string conversionPattern)
 {
     AdoNetAppenderParameter param = new AdoNetAppenderParameter();
     param.ParameterName = paramName;
     param.DbType = System.Data.DbType.String;
     param.Size = size;
     param.Layout = new Layout2RawLayoutAdapter(new PatternLayout(conversionPattern));
     appender.AddParameter(param);
 }
 public static KnockoutBindingApplier WithMetadata(this KnockoutBindingApplier applier)
 {
     if (applier.Model != null)
     {
         var metadata = new KnockoutMetadataAdapter().Adapt(applier.Model.GetType());
         applier.AddParameter(metadata);
     }
     return applier;
 }
        public static void AddTypeInclude(this RestRequest request, IEnumerable<ActionType> actionIncludes)
        {
            var includeString = "all";

            if (actionIncludes != null && actionIncludes.Any())
                includeString = string.Join(",", actionIncludes.Select(f => f.ToTrelloString()));

            request.AddParameter("actions", includeString, ParameterType.GetOrPost);
        }
Example #22
0
        internal static RestRequest AddParameters(this RestRequest self, Dictionary<string, string> parameters)
        {
            List<KeyValuePair<string, string>> list = parameters.ToList();
            if (list.Count > 0)
            {
                list.ForEach(kvp => self.AddParameter(kvp.Key, kvp.Value));
            }

            return self;
        }
 internal static void AddFromInputNode(this List<KeyValuePair<string, string>> list, HtmlNode node)
 {
     if (!node.Attributes.ContainsKey("type"))
     {
         list.AddParameter(node);
         return;
     }
     var type = node.Attributes["type"];
     if (!"radio".EqualsIgnoreCase(type) && !"checkbox".EqualsIgnoreCase(type))
     {
         list.AddParameter(node);
         return;
     }
     if (node.Attributes.ContainsKey("checked"))
     {
         list.AddParameter(node);
         return;
     }
 }
Example #24
0
        public static IRoute AddError(this IRoute route, IError error)
        {
            if (!route.Contains(KnownParameters.Errors))
                route.AddParameter(KnownParameters.Errors, new List<IError>());

            var errors = route[KnownParameters.Errors] as List<IError>;
            errors.Add(error);

            return route;
        }
Example #25
0
        public static IRestRequest AddOrSetParameter(this IRestRequest req, string name, object value)
        {
            var parms = req.Parameters.Where(p => String.Compare(p.Name, name, true) == 0);
            if (parms.Any())
                parms.First().Value = value;
            else
                req.AddParameter(name, value);

            return req;
        }
Example #26
0
        /// <summary>
        /// Extension method for RestRequest to allow calling AddParameter with an anonymous object.
        /// </summary>
        /// <example>
        /// var request = new RestRequest();
        /// request.AddParameter(new
        /// {
        ///     parameter1 = "Value 1",
        ///     parameter2 = "Value 2"
        /// });
        /// </example>
        /// <param name="request">RestRequest instance.</param>
        /// <param name="data">The object with properties.</param>
        /// <returns>IRestRequest</returns>
        public static IRestRequest AddParameter(this RestRequest request, object data)
        {
            var type = data.GetType();
            var properties = type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);

            foreach (var property in properties)
            {
                var value = property.GetValue(data);

                if (value != null || (value is Nullable<int> && ((Nullable<int>)value).HasValue))
                {
                    request.AddParameter(property.Name, value.ToString());
                }
            }

            return request;
        }
        public static void WithMetadata(this RestRequest request, IDictionary<string, object> metadata, string metadataKey = null)
        {
            if(request == null)
            {
                throw new ArgumentNullException("request", "request cannot be null.");
            }

            if (metadata != null)
            {
                metadataKey = metadataKey ?? "metadata";

                foreach (string key in metadata.Keys)
                {
                    object value = metadata[key];

                    if (value != null)
                    {
                        string requestMetadataKey = string.Concat(metadataKey, "[", key, "]");
                        request.AddParameter(requestMetadataKey, metadata[key]);
                    }
                }
            }
        }
        /// <summary>
        /// Automatically create parameters from object properties
        /// </summary>
        /// <param name="request">The REST request to add this parameter to</param>
        /// <param name="obj">Object to serialize to the request body</param>
        /// <param name="objProperties">The object properties</param>
        /// <param name="filterMode">Include or exclude the properties?</param>
        /// <returns>The request object to allow call chains</returns>
        public static IRestRequest AddObject(this IRestRequest request, object obj, IEnumerable<string> objProperties, PropertyFilterMode filterMode)
        {
            var type = obj.GetType();

            var objectProperties = objProperties == null ? null : new HashSet<string>(objProperties);
            var addedProperties = new HashSet<string>();

            while (type != typeof(object))
            {
#if NO_TYPEINFO
                var typeInfo = type;
                var props = typeInfo.GetProperties();
#else
                var typeInfo = type.GetTypeInfo();
                var props = typeInfo.DeclaredProperties;
#endif

                foreach (var prop in props.Where(x => !addedProperties.Contains(x.Name)))
                {
                    bool isAllowed;

                    if (objectProperties == null)
                    {
                        isAllowed = true;
                    }
                    else
                    {
                        if (filterMode == PropertyFilterMode.Include)
                        {
                            isAllowed = objectProperties.Contains(prop.Name);
                        }
                        else
                        {
                            isAllowed = !objectProperties.Contains(prop.Name);
                        }
                    }

                    if (!isAllowed)
                        continue;

                    addedProperties.Add(prop.Name);

                    var propType = prop.PropertyType;
                    var val = prop.GetValue(obj, null);

                    if (val != null)
                    {
                        if (propType.IsArray)
                        {
                            var elementType = propType.GetElementType();
#if NO_TYPEINFO
                            var elementTypeInfo = elementType;
#else
                            var elementTypeInfo = elementType.GetTypeInfo();
#endif

                            if (((Array)val).Length > 0 &&
                                (elementTypeInfo.IsPrimitive || elementTypeInfo.IsValueType || elementType == typeof(string)))
                            {
                                // convert the array to an array of strings
                                var values =
                                    (from object item in ((Array)val) select item.ToString()).ToArray<string>();
                                val = string.Join(",", values);
                            }
                            else
                            {
                                // try to cast it
                                val = string.Join(",", (string[])val);
                            }
                        }

                        request.AddParameter(prop.Name, val);
                    }
                }

                type = typeInfo.BaseType;
            }

            return request;
        }
 /// <summary>
 /// Body to add to the parameters using the <see cref="RestSharp.Portable.IRestRequest.Serializer" />
 /// </summary>
 /// <param name="request">The REST request to add this parameter to</param>
 /// <param name="obj">Object to serialize to the request body</param>
 /// <returns>The request object to allow call chains</returns>
 public static IRestRequest AddBody(this IRestRequest request, object obj)
 {
     var serializer = request.Serializer;
     var data = serializer.Serialize(obj);
     return request.AddParameter(new Parameter { Value = data, Type = ParameterType.RequestBody, ContentType = serializer.ContentType });
 }
 public static IRestRequest AddFile(this IRestRequest request, FileParameter parameter)
 {
     return request.AddParameter(parameter);
 }