/// <summary> /// 根据md5值从hfs上获取对应的filecode /// </summary> /// <param name="md5"></param> /// <returns></returns> public static string GetFileCodeByMD5(string md5) { var address = ConfigHelper.GetConfigString("UploadIP"); var client = ServiceProxyFactory <IFileUpload> .CreateProxy(address); return(client.GetFileCodeByMD5(md5)); }
private static byte[] DownloadFileFromNetDisk(string downFileType, string fileCode) { MemoryStream ms = null; try { var filetype = Path.GetExtension(fileCode); var filecode = Path.GetFileName(fileCode); if (filecode == string.Empty || filetype == string.Empty) { return(null); } //下载 var address = ConfigHelper.GetConfigString("DownloadIP"); var client = ServiceProxyFactory <IFileDownload> .CreateProxy(address); ms = client.DownloadFile(fileCode); } catch { return(null); } finally { if (ms != null) { ms.Close(); } } return(ms.ToArray()); }
/// <summary> /// Creates the proxy. /// </summary> private T GetProxy <T>() { _svc = new TestIgniteService(Binary); var prx = ServiceProxyFactory <T> .CreateProxy(InvokeProxyMethod); Assert.IsFalse(ReferenceEquals(_svc, prx)); return(prx); }
public virtual MemoryStream DownLoadFile(string fileCode, string fileType, string fileExtension) { //创建下载客户端对象 var client = ServiceProxyFactory <IFileDownload> .CreateProxy(ConfigHelper.GetConfigString("DownloadIP")); using (MemoryStream ms = client.Download("5e8b1cm8#%", fileType, fileCode, fileExtension)) { return(new MemoryStream(ms.ToArray())); } }
/** <inheritdoc /> */ public T GetServiceProxy <T>(string serviceName) where T : class { IgniteArgumentCheck.NotNullOrEmpty(serviceName, "name"); var platformType = GetServiceDescriptor(serviceName).PlatformType; return(ServiceProxyFactory <T> .CreateProxy( (method, args) => InvokeProxyMethod(serviceName, method, args, platformType) )); }
private static void Main() { //客户端基本服务。 ISerializer <string> serializer = new JsonSerializer(); ISerializer <byte[]> byteArraySerializer = new StringByteArraySerializer(serializer); ISerializer <object> objectSerializer = new StringObjectSerializer(serializer); IServiceIdGenerator serviceIdGenerator = new DefaultServiceIdGenerator(new ConsoleLogger <DefaultServiceIdGenerator>()); var typeConvertibleService = new DefaultTypeConvertibleService(new[] { new DefaultTypeConvertibleProvider(objectSerializer) }, new ConsoleLogger <DefaultTypeConvertibleService>()); var serviceRouteManager = new SharedFileServiceRouteManager("d:\\routes.txt", serializer, new ConsoleLogger <SharedFileServiceRouteManager>()); //zookeeper服务路由管理者。 // var serviceRouteManager = new ZooKeeperServiceRouteManager(new ZooKeeperServiceRouteManager.ZookeeperConfigInfo("172.18.20.132:2181"), serializer, new ConsoleLogger<ZooKeeperServiceRouteManager>()); // IAddressSelector addressSelector = new RandomAddressSelector(); IAddressSelector addressSelector = new PollingAddressSelector(); IAddressResolver addressResolver = new DefaultAddressResolver(serviceRouteManager, new ConsoleLogger <DefaultAddressResolver>(), addressSelector); ITransportClientFactory transportClientFactory = new DotNettyTransportClientFactory(byteArraySerializer, new ConsoleLogger <DotNettyTransportClientFactory>()); var remoteInvokeService = new RemoteInvokeService(addressResolver, transportClientFactory, new ConsoleLogger <RemoteInvokeService>()); //服务代理相关。 IServiceProxyGenerater serviceProxyGenerater = new ServiceProxyGenerater(serviceIdGenerator); var services = serviceProxyGenerater.GenerateProxys(new[] { typeof(IUserService) }).ToArray(); IServiceProxyFactory serviceProxyFactory = new ServiceProxyFactory(remoteInvokeService, typeConvertibleService); //创建IUserService的代理。 var userService = serviceProxyFactory.CreateProxy <IUserService>(services.Single(typeof(IUserService).IsAssignableFrom)); var logger = new ConsoleLogger(); while (true) { Task.Run(async() => { try { Console.WriteLine($"userService.GetUserName:{await userService.GetUserName(1)}"); Console.WriteLine($"userService.GetUserId:{await userService.GetUserId("rabbit")}"); Console.WriteLine($"userService.GetUserLastSignInTime:{await userService.GetUserLastSignInTime(1)}"); Console.WriteLine($"userService.Exists:{await userService.Exists(1)}"); var user = await userService.GetUser(1); Console.WriteLine($"userService.GetUser:name={user.Name},age={user.Age}"); Console.WriteLine($"userService.Update:{await userService.Update(1, user)}"); Console.WriteLine($"userService.GetDictionary:{(await userService.GetDictionary())["key"]}"); await userService.TryThrowException(); } catch (RpcRemoteException remoteException) { logger.Error(remoteException.Message); } }).Wait(); Console.ReadLine(); } }
/** <inheritdoc /> */ public T GetServiceProxy <T>(string serviceName, IServiceCallContext callCtx) where T : class { IgniteArgumentCheck.NotNullOrEmpty(serviceName, "name"); IgniteArgumentCheck.Ensure(callCtx == null || callCtx is ServiceCallContext, "callCtx", "custom implementation of " + typeof(ServiceCallContext).Name + " is not supported." + " Please use " + typeof(ServiceCallContextBuilder).Name + " to create it."); var platformType = GetServiceDescriptor(serviceName).PlatformType; IDictionary callAttrs = callCtx == null ? null : ((ServiceCallContext)callCtx).Values(); return(ServiceProxyFactory <T> .CreateProxy( (method, args) => InvokeProxyMethod(serviceName, method, args, platformType, callAttrs) )); }
private static UploadRetMsg UploadFile(string fileName, string fileType, long fileSize, Stream fileData) { IFileUpload client = ServiceProxyFactory <IFileUpload> .CreateProxy(ConfigHelper.GetConfigString("UploadIP")); UploadInMsg uploadMessage = new UploadInMsg() { BID = fileType, ticket = "5e8b1cm8#%", FileName = fileName, FileData = fileData, FileSize = fileSize }; UploadRetMsg resultMessage = client.UploadFile(uploadMessage); return(resultMessage); }
/** <inheritdoc /> */ public T GetServiceProxy <T>(string serviceName) where T : class { IgniteArgumentCheck.NotNullOrEmpty(serviceName, "name"); return(ServiceProxyFactory <T> .CreateProxy((method, args) => InvokeProxyMethod(serviceName, method, args))); }