コード例 #1
0
        /// <summary>
        /// 获取Orleans服务集群客户端
        /// </summary>
        /// <param name="clusterId">Orleans集群的唯一ID</param>
        /// <param name="serviceId">Orleans服务的唯一ID</param>
        /// <param name="connectionString">Orleans数据库连接串</param>
        /// <returns>Orleans服务集群客户端</returns>
        public static IClusterClient Fetch(string clusterId, string serviceId, string connectionString)
        {
            return(_cache.GetValue(String.Format("{0}*{1}", clusterId, serviceId), () =>
            {
                IClusterClient value = new ClientBuilder()
                                       .ConfigureLogging(logging => logging.AddConsole())
                                       .Configure <ConnectionOptions>(options => { options.ProtocolVersion = NetworkProtocolVersion.Version2; })
                                       .Configure <ClusterOptions>(options =>
                {
                    options.ClusterId = clusterId;
                    options.ServiceId = serviceId;
                })
                                       .UseAdoNetClustering(options =>
                {
                    options.ConnectionString = connectionString;
#if PgSQL
                    options.Invariant = "Npgsql";
#endif
#if MySQL
                    options.Invariant = "MySql.Data.MySqlClient";
#endif
#if ORA
                    options.Invariant = "Oracle.DataAccess.Client";
#endif
                })
                                       .ConfigureApplicationParts(parts =>
                {
                    parts.AddPluginPart();
                })
                                       .AddSimpleMessageStreamProvider(StreamProvider.Name)
                                       .Build();
                value.Connect().Wait();
                return value;
            }));
        }
コード例 #2
0
        /// <summary>
        /// 检索插件类
        /// </summary>
        /// <param name="assembly">程序集</param>
        /// <param name="throwIfNotFound">如果为 true, 则会在找不到信息时引发 ArgumentException; 如果为 false, 则在找不到信息时返回 null</param>
        /// <returns>插件类</returns>
        public static Type FindPluginType(Assembly assembly, bool throwIfNotFound = false)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            return(_typeCache.GetValue(assembly.GetName().Name, () =>
            {
                foreach (Type item in assembly.GetExportedTypes())
                {
                    if (!item.IsClass || item.IsAbstract || item.IsGenericType || item.IsCOMObject)
                    {
                        continue;
                    }
                    if (typeof(IPlugin).IsAssignableFrom(item))
                    {
                        return item;
                    }
                }

                if (throwIfNotFound)
                {
                    throw new ArgumentException(String.Format("程序集 {0} 中不存在实现IPlugin的插件类", assembly.FullName), nameof(assembly));
                }
                return null;
            }));
        }
コード例 #3
0
 /// <summary>
 /// 获取控制器的授权角色
 /// </summary>
 /// <param name="typeInfo">TypeInfo</param>
 /// <param name="methodInfo">MethodInfo</param>
 /// <returns>控制器的授权角色</returns>
 public static ControllerRole Fetch(TypeInfo typeInfo, MethodInfo methodInfo)
 {
     return(_cache.GetValue(Standards.FormatCompoundKey(typeInfo.FullName, methodInfo.Name, methodInfo.GetHashCode()), () =>
                            FetchRoot(Database.Default, p => p.ControllerName == typeInfo.FullName && p.ActionName == methodInfo.Name,
                                      () => new ControllerRole(Database.Default.DataSourceKey, Database.Default.Sequence.Value, typeInfo, methodInfo))
                            ));
 }
コード例 #4
0
        public UserToken Find(string uid)
        {
            var idx = m_indexMap.GetValue(uid, -1);

            if (idx >= 0)
            {
                return(m_pool[idx]);
            }
            return(null);
        }
コード例 #5
0
        /// <summary>
        /// 订阅
        /// </summary>
        /// <param name="groupName">组名</param>
        public async Task SubscribeAsync(string groupName)
        {
            _connectedInfos.GetValue(Context.ConnectionId, () => new SynchronizedList <string>()).AddOnce(groupName);
            await Groups.AddToGroupAsync(Context.ConnectionId, groupName);

            _subscribers.GetValue(groupName, async() =>
            {
                Subscriber subscriber = new Subscriber(this, groupName);
                await subscriber.SubscribeAsync(ClusterClient.Default.GetSimpleMessageStreamProvider().GetStream <string>(StreamIds.GroupStreamId, groupName));
                return(subscriber);
            });
        }
コード例 #6
0
        private static T FillAllChildren(T root)
        {
            if (root == null)
            {
                return(null);
            }

            SynchronizedDictionary <long, List <T> > allChildren = new SynchronizedDictionary <long, List <T> >();

            foreach (T item in root.SelfSheet.SelectEntity <T>(p => p.RootId == root.Id && p.Id != root.Id))
            {
                allChildren.GetValue(item.ParentId, () => new List <T>()).Add(item);
            }
            FillChildren(root, allChildren);
            return(root);
        }
コード例 #7
0
        /// <summary>
        /// 构造动态执行构建函数
        /// </summary>
        public static DynamicCtorDelegate GetConstructor(Type objectType)
        {
            if (objectType == null)
            {
                throw new ArgumentNullException(nameof(objectType));
            }

            return(_classCtorCache.GetValue(objectType.FullName, () =>
            {
                ConstructorInfo constructor = objectType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
                if (constructor == null)
                {
                    throw new NotSupportedException(String.Format("不支持多参数的 {0} 构建函数", objectType.FullName));
                }
                return CreateConstructor(constructor);
            }));
        }
コード例 #8
0
ファイル: BusinessBase.cs プロジェクト: phenixiii/Phenix.NET7
        /// <summary>
        /// 设置从业务对象
        /// </summary>
        /// <param name="ignoreRepeat">忽略重复的</param>
        /// <param name="detail">从业务对象</param>
        public void SetDetail <TDetail>(bool ignoreRepeat = false, params TDetail[] detail)
            where TDetail : BusinessBase <TDetail>
        {
            if (detail == null || detail.Length == 0)
            {
                return;
            }
            List <IBusiness> value = _details.GetValue(typeof(TDetail), () => new List <IBusiness>());

            foreach (TDetail item in detail)
            {
                if (ignoreRepeat || !value.Contains(item))
                {
                    item.Master = this;
                    value.Add(item);
                }
            }
        }
コード例 #9
0
ファイル: Utilities.cs プロジェクト: phenixiii/Phenix.NET7
        /// <summary>
        /// 加载类型
        /// </summary>
        /// <param name="typeName">类名</param>
        /// <param name="assemblyName">程序集名</param>
        /// <returns>类</returns>
        public static Type LoadType(string typeName, string assemblyName = null)
        {
            if (String.IsNullOrEmpty(typeName))
            {
                return(null);
            }

            Type result = Type.GetType(typeName, false);

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

            if (!String.IsNullOrEmpty(assemblyName))
            {
                Assembly assembly = LoadAssembly(assemblyName);
                return(assembly != null?assembly.GetType(typeName, false) : null);
            }

            return(_typeCache.GetValue(typeName, () =>
            {
                assemblyName = typeName;
                while (true)
                {
                    int i = assemblyName.LastIndexOf('.');
                    if (i > 0)
                    {
                        assemblyName = assemblyName.Remove(i);
                        Type value = LoadType(typeName, assemblyName);
                        if (value != null)
                        {
                            return value;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                return null;
            }));
        }
コード例 #10
0
ファイル: PluginHost.cs プロジェクト: phenixiii/Phenix.NET7
        /// <summary>
        /// 获取插件
        /// </summary>
        /// <param name="assembly">程序集</param>
        /// <param name="onMessage">插件发送过来的消息</param>
        public IPlugin GetPlugin(Assembly assembly, Func <IPlugin, object, object> onMessage = null)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            return(_cache.GetValue(assembly.GetName().Name, () =>
            {
                try
                {
                    return PluginBase.New(assembly, this, onMessage);
                }
                catch (Exception ex)
                {
                    Task.Run(() => EventLog.SaveLocal(MethodBase.GetCurrentMethod(), assembly.GetName().Name, ex));
                    throw;
                }
            }));
        }
コード例 #11
0
ファイル: EnumKeyValue.cs プロジェクト: phenixiii/Phenix.NET7
        /// <summary>
        /// 根据枚举类型定义构建
        /// </summary>
        /// <param name="enumType">枚举类型</param>
        private static IList <EnumKeyValue> Fetch(Type enumType)
        {
            enumType = Utilities.LoadType(enumType); //主要用于IDE环境、typeof(T)

            if (enumType == null)
            {
                throw new ArgumentNullException(nameof(enumType));
            }
            if (!enumType.IsEnum)
            {
                throw new ArgumentException(String.Format("类 {0} 应定义为枚举", enumType.FullName), nameof(enumType));
            }

            return(_cache.GetValue(enumType.FullName, () =>
            {
                FieldInfo[] fieldInfos = enumType.GetFields(BindingFlags.Static | BindingFlags.Public);
                List <EnumKeyValue> value = new List <EnumKeyValue>(fieldInfos.Length);
                foreach (FieldInfo item in fieldInfos)
                {
                    value.Add(new EnumKeyValue((Enum)item.GetValue(enumType), (EnumCaptionAttribute)Attribute.GetCustomAttribute(item, typeof(EnumCaptionAttribute))));
                }
                return value;
            }));
        }
コード例 #12
0
 /// <summary>
 /// 获取Orleans流提供者
 /// </summary>
 /// <param name="clusterId">Orleans集群的唯一ID</param>
 /// <param name="serviceId">Orleans服务的唯一ID</param>
 /// <param name="connectionString">Orleans数据库连接串</param>
 /// <returns>流提供者</returns>
 public static IStreamProvider Fetch(string clusterId, string serviceId, string connectionString)
 {
     return(_cache.GetValue(String.Format("{0}*{1}", clusterId, serviceId), () => ClusterClient.Fetch(clusterId, serviceId, connectionString).GetStreamProvider(Name)));
 }
コード例 #13
0
        /// <summary>
        /// 读取信息(分离出当前线程语言的中英文文本)
        /// Thread.CurrentThread.CurrentCulture.Name为非'zh-'时返回后半截
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="inEncrypt">是否加密</param>
        public static string ReadValue(string key, bool inEncrypt = false)
        {
            try
            {
                return _cache.GetValue(key, () =>
                {
                    string pendingValue;
#if PgSQL
                    using (DataReader reader = Database.CreateDataReader(@"
select AS_Value, AS_ValueEncrypted
from PH7_AppSettings
where AS_Key = @AS_Key",
#endif
#if MsSQL
                    using (DataReader reader = Database.CreateDataReader(@"
select AS_Value, AS_ValueEncrypted
from PH7_AppSettings
where AS_Key = @AS_Key",
#endif
#if MySQL
                    using (DataReader reader = Database.CreateDataReader(@"
select AS_Value, AS_ValueEncrypted
from PH7_AppSettings
where AS_Key = ?AS_Key",
#endif
#if ORA
                    using (DataReader reader = Database.CreateDataReader(@"
select AS_Value, AS_ValueEncrypted
from PH7_AppSettings
where AS_Key = :AS_Key",
#endif
                        CommandBehavior.SingleRow))
                    {
                        reader.CreateParameter("AS_Key", key);
                        if (reader.Read())
                            if (inEncrypt)
                                if (reader.IsDBNull(1) || reader.GetInt32(1) != 1)
                                    pendingValue = reader.GetString(0);
                                else
                                    try
                                    {
                                        return AppRun.SplitCulture(Decrypt(reader.GetString(0)));
                                    }
                                    catch (SystemException) //FormatException & CryptographicException
                                    {
                                        pendingValue = reader.GetString(0);
                                    }
                            else
                                return AppRun.SplitCulture(reader.GetString(0));
                        else
                            throw new KeyNotFoundException();
                    }

                    if (pendingValue != null)
#if PgSQL
                        Database.ExecuteNonQuery(@"
update PH7_AppSettings set
  AS_Value = @AS_Value,
  AS_ValueEncrypted = 1
where AS_Key = @AS_Key",
#endif
#if MsSQL
                        Database.ExecuteNonQuery(@"
update PH7_AppSettings set
  AS_Value = @AS_Value,
  AS_ValueEncrypted = 1
where AS_Key = @AS_Key",
#endif
#if MySQL
                        Database.ExecuteNonQuery(@"
update PH7_AppSettings set
  AS_Value = ?AS_Value,
  AS_ValueEncrypted = 1
where AS_Key = ?AS_Key",
#endif
#if ORA
                        Database.ExecuteNonQuery(@"
update PH7_AppSettings set
  AS_Value = :AS_Value,
  AS_ValueEncrypted = 1
where AS_Key = :AS_Key",
#endif
                            ParamValue.Input("AS_Value", Encrypt(pendingValue)),
                            ParamValue.Input("AS_Key", key));

                    return AppRun.SplitCulture(pendingValue);
                });
            }
コード例 #14
0
 private Alley FetchAlley(string locationAlley)
 {
     return(_alleyDictionary.GetValue(locationAlley, () => new Alley(this, locationAlley)));
 }
コード例 #15
0
        /// <summary>
        /// 获取Orleans服务集群客户端
        /// </summary>
        /// <param name="clusterId">Orleans集群的唯一ID</param>
        /// <param name="serviceId">Orleans服务的唯一ID</param>
        /// <param name="connectionString">Orleans数据库连接串</param>
        /// <returns>Orleans服务集群客户端</returns>
        public static IClusterClient Fetch(string clusterId, string serviceId, string connectionString)
        {
            return(_cache.GetValue(Standards.FormatCompoundKey(clusterId, serviceId), () =>
            {
                IClusterClient value = new ClientBuilder()
                                       .Configure <SerializationProviderOptions>(options =>
                {
                    options.SerializationProviders.Add(typeof(BondSerializer));
                    options.FallbackSerializationProvider = typeof(BondSerializer);
                })
                                       .Configure <ConnectionOptions>(options => { options.ProtocolVersion = NetworkProtocolVersion.Version2; })
                                       .Configure <ClusterOptions>(options =>
                {
                    options.ClusterId = clusterId;
                    options.ServiceId = serviceId;
                })
                                       .UseAdoNetClustering(options =>
                {
                    options.ConnectionString = connectionString;
#if PgSQL
                    options.Invariant = "Npgsql";
#endif
#if MsSQL
                    options.Invariant = "System.Data.SqlClient";
#endif
#if MySQL
                    options.Invariant = "MySql.Data.MySqlClient";
#endif
#if ORA
                    options.Invariant = "Oracle.DataAccess.Client";
#endif
                })
                                       .ConfigureApplicationParts(parts =>
                {
                    /*
                     * 装配Actor协议
                     * 业务程序集都应该统一采用"*.Business.dll"作为文件名的后缀
                     * 契约程序集都应该统一采用"*.Contract.dll"作为文件名的后缀
                     * 以上程序集都应该被部署到主程序的执行目录下
                     */
                    foreach (string fileName in Directory.GetFiles(Phenix.Core.AppRun.BaseDirectory, "*.Business.dll"))
                    {
                        parts.AddApplicationPart(Assembly.LoadFrom(fileName)).WithReferences().WithCodeGeneration();
                    }
                    foreach (string fileName in Directory.GetFiles(Phenix.Core.AppRun.BaseDirectory, "*.Contract.dll"))
                    {
                        parts.AddApplicationPart(Assembly.LoadFrom(fileName)).WithReferences().WithCodeGeneration();
                    }
                })
                                       .AddSimpleMessageStreamProvider(ContextKeys.SimpleMessageStreamProviderName)
                                       .AddOutgoingGrainCallFilter(context =>
                {
                    if (context.Grain is ISecurityContext)
                    {
                        IIdentity currentIdentity = Principal.CurrentIdentity;
                        if (currentIdentity != null)
                        {
                            RequestContext.Set(ContextKeys.CurrentIdentityCompanyName, currentIdentity.CompanyName);
                            RequestContext.Set(ContextKeys.CurrentIdentityUserName, currentIdentity.UserName);
                            RequestContext.Set(ContextKeys.CurrentIdentityCultureName, currentIdentity.CultureName);
                        }
                    }

                    if (context.Grain is ITraceLogContext)
                    {
                        long traceKey;
                        if (RequestContext.Get(ContextKeys.TraceKey) == null)
                        {
                            traceKey = Database.Default.Sequence.Value;
                            RequestContext.Set(ContextKeys.TraceKey, traceKey);
                        }
                        else
                        {
                            traceKey = (long)RequestContext.Get(ContextKeys.TraceKey);
                        }

                        int traceOrder = RequestContext.Get(ContextKeys.TraceOrder) != null ? (int)RequestContext.Get(ContextKeys.TraceOrder) + 1 : 0;
                        RequestContext.Set(ContextKeys.TraceOrder, traceOrder);

                        Task.Run(() => EventLog.Save(context.InterfaceMethod, Phenix.Core.Reflection.Utilities.JsonSerialize(context.Arguments), traceKey, traceOrder));
                        try
                        {
                            return context.Invoke();
                        }
                        catch (Exception ex)
                        {
                            Task.Run(() => EventLog.Save(context.InterfaceMethod, Phenix.Core.Reflection.Utilities.JsonSerialize(context.Arguments), traceKey, traceOrder, ex));
                            throw;
                        }
                    }

                    return context.Invoke();
                })
                                       .Build();
                AsyncHelper.RunSync(() => value.Connect());
                return value;
            }));
        }
コード例 #16
0
ファイル: IcCustomer.cs プロジェクト: hzjianghe/Phenix.NET7
 private Area FetchArea(string locationArea)
 {
     return(_areaDictionary.GetValue(locationArea, () => new Area(this, locationArea)));
 }
コード例 #17
0
ファイル: Alley.cs プロジェクト: hzjianghe/Phenix.NET7
 private Location FetchLocation(string locationOrdinal)
 {
     return(_locationDictionary.GetValue(locationOrdinal, () => new Location(this, locationOrdinal)));
 }