/// <summary>
 /// Initializes a new instance of the ComposedContinuation class.
 /// </summary>
 /// <param name="filter">The filter to compose.</param>
 /// <param name="next">The continuation to compose.</param>
 public ComposedContinuation(IServiceFilter filter, IServiceFilterContinuation next)
 {
     Debug.Assert(filter != null, "filter cannot be null!");
     Debug.Assert(next != null, "next cannot be null!");
     this.Filter = filter;
     this.Next = next;
 }
        /// <summary>
        /// Add all services which the concrete type implements
        /// </summary>
        /// <param name="serviceFilter">Used to filter implemented services.</param>
        public void AddServices(IServiceFilter serviceFilter)
        {
            if (serviceFilter == null)
            {
                throw new ArgumentNullException("serviceFilter");
            }

            foreach (var service in ConcreteType.GetInterfaces())
            {
                if (!serviceFilter.CanRegisterAs(service))
                {
                    continue;
                }

                AddService(service);
            }

            if (!Services.Any())
            {
                AddService(ConcreteType);
            }

            // Allow non standard filters do decide whether we should get registered
            // as concrete
            else if (!(serviceFilter is NonFrameworkClasses) && serviceFilter.CanRegisterAs(ConcreteType))
            {
                AddService(ConcreteType);
            }
        }
 /// <summary>
 /// Initializes a new instance of the ComposedContinuation class.
 /// </summary>
 /// <param name="filter">The filter to compose.</param>
 /// <param name="next">The continuation to compose.</param>
 public ComposedContinuation(IServiceFilter filter, IServiceFilterContinuation next)
 {
     Debug.Assert(filter != null, "filter cannot be null!");
     Debug.Assert(next != null, "next cannot be null!");
     this.Filter = filter;
     this.Next   = next;
 }
        /// <summary>
        /// Initializes a new instance of the ComposedServiceFilter class.
        /// </summary>
        /// <param name="first">The first IServiceFilter to apply.</param>
        /// <param name="second">The second IServiceFilter to apply.</param>
        public ComposedServiceFilter(IServiceFilter first, IServiceFilter second)
        {
            Debug.Assert(first != null, "first cannot be null!");
            Debug.Assert(second != null, "second cannot be null!");

            this.First  = first;
            this.Second = second;
        }
        /// <summary>
        /// Initializes a new instance of the ComposedServiceFilter class.
        /// </summary>
        /// <param name="first">The first IServiceFilter to apply.</param>
        /// <param name="second">The second IServiceFilter to apply.</param>
        public ComposedServiceFilter(IServiceFilter first, IServiceFilter second)
        {
            Debug.Assert(first != null, "first cannot be null!");
            Debug.Assert(second != null, "second cannot be null!");

            this.First = first;
            this.Second = second;
        }
Exemple #6
0
        public void AddLast(IServiceFilter filter)
        {
            if (filter == null)
            {
                return;
            }

            _filterLinkedList.AddLast(filter);
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the MobileServiceClient class based
        /// on an existing instance.
        /// </summary>
        /// <param name="service">
        /// An existing instance of the MobileServices class to copy.
        /// </param>
        private MobileServiceClient(MobileServiceClient service)
        {
            Debug.Assert(service != null, "service cannot be null!");

            this.ApplicationUri = service.ApplicationUri;
            this.ApplicationKey = service.ApplicationKey;
            this.CurrentUser = service.CurrentUser;
            this.filter = service.filter;
        }
 /// <summary>
 /// Apply a chain of IServiceFilters to an HTTP request and get the
 /// corresponding HTTP response.
 /// </summary>
 /// <param name="request">The HTTP request.</param>
 /// <param name="filter">
 /// The filter (or chain of filters composed together into a single
 /// filter) to apply to the request to obtain the response.
 /// </param>
 /// <returns>The HTTP response.</returns>
 public static Task<IServiceFilterResponse> ApplyAsync(IServiceFilterRequest request, IServiceFilter filter)
 {
     return (filter != null) ?
         // If we have a filter, create a new instance of this type to
         // provide the final default continuation
         filter.Handle(request, new ServiceFilter()) :
         // If we don't have a filter, just return the response directly
         request.GetResponse();
 }
Exemple #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ContainerRegistrar"/> class.
 /// </summary>
 /// <param name="filter">The filter.</param>
 /// <param name="defaultLifetime">The default lifetime if not specified in the methods.</param>
 public ContainerRegistrar(IServiceFilter filter, Lifetime defaultLifetime = Lifetime.Scoped)
 {
     if (filter == null)
     {
         throw new ArgumentNullException("filter");
     }
     _serviceFilter   = filter;
     _defaultLifetime = defaultLifetime;
 }
        /// <summary>
        /// Add all services which the concrete type implements
        /// </summary>
        /// <param name="serviceFilter">Used to filter implemented services.</param>
        public void AddServices(IServiceFilter serviceFilter)
        {
            if (serviceFilter == null) throw new ArgumentNullException("serviceFilter");

            foreach (var service in ConcreteType.GetInterfaces())
            {
                if (!serviceFilter.CanRegisterAs(service))
                    continue;

                AddService(service);
            }

            if (!Services.Any())
                AddService(ConcreteType);
        }
        /// <summary>
        /// Perform a web request and include the standard Mobile Services
        /// headers.
        /// </summary>
        /// <param name="method">
        /// The HTTP method used to request the resource.
        /// </param>
        /// <param name="uriFragment">
        /// URI of the resource to request (relative to the Mobile Services
        /// runtime).
        /// </param>
        /// <param name="content">
        /// Optional content to send to the resource.
        /// </param>
        /// <param name="ignoreFilters">
        /// Optional parameter to indicate if the client filters should be ignored
        /// and the request should be sent directly. Is <c>false</c> by default.
        /// </param>
        /// <returns>The JSON value of the response.</returns>
        internal async Task <IJsonValue> RequestAsync(string method, string uriFragment, IJsonValue content, bool ignoreFilters = false)
        {
            Debug.Assert(!string.IsNullOrEmpty(method), "method cannot be null or empty!");
            Debug.Assert(!string.IsNullOrEmpty(uriFragment), "uriFragment cannot be null or empty!");

            // Create the web request
            IServiceFilterRequest request = new ServiceFilterRequest();

            request.Uri    = new Uri(this.ApplicationUri, uriFragment);
            request.Method = method.ToUpper();
            request.Accept = RequestJsonContentType;

            // Set Mobile Services authentication, application, and telemetry
            // headers
            request.Headers[RequestInstallationIdHeader] = applicationInstallationId;
            if (!string.IsNullOrEmpty(this.ApplicationKey))
            {
                request.Headers[RequestApplicationKeyHeader] = this.ApplicationKey;
            }
            if (this.CurrentUser != null && !string.IsNullOrEmpty(this.CurrentUser.MobileServiceAuthenticationToken))
            {
                request.Headers[RequestAuthenticationHeader] = this.CurrentUser.MobileServiceAuthenticationToken;
            }

            // TODO: Set the User-Agent header; currently HttpWebRequest throws when the
            // User-Agent header is set.

            // Add any request as JSON
            if (content != null)
            {
                request.ContentType = RequestJsonContentType;
                request.Content     = content.Stringify();
            }

            // Send the request and get the response back as JSON
            IServiceFilter         filter   = ignoreFilters ? null : this.filter;
            IServiceFilterResponse response = await ServiceFilter.ApplyAsync(request, filter);

            IJsonValue body = GetResponseJsonAsync(response);

            // Throw errors for any failing responses
            if (response.ResponseStatus != ServiceFilterResponseStatus.Success || response.StatusCode >= 400)
            {
                ThrowInvalidResponse(request, response, body);
            }

            return(body);
        }
 /// <summary>
 ///     Deploys all instances of the current service that match the given predicate.
 /// </summary>
 /// ///
 /// <remarks>
 ///     Sequentially executes the registered setup, deployment and configuration actions for each instance that
 ///     matches the given predicate.
 /// </remarks>
 public void DeployService(IServiceFilter filter)
 {
     try
     {
         foreach (var instance in filter.GetInstances(Instances))
         {
             RunActions(SetupActions, DeployPhase.Setup, instance);
             RunActions(DeployActions, DeployPhase.Deploy, instance);
             RunActions(ConfigureActions, DeployPhase.Configure, instance);
         }
     }
     catch (ActionInvocationException ex)
     {
         _context.Log.Error("Exception encountered during deployment execution");
         _context.Log.Error(ex.Message);
         throw;
     }
 }
        public MobileServiceClient WithFilter(IServiceFilter filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }

            // "Clone" the current service
            MobileServiceClient extended = new MobileServiceClient(this);

            // Chain this service's filter with the new filter for the
            // extended service.  Note that we're
            extended.filter = (this.filter != null) ?
                              new ComposedServiceFilter(this.filter, filter) :
                              filter;

            return(extended);
        }
        /// <summary>
        /// Add all services which the concrete type implements
        /// </summary>
        /// <param name="serviceFilter">Used to filter implemented services.</param>
        public void AddServices(IServiceFilter serviceFilter)
        {
            if (serviceFilter == null) throw new ArgumentNullException("serviceFilter");

            foreach (var service in ConcreteType.GetInterfaces())
            {
                if (!serviceFilter.CanRegisterAs(service))
                    continue;

                AddService(service);
            }

            if (!Services.Any())
                AddService(ConcreteType);

            // Allow non standard filters do decide whether we should get registered
            // as concrete
            else if (!(serviceFilter is NonFrameworkClasses) && serviceFilter.CanRegisterAs(ConcreteType))
                AddService(ConcreteType);
        }
Exemple #15
0
        public ITableView Get(IServiceFilter filter)
        {
            Func <T, bool> func = entity => true;

            if (filter.Ids.Any())
            {
                func = entity => func(entity) && filter.Ids.Contains(entity.Id);
            }

            var entities = _repository.Get((T el) => func(el));

            if (filter.PageInfo != null)
            {
                entities = entities.Skip((filter.PageInfo.CurrentPage - 1) * filter.PageInfo.PageSize)
                           .Take(filter.PageInfo.PageSize);
            }

            // TODO
            return(new TableView());
        }
Exemple #16
0
 /// <summary>
 /// Apply a chain of IServiceFilters to an HTTP request and get the
 /// corresponding HTTP response.
 /// </summary>
 /// <param name="request">The HTTP request.</param>
 /// <param name="filter">
 /// The filter (or chain of filters composed together into a single
 /// filter) to apply to the request to obtain the response.
 /// </param>
 /// <returns>The HTTP response.</returns>
 public static async Task <IServiceFilterResponse> ApplyAsync(IServiceFilterRequest request, IServiceFilter filter)
 {
     return((filter != null) ?
            // If we have a filter, create a new instance of this type to
            // provide the final default continuation
            await filter.Handle(request, new ServiceFilter()) :
            // If we don't have a filter, just return the response directly
            await request.GetResponse());
 }
Exemple #17
0
        protected override void Before_each_spec()
        {
            _filter = Mock<IServiceFilter>();

             _theUnit = new ServiceActivator();
        }
        /// <summary>
        /// Initializes a new instance of the MobileServiceClient class based
        /// on an existing instance.
        /// </summary>
        /// <param name="service">
        /// An existing instance of the MobileServices class to copy.
        /// </param>
        private MobileServiceClient(MobileServiceClient service)
        {
            Debug.Assert(service != null, "service cannot be null!");

            this.ApplicationUri = service.ApplicationUri;
            this.ApplicationKey = service.ApplicationKey;
            this.CurrentUser = service.CurrentUser;
            this.filter = service.filter;
            this.login = new MobileServiceLogin(this);
        }
Exemple #19
0
 public ITableView Get(IServiceFilter filter)
 {
     throw new System.NotImplementedException();
 }
        public MobileServiceClient WithFilter(IServiceFilter filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }

            // "Clone" the current service
            MobileServiceClient extended = new MobileServiceClient(this);

            // Chain this service's filter with the new filter for the
            // extended service.  Note that we're 
            extended.filter = (this.filter != null) ?
                new ComposedServiceFilter(this.filter, filter) :
                filter;

            return extended;
        }
        /// <summary>
        /// Initializes a new instance of the MobileServiceClient class based
        /// on an existing instance.
        /// </summary>
        /// <param name="service">
        /// An existing instance of the MobileServices class to copy.
        /// </param>
        private MobileServiceClient(MobileServiceClient service)
        {
            Debug.Assert(service != null, "service cannot be null!");

            this.ApplicationUri = service.ApplicationUri;
            this.ApplicationKey = service.ApplicationKey;
            this.CurrentUser = service.CurrentUser;
            this.currentUserAuthenticationToken = service.currentUserAuthenticationToken;
            this.filter = service.filter;
        }
Exemple #22
0
 public void RegisterFilter(IServiceFilter filter)
 {
     _filterChain.AddLast(filter);
 }
Exemple #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ContainerRegistrar"/> class.
 /// </summary>
 /// <param name="defaultLifetime">The default lifetime if not specified in the methods.</param>
 public ContainerRegistrar(Lifetime defaultLifetime = Lifetime.Scoped)
 {
     _defaultLifetime = defaultLifetime;
     _serviceFilter   = new NonFrameworkClasses();
 }