public RestGetQueryProvider(IRestClient client, ISerializerFactory serializerFactory, IExpressionProcessor expressionProcessor, IMemberNameResolver memberNameResolver, IEnumerable <IValueWriter> valueWriters, Type sourceType)
     : base(client, serializerFactory, expressionProcessor, memberNameResolver, valueWriters, sourceType)
 {
     CustomContract.Requires(client != null);
     CustomContract.Requires(serializerFactory != null);
     CustomContract.Requires(expressionProcessor != null);
     CustomContract.Requires(valueWriters != null);
     CustomContract.Requires(sourceType != null);
 }
        /// <summary>
        /// Expands the specified source.
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="source">The source <see cref="IQueryable"/>.</param>
        /// <param name="memberNameResolver">The <see cref="IMemberNameResolver"/> to resolve names.</param>
        /// <param name="properties">The paths to expand.</param>
        /// <returns>An <see cref="IQueryable{T}"/> for continued querying.</returns>
        public static IQueryable <TSource> Expand <TSource>(this IQueryable <TSource> source, IMemberNameResolver memberNameResolver, params Expression <Func <TSource, object> >[] properties)
        {
            CustomContract.Requires <ArgumentNullException>(source != null);
            CustomContract.Assume(properties != null);

            var propertyNames = string.Join(",", properties.Where(x => x != null).Select(property => ResolvePropertyName(property, memberNameResolver)));

            return(Expand(source, propertyNames));
        }
示例#3
0
        public Group Create(Group group)
        {
            CustomContract.Requires <ArgumentNullException>(group != null, "Group is null");
            CustomContract.Requires <ArgumentNullException>(
                !string.IsNullOrEmpty(group.Label),
                "Label is a required field");

            return(this.createRestService.Create(group));
        }
示例#4
0
        public Stream Put(Uri uri, Stream input)
        {
            CustomContract.Requires <ArgumentNullException>(uri != null);
            CustomContract.Requires <ArgumentException>(uri.Scheme == HttpUtility.UriSchemeHttp || uri.Scheme == HttpUtility.UriSchemeHttps);
            CustomContract.Requires <ArgumentNullException>(input != null);
            CustomContract.Ensures(CustomContract.Result <Stream>() != null);

            throw new NotImplementedException();
        }
        public static bool IsFunction(this string expression)
        {
            CustomContract.Requires <ArgumentNullException>(expression != null);

            var open  = expression.IndexOf('(');
            var close = expression.IndexOf(')');

            return(open > 0 && close > -1);
        }
示例#6
0
            public XmlDataContractSerializer(IEnumerable <Type> knownTypes)
            {
                CustomContract.Requires(knownTypes != null);

                var array = knownTypes.ToArray();

                _serializer     = new DataContractSerializer(typeof(T), array);
                _listSerializer = new DataContractSerializer(typeof(List <T>), array);
            }
示例#7
0
        public BaseBlock(Types BlockType, byte [] Body, bool reverseByteOrder, long PositionInStream = 0)
        {
            CustomContract.Requires <ArgumentNullException>(Body != null, "Body cannot be null");

            this.BlockType        = BlockType;
            this.Body             = Body;
            this.ReverseByteOrder = reverseByteOrder;
            this.PositionInStream = PositionInStream;
        }
            public IEnumerable <ParameterExpression> GetParameters(Expression expr)
            {
                CustomContract.Requires(expr != null);
                CustomContract.Ensures(CustomContract.Result <IEnumerable <ParameterExpression> >() != null);

                _parameters = new List <ParameterExpression>();
                Visit(expr);
                return(_parameters);
            }
        public bool Update(Contact item)
        {
            CustomContract.Requires <ArgumentNullException>(item != null, "Contact is null");
            CustomContract.Requires <ArgumentNullException>(
                !string.IsNullOrEmpty(item.FirstName),
                "First name is not set");

            return(this.updateRestService.Update(item.CreateRequest()));
        }
示例#10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RestContext{T}"/> class.
        /// </summary>
        /// <param name="client">The <see cref="IRestClient"/> to use for requests.</param>
        /// <param name="serializerFactory">The <see cref="ISerializerFactory"/> to create <see cref="ISerializer{T}"/> to handling responses.</param>
        /// <param name="memberNameResolver">The <see cref="IMemberNameResolver"/> to use for alias resolution.</param>
        /// <param name="valueWriters">The <see cref="IEnumerable{IValueWriter}"/> for writing custom values.</param>
        public RestContext(IRestClient client, ISerializerFactory serializerFactory, IMemberNameResolver memberNameResolver, IEnumerable <IValueWriter> valueWriters)
        {
            CustomContract.Requires <ArgumentNullException>(client != null);
            CustomContract.Requires <ArgumentNullException>(serializerFactory != null);
            CustomContract.Requires <ArgumentNullException>(memberNameResolver != null);
            CustomContract.Requires <ArgumentNullException>(valueWriters != null);

            _getQueryable = new RestGetQueryable <T>(client, serializerFactory, memberNameResolver, valueWriters, typeof(T));
        }
示例#11
0
        public Contact Create(Contact item)
        {
            CustomContract.Requires <ArgumentNullException>(item != null, "Contact is null");
            CustomContract.Requires <ArgumentNullException>(
                !string.IsNullOrEmpty(item.FirstName),
                "First name is not set");

            return(new Contact().CreateFromResponse(this.createRestService.Create(item.CreateRequest())));
        }
示例#12
0
        public PcapNGWriter(Stream stream, List <HeaderWithInterfacesDescriptions> headersWithInterface)
        {
            CustomContract.Requires <ArgumentNullException>(stream != null, "stream cannot be null");
            CustomContract.Requires <ArgumentNullException>(headersWithInterface != null, "headersWithInterface list cannot be null");

            CustomContract.Requires <ArgumentException>(headersWithInterface.Count >= 1, "headersWithInterface list is empty");

            Initialize(stream, headersWithInterface);
        }
        /// <summary>
        /// The Interface Description Block is mandatory. This block is needed to specify the characteristics of the network interface
        /// on which the capture has been made. In order to properly associate the captured data to the corresponding interface, the Interface
        /// Description Block must be defined before any other block that uses it; therefore, this block is usually placed immediately after
        /// the Section Header Block.
        /// </summary>
        public InterfaceDescriptionBlock(LinkTypes LinkType, int SnapLength, InterfaceDescriptionOption Options, long PositionInStream = 0)
        {
            CustomContract.Requires <ArgumentNullException>(Options != null, "Options cannot be null");

            this.LinkType         = LinkType;
            this.SnapLength       = SnapLength;
            this.options          = Options;
            this.PositionInStream = PositionInStream;
        }
示例#14
0
 private void OnReadPacket(IPacket packet)
 {
     CustomContract.Requires <ArgumentNullException>(packet != null, "packet cannot be null");
     CommonDelegates.ReadPacketEventDelegate handler = OnReadPacketEvent;
     if (handler != null)
     {
         handler(this.headersWithInterface.Last(), packet);
     }
 }
示例#15
0
        private static object GetValue(Expression input)
        {
            CustomContract.Requires(input != null);

            var objectMember = Expression.Convert(input, typeof(object));
            var getterLambda = Expression.Lambda <Func <object> >(objectMember).Compile();

            return(getterLambda());
        }
示例#16
0
        private static string GetOperation(Expression expression)
        {
            CustomContract.Requires(expression != null);

            switch (expression.NodeType)
            {
            case ExpressionType.Add:
                return("add");

            case ExpressionType.AddChecked:
                break;

            case ExpressionType.And:
            case ExpressionType.AndAlso:
                return("and");

            case ExpressionType.Divide:
                return("div");

            case ExpressionType.Equal:
                return("eq");

            case ExpressionType.GreaterThan:
                return("gt");

            case ExpressionType.GreaterThanOrEqual:
                return("ge");

            case ExpressionType.LessThan:
                return("lt");

            case ExpressionType.LessThanOrEqual:
                return("le");

            case ExpressionType.Modulo:
                return("mod");

            case ExpressionType.Multiply:
                return("mul");

            case ExpressionType.Not:
                return("not");

            case ExpressionType.NotEqual:
                return("ne");

            case ExpressionType.Or:
            case ExpressionType.OrElse:
                return("or");

            case ExpressionType.Subtract:
                return("sub");
            }

            return(string.Empty);
        }
示例#17
0
        public static NameResolutionRecord Parse(BinaryReader binaryReader, bool reverseByteOrder, Action <Exception> ActionOnException)
        {
            CustomContract.Requires <ArgumentNullException>(binaryReader != null, "binaryReader cannot be null");

            List <NameResolutionRecordEntry>      listRecords  = new List <NameResolutionRecordEntry>();
            List <KeyValuePair <ushort, byte[]> > keyValueList = EkstractOptions(binaryReader, reverseByteOrder, ActionOnException);

            foreach (var item in keyValueList)
            {
                try
                {
                    switch (item.Key)
                    {
                    case (ushort)NameResolutionRecordEntry.NameResolutionRecordCode.Ip4Record:
                    {
                        if (item.Value.Length >= 4)
                        {
                            byte[]    addrTemp = item.Value.Take(4).ToArray();
                            byte[]    descTemp = item.Value.Skip(4).Take(item.Value.Length - 4).ToArray();
                            IPAddress addr     = new IPAddress(addrTemp);
                            string    desc     = UTF8Encoding.UTF8.GetString(descTemp);
                            NameResolutionRecordEntry record = new NameResolutionRecordEntry(addr, desc);
                            listRecords.Add(record);
                        }
                        break;
                    }

                    case (ushort)NameResolutionRecordEntry.NameResolutionRecordCode.Ip6Record:
                    {
                        if (item.Value.Length >= 16)
                        {
                            byte[]    addrTemp = item.Value.Take(16).ToArray();
                            byte[]    descTemp = item.Value.Skip(16).Take(item.Value.Length - 16).ToArray();
                            IPAddress addr     = new IPAddress(addrTemp);
                            string    desc     = UTF8Encoding.UTF8.GetString(descTemp);
                            NameResolutionRecordEntry record = new NameResolutionRecordEntry(addr, desc);
                            listRecords.Add(record);
                        }
                        break;
                    }

                    case (ushort)NameResolutionRecordEntry.NameResolutionRecordCode.EndOfRecord:
                    default:
                        break;
                    }
                }
                catch (Exception exc)
                {
                    if (ActionOnException != null)
                    {
                        ActionOnException(exc);
                    }
                }
            }
            return(new NameResolutionRecord(listRecords));
        }
示例#18
0
        protected static List <KeyValuePair <ushort, byte[]> > EkstractOptions(BinaryReader binaryReader, bool reverseByteOrder, Action <Exception> ActionOnException)
        {
            CustomContract.Requires <ArgumentNullException>(binaryReader != null, "binaryReader cannot be null");
            UInt16 optionCode;

            byte[] value = null;
            UInt16 valueLength;
            int    remainderLength;

            List <KeyValuePair <ushort, byte[]> > ret = new List <KeyValuePair <ushort, byte[]> >();

            if (binaryReader.BaseStream.Position + 4 >= binaryReader.BaseStream.Length)
            {
                return(ret);
            }

            try
            {
                while (binaryReader.BaseStream.Position + 4 <= binaryReader.BaseStream.Length)
                {
                    optionCode  = binaryReader.ReadUInt16().ReverseByteOrder(reverseByteOrder);
                    valueLength = binaryReader.ReadUInt16().ReverseByteOrder(reverseByteOrder);
                    if (valueLength > 0)
                    {
                        value = binaryReader.ReadBytes(valueLength);
                        if (value.Length < valueLength)
                        {
                            throw new EndOfStreamException("Unable to read beyond the end of the stream");
                        }
                        remainderLength = (int)valueLength % AlignmentBoundary;
                        if (remainderLength > 0)
                        {
                            binaryReader.ReadBytes(AlignmentBoundary - remainderLength);
                        }
                    }
                    else
                    {
                        break;
                    }

                    ret.Add(new KeyValuePair <ushort, byte[]>(optionCode, value));
                    if (optionCode == EndOfOption)
                    {
                        break;
                    }
                }
            }
            catch (Exception exc)
            {
                if (ActionOnException != null)
                {
                    ActionOnException(exc);
                }
            }
            return(ret);
        }
示例#19
0
        public HashBlock(byte[] inputArray)
        {
            CustomContract.Requires <ArgumentNullException>(inputArray != null, "inputArray cannot be null");
            CustomContract.Requires <ArgumentException>(inputArray.Length >= 2, "HashBlock, inputArray length < 2");

            byte tempAlgorithm = inputArray[0];

            Algorithm = Enum.IsDefined(typeof(HashAlgorithm), tempAlgorithm) ? (HashAlgorithm)tempAlgorithm : HashAlgorithm.Invalid;
            Value     = inputArray.Skip(1).Take(inputArray.Length - 1).ToArray();
        }
        public HeaderWithInterfacesDescriptions(SectionHeaderBlock header, List <InterfaceDescriptionBlock> interfaceDescriptions)
        {
            CustomContract.Requires <ArgumentNullException>(header != null, "Header cannot be null");
            CustomContract.Requires <ArgumentNullException>(interfaceDescriptions != null, "Interface description list cannot be null");

            CustomContract.Requires <ArgumentException>(interfaceDescriptions.Count >= 1, "Interface description list is empty");

            this.Header = header;
            this.interfaceDescriptions = interfaceDescriptions;
        }
        public static EnchantedPacketBlock CreateEnchantedPacketFromIPacket(IPacket packet, Action <Exception> ActionOnException)
        {
            CustomContract.Requires <ArgumentNullException>(packet != null, "packet cannot be null");
            CustomContract.Requires <ArgumentNullException>(packet.Data != null, "packet.Data cannot be null");
            TimestampHelper timestampHelper = new TimestampHelper(packet.Seconds, packet.Microseconds);

            EnchantedPacketBlock enchantedBlock = new EnchantedPacketBlock(0, timestampHelper, packet.Data.Length, packet.Data, new EnchantedPacketOption(), 0);

            return(enchantedBlock);
        }
示例#22
0
        private IQueryable <TResult> InnerCreateQueryable <TResult>(IRestClient client, ISerializerFactory serializerFactory, IMemberNameResolver memberNameResolver, IEnumerable <IValueWriter> valueWriters, Expression expression, Type sourceType)
        {
            CustomContract.Requires(client != null);
            CustomContract.Requires(serializerFactory != null);
            CustomContract.Requires(expression != null);
            CustomContract.Requires(memberNameResolver != null);
            CustomContract.Requires(valueWriters != null);

            return(new RestGetQueryable <TResult>(client, serializerFactory, memberNameResolver, valueWriters, sourceType, expression));
        }
示例#23
0
        public void AddRecipeIngredient(Ingredient ingredient, float quantity, Units units)
        {
            CustomContract.Requires <ArgumentNullException>(ingredient != null);
            CustomContract.Requires <ArgumentNullException>(quantity > float.Epsilon);

            RecipeIngredients.Add(new RecipeIngredient()
            {
                IngredientID = ingredient.ID, Quantity = quantity, Unit = (int)units
            });
        }
        private Expression GetBooleanExpression(string filter, IFormatProvider formatProvider)
        {
            CustomContract.Requires(filter != null);

            var booleanExpression = _valueReader.Read(typeof(bool), filter, formatProvider) as ConstantExpression;

            return(booleanExpression != null && booleanExpression.Value != null
                                ? booleanExpression
                                : null);
        }
示例#25
0
        /// <summary>
        /// The Interface Statistics Block contains the capture statistics for a given interface and it is optional. The statistics are referred
        /// to the interface defined in the current Section identified by the Interface ID field. An Interface Statistics Block is normally
        /// placed at the end of the file, but no assumptions can be taken about its position - it can even appear multiple times for the same
        /// interface.
        /// </summary>
        public InterfaceStatisticsBlock(int InterfaceID, TimestampHelper Timestamp, InterfaceStatisticsOption Options, long PositionInStream = 0)
        {
            CustomContract.Requires <ArgumentNullException>(Timestamp != null, "Timestamp cannot be null");
            CustomContract.Requires <ArgumentNullException>(Options != null, "Options cannot be null");

            this.InterfaceID      = InterfaceID;
            this.Timestamp        = Timestamp;
            this.options          = Options;
            this.PositionInStream = PositionInStream;
        }
示例#26
0
 private void Initialize(Stream stream, SectionHeader header)
 {
     CustomContract.Requires <ArgumentNullException>(stream != null, "stream cannot be null");
     CustomContract.Requires <Exception>(stream.CanWrite == true, "Cannot write to stream");
     CustomContract.Requires <ArgumentNullException>(header != null, "header cannot be null");
     this.header  = header;
     this.stream  = stream;
     binaryWriter = new BinaryWriter(stream);
     binaryWriter.Write(header.ConvertToByte());
 }
示例#27
0
        public bool Delete(int id)
        {
            CustomContract.Requires <ArgumentNullException>(id > 0, "Id is 0 or less");

            var request = this.GetRequest(this.Endpoint + "/" + id, Method.DELETE);

            var response = this.Client.Execute(request);

            return(this.ProcessResult(response, HttpStatusCode.OK));
        }
示例#28
0
        public bool Update(Task item)
        {
            CustomContract.Requires <ArgumentNullException>(item != null, "Task is null");
            CustomContract.Requires <ArgumentNullException>(!string.IsNullOrEmpty(item.Title), "Title is not set");
            CustomContract.Requires <ArgumentNullException>(item.DueDate != null, "Task is null");
            CustomContract.Requires <ArgumentNullException>(item.Contact != null, "Task is null");
            CustomContract.Requires <ArgumentNullException>(item.Category != null, "Task is null");

            return(this.updateRestService.Update(item.CreateRequest()));
        }
        public NameResolutionOption(string Comment = null, string DnsName = null, IPAddress DnsIp4Addr = null, IPAddress DnsIp6Addr = null)
        {
            CustomContract.Requires <ArgumentException>(DnsIp4Addr == null || DnsIp4Addr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork, "dnsIp4Addr is not AddressFamily.InterNetwork");
            CustomContract.Requires <ArgumentException>(DnsIp6Addr == null || DnsIp6Addr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6, "dnsIp6Addr is not AddressFamily.InterNetworkV6");

            this.Comment    = Comment;
            this.DnsName    = DnsName;
            this.dnsIp4Addr = DnsIp4Addr;
            this.dnsIp6Addr = DnsIp6Addr;
        }
示例#30
0
 private void OnReadPacket(IPacket packet)
 {
     CustomContract.Requires <ArgumentNullException>(Header != null, "Header cannot be null");
     CustomContract.Requires <ArgumentNullException>(packet != null, "packet cannot be null");
     CommonDelegates.ReadPacketEventDelegate handler = OnReadPacketEvent;
     if (handler != null)
     {
         handler(Header, packet);
     }
 }