Ejemplo n.º 1
0
        private static void GetProcessors()
        {
            try
            {
                ManagementObjectSearcher myProcessorObject = new ManagementObjectSearcher("select * from Win32_Processor");

                foreach (ManagementObject obj in myProcessorObject.Get())
                {
                    Console.WriteLine("Name  -  " + obj["Name"]);
                    Console.WriteLine("DeviceID  -  " + obj["DeviceID"]);
                    Console.WriteLine("CurrentClockSpeed  -  " + obj["CurrentClockSpeed"]);
                    Console.WriteLine("NumberOfCores  -  " + obj["NumberOfCores"]);
                    Console.WriteLine("NumberOfEnabledCore  -  " + obj["NumberOfEnabledCore"]);
                    Console.WriteLine("NumberOfLogicalProcessors  -  " + obj["NumberOfLogicalProcessors"]);
                    Console.WriteLine("AddressWidth  -  " + obj["AddressWidth"]);

                    var data = new ProcessorData()
                    {
                        Name                      = obj["Name"].ToString(),
                        DeviceId                  = obj["DeviceID"].ToString(),
                        CurrentClockSpeed         = obj["CurrentClockSpeed"].ToString(),
                        NumberOfCores             = obj["NumberOfCores"].ToString(),
                        NumberOfEnabledCores      = obj["NumberOfEnabledCore"].ToString(),
                        NumberOfLogicalProcessors = obj["NumberOfLogicalProcessors"].ToString(),
                        AddressWidth              = obj["AddressWidth"].ToString()
                    };

                    _AssetDataService.CreateProcessorData(_MachineData.Id, data);
                }
            }
            catch (Exception e)
            {
                _AssetDataService.CreateError(_MachineData.Id, "GetProcessors", e);
            }
        }
Ejemplo n.º 2
0
            public bool MoveNext(IEnumerator enumerator)
            {
                bool advance = false;

                switch (data.type)
                {
                case DataType.WaitForSeconds:
                    advance = data.targetTime <= EditorApplication.timeSinceStartup;
                    break;

                case DataType.EditorCoroutine:
                    advance = (data.current as EditorCoroutine).isDone;
                    break;

                case DataType.AsyncOp:
                    advance = (data.current as AsyncOperation).isDone;
                    break;

                default:
                    advance = data.current == enumerator.Current;
                    break;
                }

                if (advance)
                {
                    data = default;
                    return(enumerator.MoveNext());
                }
                return(true);
            }
Ejemplo n.º 3
0
            public void Set(object yield)
            {
                if (yield == data.current)
                {
                    return;
                }

                var    type       = yield.GetType();
                var    dataType   = DataType.None;
                double targetTime = -1;

                if (type == typeof(EditorWaitForSeconds))
                {
                    targetTime = EditorApplication.timeSinceStartup + (yield as EditorWaitForSeconds).WaitTime;
                    dataType   = DataType.WaitForSeconds;
                }
                else if (type == typeof(EditorCoroutine))
                {
                    dataType = DataType.EditorCoroutine;
                }
                else if (type == typeof(AsyncOperation) || type.IsSubclassOf(typeof(AsyncOperation)))
                {
                    dataType = DataType.AsyncOp;
                }

                data = new ProcessorData {
                    current = yield, targetTime = targetTime, type = dataType
                };
            }
Ejemplo n.º 4
0
            public bool MoveNext(IEnumerator enumerator)
            {
                bool advance = false;

                switch (data.type)
                {
                case DataType.WaitForSeconds:
                    advance = data.targetTime <= EditorApplication.timeSinceStartup;
                    break;

                case DataType.EditorCoroutine:
                    advance = (data.current as EditorCoroutine).m_IsDone;
                    break;

                case DataType.AsyncOP:
                    advance = (data.current as AsyncOperation).isDone;
                    break;

                default:
                    advance = data.current == enumerator.Current;     //a IEnumerator or a plain object was passed to the implementation
                    break;
                }

                if (advance)
                {
                    data = default(ProcessorData);
                    return(enumerator.MoveNext());
                }
                return(true);
            }
        public void CreateProcessorData(int probeDataId, ProcessorData data)
        {
            data.ProbeDataId = probeDataId;
            data.CreatedOn   = DateTime.UtcNow;

            _Context.ProcessorData.Add(data);
            _Context.SaveChanges();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 创建指定类型中与默认标识相关的静态方法切换器,会自动推断关键参数(使用不同子类的参数,必须是唯一的)。
        /// </summary>
        /// <typeparam name="TDelegate">使用基类型调用方法的委托。</typeparam>
        /// <param name="type">在其中查找静态方法的类型。</param>
        /// <returns><paramref name="type"/> 中与默认标识相关的静态方法切换器。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="type"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentException"><typeparamref name="TDelegate"/> 不是委托类型。</exception>
        /// <exception cref="ArgumentException">委托类型与处理器不匹配。</exception>
        /// <exception cref="ArgumentException">处理器的参数不匹配。</exception>
        /// <exception cref="ArgumentException">没有找到唯一的关键参数。</exception>
        public static TDelegate Create <TDelegate>(Type type)
            where TDelegate : class
        {
            CommonExceptions.CheckArgumentNull(type, "type");
            Contract.Ensures(Contract.Result <TDelegate>() != null);
            CommonExceptions.CheckDelegateType(typeof(TDelegate));
            ProcessorData data = GetMethods <TDelegate>(type, ProcessorAttribute.DefaultId, true);

            return(CreateSwitcher <TDelegate>(data, ProcessorAttribute.DefaultId, null));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 创建指定对象中与默认指定相关的实例方法切换器,会自动推断关键参数(使用不同子类的参数,必须是唯一的)。
        /// </summary>
        /// <typeparam name="TDelegate">使用基类型调用方法的委托。</typeparam>
        /// <param name="target">在其中查找实例方法的对象。</param>
        /// <returns><paramref name="target"/> 中与默认标识相关的实例方法切换器。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="target"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentException"><typeparamref name="TDelegate"/> 不是委托类型。</exception>
        /// <exception cref="ArgumentException">委托类型与处理器不匹配。</exception>
        /// <exception cref="ArgumentException">处理器的参数不匹配。</exception>
        /// <exception cref="ArgumentException">没有找到唯一的关键参数。</exception>
        public static TDelegate Create <TDelegate>(object target)
            where TDelegate : class
        {
            CommonExceptions.CheckArgumentNull(target, "target");
            Contract.Ensures(Contract.Result <TDelegate>() != null);
            CommonExceptions.CheckDelegateType(typeof(TDelegate));
            ProcessorData data = GetMethods <TDelegate>(target.GetType(), ProcessorAttribute.DefaultId, false);

            return(CreateSwitcher <TDelegate>(data, ProcessorAttribute.DefaultId, target));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 创建指定类型中与标识指定相关的静态方法切换器,会自动推断关键参数(使用不同子类的参数,必须是唯一的)。
        /// </summary>
        /// <typeparam name="TDelegate">使用基类型调用方法的委托。</typeparam>
        /// <param name="type">在其中查找静态方法的类型。</param>
        /// <param name="id">处理器的标识。</param>
        /// <returns><paramref name="type"/> 中与指定标识相关的静态方法切换器。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="type"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="id"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentException"><paramref name="id"/> 为空字符串。</exception>
        /// <exception cref="ArgumentException"><typeparamref name="TDelegate"/> 不是委托类型。</exception>
        /// <exception cref="ArgumentException">委托类型与处理器不匹配。</exception>
        /// <exception cref="ArgumentException">处理器的参数不匹配。</exception>
        /// <exception cref="ArgumentException">没有找到唯一的关键参数。</exception>
        public static TDelegate Create <TDelegate>(Type type, string id)
            where TDelegate : class
        {
            CommonExceptions.CheckArgumentNull(type, "type");
            CommonExceptions.CheckStringEmpty(id, "id");
            Contract.Ensures(Contract.Result <TDelegate>() != null);
            CommonExceptions.CheckDelegateType(typeof(TDelegate));
            ProcessorData data = GetMethods <TDelegate>(type, id, true);

            return(CreateSwitcher <TDelegate>(data, id, null));
        }
Ejemplo n.º 9
0
 public void SetProperty(ProcessorData processor, object value)
 {
     try
     {
         this.Property.Invoke(processor, new[] { value });
     }
     catch (Exception ex)
     {
         WFLogger.NLogger.ErrorException("Invoke failed", ex);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 创建与指定委托列表相关的方法切换器,会自动推断关键参数(使用不同子类的参数,必须是唯一的)。
        /// </summary>
        /// <typeparam name="TDelegate">使用基类型调用方法的委托类型。</typeparam>
        /// <param name="delegates">使用不同子类作为参数的委托列表。</param>
        /// <returns>与 <paramref name="delegates"/> 相关的方法切换器。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="delegates"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentException"><paramref name="delegates"/> 中存在为 <c>null</c> 的委托。</exception>
        /// <exception cref="ArgumentException"><typeparamref name="TDelegate"/> 不是委托类型。</exception>
        /// <exception cref="ArgumentException">委托类型与处理器不匹配。</exception>
        /// <exception cref="ArgumentException">处理器的参数不匹配。</exception>
        /// <exception cref="ArgumentException">没有找到唯一的关键参数。</exception>
        /// <overloads>
        /// <summary>
        /// 创建方法切换器,会自动推断关键参数(使用不同子类的参数,必须是唯一的)。
        /// </summary>
        /// </overloads>
        public static TDelegate Create <TDelegate>(params Delegate[] delegates)
            where TDelegate : class
        {
            CommonExceptions.CheckCollectionItemNull(delegates, nameof(delegates));
            Contract.Ensures(Contract.Result <TDelegate>() != null);
            CommonExceptions.CheckDelegateType(typeof(TDelegate));
            var data = new ProcessorData(delegates);

            CheckDelegateType <TDelegate>(data);
            return(CreateSwitcher <TDelegate>(data, null, null));
        }
Ejemplo n.º 11
0
        //- @Register -//
        public override void Register()
        {
            String blogGuid = ParameterMap.PeekSafely("blogGuid");

            if (String.IsNullOrEmpty(blogGuid))
            {
                throw new System.Configuration.ConfigurationErrorsException("blogPage parameter is required for the Blog component.");
            }
            //+ factory
            AddFactory(FactoryData.Create("Minima.Web.Processing.ProcessorFactory, Minima.Web"));
            //+ processor
            AddProcessor(ProcessorData.Create <ProcessorData>("__$Minima$InitProcessor", new Object[] { blogGuid }));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 返回与指定类型和标识相关的处理器数据。
        /// </summary>
        /// <typeparam name="TDelegate">调用委托的类型。</typeparam>
        /// <param name="type">处理器所属的类型。</param>
        /// <param name="id">处理器的标识。</param>
        /// <param name="needStatic">需要的是否是静态方法。</param>
        /// <returns>与指定类型和标识相关的处理器数据。</returns>
        /// <exception cref="ArgumentException">委托类型与处理器不匹配。</exception>
        private static ProcessorData GetMethods <TDelegate>(Type type, string id, bool needStatic)
        {
            Contract.Requires(type != null && id != null);
            Contract.Ensures(Contract.Result <ProcessorData>() != null);
            ProcessorData data = methodDict.GetOrAdd(string.Concat(type.FullName, "_", id),
                                                     key => new ProcessorData(type, id));

            if (data.IsStatic != needStatic)
            {
                throw CommonExceptions.ProcessorMismatch(type, id);
            }
            CheckDelegateType <TDelegate>(data);
            return(data);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 创建指定对象中与默认指定相关的实例方法切换器,会自动推断关键参数(使用不同子类的参数,必须是唯一的)。
        /// </summary>
        /// <typeparam name="TDelegate">使用基类型调用方法的委托。</typeparam>
        /// <param name="target">在其中查找实例方法的对象。</param>
        /// <returns><paramref name="target"/> 中与默认标识相关的实例方法切换器。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="target"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentException"><typeparamref name="TDelegate"/> 不是委托类型。</exception>
        /// <exception cref="ArgumentException">委托类型与处理器不匹配。</exception>
        /// <exception cref="ArgumentException">处理器的参数不匹配。</exception>
        /// <exception cref="ArgumentException">没有找到唯一的关键参数。</exception>
        public static TDelegate Create <TDelegate>(object target)
            where TDelegate : class
        {
            if (target == null)
            {
                throw CommonExceptions.ArgumentNull("target");
            }
            Contract.Ensures(Contract.Result <TDelegate>() != null);
            if (!typeof(TDelegate).IsSubclassOf(typeof(Delegate)))
            {
                throw CommonExceptions.MustBeDelegate("TDelegate", typeof(TDelegate));
            }
            ProcessorData data = GetMethods <TDelegate>(target.GetType(), ProcessorAttribute.DefaultId, false);

            return(CreateSwitcher <TDelegate>(data, ProcessorAttribute.DefaultId, target));
        }
Ejemplo n.º 14
0
 public void SetTargetValue(ProcessorData processor, object value)
 {
     if ((this.Src.TargetType == WFMappingTarget.TargetTypes.Value) ||
         ((this.Src.TargetType == WFMappingTarget.TargetTypes.Property) &&
          (this.Src.Property.ReturnType == this.Target.Property.GetParameters()[0].ParameterType)))
     {
         try
         {
             if (this.Src.TargetType == WFMappingTarget.TargetTypes.Value)
             {
                 value = GenericCastClass.Cast((string)value, this.Target.Property.GetParameters()[0].ParameterType);
             }
             this.Target.SetProperty(processor, value);
         }
         catch (Exception ex)
         {
             WFLogger.NLogger.ErrorException("Cast failed", ex);
         }
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// 创建指定对象中与标识指定相关的实例方法切换器,会自动推断关键参数(使用不同子类的参数,必须是唯一的)。
        /// </summary>
        /// <typeparam name="TDelegate">使用基类型调用方法的委托。</typeparam>
        /// <param name="target">在其中查找实例方法的对象。</param>
        /// <param name="id">处理器的标识。</param>
        /// <returns><paramref name="target"/> 中与指定标识相关的实例方法切换器。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="target"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="id"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentException"><paramref name="id"/> 为空字符串。</exception>
        /// <exception cref="ArgumentException"><typeparamref name="TDelegate"/> 不是委托类型。</exception>
        /// <exception cref="ArgumentException">委托类型与处理器不匹配。</exception>
        /// <exception cref="ArgumentException">处理器的参数不匹配。</exception>
        /// <exception cref="ArgumentException">没有找到唯一的关键参数。</exception>
        public static TDelegate Create <TDelegate>(object target, string id)
            where TDelegate : class
        {
            if (target == null)
            {
                throw CommonExceptions.ArgumentNull("target");
            }
            if (string.IsNullOrEmpty(id))
            {
                throw CommonExceptions.StringEmpty("id");
            }
            Contract.Ensures(Contract.Result <TDelegate>() != null);
            if (!typeof(TDelegate).IsSubclassOf(typeof(Delegate)))
            {
                throw CommonExceptions.MustBeDelegate("TDelegate", typeof(TDelegate));
            }
            ProcessorData data = GetMethods <TDelegate>(target.GetType(), id, false);

            return(CreateSwitcher <TDelegate>(data, id, target));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 检查委托类型是否与处理器兼容。
        /// </summary>
        /// <typeparam name="TDelegate">调用委托的类型。</typeparam>
        /// <param name="data">处理器的数据。</param>
        /// <exception cref="ArgumentException">委托类型与处理器不匹配。</exception>
        private static void CheckDelegateType <TDelegate>(ProcessorData data)
        {
            Contract.Requires(data != null);
            Type dlgType = typeof(TDelegate);

            if (data.IsStatic)
            {
                if (data.DelegateType != dlgType)
                {
                    // 检查静态委托参数。
                    ParameterInfo[] paramInfos    = data.DelegateType.GetMethod("Invoke").GetParametersNoCopy();
                    ParameterInfo[] dlgParamInfos = dlgType.GetMethod("Invoke").GetParametersNoCopy();
                    if (paramInfos.Length != dlgParamInfos.Length)
                    {
                        throw CommonExceptions.DelegateCompatible(data.DelegateType, dlgType);
                    }
                    if (paramInfos.Where((param, idx) => !param.ParameterType.IsExplicitFrom(dlgParamInfos[idx].ParameterType))
                        .Any())
                    {
                        throw CommonExceptions.DelegateCompatible(data.DelegateType, dlgType);
                    }
                }
            }
            else
            {
                // 检查实例委托参数,要考虑实例对应的参数。
                ParameterInfo[] paramInfos    = data.DelegateType.GetMethod("Invoke").GetParametersNoCopy();
                ParameterInfo[] dlgParamInfos = dlgType.GetMethod("Invoke").GetParametersNoCopy();
                if (paramInfos.Length != dlgParamInfos.Length + 1)
                {
                    throw CommonExceptions.DelegateCompatible(data.DelegateType, dlgType);
                }
                for (int i = 1; i < paramInfos.Length; i++)
                {
                    if (!paramInfos[i].ParameterType.IsExplicitFrom(dlgParamInfos[i - 1].ParameterType))
                    {
                        throw CommonExceptions.DelegateCompatible(data.DelegateType, dlgType);
                    }
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 创建与指定委托列表相关的方法切换器,会自动推断关键参数(使用不同子类的参数,必须是唯一的)。
        /// </summary>
        /// <typeparam name="TDelegate">使用基类型调用方法的委托类型。</typeparam>
        /// <param name="delegates">使用不同子类作为参数的委托列表。</param>
        /// <returns>与 <paramref name="delegates"/> 相关的方法切换器。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="delegates"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentException"><paramref name="delegates"/> 中存在为 <c>null</c> 的委托。</exception>
        /// <exception cref="ArgumentException"><typeparamref name="TDelegate"/> 不是委托类型。</exception>
        /// <exception cref="ArgumentException">委托类型与处理器不匹配。</exception>
        /// <exception cref="ArgumentException">处理器的参数不匹配。</exception>
        /// <exception cref="ArgumentException">没有找到唯一的关键参数。</exception>
        /// <overloads>
        /// <summary>
        /// 创建方法切换器,会自动推断关键参数(使用不同子类的参数,必须是唯一的)。
        /// </summary>
        /// </overloads>
        public static TDelegate Create <TDelegate>(params Delegate[] delegates)
            where TDelegate : class
        {
            if (delegates == null)
            {
                throw CommonExceptions.ArgumentNull("delegates");
            }
            if (delegates.Any(d => d == null))
            {
                throw CommonExceptions.CollectionItemNull("delegates");
            }
            Contract.Ensures(Contract.Result <TDelegate>() != null);
            if (!typeof(TDelegate).IsSubclassOf(typeof(Delegate)))
            {
                throw CommonExceptions.MustBeDelegate("TDelegate", typeof(TDelegate));
            }
            ProcessorData data = new ProcessorData(delegates);

            CheckDelegateType <TDelegate>(data);
            return(CreateSwitcher <TDelegate>(data, null, null));
        }
Ejemplo n.º 18
0
        public Guid Execute(ProcessorData procdata)
        {
            Guid guid = Guid.Empty;

            if (this.Proxy != null)
            {
                // need to set property table for all properties having KRSrcWorkflow attribute
                foreach (PropertyInfo pi in procdata.GetType().GetProperties().Where(x => x.GetCustomAttributes(false).Count(y => y.GetType().Name == typeof(KRSrcWorkflowAttribute).Name) > 0))
                {
                    MethodInfo method  = procdata.GetType().GetMethod("SetProperty");
                    MethodInfo generic = method.MakeGenericMethod(pi.PropertyType);
                    generic.Invoke(procdata, new object[] { pi.Name, pi.GetValue(procdata, null) });

                    Console.WriteLine(pi.Name);
                }

                guid = this.Proxy.Execute((ProcessorData)procdata.Clone());
            }

            return(guid);
        }
Ejemplo n.º 19
0
        //- @Register -//
        public override void Register()
        {
            String blogGuid = ParameterMap.PeekSafely("blogGuid");

            if (String.IsNullOrEmpty(blogGuid))
            {
                throw new System.Configuration.ConfigurationErrorsException("blogPage parameter is required for the Blog component.");
            }
            //+ factory
            AddFactory(FactoryData.Create("Minima.Web.Processing.HandlerFactory, Minima.Web"));
            AddFactory(FactoryData.Create("Minima.Web.Processing.ProcessorFactory, Minima.Web"));
            //+ processor
            AddProcessor(ProcessorData.Create <ProcessorData>("__$Minima$InitProcessor", new Object[] { blogGuid }));
            //+ handler
            AddEndpoint(EndpointData.Create(SelectorType.EndsWith, "/rsd.xml", "__$Minima$BlogDiscovery"));
            AddEndpoint(EndpointData.Create(SelectorType.EndsWith, "/wlwmanifest.xml", "__$Minima$WindowsLiveWriterManifest"));
            AddEndpoint(EndpointData.Create(SelectorType.EndsWith, "/blogmap.xml", "__$Minima$SiteMap"));
            AddEndpoint(EndpointData.Create(SelectorType.Contains, "/xml-rpc", "__$Minima$MetaWeblogApi"));
            AddEndpoint(EndpointData.Create(SelectorType.Contains, "/xml-rpc/", "__$Minima$MetaWeblogApi"));
            AddEndpoint(EndpointData.Create(SelectorType.Contains, "/imagestore", "__$Minima$Image"));
        }
Ejemplo n.º 20
0
        public object GetValue(ProcessorData processor)
        {
            object value = null;

            if (this.TargetType == WFMappingTarget.TargetTypes.Property)
            {
                try
                {
                    value = this.Property.Invoke(processor, new object[0]);
                }
                catch (Exception ex)
                {
                    WFLogger.NLogger.ErrorException(String.Format("Invoke failed for property: {0} on type: {1}", this.Property.Name, processor.GetType().FullName), ex);
                }
            }
            else if (this.TargetType == WFMappingTarget.TargetTypes.Value)
            {
                value = this.Value;
            }

            return(value);
        }
Ejemplo n.º 21
0
 public void SetProperty(ProcessorData processor, object value)
 {
     try
     {
         this.Property.Invoke(processor, new[] { value });
     }
     catch (Exception ex)
     {
         WFLogger.NLogger.ErrorException("Invoke failed", ex);
     }
 }
Ejemplo n.º 22
0
 private static void LoadSingleProcessorData(WebDomainData data, String processorType, Object[] parameterArray, String source)
 {
     ProcessEachSettingToken(parameterArray);
     //+
     var readerWriterLockSlim = new ReaderWriterLockSlim();
     try
     {
         readerWriterLockSlim.EnterUpgradeableReadLock();
         try
         {
             IProcessor processor = null;
             //+
             if (RouteCache.ProcessorCache.ContainsKey(processorType))
             {
                 processor = RouteCache.ProcessorCache[processorType];
             }
             else
             {
                 readerWriterLockSlim.EnterWriteLock();
                 //+
                 try
                 {
                     if (!RouteCache.ProcessorCache.ContainsKey(processorType))
                     {
                         processor = ProcessorActivator.Create<IProcessor>(processorType, RouteCache.ProcessorFactoryCache);
                         if (processor == null)
                         {
                             throw new InvalidProcessorException(String.Format(Resource.Processor_Invalid, processorType));
                         }
                         //+
                         RouteCache.ProcessorCache.Add(processorType, processor);
                     }
                 }
                 finally
                 {
                     readerWriterLockSlim.ExitWriteLock();
                 }
             }
             if (processor == null)
             {
                 return;
             }
             ProcessorData processorData;
             if (processor is InitProcessor)
             {
                 processorData = new ProcessorData
                                 {
                                     ProcessorType = processorType, ParameterArray = parameterArray
                                 };
                 processorData.Source = String.IsNullOrEmpty(source) ? Info.System : source;
                 data.InitProcessorDataList.Add(processorData);
             }
             else if (processor is SelectionProcessor)
             {
                 processorData = new ProcessorData
                                 {
                                     ProcessorType = processorType, ParameterArray = parameterArray
                                 };
                 processorData.Source = String.IsNullOrEmpty(source) ? Info.System : source;
                 data.SelectionProcessorDataList.Add(processorData);
             }
             else if (processor is OverrideProcessor)
             {
                 processorData = new ProcessorData
                                 {
                                     ProcessorType = processorType, ParameterArray = parameterArray
                                 };
                 processorData.Source = String.IsNullOrEmpty(source) ? Info.System : source;
                 data.OverrideProcessorDataList.Add(processorData);
             }
             else if (processor is StateProcessor)
             {
                 processorData = new ProcessorData
                                 {
                                     ProcessorType = processorType, ParameterArray = parameterArray
                                 };
                 processorData.Source = String.IsNullOrEmpty(source) ? Info.System : source;
                 data.StateProcessorDataList.Add(processorData);
             }
             else if (processor is PostRenderProcessor)
             {
                 processorData = new ProcessorData
                                 {
                                     ProcessorType = processorType, ParameterArray = parameterArray
                                 };
                 processorData.Source = String.IsNullOrEmpty(source) ? Info.System : source;
                 data.PostRenderProcessorDataList.Add(processorData);
             }
             else if (processor is ErrorProcessor)
             {
                 processorData = new ErrorProcessorData
                                 {
                                     ProcessorType = processorType, ParameterArray = parameterArray
                                 };
                 processorData.Source = String.IsNullOrEmpty(source) ? Info.System : source;
                 var epd = ((ErrorProcessorData)processorData);
                 epd.Init();
                 data.ErrorProcessorDataList.Add(epd);
             }
         }
         finally
         {
             readerWriterLockSlim.ExitUpgradeableReadLock();
         }
     }
     catch (Exception ex)
     {
         if (WebProcessingReportController.Reporter.Initialized)
         {
             var map = new Map();
             map.Add("Section", "Processor");
             map.Add("Type", processorType);
             map.Add("Message", ex.Message);
             map.Add("Exception Type", ex.GetType().FullName);
             //+
             WebProcessingReportController.Reporter.AddMap(map);
         }
     }
 }
Ejemplo n.º 23
0
 //- #AddProcessor -//
 protected void AddProcessor(ProcessorData processorData)
 {
     processorData.Source = Key;
     _processorDataList.Add(processorData);
 }
Ejemplo n.º 24
0
        /// <summary>
        /// 返回与指定处理器数据相关的指定类型的委托。
        /// </summary>
        /// <typeparam name="TDelegate">委托的类型。</typeparam>
        /// <param name="data">处理器数据。</param>
        /// <param name="id">处理器标识。</param>
        /// <param name="instance">处理器要绑定到的实例。</param>
        /// <returns>与 <paramref name="data"/> 相关的 <typeparamref name="TDelegate"/> 类型的委托。</returns>
        private static TDelegate CreateSwitcher <TDelegate>(ProcessorData data, string id, object instance)
            where TDelegate : class
        {
            Contract.Requires(data != null);
            MethodInfo invoke = typeof(TDelegate).GetInvokeMethod();

            Type[] paramTypes = invoke.GetParameterTypes();
            object closure;

            if (data.IsStatic)
            {
                closure = data.Processors;
            }
            else
            {
                closure = new Closure(new[] { instance, data.Processors }, null);
            }
            DynamicMethod method = new DynamicMethod("MethodSwitcher", invoke.ReturnType,
                                                     paramTypes.Insert(0, closure.GetType()), true);
            ILGenerator il = method.GetILGenerator();

            // 静态方法中,arg_0 用作存储处理器委托字典。
            il.Emit(OpCodes.Ldarg_0);
            if (!data.IsStatic)
            {
                // 实例方法中,arg_0.Constants[1] 用作存储处理器委托字典。
                il.Emit(OpCodes.Ldfld, Reflections.ClosureConstants);
                il.EmitInt(1);
                il.Emit(OpCodes.Ldelem_Ref);
                il.Emit(OpCodes.Castclass, typeof(Dictionary <Type, Delegate>));
            }
            // 判断关键参数是否为 null。
            il.EmitLoadArg(data.KeyIndex + 1);
            Label keyNullCase = il.DefineLabel();

            il.Emit(OpCodes.Brtrue, keyNullCase);
            // 关键参数为 null,将 object 作为查找类型。
            il.EmitConstant(typeof(object));
            Label endKeyNull = il.DefineLabel();

            il.Emit(OpCodes.Br, endKeyNull);
            // 关键参数不为 null,将参数类型作为查找类型。
            il.MarkLabel(keyNullCase);
            il.EmitLoadArg(data.KeyIndex + 1);
            il.Emit(OpCodes.Call, methodGetType);
            il.MarkLabel(endKeyNull);
            // 调用 GetMethod 方法,取得方法委托。
            il.EmitConstant(id);
            il.Emit(OpCodes.Call, methodGetMethod);
            il.Emit(OpCodes.Castclass, data.DelegateType);
            //// 载入参数,调用委托。
            Type[] originParamTypes = data.DelegateParamTypes;
            if (!data.IsStatic)
            {
                // 载入实例。
                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Ldfld, Reflections.ClosureConstants);
                il.EmitInt(0);
                il.Emit(OpCodes.Ldelem_Ref);
                il.EmitConversion(typeof(object), instance.GetType(), true);
            }
            int offset = data.IsStatic ? 0 : 1;

            for (int i = 0; i < paramTypes.Length; i++)
            {
                Type targetType = originParamTypes[i + offset];
                Contract.Assume(targetType != null);
                il.EmitLoadArg(i + 1, paramTypes[i], targetType);
            }
            il.Emit(OpCodes.Callvirt, data.DelegateType.GetInvokeMethod());
            Type returnType       = originParamTypes[originParamTypes.Length - 1];
            Type targetReturnType = invoke.ReturnType;

            // 转换返回类型。
            if (returnType == typeof(void))
            {
                if (targetReturnType != typeof(void))
                {
                    il.EmitConstant(null, targetReturnType);
                }
            }
            else
            {
                if (targetReturnType == typeof(void))
                {
                    il.Emit(OpCodes.Pop);
                }
                else if (returnType != targetReturnType)
                {
                    il.EmitConversion(returnType, targetReturnType, true);
                }
            }
            il.Emit(OpCodes.Ret);
            return(method.CreateDelegate(typeof(TDelegate), closure) as TDelegate);
        }
Ejemplo n.º 25
0
        public object GetValue(ProcessorData processor)
        {
            object value = null;
            if (this.TargetType == WFMappingTarget.TargetTypes.Property)
            {
                try
                {
                    value = this.Property.Invoke(processor, new object[0]);
                }
                catch (Exception ex)
                {
                    WFLogger.NLogger.ErrorException(String.Format("Invoke failed for property: {0} on type: {1}", this.Property.Name, processor.GetType().FullName), ex);
                }
            }
            else if (this.TargetType == WFMappingTarget.TargetTypes.Value)
                value = this.Value;

            return value;
        }
Ejemplo n.º 26
0
 public object GetSrcValue(ProcessorData processor)
 {
     return(this.Src.GetValue(processor));
 }