public ProjectViewModel(ISiteStorage siteStorage, IProjectProvider projectProvider, ITemplateProvider templateProvider, IComposer composer)
 {
     this.siteStorage = siteStorage;
     this.projectProvider = projectProvider;
     this.templateProvider = templateProvider;
     this.composer = composer;
 }
Beispiel #2
0
        private void LoadComposers()
        {
            Outgoing = new Dictionary <Type, IComposer>();

            IEnumerable <Type> composers = GetImplementing <IComposer>();

            foreach (Type composerType in composers)
            {
                short id = library.GetOutgoingId(composerType.Name);

                if (id > 0)
                {
                    IComposer composer = (IComposer)Activator.CreateInstance(composerType);
                    composer.Init(id, pool);

                    // TODO Remove one Add
                    Outgoing.Add(composerType, composer);
                    if (composerType.BaseType.Namespace.StartsWith("Yupi.Messages.Contracts") &&
                        !composerType.BaseType.Name.StartsWith("AbstractComposer"))
                    {
                        Outgoing.Add(composerType.BaseType, composer);
                    }
                }
            }
        }
Beispiel #3
0
 public EqualityCondition(
     IComposer left,
     IComposer right)
 {
     _left  = left;
     _right = right;
 }
 public PropertyComposer(
     string name,
     IComposer innerComposer)
 {
     Name           = name ?? throw new ArgumentNullException(nameof(name));
     _innerComposer = innerComposer ?? throw new ArgumentNullException(nameof(innerComposer));
 }
        public static void Setup(IComposer componentContext, HttpConfiguration configuration)
        {
            var webApiDependencyResolver = componentContext.GetComponent <IWebApiDependencyResolverContract>();

            configuration.DependencyResolver = webApiDependencyResolver ?? throw new CompositionException(
                                                         "No provider component for IWebApiDependencyResolverContract is registered. " +
                                                         "Make sure you've included the correct libraries in the composition config.");
        }
        /// <summary>
        /// Checks if the bootstapper is inialized if now it inializes it
        /// </summary>
        public static CompositionContainer EnsureLocatorBootstrapper()
        {
            IComposer composer = null;

            if (Designer.IsInDesignMode)
            {
                if (designTimeComposer == null)
                {
                    designTimeComposer = new DefaultDesignTimeComposer();
                }
                composer = designTimeComposer;
            }
            else
            {
                if (runtimeComposer == null) // if the composer is not set then we should use the default one
                {
                    runtimeComposer = new DefaultRuntimeComposer();
                }
                composer = runtimeComposer;
            }

            CompositionContainer container;

            if (composer is IContainerProvider)
            {
                container = ((IContainerProvider)composer).CreateContainer();

                var mefedProviderLocated = container.Providers.OfType <IMEFedMVVMExportProvider>().Any();
                if (!mefedProviderLocated)
                {
                    throw new InvalidOperationException("ContainerProvider did not include MEFedMVVMExportProvider in the CompositionContainer");
                }
            }
            else
            {
                var catalog       = composer.InitializeContainer();
                var mefedProvider = new MEFedMVVMExportProvider(MEFedMVVMCatalog.CreateCatalog(catalog));
                var providersList = new List <ExportProvider>();

                //check if there are any custom export providers
                var providers = composer.GetCustomExportProviders();
                if (providers != null && providers.Count() != 0)
                {
                    providersList.AddRange(providers);
                }

                //add mefedMVVM provider
                providersList.Add(mefedProvider);

                container = new CompositionContainer(providersList.ToArray());
                foreach (var imefedProvider in container.Providers.OfType <IMEFedMVVMExportProvider>())
                {
                    imefedProvider.SourceProvider = container;
                }
            }

            return(container);
        }
Beispiel #7
0
 public IfElseComposer(
     ICondition condition,
     IComposer ifComposer,
     IComposer elseComposer)
 {
     _condition    = condition;
     _elseComposer = elseComposer;
     _ifComposer   = ifComposer;
 }
        /// <summary>
        /// Removes a ComposablePart from the composition</summary>
        /// <param name="composer">IComposer</param>
        /// <param name="composablePart">ComposablePart to remove from the compositoi</param>
        public static void RemovePart(this IComposer composer, ComposablePart composablePart)
        {
            Requires.NotNull(composer, "composer");
            Requires.NotNull(composablePart, "composablePart");

            var batch = new CompositionBatch(Enumerable.Empty <ComposablePart>(), new ComposablePart[] { composablePart });

            composer.Container.Compose(batch);
        }
Beispiel #9
0
 public FilterIterator(
     IComposer iterable,
     string lambdaVarName,
     ICondition condition)
 {
     _iterable      = iterable ?? throw new ArgumentNullException(nameof(iterable));
     _lambdaVarName = lambdaVarName ?? throw new ArgumentNullException(nameof(lambdaVarName));
     _condition     = condition ?? throw new ArgumentNullException(nameof(condition));
 }
Beispiel #10
0
 public MapIterator(
     IComposer iterable,
     string lambdaVarName,
     IComposer lambdaOperation)
 {
     _iterable        = iterable ?? throw new ArgumentNullException(nameof(iterable));
     _lambdaVarName   = lambdaVarName ?? throw new ArgumentNullException(nameof(lambdaVarName));
     _lambdaOperation = lambdaOperation ?? throw new ArgumentNullException(nameof(lambdaOperation));
 }
        /// <summary>
        /// Inserts a composer.
        /// </summary>
        /// <param name="composer">The composer.</param>
        /// <returns></returns>
        public async Task <IComposer> InsertAsync(IComposer composer)
        {
            ComposerEntity composerEntity = Mapper.Map <ComposerEntity>(composer);

            composerEntity = await UnitOfWork.InsertAsync(composerEntity);

            await UnitOfWork.CommitAsync();

            return(Mapper.Map <IComposer>(composerEntity));
        }
Beispiel #12
0
        public async Task <HttpResponseMessage> CreateAsync([FromBody] ComposerModel composer)
        {
            IComposer newComposer = Service.Create();

            Mapper.Map(composer, newComposer);

            IComposer resultComposer = await Service.InsertAsync(newComposer);

            return(Request.CreateResponse(HttpStatusCode.OK, Mapper.Map <ComposerModel>(resultComposer)));
        }
Beispiel #13
0
 /// <summary>
 /// Writes records of type T, using the specified composer to compose the file.
 /// </summary>
 /// <typeparam name="T">The type of objects to write/compose.</typeparam>
 /// <param name="stream">The <see cref="Stream"/> to write to.</param>
 /// <param name="values">The values to write to the file.</param>
 /// <param name="composer">The <see cref="IComposer{T}"/> to use when writing the file.</param>
 /// <param name="lineseparator">The lineseparator to use (see <see cref="DEFAULTLINESEPARATOR"/>).</param>
 public void WriteRecords <T>(Stream stream, IEnumerable <T> values, IComposer <T> composer, string lineseparator = DEFAULTLINESEPARATOR)
 {
     using (var w = new StreamWriter(stream, composer.Encoding))
     {
         foreach (var v in values)
         {
             w.Write(composer.Compose(v) + lineseparator);
         }
     }
 }
Beispiel #14
0
        public void Initialize(IComposer composer)
        {
            if (_contractTypes.Count < 1)
            {
                throw new CompositionException($"No open contracts found nor added for the type {_targetType.Name}. " +
                                               "Use [Contract] attribute or use Fluent syntax to introduce contracts");
            }

            _composer = composer;
        }
Beispiel #15
0
        public object Query(IComposer composer)
        {
            IComposer composerToUse = ComposerOverride ?? composer;

            if (composerToUse == null)
            {
                throw new ArgumentNullException("composer");
            }

            return(composerToUse.GetVariable(VariableName));
        }
        public object Query(IComposer composer)
        {
            IComposer composerToUse = ComposerOverride ?? composer;

            if (composerToUse == null)
            {
                throw new ArgumentNullException(nameof(composer));
            }

            return(ValueCalculator(composerToUse));
        }
Beispiel #17
0
        public object Query(IComposer composer)
        {
            IComposer composerToUse = ComposerOverride ?? composer;

            if (composerToUse == null)
            {
                throw new ArgumentNullException("composer");
            }

            return(composerToUse.GetComponent(ContractType, ContractName));
        }
        /// <summary>
        /// Creates a ComposablePart from an attributed object and adds it to the composition</summary>
        /// <param name="composer">IComposer</param>
        /// <param name="attributedPart">Attributed object to add to the composition</param>
        /// <returns>ComposablePart from the attributed object</returns>
        /// <remarks>This method creates a ComposablePart from the attributed object, adds it to a CompositionBatch
        /// and then executes composition on this CompositionBatch.</remarks>
        public static ComposablePart AddPart(this IComposer composer, object attributedPart)
        {
            Requires.NotNull(composer, "composer");
            Requires.NotNull(attributedPart, "attributedPart");

            ComposablePart part  = AttributedModelServices.CreatePart(attributedPart);
            var            batch = new CompositionBatch(new ComposablePart[] { part }, Enumerable.Empty <ComposablePart>());

            composer.Container.Compose(batch);

            return(part);
        }
Beispiel #19
0
        public LocalComponentFactory(Type targetType)
        {
            _targetType = targetType ?? throw new ArgumentNullException(nameof(targetType));

            _composer                       = null;
            _componentCache                 = null;
            _componentCacheQuery            = null;
            _targetConstructor              = null;
            _constructorArgs                = null;
            _initializationPoints           = new List <InitializationPointSpecification>();
            _compositionNotificationMethods = null;
        }
Beispiel #20
0
 public ReduceIterator(
     IComposer iterable,
     IComposer initialAccumulator,
     string accumulatorName,
     string lambdaVarName,
     IComposer reducer)
 {
     _iterable           = iterable ?? throw new ArgumentNullException(nameof(iterable));
     _initialAccumulator = initialAccumulator;
     _accumulatorName    = accumulatorName ?? throw new ArgumentNullException(nameof(accumulatorName));
     _lambdaVarName      = lambdaVarName ?? throw new ArgumentNullException(nameof(lambdaVarName));
     _reducer            = reducer ?? throw new ArgumentNullException(nameof(reducer));
 }
Beispiel #21
0
        public static void Bind(IComposer composer)
        {
            var currentThreadId = Thread.CurrentThread.ManagedThreadId;

            if (composer == null)
            {
                Unbind();
            }
            else
            {
                composers[currentThreadId] = composer;
            }
        }
Beispiel #22
0
        /// <summary>
        /// Convenience method that constructs a new <see cref="IBootstrap{TTarget}"/>
        /// participant that will invoke your action, and participates it with this composer.
        /// Since this will construct a new participant, the new
        /// added instance is returned here.
        /// See also <see cref="DelegateComposerParticipant{TTarget}"/>.
        /// </summary>
        /// <typeparam name="TTarget">The type of the target handled
        /// by the specific <see cref="IComposer{TTarget}"/>.</typeparam>
        /// <param name="composer">Required.</param>
        /// <param name="bootstrap">Required.</param>
        /// <param name="oneTimeOnly">Optional.</param>
        /// <returns>Not null: the added participant.</returns>
        /// <exception cref="ArgumentNullException"/>
        public static DelegateComposerParticipant <TTarget> ParticipateBootstrapDelegate <TTarget>(
            this IComposer <TTarget> composer,
            Action <ComposerEventArgs <TTarget> > bootstrap,
            bool oneTimeOnly = false)
        {
            if (composer == null)
            {
                throw new ArgumentNullException(nameof(composer));
            }
            DelegateComposerParticipant <TTarget> delegateParticipant = new DelegateComposerParticipant <TTarget>(null, bootstrap);

            composer.Participate(delegateParticipant, oneTimeOnly);
            return(delegateParticipant);
        }
Beispiel #23
0
        /// <summary>
        /// Convenience method that constructs a new <see cref="IProvideParts{TTarget}"/>
        /// participant that will invoke your action, and participates it with this composer.
        /// Since this will construct a new participant, the new
        /// added instance is returned here.
        /// See also <see cref="DelegateComposerParticipant{TTarget}"/>.
        /// </summary>
        /// <typeparam name="TTarget">The type of the target handled
        /// by the specific <see cref="IComposer{TTarget}"/>.</typeparam>
        /// <param name="composer">Required.</param>
        /// <param name="provideParts">Required.</param>
        /// <param name="oneTimeOnly">Optional.</param>
        /// <returns>Not null: the added participant.</returns>
        /// <exception cref="ArgumentNullException"/>
        public static DelegateComposerParticipant <TTarget> ParticipatePartsDelegate <TTarget>(
            this IComposer <TTarget> composer,
            Action <ProvidePartsEventArgs <TTarget> > provideParts,
            bool oneTimeOnly = false)
        {
            if (composer == null)
            {
                throw new ArgumentNullException(nameof(composer));
            }
            DelegateComposerParticipant <TTarget> delegateParticipant = new DelegateComposerParticipant <TTarget>(provideParts);

            composer.Participate(delegateParticipant, oneTimeOnly);
            return(delegateParticipant);
        }
Beispiel #24
0
        /// <summary>
        /// Convenience method that constructs a new <see cref="IRequestComposition{TTarget}"/>
        /// participant that will raise the <see cref="IRequestComposition{TTarget}.CompositionRequested"/>
        /// event, and participates it with this composer.
        /// Since this will construct a new participant, the new
        /// added instance is returned here.
        /// See also <see cref="DelegateComposerParticipant{TTarget}"/>.
        /// </summary>
        /// <typeparam name="TTarget">The type of the target handled
        /// by the specific <see cref="IComposer{TTarget}"/>.</typeparam>
        /// <param name="composer">Required.</param>
        /// <param name="requestComposition">Will be set to an action that will
        /// raise the <see cref="IRequestComposition{TTarget}.CompositionRequested"/>
        /// event from the returned participant.</param>
        /// <param name="oneTimeOnly">Optional.</param>
        /// <returns>Not null: the added participant.</returns>
        /// <exception cref="ArgumentNullException"/>
        public static DelegateComposerParticipant <TTarget> ParticipateRequestCompositionDelegate <TTarget>(
            this IComposer <TTarget> composer,
            out Action <RequestCompositionEventArgs <TTarget> > requestComposition,
            bool oneTimeOnly = false)
        {
            if (composer == null)
            {
                throw new ArgumentNullException(nameof(composer));
            }
            DelegateComposerParticipant <TTarget> delegateParticipant
                = new DelegateComposerParticipant <TTarget>(out requestComposition);

            composer.Participate(delegateParticipant, oneTimeOnly);
            return(delegateParticipant);
        }
Beispiel #25
0
        public static void Unbind(IComposer composer)
        {
            if (!composers.ContainsValue(composer))
            {
                return;
            }

            foreach (var pair in composers)
            {
                if (ReferenceEquals(pair.Value, composer))
                {
                    composers.Remove(pair.Key);
                }
            }
        }
Beispiel #26
0
        /// <summary>
        /// This helper method will check and construct a new variant participant, that
        /// implements the composer's covariant type, and contributes all supported interfaces to
        /// the composer. Since this will construct a new participant, the actual
        /// added instance is returned here.
        /// </summary>
        /// <typeparam name="TSuper">The delegate's actual type.</typeparam>
        /// <typeparam name="TTarget">This composer's implemented type.</typeparam>
        /// <param name="composer">Required.</param>
        /// <param name="participant">Required.</param>
        /// <param name="oneTimeOnly">Optional.</param>
        /// <returns>The actual added instance.</returns>
        /// <exception cref="ArgumentNullException"/>
        public static VariantParticipant <TSuper, TTarget> ParticipateAs <TSuper, TTarget>(
            this IComposer <TTarget> composer,
            IComposerParticipant <TSuper> participant,
            bool oneTimeOnly = false)
            where TTarget : TSuper
        {
            if (composer == null)
            {
                throw new ArgumentNullException(nameof(composer));
            }
            VariantParticipant <TSuper, TTarget> variantParticipant
                = new VariantParticipant <TSuper, TTarget>(participant);

            composer.Participate(variantParticipant, oneTimeOnly);
            return(variantParticipant);
        }
Beispiel #27
0
        public GenericLocalComponentFactory(Type targetType)
        {
            if ((!targetType.ContainsGenericParameters) || (!targetType.IsGenericType))
            {
                throw new ArgumentException("TargetType in GenericLocalComponentFactory should be an open generic type.");
            }

            _targetType = targetType;
            _composer   = null;

            _contractTypes        = new Dictionary <Type, Type>();
            _subFactories         = new ConcurrentDictionary <Type, LocalComponentFactory>();
            _initializationPoints = new List <InitializationPointSpecification>();

            ExtractContractTypes();
        }
Beispiel #28
0
        public GenericLocalComponentFactory(Type targetType)
        {
            if (!targetType.IsOpenGenericType())
            {
                throw new ArgumentException("TargetType in GenericLocalComponentFactory should be an open generic type.");
            }

            _targetType = targetType;
            _composer   = null;

            _contractTypes                  = new Dictionary <Type, Type>();
            _subFactories                   = new ConcurrentDictionary <Type, LocalComponentFactory>();
            _constructorArgs                = null;
            _initializationPoints           = null;
            _compositionNotificationMethods = null;

            ExtractContractTypes();
        }
Beispiel #29
0
        /// <summary>
        /// This method provides an implementation for an <see cref="IComposer{TTarget}"/>
        /// to handle this event. This checks the <see cref="Participant"/>, and the
        /// <see cref="Request"/>, and will invoke your <paramref name="composer"/>
        /// as specified.
        /// </summary>
        /// <typeparam name="T">Your <paramref name="composer"/>
        /// actual (covariant) type.</typeparam>
        /// <param name="composer">Not null.</param>
        /// <returns>True if any method was invoked on the <paramref name="composer"/>.
        /// False if not invoked.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public bool Handle <T>(IComposer <T> composer)
            where T : TTarget
        {
            if (composer == null)
            {
                throw new ArgumentNullException(nameof(composer));
            }
            if (Participant == null)
            {
                return(false);
            }
            IComposer <TTarget> targetComposer = composer as IComposer <TTarget>;

            switch (Request)
            {
            case ParticipantRequest.Add:
                if (targetComposer != null)
                {
                    targetComposer.Participate(Participant);
                    return(true);
                }
                composer.ParticipateAs(Participant);
                return(true);

            case ParticipantRequest.AddOneTimeOnly:
                if (targetComposer != null)
                {
                    targetComposer.Participate(Participant, true);
                    return(true);
                }
                composer.ParticipateAs(Participant, true);
                return(true);

            case ParticipantRequest.Remove:
                if (targetComposer != null)
                {
                    targetComposer.Remove(Participant);
                    return(true);
                }
                composer.Remove(new VariantParticipant <TTarget, T>(Participant));
                return(true);
            }
            return(false);
        }
Beispiel #30
0
        /// <summary>
        /// Convenience method that constructs a new
        /// <see cref="AggregateComposerParticipant{TTarget}"/> from the
        /// given list, and participates it with your composer. All interfaces
        /// implemented by your participants will be invoked. Since this
        /// will construct a new participant, the actual
        /// added instance is returned here.
        /// </summary>
        /// <typeparam name="TTarget">The type of the target handled
        /// by the specific <see cref="IComposer{TTarget}"/>.</typeparam>
        /// <param name="composer">Required.</param>
        /// <param name="participants">Required.</param>
        /// <param name="oneTimeOnly">Optional.</param>
        /// <param name="disposeParticipantsWithAggregate">Defaults to true: the participants
        /// will be disposed with this new aggregate participant.</param>
        /// <returns>Not null.</returns>
        /// <exception cref="ArgumentNullException"/>
        public static AggregateComposerParticipant <TTarget> Aggregate <TTarget>(
            this IComposer <TTarget> composer,
            IEnumerable <IComposerParticipant <TTarget> > participants,
            bool oneTimeOnly = false,
            bool disposeParticipantsWithAggregate = true)
        {
            if (composer == null)
            {
                throw new ArgumentNullException(nameof(composer));
            }
            AggregateComposerParticipant <TTarget> aggregateParticipant
                = new AggregateComposerParticipant <TTarget>(participants)
                {
                DisposeParticipantsWithThis = disposeParticipantsWithAggregate
                };

            composer.Participate(aggregateParticipant, oneTimeOnly);
            return(aggregateParticipant);
        }
        public object Query(IComposer composer)
        {
            var composerToUse = ComposerOverride ?? composer;

            if (composerToUse == null)
            {
                throw new ArgumentNullException(nameof(composer));
            }

            var provider = composerToUse.GetComponent <IResourceProvider>();

            if (provider == null)
            {
                throw new CompositionException(
                          "Can't query for resource managers, no resource provider component is registered with the composer.");
            }

            return(provider.GetResourceManager(ResourceId));
        }
Beispiel #32
0
 public Constructor(IComposer composer)
 {
     this.composer = composer;
 }
 /// <summary>
 /// forces the Locator to use this composer
 /// </summary>
 ///<param name="designTimeComposer">The compose to create the CompositionContainer</param>
 ///<param name="runtimeComposer">The composer to use for runtime</param>
 public static void ApplyComposer(IComposer runtimeComposer)
 {
     LocatorBootstrapper.runtimeComposer = runtimeComposer;
 }
Beispiel #34
0
 /// <summary>
 /// Notification when part's imports have been satisfied</summary>
 public void OnImportsSatisfied()
 {
     Current = m_composer;
 }
Beispiel #35
0
 /// <summary>
 /// Cconfigures the IComposer instance</summary>
 /// <param name="composer">IComposer instance</param>
 public static void Configure(IComposer composer)
 {
     Current = composer;
 }