Example #1
0
 /// <summary>
 /// 字符查找数量
 /// </summary>
 /// <param name="start">起始位置,不能为null</param>
 /// <param name="end">结束位置,不能为null</param>
 /// <param name="valueMap">字符集合</param>
 /// <param name="value">一个合法值</param>
 /// <returns>字符数量</returns>
 public unsafe static int AsciiCount(char* start, char* end, fastCSharp.String.asciiMap valueMap, char value)
 {
     return asciiCount(start, end, valueMap.Map, value);
 }
 private bool create(fastCSharp.code.cSharp.tcpBase.subByteUnmanagedStream stream)
 {
     timeIdentity identity = getIdentity(ref stream.Buffer);
     return stream.Buffer.array != null && physicalSet.Default.Create(identity.GetIdentity(), stream.Buffer);
 }
 private unsafe int append(fastCSharp.code.cSharp.tcpBase.subByteUnmanagedStream dataStream)
 {
     timeIdentity identity = getIdentity(ref dataStream.Buffer);
     return dataStream.Buffer.array != null ? physicalSet.Default.Append(identity.GetIdentity(), dataStream.Buffer) : 0;
 }
Example #4
0
 /// <summary>
 /// 创建TCP客户端
 /// </summary>
 /// <param name="attribute">配置信息</param>
 /// <returns>TCP客户端,失败返回null</returns>
 internal static Socket Create(fastCSharp.code.cSharp.tcpServer attribute)
 {
     Socket socket = null;
     try
     {
         if (attribute.IpAddress == IPAddress.Any)
         {
             if (!isAnyIpAddress) log.Error.Add("客户端TCP连接失败(" + attribute.ServiceName + " " + attribute.Host + ":" + attribute.Port.toString() + ")", true, false);
             isAnyIpAddress = true;
             return null;
         }
         isAnyIpAddress = false;
         socket = new Socket(attribute.IpAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
         socket.Connect(attribute.IpAddress, attribute.Port);
         return socket;
     }
     catch (Exception error)
     {
         log.Error.Add(error, "客户端TCP连接失败(" + attribute.ServiceName + " " + attribute.IpAddress.ToString() + ":" + attribute.Port.toString() + ")", false);
         log.Error.Add("客户端TCP连接失败(" + attribute.ServiceName + " " + attribute.IpAddress.ToString() + ":" + attribute.Port.toString() + ")", true, false);
         if (socket != null) socket.Close();
     }
     return null;
 }
Example #5
0
 /// <summary>
 /// TCP调用服务端
 /// </summary>
 /// <param name="attribute">配置信息</param>
 /// <param name="isStart">是否启动客户端</param>
 public client(fastCSharp.code.cSharp.tcpServer attribute, bool isStart)
 {
     this.attribute = attribute;
     if (isStart) start();
 }
 /// <summary>
 /// 泛型方法调用
 /// </summary>
 /// <param name="method">泛型方法信息</param>
 /// <param name="types">泛型参数类型集合</param>
 /// <param name="parameters">调用参数</param>
 /// <returns>返回值</returns>
 public static object InvokeGenericMethod(MethodInfo method, fastCSharp.code.remoteType[] types, params object[] parameters)
 {
     if (method == null) fastCSharp.log.Error.Throw(fastCSharp.log.exceptionType.Null);
     return method.MakeGenericMethod(types.getArray(value => value.Type)).Invoke(null, parameters);
 }
 /// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="verify">TCP验证实例</param>
 /// <param name="isStart">是否启动连接</param>
 public tcpServerSegmentation(fastCSharp.setup.cSharp.tcpServer attribute = null, fastCSharp.setup.cSharp.tcpBase.ITcpVerifyClient verify = null, bool isStart = true)
 {
     _tcpClient_ = new fastCSharp.net.tcpClient(attribute ?? fastCSharp.setup.cSharp.tcpServer.GetConfig("tcpServerSegmentation", typeof(fastCSharp.testCase.tcpServerSegmentation)), verify, isStart);
 }
 private void read(fileBlockStream.index index, ref fastCSharp.code.cSharp.tcpBase.subByteArrayEvent buffer, Func<fastCSharp.code.cSharp.asynchronousMethod.returnValue<fastCSharp.code.cSharp.tcpBase.subByteArrayEvent>, bool> onReturn)
 {
     fileBlockStream fileStream = this.fileStream;
     if (fileStream == null) onReturn(default(fastCSharp.code.cSharp.tcpBase.subByteArrayEvent));
     else fileStream.Read(index, onReturn);
 }
 /// <summary>
 /// 设置TCP服务端
 /// </summary>
 /// <param name="tcpServer">TCP服务端</param>
 public void SetTcpServer(fastCSharp.net.tcp.server tcpServer)
 {
     server = tcpServer;
     fileWatcher = new createFlieTimeoutWatcher(fastCSharp.config.processCopy.Default.CheckTimeoutSeconds, onFileWatcherTimeout, fastCSharp.diagnostics.processCopyServer.DefaultFileWatcherFilter);
     if (!fastCSharp.config.pub.Default.IsService && fastCSharp.config.processCopy.Default.WatcherPath != null)
     {
         try
         {
             fileWatcher.Add(fastCSharp.config.processCopy.Default.WatcherPath);
         }
         catch (Exception error)
         {
             log.Error.Add(error, fastCSharp.config.processCopy.Default.WatcherPath, false);
         }
     }
     if (IsLoadCache)
     {
         try
         {
             string cacheFileName = this.cacheFileName;
             if (File.Exists(cacheFileName))
             {
                 interlocked.NoCheckCompareSetSleep0(ref loadCacheLock);
                 try
                 {
                     if (!IsLoadedCache)
                     {
                         saveInfo saveInfo = fastCSharp.emit.dataDeSerializer.DeSerialize<saveInfo>(File.ReadAllBytes(cacheFileName));
                         if (saveInfo.ForwardHost.Port != 0) setForward(saveInfo.ForwardHost);
                         if (saveInfo.Domains.length() != 0)
                         {
                             foreach (saveInfo.domainServer domain in saveInfo.Domains)
                             {
                                 try
                                 {
                                     start(domain.AssemblyPath, domain.ServerType, domain.Domains, domain.IsShareAssembly);
                                 }
                                 catch (Exception error)
                                 {
                                     log.Error.Add(error, null, false);
                                 }
                             }
                         }
                         IsLoadedCache = true;
                     }
                 }
                 finally { loadCacheLock = 0; }
             }
         }
         catch (Exception error)
         {
             log.Error.Add(error, null, false);
         }
     }
 }
Example #10
0
 /// <summary>
 /// 输出类定义结束段代码
 /// </summary>
 /// <param name="definition">类定义</param>
 protected void outEnd(fastCSharp.setup.cSharp.cSharper.definition definition)
 {
     if (definition != null)
     {
         _code_.Add(definition.End);
         fastCSharp.setup.cSharp.coder.Add(GetType(), CodeType.Type, _code_.ToString());
     }
 }
 private unsafe long write(fastCSharp.code.cSharp.tcpBase.subByteUnmanagedStream dataStream)
 {
     if (fileStream != null)
     {
         subArray<byte> buffer = dataStream.Buffer;
         if (buffer.Count != 0)
         {
             fixed (byte* bufferFixed = buffer.array)
             {
                 byte* start = bufferFixed - sizeof(int);
                 *(int*)start = buffer.Count;
                 return fileStream.UnsafeWrite(start, buffer.Count + (-buffer.Count & 3) + sizeof(int));
             }
         }
     }
     return -1;
 }
Example #12
0
 /// <summary>
 /// 获取泛型类型函数信息
 /// </summary>
 /// <param name="remoteType">调用代理类型</param>
 /// <param name="methodName">调用函数名称</param>
 /// <returns>泛型类型函数信息</returns>
 private static MethodInfo getGenericTypeMethod(fastCSharp.code.remoteType remoteType, string methodName)
 {
     Type type = remoteType.Type;
     if (type.Name == GenericTypeServerName && type.DeclaringType.IsGenericType)
     {
         tcpCall tcpCall = fastCSharp.code.typeAttribute.GetAttribute<tcpCall>(type, false, false);
         if (tcpCall != null && tcpCall.IsGenericTypeServerMethod)
         {
             tcpCall = fastCSharp.code.typeAttribute.GetAttribute<tcpCall>(type.DeclaringType, false, true);//cSharp.Default.IsInheritAttribute
             if (tcpCall != null && tcpCall.IsSetup)
             {
                 keyValue<Type, fastCSharp.stateSearcher.ascii<MethodInfo>> methods;
                 int version = genericTypeMethodVersion;
                 if (!genericTypeMethods.TryGetValue(type, out methods) || methods.Key != type)
                 {
                     interlocked.CompareSetSleep(ref genericTypeMethodLock);
                     try
                     {
                         if (version == genericTypeMethodVersion || !genericTypeMethods.TryGetValue(type, out methods))
                         {
                             MethodInfo[] methodInfos = type.GetMethods(BindingFlags.Static | BindingFlags.Public);
                             methods = new keyValue<Type, fastCSharp.stateSearcher.ascii<MethodInfo>>(type, new fastCSharp.stateSearcher.ascii<MethodInfo>(methodInfos.getArray(value => value.Name), methodInfos));
                             genericTypeMethods.Add(type, methods);
                             ++genericTypeMethodVersion;
                         }
                     }
                     finally { genericTypeMethodLock = 0; }
                 }
                 return methods.Value.Get(methodName);
             }
         }
     }
     log.Error.Throw(type.fullName() + " 不符合泛型类型服务器端调用", false, false);
     return null;
 }
Example #13
0
 /// <summary>
 /// 泛型类型函数调用
 /// </summary>
 /// <param name="remoteType">调用代理类型</param>
 /// <param name="methodName">调用函数名称</param>
 /// <param name="parameters">调用参数</param>
 /// <returns>函数返回值</returns>
 public static object InvokeGenericTypeMethod(fastCSharp.code.remoteType remoteType, string methodName, params object[] parameters)
 {
     return getGenericTypeMethod(remoteType, methodName).Invoke(null, parameters);
 }
Example #14
0
 /// <summary>
 /// 泛型类型函数调用
 /// </summary>
 /// <param name="remoteType">调用代理类型</param>
 /// <param name="methodName">调用函数名称</param>
 /// <param name="methodGenericTypes">方法泛型参数集合</param>
 /// <param name="parameters">调用参数</param>
 /// <returns>函数返回值</returns>
 public static object InvokeGenericTypeMethod(fastCSharp.code.remoteType remoteType, string methodName, fastCSharp.code.remoteType[] methodGenericTypes, params object[] parameters)
 {
     return getGenericTypeMethod(remoteType, methodName).MakeGenericMethod(methodGenericTypes.getArray(value => value.Type)).Invoke(null, parameters);
 }
Example #15
0
 /// <summary>
 /// 字符查找
 /// </summary>
 /// <param name="start">起始位置,不能为null</param>
 /// <param name="end">结束位置,不能为null</param>
 /// <param name="valueMap">字符集合</param>
 /// <returns>字符位置,失败为null</returns>
 public unsafe static char* FindLastNot(char* start, char* end, fastCSharp.String.asciiMap valueMap)
 {
     return findLastNotAscii(start, end, valueMap.Map);
 }
 /// <summary>
 /// 设置TCP服务端
 /// </summary>
 /// <param name="tcpServer">TCP服务端</param>
 public void SetTcpServer(fastCSharp.net.tcp.server tcpServer)
 {
     bool isSave = false;
     Monitor.Enter(guardLock);
     if (guards == null)
     {
         try
         {
             guards = dictionary.CreateInt<copyer>();
             if (File.Exists(cacheFile))
             {
                 foreach (copyer copyer in fastCSharp.emit.dataDeSerializer.DeSerialize<copyer[]>(File.ReadAllBytes(cacheFile)))
                 {
                     guards.Add(copyer.ProcessId, copyer);
                     if (!copyer.Guard(this))
                     {
                         guards.Remove(copyer.ProcessId);
                         isSave = true;
                     }
                 }
             }
         }
         catch (Exception error)
         {
             log.Error.Add(error, null, false);
             try
             {
                 File.Delete(cacheFile);
             }
             catch (Exception error1)
             {
                 log.Default.Add(error1, null, false);
             }
         }
     }
     Monitor.Exit(guardLock);
     if (isSave) saveCache();
 }
Example #17
0
 /// <summary>
 /// 字符查找
 /// </summary>
 /// <param name="start">起始位置,不能为null</param>
 /// <param name="end">结束位置,不能为null</param>
 /// <param name="valueMap">字符集合</param>
 /// <param name="value">一个合法值</param>
 /// <returns>字符位置,失败为null</returns>
 public unsafe static char* Find(char* start, char* end, fastCSharp.String.asciiMap valueMap, char value)
 {
     return findAscii(start, end, valueMap.Map, value);
 }
Example #18
0
 /// <summary>
 /// TCP调用服务端
 /// </summary>
 /// <param name="attribute">配置信息</param>
 protected server(fastCSharp.code.cSharp.tcpServer attribute)
 {
     if (attribute == null) log.Error.Throw(log.exceptionType.Null);
     if (attribute.TcpRegisterName != null)
     {
         tcpRegisterClient = fastCSharp.net.tcp.tcpRegister.client.Get(attribute.TcpRegisterName);
         if (tcpRegisterClient == null) log.Error.Throw("TCP注册服务 " + attribute.TcpRegisterName + " 链接失败", true, false);
         fastCSharp.net.tcp.tcpRegister.registerState state = tcpRegisterClient.Register(attribute);
         if (state != fastCSharp.net.tcp.tcpRegister.registerState.Success) log.Error.Throw("TCP服务注册 " + attribute.ServiceName + " 失败 " + state.ToString(), true, false);
         log.Default.Add(attribute.ServiceName + " 注册 " + attribute.Host + ":" + attribute.Port.toString(), false, false);
     }
     if (!attribute.IsServer) log.Default.Add("配置未指明的TCP服务端 " + attribute.ServiceName, true, false);
     this.attribute = attribute;
 }