public void Deserialize(Runtime.Serialization.IO.CompactReader reader) { _cacheId = reader.ReadObject() as string; _loadBalance = reader.ReadBoolean(); _isRegisteredLocal = reader.ReadBoolean(); //Needs to be intinalized at every read _serversPriorityList = new Dictionary <int, CacheServer>(); int lenght = reader.ReadInt32(); for (int i = 0; i < lenght; i++) { _serversPriorityList.Add(reader.ReadInt32(), reader.ReadObject() as CacheServer); } _serverName = reader.ReadObject() as string; _bindIp = reader.ReadObject() as string; _serverRuntimeContext = reader.ReadObject() as string == "1" ? RtContextValue.JVCACHE : RtContextValue.NCACHE; if (reader.ReadBoolean()) { _serverMapping = reader.ReadObject() as ServerMapping; } _enableClientLogs = reader.ReadBoolean(); _logLevel = reader.ReadObject() as string; _enableServerPriorities = reader.ReadBoolean(); }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager); } catch (Exception exc) { if (!base.immatureId.Equals("-2")) { //_resultPacket = clientManager.ReplyPacket(base.ExceptionPacket(exc, base.immatureId), base.ParsingExceptionMessage(exc)); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } return; } try { //Fetch mapped servers ServerMapping serverMapping = Management.MappingConfiguration.MappingConfigurationManager.GetMappingConfiguration().ClientIPMapping; Mapping[] mappedServers = serverMapping.MappingServers; Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.GetServerMappingResponse getServerMappingResponse = new Alachisoft.NCache.Common.Protobuf.GetServerMappingResponse(); if (mappedServers != null) { for (int i = 0; i < mappedServers.Length; i++) { Common.Protobuf.ServerMapping mappingObject = new Common.Protobuf.ServerMapping(); //Map the server list to protobuf object mappingObject.privateIp = mappedServers[i].PrivateIP; mappingObject.privatePort = mappedServers[i].PrivatePort; mappingObject.publicIp = mappedServers[i].PublicIP; mappingObject.publicPort = mappedServers[i].PublicPort; //Adding to list to be sent as a response getServerMappingResponse.serverMapping.Add(mappingObject); } } else { SocketServer.Logger.NCacheLog.Error("Server Mapping is null"); } response.getServerMappingResponse = getServerMappingResponse; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_SERVER_MAPPING; response.requestId = command.requestID; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { //_resultPacket = clientManager.ReplyPacket(base.ExceptionPacket(exc, cmdInfo.RequestId), base.ExceptionMessage(exc)); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } }
private static ServerMapping GetServerMapping(Hashtable settings) { ServerMapping serverMapping = new ServerMapping(); if (settings.ContainsKey("server-end-point")) serverMapping.MappingServers = GetMapping((Hashtable)settings["server-end-point"]); return serverMapping; }
private static ServerMapping GetServerMapping(Hashtable settings) { ServerMapping serverMapping = new ServerMapping(); if (settings.ContainsKey("server-end-point")) { serverMapping.MappingServers = GetMapping((Hashtable)settings["server-end-point"]); } return(serverMapping); }
private static Hashtable GetServerMapping(ServerMapping serverMapping) { Hashtable settings = new Hashtable(); if (serverMapping.MappingServers != null && serverMapping.MappingServers.Length > 0) { foreach (Mapping mapping in serverMapping.MappingServers) { settings.Add(mapping.PrivateIP, GetMapping(mapping)); } } return(settings); }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { #if !DEVELOPMENT try { ServerMapping serverMapping = Management.MappingConfiguration.MappingConfigurationManager.GetMappingConfiguration().ClientIPMapping; Mapping[] mappedServers = serverMapping.MappingServers; Common.Protobuf.Response response = new Common.Protobuf.Response(); Common.Protobuf.GetServerMappingResponse getServerMappingResponse = new Common.Protobuf.GetServerMappingResponse(); if (mappedServers != null) { for (int i = 0; i < mappedServers.Length; i++) { Common.Protobuf.ServerMapping mappingObject = new Common.Protobuf.ServerMapping(); //Map the server list to protobuf object mappingObject.privateIp = mappedServers[i].PrivateIP; mappingObject.privatePort = mappedServers[i].PrivatePort; mappingObject.publicIp = mappedServers[i].PublicIP; mappingObject.publicPort = mappedServers[i].PublicPort; //Adding to list to be sent as a response getServerMappingResponse.serverMapping.Add(mappingObject); } } else { SocketServer.Logger.NCacheLog.Error("Server Mapping is null"); } response.getServerMappingResponse = getServerMappingResponse; response.responseType = Common.Protobuf.Response.Type.GET_SERVER_MAPPING; response.requestId = command.requestID; response.commandID = command.commandID; _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithoutType(exc, command.requestID, command.commandID)); } #endif }
/// <summary> /// The main entry point for the tool. /// </summary> static public void Run(string[] args) { try { object param = new AddClientNodeParam(); CommandLineArgumentParser.CommandLineParser(ref param, args); cParam = (AddClientNodeParam)param; if (cParam.IsUsage) { AssemblyUsage.PrintLogo(cParam.IsLogo); AssemblyUsage.PrintUsage(); return; } if (!ValidateParameters()) { return; } bool multipleServers = false; if (cParam.Server != null || cParam.Server != string.Empty) { _serverList = cParam.Server.Split(','); if (_serverList.Length > 1 || (_serverList[0].Contains(":"))) { multipleServers = true; } } tryNextServer: if (multipleServers) { string[] serverAddress = _serverList[index].Split(':'); if (serverAddress.Length == 2) { if (!IsValidIP(serverAddress[0])) { Console.Error.WriteLine("Error: Invalid Server IP."); return; } NCache.ServerName = serverAddress[0]; try { NCache.Port = Convert.ToInt32(serverAddress[1]); } catch (Exception) { throw new Exception("Invalid Port :" + serverAddress[1] + " specified for server : " + serverAddress[0] + "."); } } else if (serverAddress.Length == 1) { if (!IsValidIP(serverAddress[0])) { Console.Error.WriteLine("Error: Invalid Server IP."); return; } NCache.ServerName = serverAddress[0]; NCache.Port = cParam.Port; if (cParam.Port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } } else { throw new Exception("Invalid server Address specified, kindly specify as [IPAdress] or [IPAdress]:[Port]."); } } else { if (cParam.Port != -1) { NCache.Port = cParam.Port; } if (cParam.Server != null || cParam.Server != string.Empty) { NCache.ServerName = cParam.Server; } if (cParam.Port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } } try { _server = NCache.ServerName; cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); } catch (Exception ex) { if (multipleServers) { if (index < _serverList.Length - 1) { Console.Error.WriteLine("Failed to connect to server : " + NCache.ServerName + ":" + NCache.Port + " \nTrying next server."); index++; goto tryNextServer; } } throw ex; } config = cacheServer.GetNewConfiguration(cParam.CacheId); //for getting server mappings if (cParam.AcquireServerMapping) { Alachisoft.NCache.Management.MappingConfiguration.Dom.MappingConfiguration mapping = cacheServer.GetServerMappingForClient(); if (mapping != null) { _clientIPMapping = mapping.ClientIPMapping; foreach (Mapping mappingServer in mapping.ManagementIPMapping.MappingServers) { if (mappingServer != null) { _managementIPMapping.Add(mappingServer.PrivateIP, mappingServer); } } } } if (config == null) { Console.Error.WriteLine("Error : The cache'{0}' does not exist on server {1}:{2} .", cParam.CacheId, NCache.ServerName, NCache.Port); return; } if (config.CacheSettings.CacheType == "clustered-cache") { Console.WriteLine("Adding client node '{0}' to cache '{1}' on server {2}:{3}.", cParam.ClientNode, cParam.CacheId, NCache.ServerName, NCache.Port); foreach (Address node in config.CacheDeployment.Servers.GetAllConfiguredNodes()) { currentServerNodes.Add(node.IpAddress.ToString()); } } else { Console.Error.WriteLine("Error: Client nodes cannot be added to local caches"); return; } if (config.CacheDeployment.ClientNodes != null) { foreach (ClientNode clientNode in config.CacheDeployment.ClientNodes.NodesList) { if (cParam.ClientNode.Equals(clientNode.Name)) { Console.Error.WriteLine("Error: " + clientNode.Name + " already part of \"" + cParam.CacheId + "\""); return; } currentClientNodes.Add(clientNode.Name); } } UpdateConfigs(); } catch (Exception ex) { Console.Error.WriteLine("Error: {0}", ex.Message); } }
/// <summary> /// Asynchronously gets an HTTP connection to an innovator instance (or proxy) at the given URL /// </summary> /// <param name="preferences">Object containing preferences for the connection</param> /// <param name="async">Whether or not to return the connection asynchronously. This is important /// as an HTTP request must be issued to determine the type of connection to create</param> /// <returns>A promise to return a connection object</returns> public static IPromise <IRemoteConnection> GetConnection(ConnectionPreferences preferences, bool async) { preferences = preferences ?? new ConnectionPreferences(); var url = preferences.Url; url = (url ?? "").TrimEnd('/'); if (url.EndsWith("Server/InnovatorServer.aspx", StringComparison.OrdinalIgnoreCase)) { url = url.Substring(0, url.Length - 21); } if (!url.EndsWith("/server", StringComparison.OrdinalIgnoreCase)) { url += "/Server"; } var configUrl = url + "/mapping.xml"; var masterService = preferences.HttpService ?? DefaultService.Invoke(); var arasSerice = preferences.HttpService ?? DefaultService.Invoke(); Func <ServerMapping, IRemoteConnection> connFactory = m => { var uri = (m.Url ?? "").TrimEnd('/'); if (!uri.EndsWith("/server", StringComparison.OrdinalIgnoreCase)) { url += "/Server"; } switch (m.Type) { case ServerType.Proxy: throw new NotSupportedException(); default: return(ArasConn(arasSerice, uri, preferences)); } }; var result = new Promise <IRemoteConnection>(); var req = new HttpRequest(); req.UserAgent = preferences.Headers.UserAgent; req.SetHeader("Accept", "text/xml"); foreach (var header in preferences.Headers.NonUserAgentHeaders()) { req.SetHeader(header.Key, header.Value); } var trace = new LogData(4, "Innovator: Try to download mapping file", Factory.LogListener) { { "url", configUrl }, }; result.CancelTarget(masterService.GetPromise(new Uri(configUrl), async, trace, req) .Progress((p, m) => result.Notify(p, m)) .Done(r => { var data = r.AsString(); if (string.IsNullOrEmpty(data)) { result.Resolve(ArasConn(arasSerice, url, preferences)); } else { try { var servers = ServerMapping.FromXml(data).ToArray(); if (servers.Length < 1) { result.Resolve(ArasConn(arasSerice, url, preferences)); } else if (servers.Length == 1) { result.Resolve(connFactory(servers.Single())); } else { foreach (var server in servers) { server.Factory = connFactory; } result.Resolve(new MappedConnection(servers, preferences.AuthCallback)); } } catch (XmlException) { result.Resolve(ArasConn(arasSerice, url, preferences)); } } }).Fail(ex => { result.Resolve(ArasConn(arasSerice, url, preferences)); })).Always(trace.Dispose); if (preferences.Credentials != null) { IRemoteConnection conn = null; return(result .Continue(c => { conn = c; return c.Login(preferences.Credentials, async); }) .Convert(u => conn)); } return(result); }
private static Hashtable GetServerMapping(ServerMapping serverMapping) { Hashtable settings = new Hashtable(); if (serverMapping.MappingServers != null && serverMapping.MappingServers.Length > 0) { foreach (Mapping mapping in serverMapping.MappingServers) settings.Add(mapping.PrivateIP, GetMapping(mapping)); } return settings; }
public void Deserialize(Runtime.Serialization.IO.CompactReader reader) { _managementMapping = reader.ReadObject() as ServerMapping; _clientMapping = reader.ReadObject() as ServerMapping; }
protected override string GetValueForExport(object row) { if (GetValueForExportHandler != null) { return(GetValueForExportHandler(row)); } if (getValueForExport == null) { var param = Expression.Parameter(typeof(object), "row"); string[] split = ServerMapping.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); Expression exp = Expression.Convert(param, row.GetType()); foreach (var field in split) { // обработка массива if (field.EndsWith("]")) { var startIndex = field.IndexOf("[", StringComparison.Ordinal); var indexStr = field.Substring(startIndex + 1, field.Length - startIndex - 2); exp = Expression.PropertyOrField(exp, field.Substring(0, startIndex)); if (typeof(IDictionary).IsAssignableFrom(exp.Type)) { var itemParams = exp.Type.GetProperty("Item").GetIndexParameters(); exp = Expression.Property(exp, "Item", Expression.Constant(Convert.ChangeType(indexStr, itemParams[0].ParameterType))); } else { exp = Expression.ArrayIndex(exp, Expression.Constant(Convert.ToInt32(indexStr))); } } else { exp = Expression.PropertyOrField(exp, field); } } if (ModelFieldType == ModelFieldType.Boolean) { if (exp.Type == typeof(bool?)) { exp = Expression.Condition(Expression.Equal(exp, Expression.Constant(null, typeof(bool?))), Expression.Constant(""), Expression.Condition(Expression.Property(exp, "Value"), Expression.Constant(TrueText), Expression.Constant(FalseText))); } else { exp = Expression.Condition(exp, Expression.Constant(TrueText), Expression.Constant(FalseText)); } } exp = Expression.Convert(exp, typeof(object)); var lambda = Expression.Lambda <Func <object, object> >(exp, param); getValueForExport = lambda.Compile(); } var value = getValueForExport(row); if (value == null) { return(null); } if (string.IsNullOrEmpty(Format)) { return(value.ToString()); } return(string.Format(Format, value)); }