コード例 #1
0
 public SharedModel(IPostable parentForm, IExportStrategy exportStrategy)
 {
     Utils.CheckNotNull(parentForm, "parentForm");
     Utils.CheckNotNull(exportStrategy, "exportStrategy");
     m_ParentForm   = parentForm;
     ExportStrategy = exportStrategy;
 }
コード例 #2
0
        /// <summary>
        /// Exports the objects loaded into this transporter (including their contents) in a custom format for transport to another system.
        /// At the target system, the data can be loaded via <see cref="LoadTransportData(Stream,IImportStrategy)"/>.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> to which to export the loaded objects.</param>
        /// <param name="strategy">The strategy to be used for exporting data. This must match the strategy used with
        /// <see cref="LoadTransportData(System.IO.Stream,Remotion.Data.DomainObjects.DomainImplementation.Transport.IImportStrategy)"/>.</param>
        public void Export(Stream stream, IExportStrategy strategy)
        {
            IEnumerable <DataContainer> transportedContainers = GetTransportedContainers();

            TransportItem[] transportItems = TransportItem.PackageDataContainers(transportedContainers).ToArray();
            strategy.Export(stream, transportItems);
        }
コード例 #3
0
        /// <summary>
        /// Internal filter method that loops through the collection of filters
        /// </summary>
        /// <param name="context">injection context</param>
        /// <param name="strategy">export strategy</param>
        /// <returns>true if the strategy matches</returns>
        private bool InternalExportStrategyFilter(IInjectionContext context, IExportStrategy strategy)
        {
            if (UseOr)
            {
                foreach (ExportStrategyFilter exportStrategyFilter in filters)
                {
                    if (exportStrategyFilter(context, strategy))
                    {
                        return true;
                    }
                }

                return false;
            }

            foreach (ExportStrategyFilter exportStrategyFilter in filters)
            {
                if (!exportStrategyFilter(context, strategy))
                {
                    return false;
                }
            }

            return true;
        }
コード例 #4
0
        /// <summary>
        /// This method is called by the export strategy when attempting to locate an export
        /// </summary>
        /// <param name="creationDelegate"></param>
        /// <param name="exportStrategyScope"></param>
        /// <param name="injectionContext"></param>
        /// <param name="exportStrategy"></param>
        /// <returns></returns>
        public object Locate(ExportActivationDelegate creationDelegate,
			IInjectionScope exportStrategyScope,
			IInjectionContext injectionContext,
			IExportStrategy exportStrategy)
        {
            if (instance.Value != null)
            {
                return instance.Value;
            }

            IDisposalScope contextdisposalScope = injectionContext.DisposalScope;
            IInjectionScope requestingScope = injectionContext.RequestingScope;

            injectionContext.DisposalScope = exportStrategyScope;
            injectionContext.RequestingScope = exportStrategyScope;

            object instanceValue = creationDelegate(exportStrategyScope, injectionContext);

            injectionContext.DisposalScope = contextdisposalScope;
            injectionContext.RequestingScope = requestingScope;

            instance.Value = instanceValue;

            IDisposable disposable = instanceValue as IDisposable;

            if (disposable != null)
            {
                disposalScope.AddDisposable(disposable);
            }

            return instance.Value;
        }
コード例 #5
0
ファイル: WhenAncestor.cs プロジェクト: jrjohn/Grace
        /// <summary>
        /// Condition meet
        /// </summary>
        /// <param name="scope">injection scope</param>
        /// <param name="injectionContext">injection context</param>
        /// <param name="exportStrategy">export strategy</param>
        /// <returns>condition</returns>
        public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy)
        {
            bool found = false;
            CurrentInjectionInfo[] injectionStack = injectionContext.GetInjectionStack();

            for (int i = injectionStack.Length - 1; i >= 0 && !found; i--)
            {
                CurrentInjectionInfo injectionInfo = injectionStack[i];

                foreach (Type ancestorType in ancestorTypes)
                {
                    if (ancestorType.GetTypeInfo().IsInterface)
                    {
                        if(injectionInfo.ActivationType == ancestorType ||
                            (injectionInfo.CurrentExportStrategy != null && injectionInfo.CurrentExportStrategy.ExportTypes.Contains(ancestorType)))
                        {
                            found = true;
                            break;
                        }
                    }
                    else if (injectionInfo.ActivationType == ancestorType)
                    {
                        found = true;
                        break;
                    }
                }
            }

            return found;
        }
コード例 #6
0
        public object Locate(ExportActivationDelegate creationDelegate,
			IInjectionScope injectionScope,
			IInjectionContext injectionContext,
			IExportStrategy exportStrategy)
        {
            IDictionary<object, object> items = OperationContext.Current.Items();
            object returnValue = items[uniqueRequestKey];

            if (returnValue == null)
            {
                IDisposalScope disposalScope = injectionContext.DisposalScope;
                IInjectionScope requestingScope = injectionContext.RequestingScope;

                injectionContext.DisposalScope = OperationContext.Current.DisposalScope();
                injectionContext.RequestingScope = exportStrategy.OwningScope;

                returnValue = creationDelegate(exportStrategy.OwningScope, injectionContext);

                injectionContext.DisposalScope = disposalScope;
                injectionContext.RequestingScope = requestingScope;

                if (returnValue != null)
                {
                    items[uniqueRequestKey] = returnValue;
                }
            }

            return returnValue;
        }
コード例 #7
0
		public object Locate(ExportActivationDelegate creationDelegate,
			IInjectionScope injectionScope,
			IInjectionContext injectionContext,
			IExportStrategy exportStrategy)
		{
			object returnValue = null;

			if (HttpContext.Current != null)
			{
				returnValue = HttpContext.Current.Items[uniqueId];
			}

			if (returnValue == null)
			{
				IDisposalScope disposalScope = injectionContext.DisposalScope;
				IInjectionScope requestingScope = injectionContext.RequestingScope;

				injectionContext.DisposalScope = MVCDisposalScopeProvider.GetDisposalScope();
				injectionContext.RequestingScope = exportStrategy.OwningScope;

				returnValue = creationDelegate(exportStrategy.OwningScope, injectionContext);

				injectionContext.DisposalScope = disposalScope;
				injectionContext.RequestingScope = requestingScope;

				if (returnValue != null && HttpContext.Current != null)
				{
					HttpContext.Current.Items[uniqueId] = returnValue;
				}
			}

			return returnValue;
		}
コード例 #8
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="exportDelegateInfo"></param>
        /// <param name="activationDelegate"></param>
        /// <param name="exportStrategy"></param>
        /// <param name="owningScope"></param>
        public FuncCompiledExportDelegate(CompiledExportDelegateInfo exportDelegateInfo,
			ExportActivationDelegate activationDelegate,
			IExportStrategy exportStrategy,
			IInjectionScope owningScope)
            : base(exportDelegateInfo,exportStrategy, owningScope)
        {
            exportActivationDelegate = activationDelegate;
        }
コード例 #9
0
        public void Inspect(IExportStrategy exportStrategy)
        {
            exportStrategy.EnrichWithDelegate((scope, context, instance) =>
                                              {
                                                  PageFactory.InitElements(_webDriver,instance);

                                                  return instance;
                                              });
        }
コード例 #10
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="property"></param>
        /// <param name="targetStrategy"></param>
        /// <param name="exportCondition"></param>
        public PropertyExportStrategy(PropertyInfo property,
			IExportStrategy targetStrategy,
			IExportCondition exportCondition)
            : base(property.PropertyType)
        {
            this.propertyInfo = property;
            this.strategy = targetStrategy;
            this.exportCondition = exportCondition;
        }
コード例 #11
0
        /// <summary>
        /// Inspect strategies
        /// </summary>
        /// <param name="exportStrategy">strategy</param>
        public void Inspect(IExportStrategy exportStrategy)
        {
            IConfigurableExportStrategy configurableExport = exportStrategy as IConfigurableExportStrategy;

            if (configurableExport != null &&
                _typesThatFunc(exportStrategy.ActivationType))
            {
                configurableExport.SetPriority(_priority);
            }
        }
コード例 #12
0
ファイル: MultipleConditions.cs プロジェクト: jrjohn/Grace
        /// <summary>
        /// Called to determine if the export strategy meets the condition to be activated
        /// </summary>
        /// <param name="scope">injection scope that this export exists in</param>
        /// <param name="injectionContext">injection context for this request</param>
        /// <param name="exportStrategy">export strategy being tested</param>
        /// <returns>true if the export meets the condition</returns>
        public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy)
        {
            foreach (IExportCondition exportCondition in exportConditions)
            {
                if (!exportCondition.ConditionMeet(scope, injectionContext, exportStrategy))
                {
                    return false;
                }
            }

            return true;
        }
コード例 #13
0
        /// <summary>
        /// This method is called by the export strategy when attempting to locate an export
        /// </summary>
        /// <param name="creationDelegate"></param>
        /// <param name="injectionScope"></param>
        /// <param name="injectionContext"></param>
        /// <param name="exportStrategy"></param>
        /// <returns></returns>
        public object Locate(ExportActivationDelegate creationDelegate,
			IInjectionScope injectionScope,
			IInjectionContext injectionContext,
			IExportStrategy exportStrategy)
        {
            if (lifestyleContainer == null)
            {
                lifestyleContainer = LocateContainer(exportStrategy.OwningScope, injectionContext);
            }

            return lifestyleContainer.Locate(creationDelegate, injectionScope, injectionContext, exportStrategy);
        }
コード例 #14
0
 public TypeDefinitionMapper(
     ICommentsProvider commentsProvider,
     ITypeDefinitionNameMapper typeDefinitionNameMapper,
     ILiteralTypeMapper literalTypeMapper,
     IEnumFieldsProvider enumFieldsProvider,
     IExportStrategy exportStrategy
     )
 {
     _commentsProvider         = commentsProvider;
     _literalTypeMapper        = literalTypeMapper;
     _enumFieldsProvider       = enumFieldsProvider;
     _exportStrategy           = exportStrategy;
     _typeDefinitionNameMapper = typeDefinitionNameMapper;
 }
コード例 #15
0
ファイル: WhenClassHas.cs プロジェクト: jrjohn/Grace
        /// <summary>
        /// Called to determine if the export strategy meets the condition to be activated
        /// </summary>
        /// <param name="scope">injection scope that this export exists in</param>
        /// <param name="injectionContext">injection context for this request</param>
        /// <param name="exportStrategy">export strategy being tested</param>
        /// <returns>true if the export meets the condition</returns>
        public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy)
        {
            if (injectionContext.TargetInfo != null)
            {
                foreach (Attribute injectionTypeAttribute in injectionContext.TargetInfo.InjectionTypeAttributes)
                {
                    if (injectionTypeAttribute.GetType().GetTypeInfo().IsAssignableFrom(attributeType.GetTypeInfo()))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
コード例 #16
0
        /// <summary>
        /// Called to determine if the export strategy meets the condition to be activated
        /// </summary>
        /// <param name="scope">injection scope that this export exists in</param>
        /// <param name="injectionContext">injection context for this request</param>
        /// <param name="exportStrategy">export strategy being tested</param>
        /// <returns>true if the export meets the condition</returns>
        public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy)
        {
            if (answer.HasValue)
            {
                return answer.Value;
            }

            bool returnValue = ConfigurationManager.AppSettings[settingName] == null;

            if (cacheAnswer)
            {
                answer = returnValue;
            }

            return returnValue;
        }
コード例 #17
0
        /// <summary>
        /// returns true when the app.config setting is equal to the provided value
        /// </summary>
        /// <param name="scope"></param>
        /// <param name="injectionContext"></param>
        /// <param name="exportStrategy"></param>
        /// <returns></returns>
        public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy)
        {
            if (answer.HasValue)
            {
                return answer.Value;
            }

            string appSetting = ConfigurationManager.AppSettings[settingName];
            bool returnValue = false;

            if (appSetting != null)
            {
                if (settingValue == null)
                {
                    return false;
                }

                if (appSetting.GetType() == settingValue.GetType())
                {
                    returnValue = Equals(settingValue, appSetting);
                }

                try
                {
                    returnValue = Equals(settingValue, Convert.ChangeType(appSetting, settingValue.GetType()));
                }
                catch (Exception exp)
                {
                    Logger.Error(
                        string.Format("Exception thrown while converting {0} to {1}", appSetting, settingValue.GetType().FullName),
                        supplemental,
                        exp);
                }
            }
            else if (settingValue == null)
            {
                returnValue = true;
            }

            if (cacheAnswer)
            {
                answer = returnValue;
            }

            return returnValue;
        }
コード例 #18
0
ファイル: WhenInjectedInto.cs プロジェクト: jrjohn/Grace
        /// <summary>
        /// Called to determine if the export strategy meets the condition to be activated
        /// </summary>
        /// <param name="scope">injection scope that this export exists in</param>
        /// <param name="injectionContext">injection context for this request</param>
        /// <param name="exportStrategy">export strategy being tested</param>
        /// <returns>true if the export meets the condition</returns>
        public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy)
        {
            IInjectionTargetInfo targetInfo = injectionContext.TargetInfo;

            if (targetInfo != null && injectedType != null)
            {
                foreach (Type type in injectedType)
                {
                    if (targetInfo.InjectionType.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
コード例 #19
0
        /// <summary>
        /// This method is called by the export strategy when attempting to locate an export
        /// </summary>
        /// <param name="creationDelegate"></param>
        /// <param name="exportStrategyScope"></param>
        /// <param name="injectionContext"></param>
        /// <param name="exportStrategy"></param>
        /// <returns></returns>
        public object Locate(ExportActivationDelegate creationDelegate,
			IInjectionScope exportStrategyScope,
			IInjectionContext injectionContext,
			IExportStrategy exportStrategy)
        {
            object returnValue = null;

            if (intanceRef != null)
            {
                returnValue = intanceRef.Target;
            }

            if (returnValue == null)
            {
                lock (lockObject)
                {
                    if (intanceRef != null)
                    {
                        returnValue = intanceRef.Target;
                    }

                    if (returnValue == null)
                    {
                        IDisposalScope disposalScope = injectionContext.DisposalScope;
                        IInjectionScope requeInjectionScope = injectionContext.RequestingScope;

                        // null scope because weak exports can't have
                        injectionContext.DisposalScope = null;
                        injectionContext.RequestingScope = exportStrategyScope;

                        returnValue = creationDelegate(exportStrategyScope, injectionContext);

                        injectionContext.DisposalScope = disposalScope;
                        injectionContext.RequestingScope = requeInjectionScope;

                        if (returnValue != null)
                        {
                            intanceRef = new WeakReference(returnValue);
                        }
                    }
                }
            }

            return returnValue;
        }
コード例 #20
0
        /// <summary>
        /// This method is called by the export strategy when attempting to locate an export
        /// </summary>
        /// <param name="creationDelegate"></param>
        /// <param name="exportStrategyScope"></param>
        /// <param name="injectionContext"></param>
        /// <param name="exportStrategy"></param>
        /// <returns></returns>
        public object Locate(ExportActivationDelegate creationDelegate,
			IInjectionScope exportStrategyScope,
			IInjectionContext injectionContext,
			IExportStrategy exportStrategy)
        {
            object returnValue = injectionContext.RequestingScope.GetExtraData(uniqueId);

            if (returnValue == null)
            {
                IInjectionScope requestScope = injectionContext.RequestingScope;

                returnValue = creationDelegate(exportStrategyScope, injectionContext);

                requestScope.SetExtraData(uniqueId, returnValue);
            }

            return returnValue;
        }
コード例 #21
0
 public DefaultInterfaceMapper(
     ICommentsProvider commentsProvider,
     IInterfaceNameMapper interfaceNameMapper,
     IInterfacePropertyMapper interfacePropertyMapper,
     IExpendTypesProvider expendTypesProvider,
     IExportStrategy exportStrategy,
     ITypeReferenceMapper typeReferenceMapper,
     IInterfacePropertiesProvider interfacePropertiesProvider
     )
 {
     _interfacePropertyMapper     = interfacePropertyMapper;
     _expendTypesProvider         = expendTypesProvider;
     _exportStrategy              = exportStrategy;
     _typeReferenceMapper         = typeReferenceMapper;
     _interfacePropertiesProvider = interfacePropertiesProvider;
     _commentsProvider            = commentsProvider;
     _interfaceNameMapper         = interfaceNameMapper;
 }
コード例 #22
0
        public string Export(string fileName, string exportType)
        {
            // get data...

            IExportStrategy exporter = null;

            switch (exportType)
            {
            case "excel":
                exporter = new ExcelExporter();
                break;

            case "pdf":
            default:
                exporter = new PDFExporter();
                break;
            }
            return(exporter.Export(fileName));
        }
コード例 #23
0
        /// <summary>
        /// Called to determine if the export strategy meets the condition to be activated
        /// </summary>
        /// <param name="scope">injection scope that this export exists in</param>
        /// <param name="injectionContext">injection context for this request</param>
        /// <param name="exportStrategy">export strategy being tested</param>
        /// <returns>true if the export meets the condition</returns>
        public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy)
        {
            if (answer.HasValue)
            {
                return answer.Value;
            }

            string appSetting = ConfigurationManager.AppSettings[settingName];

            bool returnValue = string.IsNullOrEmpty(appSetting) ||
                               string.Compare("false", appSetting, StringComparison.CurrentCultureIgnoreCase) == 0;

            if (cacheAnswer)
            {
                answer = returnValue;
            }

            return returnValue;
        }
コード例 #24
0
        /// <summary>
        /// This method is called by the export strategy when attempting to locate an export
        /// </summary>
        /// <param name="creationDelegate"></param>
        /// <param name="injectionScope"></param>
        /// <param name="injectionContext"></param>
        /// <param name="exportStrategy"></param>
        /// <returns></returns>
        public object Locate(ExportActivationDelegate creationDelegate,
			IInjectionScope injectionScope,
			IInjectionContext injectionContext,
			IExportStrategy exportStrategy)
        {
            object returnValue = injectionContext.GetExtraData(key);

            if (returnValue == null)
            {
                returnValue = creationDelegate(injectionScope, injectionContext);

                if (returnValue != null)
                {
                    injectionContext.SetExtraData(key, returnValue);
                }
            }

            return returnValue;
        }
コード例 #25
0
        public object Locate(ExportActivationDelegate creationDelegate,
            IInjectionScope injectionScope,
            IInjectionContext injectionContext,
            IExportStrategy exportStrategy)
        {
            object returnValue = null;
            IInjectionScope locateScope = FindNamedScope(injectionContext.RequestingScope);

            if (locateScope == null)
            {
                throw new InjectionScopeCouldNotBeFoundException(_namedScope);
            }

            returnValue = locateScope.GetExtraData(_uniqueId);

            if (returnValue != null)
            {
                return returnValue;
            }

            lock (_lockObject)
            {
                returnValue = locateScope.GetExtraData(_uniqueId) ??
                              SingletonLifestyle.CreateInSingletonScope(creationDelegate,
                                  locateScope,
                                  injectionContext);

                if (returnValue != null)
                {
                    locateScope.SetExtraData(_uniqueId, returnValue);

                    IDisposable disposable = returnValue as IDisposable;

                    if (disposable != null)
                    {
                        locateScope.AddDisposable(disposable);
                    }
                }
            }

            return returnValue;
        }
コード例 #26
0
        /// <summary>
        /// increases the strategies priority based on the number of closed parameters it has
        /// </summary>
        /// <param name="exportStrategy"></param>
        public void Inspect(IExportStrategy exportStrategy)
        {
            IConfigurableExportStrategy configurableExport = exportStrategy as IConfigurableExportStrategy;

            if (configurableExport != null && exportStrategy.ActivationType.GetTypeInfo().IsGenericTypeDefinition)
            {
                int maxClosed = 0;
                int openGenericParams = exportStrategy.ActivationType.GetTypeInfo().GenericTypeParameters.Length;

                foreach (Type exportType in exportStrategy.ExportTypes)
                {
                    int exportTypeParamCount = exportType.GetTypeInfo().GenericTypeParameters.Length;
                    int numClosed = exportTypeParamCount - openGenericParams;

                    if (numClosed > maxClosed)
                    {
                        maxClosed = numClosed;
                    }
                }

                configurableExport.SetPriority(configurableExport.Priority + maxClosed);
            }
        }
コード例 #27
0
        /// <summary>
        /// Creates a new <see cref="FileExport"/>.
        /// </summary>
        /// <param name="createDataReaderPool">
        /// The factory method for creating an <see cref="IDataReaderPool"/> to
        /// pass to the export strategies
        /// </param>
        /// <param name="createSubProgressReporter">The factory method for creating a sub-progress reporter</param>
        /// <param name="dataBlockScanner">The data block scanner</param>
        /// <param name="saveAsSingleFile">The strategy for saving a single input file</param>
        /// <param name="saveAsContiguousFile">The strategy for saving multiple results as a single file</param>
        /// <param name="saveAsSeparateFiles">The strategy for saving multiple results as separate files</param>
        /// <param name="exportToXml">The strategy for exporting results to an XML document</param>
        public FileExport(Creator <IDataReaderPool> createDataReaderPool,
                          Creator <IProgressReporter, IProgressReporter, long, long, long> createSubProgressReporter,
                          DataBlockScanner dataBlockScanner,
                          IExportStrategy <IInputFile> saveAsSingleFile,
                          IExportStrategy <IDataPacket> saveAsContiguousFile,
                          IExportStrategy <IEnumerable <object> > saveAsSeparateFiles,
                          ExportToXml exportToXml)
        {
            PreConditions.Argument("createDataReaderPool").Value(createDataReaderPool).IsNotNull();
            PreConditions.Argument("createSubProgressReporter").Value(createSubProgressReporter).IsNotNull();
            PreConditions.Argument("dataBlockScanner").Value(dataBlockScanner).IsNotNull();
            PreConditions.Argument("saveAsSingleFile").Value(saveAsSingleFile).IsNotNull();
            PreConditions.Argument("saveAsContiguousFile").Value(saveAsContiguousFile).IsNotNull();
            PreConditions.Argument("saveAsSeparateFiles").Value(saveAsSeparateFiles).IsNotNull();
            PreConditions.Argument("exportToXml").Value(exportToXml).IsNotNull();

            _createDataReaderPool      = createDataReaderPool;
            _createSubProgressReporter = createSubProgressReporter;
            _dataBlockScanner          = dataBlockScanner;
            _saveAsSingleFile          = saveAsSingleFile;
            _saveAsContiguousFile      = saveAsContiguousFile;
            _saveAsSeparateFiles       = saveAsSeparateFiles;
            _exportToXml = exportToXml;
        }
コード例 #28
0
        public void Inspect(IExportStrategy exportStrategy)
        {
            CompiledExportStrategy compiledExportStrategy = exportStrategy as CompiledExportStrategy;

            if (compiledExportStrategy != null)
            {
                foreach (PropertyInfo declaredProperty in exportStrategy.ActivationType.GetRuntimeProperties())
                {
                    if (!declaredProperty.CanWrite ||
                        declaredProperty.SetMethod.IsStatic ||
                        !ReflectionService.CheckTypeIsBasedOnAnotherType(declaredProperty.PropertyType, _propertyType))
                    {
                        continue;
                    }

                    if (!string.IsNullOrEmpty(_propertyName) &&
                        string.Compare(_propertyName,declaredProperty.Name,StringComparison.CurrentCultureIgnoreCase) != 0)
                    {
                        continue;
                    }

                    if (_propertyPicker != null &&
                        !_propertyPicker(declaredProperty))
                    {
                        continue;
                    }

                    compiledExportStrategy.ImportProperty(new ImportPropertyInfo
                                                          {
                                                              AfterConstruction = _afterConstructor,
                                                              Property = declaredProperty,
                                                              ValueProvider = _valueProvider
                                                          });
                }
            }
        }
コード例 #29
0
        public void StrategyInitializing(IExportStrategy exportStrategy)
        {
            CompiledExportStrategy compiledExportStrategy = exportStrategy as CompiledExportStrategy;

            if (compiledExportStrategy != null)
            {
                foreach (PropertyInfo declaredProperty in exportStrategy.ActivationType.GetTypeInfo().DeclaredProperties)
                {
                    if (!declaredProperty.CanWrite ||
                        declaredProperty.SetMethod.IsStatic ||
                        !ReflectionService.CheckTypeIsBasedOnAnotherType(declaredProperty.PropertyType, _propertyType))
                    {
                        continue;
                    }

                    if (!string.IsNullOrEmpty(_propertyName) &&
                        _propertyName != declaredProperty.Name)
                    {
                        continue;
                    }

                    if (_propertyPicker != null &&
                        !_propertyPicker(declaredProperty))
                    {
                        continue;
                    }

                    compiledExportStrategy.ImportProperty(new ImportPropertyInfo
                                                          {
                                                              AfterConstruction = _afterConstructor,
                                                              Property = declaredProperty,
                                                              ValueProvider = _valueProvider
                                                          });
                }
            }
        }
コード例 #30
0
        public void GivenExportTypeTest()
        {
            var exportType = "excel";

            // 完整重構的 strategy
            // 在報表物件內部已不再包含策略的選擇(switch),變成需由外部決定後再傳入報表物件
            IExportStrategy exporter = null;

            switch (exportType)
            {
            case "pdf":
                exporter = new PDFExporter();
                break;

            case "excel":
            default:
                exporter = new ExcelExporter();
                break;
            }
            var reportObj = new LunchReport_V3(exporter);
            var result    = reportObj.Export("午餐清單");

            Assert.AreEqual(exportType, _GetFileExt(result));
        }
コード例 #31
0
ファイル: Forest.cs プロジェクト: pavl0v/RandomForest
 public Forest()
 {
     _trees          = new List <Tree.Tree>();
     _exportStrategy = new ExportToJson();
     _splitter       = new SplitterRss();
 }
コード例 #32
0
		public void Add(IExportStrategy strategy)
		{
			strategies.Add(strategy);
		}
コード例 #33
0
 public ReportExporter(IExportStrategy strategy)
 {
     this.ExportStrategy = strategy;
 }
コード例 #34
0
 public LunchReport_V3(IExportStrategy exporter)
 {
     _exporter = exporter;
 }
コード例 #35
0
 public void SetFormat(Constants.FORMATS_AVALIBLES format)
 {
     logger.Info("Export {0}", format);
     _ExporterStrategy = _ExporterStrategies[format];
 }
コード例 #36
0
 public SimpleCompiledExportDelegate(CompiledExportDelegateInfo exportDelegateInfo, IExportStrategy exportStrategy)
     : base(exportDelegateInfo, exportStrategy,null)
 {
 }
コード例 #37
0
 public FinancialReport(IExportStrategy exportStrategy)
 {
     _exportStrategy = exportStrategy;
 }
コード例 #38
0
ファイル: SingletonLifestyle.cs プロジェクト: jrjohn/Grace
        /// <summary>
        /// This method is called by the export strategy when attempting to locate an export
        /// </summary>
        /// <param name="creationDelegate"></param>
        /// <param name="exportStrategyScope"></param>
        /// <param name="injectionContext"></param>
        /// <param name="exportStrategy"></param>
        /// <returns></returns>
        public object Locate(ExportActivationDelegate creationDelegate,
			IInjectionScope exportStrategyScope,
			IInjectionContext injectionContext,
			IExportStrategy exportStrategy)
        {
            if (instance == null)
            {
                lock (lockObject)
                {
                    if (instance == null)
                    {
                        instance = CreateInSingletonScope(creationDelegate, exportStrategy.OwningScope, injectionContext);
                    }
                }
            }

            return instance;
        }
コード例 #39
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 /// <param name="exportDelegateInfo"></param>
 /// <param name="exportStrategy"></param>
 /// <param name="owningScope"></param>
 public InstanceCompiledExportDelegate(CompiledExportDelegateInfo exportDelegateInfo,
     IExportStrategy exportStrategy,
     IInjectionScope owningScope)
     : base(exportDelegateInfo, exportStrategy, owningScope)
 {
 }
コード例 #40
0
 private TransportedDomainObjects ExportAndLoadTransportData(IImportStrategy importStrategy, IExportStrategy exportStrategy)
 {
     _transporter.Export(_stream, exportStrategy);
     _stream.Seek(0, SeekOrigin.Begin);
     return(DomainObjectTransporter.LoadTransportData(_stream, importStrategy));
 }
コード例 #41
0
		/// <summary>
		/// Returns true only when there is no debugger attached
		/// </summary>
		/// <param name="scope"></param>
		/// <param name="injectionContext"></param>
		/// <param name="exportStrategy"></param>
		/// <returns></returns>
		public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy)
		{
			return !Debugger.IsAttached;
		}
コード例 #42
0
        /// <summary>
        /// Locate object
        /// </summary>
        /// <param name="creationDelegate"></param>
        /// <param name="injectionScope"></param>
        /// <param name="injectionContext"></param>
        /// <param name="exportStrategy"></param>
        /// <returns></returns>
        public object Locate(ExportActivationDelegate creationDelegate,
			IInjectionScope injectionScope,
			IInjectionContext injectionContext,
			IExportStrategy exportStrategy)
        {
            object scopeName = valueDelegate(injectionScope, injectionContext);
            Tuple<object, IDisposalScope> trackedObject;

            if (!scopedObjects.TryGetValue(scopeName, out trackedObject))
            {
                IDisposalScope disposalScope = injectionContext.DisposalScope;
                IInjectionScope requestingScope = injectionContext.RequestingScope;

                IDisposalScope newDisposalScope = new DisposalScope();

                injectionContext.DisposalScope = newDisposalScope;
                injectionContext.RequestingScope = exportStrategy.OwningScope;

                object locatedObject = creationDelegate(injectionScope, injectionContext);

                injectionContext.DisposalScope = disposalScope;
                injectionContext.RequestingScope = requestingScope;

                if (locatedObject != null)
                {
                    trackedObject = new Tuple<object, IDisposalScope>(locatedObject, newDisposalScope);

                    scopedObjects[scopeName] = trackedObject;

                    INotifyWhenDisposed notifyWhenDisposed = scopeName as INotifyWhenDisposed;

                    if (notifyWhenDisposed != null)
                    {
                        notifyWhenDisposed.Disposed += (sender, args) =>
                                                       {
                                                           scopedObjects.Remove(scopeName);
                                                                     newDisposalScope.Dispose();
                                                       };
                    }

                    return locatedObject;
                }
            }
            else
            {
                return trackedObject.Item1;
            }

            return null;
        }
コード例 #43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProfileExporter"/> class.
 /// </summary>
 /// <param name="exportStrategy">The strategy to use when exporting profiles</param>
 public ProfileExporter(IExportStrategy exportStrategy)
 {
     this.exportStrategy = exportStrategy;
 }
コード例 #44
0
 /// <summary>
 /// Adds a secondary export strategy to this strategy
 /// </summary>
 /// <param name="strategy">export strategy</param>
 protected void AddSecondaryExport(IExportStrategy strategy)
 {
     _secondaryExports = _secondaryExports.Add(strategy);
 }