コード例 #1
0
        public bool IsSatisfiedBy(ISourceContext context)
        {
            if (RequestedType == context.SourceType)
            {
                TypeToUse = context.SourceType;
                return(true);
            }

            var discovered = RequestedType.BaseType;

            while (discovered != null)
            {
                if (discovered == context.SourceType)
                {
                    TypeToUse = discovered;
                    return(true);
                }
                discovered = discovered.BaseType;
            }

            if (RequestedType.GetInterfaces().Length <= 0)
            {
                return(false);
            }
            foreach (var theInterfaceType in RequestedType.GetInterfaces())
            {
                if (context.SourceType == theInterfaceType)
                {
                    TypeToUse = theInterfaceType;
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        public bool IsSatisfiedBy(ISourceContext context)
        {
            if(RequestedType==context.SourceType)
            {
                TypeToUse = context.SourceType;
                return true;
            }

            var discovered = RequestedType.BaseType;
            while (discovered != null)
            {
                if(discovered==context.SourceType)
                {
                    TypeToUse = discovered;
                    return true;
                }
                discovered = discovered.BaseType;
            }

            if (RequestedType.GetInterfaces().Length <= 0)
            {
                return false;
            }
            foreach (var theInterfaceType in RequestedType.GetInterfaces())
            {
                if (context.SourceType == theInterfaceType)
                {
                    TypeToUse = theInterfaceType;
                    return true;
                }
            }
            return false;
        }
コード例 #3
0
        public ExtractPagesTests()
        {
            this.persistence      = Substitute.For <ISourcesPersistence>();
            this.sourceRepository = Substitute.For <ISourcesRepository>();
            this.context          = Substitute.For <ISourceContext>();
            this.imageService     = new FakeImageService();
            var matcher = Substitute.For <IUriTemplateMatcher>();

            this.httpMessageHandler = new MockHttpMessageHandler();

            matcher.Match <Brochure>(Arg.Any <Uri>())
            .Returns(new UriTemplateMatches(new Dictionary <string, object>
            {
                { "id", 10 },
            }));

            this.sourceRepository.GetBrochure(Arg.Any <Uri>())
            .Returns(Task.FromResult(new Brochure
            {
                Id = new Uri(SourceId),
            }));

            this.functions = new ExtractPages(
                this.sourceRepository,
                this.imageService,
                matcher,
                this.context,
                this.persistence);

            this.functions.Client = this.httpMessageHandler.ToHttpClient();
        }
コード例 #4
0
 public DestinationConfigurationMemento(Type destinationType, IDescribeMappableProperty[] destinationProperties, ISourceContext[] sourceContexts, Convention[] conventions)
 {
     DestinationType = destinationType;
     DestinationProperties = destinationProperties;
     SourceContexts = sourceContexts;
     Conventions = conventions;
 }
コード例 #5
0
        /// <summary>
        ///  Inicializa a instancia com os parametros informados.
        /// </summary>
        /// <param name="parameters">Dicionário com os parametros de inicialização.</param>
        public void Init(System.Collections.IDictionary parameters)
        {
            var sourceContext       = parameters["sourceContext"] as ISourceContext;
            var manager             = parameters["manager"] as IDataCacheManager;
            var logger              = parameters["logger"] as Colosoft.Logging.ILogger;
            var typeSchema          = parameters["typeSchema"] as Colosoft.Data.Schema.ITypeSchema;
            var cacheLoaderObserver = parameters["cacheLoaderObserver"] as ICacheLoaderObserver;
            var typesMetadata       = parameters["typesMetadata"] as IList <ITypeMetadata>;

            sourceContext.Require("sourceContext").NotNull();
            manager.Require("manager").NotNull();
            if (typesMetadata == null)
            {
                typeSchema.Require("typeSchema").NotNull();
            }
            logger.Require("logger").NotNull();
            _sourceContext = sourceContext;
            _manager       = manager;
            _logger        = logger;
            _typeSchema    = typeSchema;
            _typesMetadata = typesMetadata;
            _started       = false;
            if (cacheLoaderObserver != null)
            {
                _observer += cacheLoaderObserver;
            }
        }
コード例 #6
0
 public SourcesRepository(
     ISourceContext context,
     EntityFactory factory,
     IUriTemplateMatcher matcher)
 {
     this.context = context;
     this.factory = factory;
     this.matcher = matcher;
 }
コード例 #7
0
        public SourceStorageLocationModule(
            IModelTemplateProvider provider,
            ISourceContext sourcesContext)
            : base(provider)
        {
            this.RequiresPermissions(Permissions.AdminSources);

            this.sourcesContext = sourcesContext;
            this.Put <StorageLocation>(this.UpdateStorageLocation);
        }
コード例 #8
0
 public EntityFactory(
     IUriTemplateExpander expander,
     IWikibusConfiguration configuration,
     [AllowNull] ClaimsPrincipal principal,
     ISourceContext context)
 {
     this.expander      = expander;
     this.configuration = configuration;
     this.principal     = principal;
     this.context       = context;
 }
コード例 #9
0
 public GoogleDriveImport(
     IDriveServiceFacade drive,
     ISourceContext context,
     ISourcesPersistence persistence,
     IPdfService pdfService)
 {
     this.drive       = drive;
     this.context     = context;
     this.persistence = persistence;
     this.pdfService  = pdfService;
 }
コード例 #10
0
 public void Run(ISourceContext <long> ctx)
 {
     while (_isRunning && _counter < 1000)
     {
         lock (ctx.GetCheckpointLock())
         {
             ctx.Collect(_counter);
             _counter++;
         }
     }
 }
コード例 #11
0
        public void Run(ISourceContext <T> ctx)
        {
            var stream = new MemoryStream(_elementsSerialized);
            var input  = new DataInputViewStreamWrapper(stream);

            // if we are restored from a checkpoint and need to skip elements, skip them now.
            var toSkip = _numElementsToSkip;

            if (toSkip <= 0)
            {
                return;
            }

            try
            {
                while (toSkip > 0)
                {
                    _serializer.Deserialize(input);
                    toSkip--;
                }
            }
            catch (Exception e)
            {
                throw new IOException("Failed to deserialize an element from the source. " +
                                      "If you are using user-defined serialization (Value and Writable types), check the " +
                                      "serialization functions.\nSerializer is " + _serializer, e);
            }

            _numElementsEmitted = _numElementsToSkip;

            var mutex = ctx.GetCheckpointLock();

            while (_isRunning && _numElementsEmitted < _numElements)
            {
                T next;
                try
                {
                    next = _serializer.Deserialize(input);
                }
                catch (Exception e)
                {
                    throw new IOException("Failed to deserialize an element from the source. " +
                                          "If you are using user-defined serialization (Value and Writable types), check the " +
                                          "serialization functions.\nSerializer is " + _serializer, e);
                }

                lock (mutex)
                {
                    ctx.Collect(next);
                    _numElementsEmitted++;
                }
            }
        }
コード例 #12
0
        public GoogleDriveImportTests()
        {
            this.context     = Substitute.For <ISourceContext>();
            this.drive       = Substitute.For <IDriveServiceFacade>();
            this.pdfService  = Substitute.For <IPdfService>();
            this.persistence = Substitute.For <ISourcesPersistence>();

            this.sut = new GoogleDriveImport(
                this.drive,
                this.context,
                this.persistence,
                this.pdfService);
        }
コード例 #13
0
 public ExtractPages(
     ISourcesRepository sources,
     ISourceImageService imageService,
     IUriTemplateMatcher matcher,
     ISourceContext sourcesContext,
     ISourcesPersistence persistence)
 {
     this.sources        = sources;
     this.imageService   = imageService;
     this.matcher        = matcher;
     this.sourcesContext = sourcesContext;
     this.persistence    = persistence;
     this.Client         = new HttpClient();
 }
コード例 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SourceImagesModule"/> class.
        /// </summary>
        public SourceImagesModule(
            IImageStorage storage,
            ISourceContext data)
        {
            this.RequiresAnyPermissions(Permissions.WriteSources, Permissions.AdminSources);

            this.imageService = new SourceImageService(storage, data);
            this.storage      = storage;
            this.data         = data;

            this.Post("/book/{id}/images", request => this.UploadImages((int)request.id));
            this.Post("/brochure/{id}/images", request => this.UploadImages((int)request.id));
            this.Delete("image/{publicId*}", this.DeleteImage);
            this.Post("image/{publicId*}", this.ReorderImages);
        }
コード例 #15
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="sourceContext"></param>
 /// <param name="sourceProvider"></param>
 public LinqSourceContext(ISourceContext sourceContext, ISourceProvider sourceProvider)
 {
     _sourceContext  = sourceContext;
     _sourceProvider = sourceProvider;
 }
コード例 #16
0
 public SourcesPersistence(ISourceContext context, IUriTemplateMatcher matcher, IUriTemplateExpander expander)
 {
     this.context  = context;
     this.matcher  = matcher;
     this.expander = expander;
 }
コード例 #17
0
 public PropertyChangedNotifyingProperty(ISourceContext <TSource> sourceContext, string name)
 {
     this.sourceContext = sourceContext;
     this.Name          = name;
 }
コード例 #18
0
 public WishlistRepository(ISourceContext context, IUriTemplateExpander expander)
 {
     this.context  = context;
     this.expander = expander;
 }
コード例 #19
0
 public CloningSourceContext(ISourceContext inner)
 {
     this.inner = inner;
 }
コード例 #20
0
 public DependencyNotifyingProperty(ISourceContext <TSource> sourceContext, DependencyProperty dependencyProperty)
 {
     this.sourceContext      = sourceContext;
     this.DependencyProperty = dependencyProperty;
 }
コード例 #21
0
 public CloningSourceContext(ISourceContext inner)
 {
     this.inner = inner;
 }
コード例 #22
0
 public EventNotifyingProperty(ISourceContext <TSource> sourceContext, Func <TSource, Action, TEventHandler> subscribe, Action <TSource, TEventHandler> unsubscribe)
 {
     this.sourceContext = sourceContext;
     this.subscribe     = subscribe;
     this.unsubscribe   = unsubscribe;
 }
コード例 #23
0
 public User(ManagementClientFactory clientFactory, IConfiguration configuration, ISourceContext context)
 {
     this.clientFactory = clientFactory;
     this.configuration = configuration;
     this.context       = context;
 }
コード例 #24
0
 public SourceImageService([AllowNull] IImageStorage storage, [AllowNull] ISourceContext data)
 {
     this.storage = storage;
     this.data    = data;
 }