public void Save() { // Create a new string builder that // contains the result xml string. StringBuilder result = new StringBuilder(); result.Append("<Servers>"); // Run through all defined servers. foreach (Server server in this.Items.Values) { result.Append(string.Format( "<Server IP=\"{0}\" Description=\"{1}\" Role=\"{2}\" Countries=\"{3}\" State=\"{4}\"></Server>", server.IP, server.Description, server.Role.ToString(), string.Join(",", server.Countries), server.State.ToString() )); } result.Append("</Servers>"); ServiceLink service = new ServiceLink( ConfigurationManager.AppSettings["LinkSwitchServiceUrl"] ); service.Request(new string[] { "Method=SetServers" }, System.Text.Encoding.UTF8.GetBytes(result.ToString())); }
private void BindServerInfo() { try { ServiceLink service = new ServiceLink(string.Format( "http://{0}/Handlers/Public.ashx", ConfigurationManager.AppSettings["LinkAdminHostname"] )); string server = service.Request(new string[] { "Method=WhoAmI" }); lblServer.Text = server; HttpContext.Current.Session["Server"] = server; } catch (Exception ex) { } try { lblInstance.Text = new DirectoryInfo(Path.GetDirectoryName( Request.PhysicalApplicationPath )).Name; } catch { } }
private void DeleteFile(string relativePath, string server) { try { ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", server )); string result = service.Request( service.Address + "?Method=DeleteFile&Path=" + relativePath, new byte[0] ); if (this.FileStates.ContainsKey(relativePath)) { this.FileStates.Remove(relativePath); } if (this.Files.ContainsKey(relativePath)) { this.Files.Remove(relativePath); } } catch (Exception ex) { } }
private bool GetServerSynchState(string ip) { if (this.ServersSynchStates.ContainsKey(ip)) { return(this.ServersSynchStates[ip]); } bool result = false; try { ServiceLink service = new ServiceLink(string.Format( "http://{0}/Handlers/Public.ashx", ConfigurationManager.AppSettings["LinkAdminHostname"] )); // Get server state of target. string serverState = service.Request(service.Address + "?Method=GetServerState" + (string.IsNullOrEmpty(ip) ? "" : ("&IP=" + ip)), new byte[0]); if (serverState == "Online") { result = true; } } catch { } this.ServersSynchStates.Add(ip, result); return(this.ServersSynchStates[ip]); }
public ConnectionQuality GetConnectionQuality() { try { ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", this.IP )); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); bool result = false; try { service.Request(new string[] { "Method=Ping" }); result = true; } catch { } stopwatch.Stop(); return(new ConnectionQuality(result, stopwatch.ElapsedMilliseconds)); } catch { return(new ConnectionQuality()); } }
public InstanceCollection(ServerCollection servers = null) { this.Servers = servers; this.Instances = new Dictionary <string, Instance>(); if (this.Servers == null) { // Get all defined servers. this.Servers = new ServerCollection(Path.Combine( HttpContext.Current.Request.PhysicalApplicationPath, "App_Data", "Servers.xml" )); } foreach (string ip in this.Servers.Items.Keys) { Server server = this.Servers.Items[ip]; if (server.State == ServerState.Offline) { continue; } ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", server.IP )); string xmlString; try { xmlString = service.Request(new string[] { "Method=GetInstances" }); } catch (Exception ex) { continue; } XmlDocument document = new XmlDocument(); document.LoadXml(xmlString); foreach (XmlNode xmlNode in document.DocumentElement.SelectNodes("Instance")) { string instanceName = xmlNode.Attributes["Name"].Value; if (!this.Instances.ContainsKey(instanceName)) { this.Instances.Add(instanceName, new Instance(this, xmlNode)); } this.Instances[instanceName].BindPortals(xmlNode, server); } } }
private void SynchFile(string server, string client, string path) { //TEST: //server = "127.0.0.1"; if (!File.Exists(path)) { return; } FileInfo fInfo = new FileInfo(path); string relativePath = path.Replace(Path.GetDirectoryName( ConfigurationManager.AppSettings["InstanceRoot"]), ""); if (this.FileStates.ContainsKey(relativePath) && long.Parse(this.FileStates[relativePath]) >= long.Parse(fInfo.LastWriteTimeUtc.ToString("yyyyMMddHHmmssfff"))) { return; } try { ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", server )); string result = service.Request( service.Address + "?Method=SynchFile&Path=" + relativePath + "&LastWriteTime=" + fInfo.LastWriteTimeUtc.ToString("yyyyMMddHHmmssfff"), File.ReadAllBytes(path) ); if (!this.LatestFileSynchActions.ContainsKey(client)) { this.LatestFileSynchActions.Add(client, DateTime.UtcNow); } else { this.LatestFileSynchActions[client] = DateTime.UtcNow; } if (!this.FileStates.ContainsKey(relativePath)) { this.FileStates.Add(relativePath, fInfo.LastWriteTimeUtc.ToString("yyyyMMddHHmmssfff")); } else { this.FileStates[relativePath] = fInfo.LastWriteTimeUtc.ToString("yyyyMMddHHmmssfff"); } this.SynchLog.Files++; } catch (Exception ex) { this.SynchLog.FilesFailed++; } }
public ServerCollection() { this.Source = null; ServiceLink service = new ServiceLink(string.Format( "http://{0}/Handlers/Public.ashx", ConfigurationManager.AppSettings["LinkAdminHostname"] )); XmlDocument document = new XmlDocument(); document.LoadXml(service.Request(new string[] { "Method=GetServers" })); Parse(document); }
public void Save() { // Create a new string builder that // contains the result xml string. StringBuilder result = new StringBuilder(); result.Append("<Servers>"); // Run through all defined servers. foreach (Server server in this.Items.Values) { result.Append(string.Format( "<Server IP=\"{0}\" Description=\"{1}\" Role=\"{2}\" Countries=\"{3}\" State=\"{4}\"></Server>", server.IP, server.Description, server.Role.ToString(), string.Join(",", server.Countries), server.State.ToString() )); } result.Append("</Servers>"); if (this.Source != null) { System.IO.File.WriteAllText( this.Source, result.ToString() ); } else { ServiceLink service = new ServiceLink(string.Format( "http://{0}/Handlers/Public.ashx", ConfigurationManager.AppSettings["LinkAdminHostname"] )); service.Request(new string[] { "Method=SetServers&Data=" + HttpUtility.UrlEncode(result.ToString()) }); } }
public ServerCollection() { // Create a new list for the result server list. this.Items = new Dictionary <string, Server>(); // Create a new xml document that // contains the server configuration. XmlDocument document = new XmlDocument(); // Build the full path to the server // configuration file and load it's // contents to the xml document. /*document.Load(Path.Combine( * Global.SwitchRoot, * "App_Data", * "Servers.xml" * ));*/ ServiceLink service = new ServiceLink( ConfigurationManager.AppSettings["LinkSwitchServiceUrl"] ); document.LoadXml(service.Request(new string[] { "Method=GetServers" })); // Run through all xml nodes that define a server. foreach (XmlNode xmlNode in document.DocumentElement.SelectNodes("Server")) { Server server = new Server(xmlNode); if (this.Items.ContainsKey(server.IP)) { continue; } // Parse the server definition. this.Items.Add(server.IP, server); } }
public bool SynchEnabled() { if (this.State == ServerState.Offline) { return(false); } ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", this.IP )); try { return(bool.Parse(service.Request(new string[] { "Method=SynchEnabled" }))); } catch { return(false); } }
protected void Session_Start(object sender, EventArgs e) { // Initialize the session's language manager. LanguageManager = new LanguageManager("", HttpContext.Current.Request.PhysicalApplicationPath); Language = LanguageManager.DefaultLanguage; // Initialize the session's permission core. //PermissionCore = new PermissionCore.PermissionCore("LinkOnline"); // Initialize the session's client manager. ClientManager = new ClientManager(); try { HttpContext.Current.Session["Version"] = System.Reflection.Assembly. GetExecutingAssembly().GetName().Version.ToString().Replace(".", ""); } catch { } ClearSessionTemp(); HierarchyFilters = new HierarchyFilterCollection(); try { ServiceLink service = new ServiceLink(string.Format( "http://{0}/Handlers/Public.ashx", ConfigurationManager.AppSettings["LinkAdminHostname"] )); string server = service.Request(new string[] { "Method=WhoAmI" }); HttpContext.Current.Session["Server"] = server; } catch (Exception ex) { } }
private void DeployUpdateAsynch(object _parameters) { object[] paramters = (object[])_parameters; Instance instance = (Instance)paramters[0]; HttpSessionState session = (HttpSessionState)paramters[1]; InstanceVersion version = new InstanceVersion((string)paramters[2]); string physicalApplicationPath = (string)paramters[3]; StringBuilder result = new StringBuilder(); result.Append("<Servers>"); int step = 0; foreach (string server in instance.Servers) { session["DeploymentStep"] = step++; // Take the server offline for the deployment. instance.Owner.Servers.Items[server].State = ServerState.Offline; instance.Owner.Servers.Save(); session["DeploymentStep"] = step++; ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", server )); string xmlString = service.Request(new string[] { "Method=DeployUpdate", "Instance=" + instance.Name, "Version=" + version.ToString() }); result.Append(string.Format( "<Server IP=\"{0}\">{1}</Server>", server, xmlString )); session["DeploymentStep"] = step++; // Bring the server online. instance.Owner.Servers.Items[server].State = ServerState.Online; instance.Owner.Servers.Save(); } result.Append("</Servers>"); string fileName = Path.Combine( physicalApplicationPath, "Logs", "Deployment_" + DateTime.Now.ToString("yyyyMMddHHmmss") ); File.WriteAllText( fileName, result.ToString() ); session["DeploymentResult"] = fileName; session["DeploymentStep"] = null; }
private void GetUsers(HttpContext context) { // Get the instance name from // the http request's parameters. string instanceName = context.Request.Params["Instance"]; // Get the client name from // the http request's parameters. string clientName = context.Request.Params["Client"]; string server = context.Request.Params["Server"]; ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", server )); string xmlString = service.Request(new string[] { "Method=GetUsers", "Client=" + clientName, "Instance=" + instanceName }); XmlDocument document = new XmlDocument(); document.LoadXml(xmlString); StringBuilder result = new StringBuilder(); result.Append("<table class=\"TableContent\">"); result.Append("<tr class=\"TableHeadline\">"); result.Append(string.Format( "<td>{0}</td>", Global.LanguageManager.GetText("Name") )); result.Append(string.Format( "<td>{0}</td>", Global.LanguageManager.GetText("FirstName") )); result.Append(string.Format( "<td>{0}</td>", Global.LanguageManager.GetText("LastName") )); result.Append(string.Format( "<td>{0}</td>", Global.LanguageManager.GetText("Mail") )); result.Append("</tr>"); foreach (XmlNode xmlNode in document.DocumentElement.SelectNodes("User")) { result.Append("<tr>"); result.Append(string.Format( "<td>{0}</td>", xmlNode.Attributes["Name"].Value )); result.Append(string.Format( "<td>{0}</td>", xmlNode.Attributes["FirstName"].Value )); result.Append(string.Format( "<td>{0}</td>", xmlNode.Attributes["LastName"].Value )); result.Append(string.Format( "<td>{0}</td>", xmlNode.Attributes["Mail"].Value )); result.Append("</tr>"); } result.Append("</table>"); context.Response.Write(result.ToString()); }
private void GetLatestSynchAction(HttpContext context) { ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", context.Request.Params["Server"] )); string xmlString = service.Request(new string[] { "Method=GetLatestSynchActions" }); if (string.IsNullOrEmpty(xmlString)) { context.Response.Write("N/A"); return; } XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(xmlString); StringBuilder result = new StringBuilder(); result.Append("<table class=\"TableContent\">"); result.Append("<tr class=\"TableHeadline\">"); result.Append(string.Format( "<td>{0}</td>", Global.LanguageManager.GetText("Client") )); result.Append(string.Format( "<td>{0}</td>", Global.LanguageManager.GetText("LatestSynchActionFilesystem") )); result.Append(string.Format( "<td>{0}</td>", Global.LanguageManager.GetText("LatestSynchActionDatabase") )); result.Append("</tr>"); foreach (XmlNode xmlNode in xmlDocument.DocumentElement.ChildNodes) { string filesystem = GetLatestSynchActionStr(xmlNode.Attributes["Filesystem"].Value); string database = GetLatestSynchActionStr(xmlNode.Attributes["Database"].Value); if (filesystem == null && database == null) { continue; } result.Append("<tr>"); result.Append(string.Format( "<td>{0}</td>", xmlNode.Attributes["Client"].Value )); result.Append(string.Format( "<td>{0}</td>", filesystem != null ? filesystem : "-" )); result.Append(string.Format( "<td>{0}</td>", database != null ? database : "-" )); result.Append("</tr>"); } result.Append("</table>"); context.Response.Write(result.ToString()); }
private void GetDeploymentDetails(HttpContext context) { // Get the name of the instance where to deploy to. string instance = context.Request.Params["Instance"]; InstanceCollection instances = new InstanceCollection(); if (!instances.Instances.ContainsKey(instance)) { return; } InstanceVersion instanceVerion = new InstanceVersion( instances.Instances[instance].Version ); // Create a new string builder that // contains the result JSON string. StringBuilder result = new StringBuilder(); result.Append("{"); result.Append(string.Format( "\"FromVersion\": \"{0}\",", instances.Instances[instance].Version )); result.Append(string.Format( "\"Errors\": [", instances.Instances[instance].Version )); bool hasErrors = false; foreach (string server in instances.Instances[instance].Servers) { if (instances.Servers.Items.ContainsKey(server) == false || instances.Servers.Items[server].State == ServerState.Offline) { hasErrors = true; result.Append(string.Format("\"{0}\",", string.Format(Global.LanguageManager.GetText( "SoftwareUpdateError_ServerOffline"), instances.Servers.Items.ContainsKey(server) ? instances.Servers.Items[server].Description : server ))); } } if (hasErrors) { result = result.Remove(result.Length - 1, 1); result.Append("]}"); context.Response.Write(result.ToString()); return; } result.Append("],"); result.Append("\"AvailableUpdates\": ["); ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", instances.Instances[instance].Servers[0] )); XmlDocument document = new XmlDocument(); document.LoadXml(service.Request(new string[] { "Method=GetAvailableUpdates" })); foreach (XmlNode xmlNode in document.DocumentElement.SelectNodes("Update")) { InstanceVersion version = new InstanceVersion( xmlNode.Attributes["Version"].Value ); if (version.ToInt() <= instanceVerion.ToInt()) { continue; } result.Append(string.Format( "\"{0}\",", (version).ToString() )); } if (result.ToString().EndsWith(",")) { result = result.Remove(result.Length - 1, 1); } result.Append("]"); result.Append("}"); context.Response.Write(result.ToString()); }
private void CreateClient(HttpContext context) { // Get the client name from // the http request's parameters. string clientName = context.Request.Params["Client"]; // Get the source instance name from // the http request's parameters. string instanceName = context.Request.Params["Instance"]; Guid[] defaultUsers = context.Request.Params["DefaultUsers"].Split(','). Select(x => Guid.Parse(x)).ToArray(); List <string> _servers = context.Request.Params["Servers"].Split( new string[] { "," }, StringSplitOptions.RemoveEmptyEntries ).ToList(); // Create on one server only, synch will do the rest. //string server = servers[0]; foreach (string server in _servers) { List <string> servers = new List <string>(); servers.AddRange(_servers.ToArray()); for (int i = 0; i < servers.Count; i++) { if (servers[i] == server) { servers.RemoveAt(i); break; } } ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", server )); string result = service.Request(new string[] { "Method=CreateClient", "Instance=" + instanceName, "Client=" + clientName, "Servers=" + string.Join(",", servers) }); if (result.StartsWith("__ERROR__")) { context.Response.Write(result); return; } XmlDocument document = new XmlDocument(); document.Load(Path.Combine( context.Request.PhysicalApplicationPath, "App_Data", "DefaultUsers.xml" )); foreach (Guid idDefaultUser in defaultUsers) { XmlNode xmlNodeDefaultUser = document.DocumentElement.SelectSingleNode(string.Format( "User[@Id=\"{0}\"]", idDefaultUser )); if (xmlNodeDefaultUser == null) { continue; } service.Request(new string[] { "Method=CreateUser", "Instance=" + instanceName, "Client=" + clientName, "Id=" + idDefaultUser, "Name=" + xmlNodeDefaultUser.Attributes["Name"].Value, "FirstName=" + xmlNodeDefaultUser.Attributes["FirstName"].Value, "LastName=" + xmlNodeDefaultUser.Attributes["LastName"].Value, "Mail=" + xmlNodeDefaultUser.Attributes["Mail"].Value, "Password="******"Password"].Value, "IdRole=" + "00000000-0000-0000-0000-000000000000" }); } } }
private void SynchDatabases() { string directoryName = Path.Combine(ConfigurationManager.AppSettings["SynchQueuePath"]); foreach (string server in Directory.GetDirectories(directoryName)) { DirectoryInfo dirInfo = new DirectoryInfo(server); // TEST ONLY: /*if (dirInfo.Name != "127.0.0.1") * continue;*/ /*if (!Directory.Exists(Path.Combine(server, "DATABASE"))) * continue;*/ foreach (string synchFile in Directory.GetFiles(server).OrderBy(x => new FileInfo(x).CreationTime)) { try { // Get server state of target. bool serverState = GetServerSynchState(dirInfo.Name); if (!serverState) { continue; } XmlDocument document = new XmlDocument(); document.Load(synchFile); string databaseName = document.DocumentElement.SelectSingleNode("Database").InnerXml; ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", dirInfo.Name )); try { string result = service.Request( service.Address + "?Method=ExecuteSynch", File.ReadAllBytes(synchFile) ); if (bool.Parse(result) == true) { File.Delete(synchFile); if (!this.LatestDatabaseSynchActions.ContainsKey(databaseName.ToLower())) { this.LatestDatabaseSynchActions.Add(databaseName.ToLower(), DateTime.UtcNow); } else { this.LatestDatabaseSynchActions[databaseName.ToLower()] = DateTime.UtcNow; } this.SynchLog.Queries++; } else { this.SynchLog.QueriesFailed++; } } catch { this.SynchLog.QueriesFailed++; } } catch (Exception ex) { this.SynchLog.QueriesFailed++; } } } }
public override void Render() { // Get all defined servers. ServerCollection servers = new ServerCollection(Path.Combine( HttpContext.Current.Request.PhysicalApplicationPath, "App_Data", "Servers.xml" )); int count = 0; // Run through all defined servers. foreach (string ip in servers.Items.Keys) { ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", ip )); XmlDocument document = new XmlDocument(); try { document.LoadXml(service.Request(new string[] { "Method=GetLog" })); } catch { continue; } pnlServers.Controls.Add(new LiteralControl(string.Format( "<div class=\"ConsoleTab {2}\" onclick=\"ShowConsoleTab(this, '{1}')\">{0}</div>", ip, ip.Replace(".", "_"), count == 0 ? "ConsoleTab_Active" : "" ))); StringBuilder htmlString = new StringBuilder(); htmlString.Append(string.Format( "<div id=\"pnlConsole{0}\" style=\"{1}\" class=\"LogEntries\">", ip.Replace(".", "_"), count != 0 ? "display:none;" : "" )); foreach (XmlNode xmlNode in document.DocumentElement.ChildNodes) { htmlString.Append(string.Format( "<div class=\"LogEntry LogType_{2}\">[{1}] {3}</div>", ip, xmlNode.Attributes["Timestamp"].Value, xmlNode.Attributes["Type"].Value, xmlNode.InnerText )); } htmlString.Append("</div>"); pnlConsole.Controls.Add(new LiteralControl(htmlString.ToString())); count++; } }
private void GetFileSynchStates() { this.FileStates = new Dictionary <string, string>(); this.Files = new Dictionary <string, string>(); InstanceCollection instances = new InstanceCollection( ConfigurationManager.AppSettings["InstanceRoot"] ); List <string> servers = new List <string>(); foreach (Instance instance in instances.Instances.Values) { foreach (Client client in instance.GetClients()) { if (client.SynchServers.Length == 0) { continue; } foreach (string server in client.SynchServers) { // TEST: //string server = "127.0.0.1"; if (servers.Contains(server)) { continue; } servers.Add(server); } } } foreach (string server in servers) { try { ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", server )); string result = service.Request( service.Address + "?Method=GetFileSynchStates", new byte[0] ); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(result); foreach (XmlNode xmlNode in xmlDocument.DocumentElement.SelectNodes("File")) { string path = xmlNode.Attributes["Path"].Value; if (this.FileStates.ContainsKey(path)) { continue; } this.FileStates.Add(path, xmlNode.Attributes["Value"].Value); this.Files.Add(path, server); } } catch (Exception ex) { } } }
private string CheckSession() { string sessionId = ""; try { ServerCollection servers = new ServerCollection(Path.Combine( Request.PhysicalApplicationPath, "App_Data", "Servers.xml" )); string server; if (Request.Cookies["ASP.NET_SessionId"] != null) { sessionId = Request.Cookies["ASP.NET_SessionId"].Value; if (!Global.Sessions.ContainsKey(sessionId)) { //sessionId = GenerateNewSessionId(); //Request.Cookies.Remove("ASP.NET_SessionId"); //Request.Cookies.Add(new HttpCookie("ASP.NET_SessionId", sessionId)); server = servers.GetServer(Request.ServerVariables["REMOTE_HOST"]); } else if (servers.Items.ContainsKey(Global.Sessions[sessionId]) == false || servers.Items[Global.Sessions[sessionId]].State == ServerState.Offline) { server = servers.GetServer(Request.ServerVariables["REMOTE_HOST"]); } else { server = Global.Sessions[sessionId]; } if (server == null) { ShowOverloadMessage(); return(null); } } else { server = servers.GetServer(Request.ServerVariables["REMOTE_HOST"]); if (server == null) { ShowOverloadMessage(); return(null); } ServiceLink service = new ServiceLink(string.Format( "http://{0}/Handlers/GlobalHandler.ashx", server )); /*Dictionary<string, string> cookies = new Dictionary<string, string>(); * * cookies.Add("ASP.NET_SessionId", GenerateNewSessionId());*/ sessionId = service.Request(new string[] { "Method=CreateSession" }); Request.Cookies.Add(new HttpCookie("ASP.NET_SessionId", sessionId)); } if (!Global.Sessions.ContainsKey(sessionId)) { Global.Sessions.Add( sessionId, server ); } else { Global.Sessions[sessionId] = server; } } catch (Exception ex) { Response.Write(ex.ToString()); Response.End(); return(null); } return(sessionId); }
private void SessionSynchTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { SessionSynchTimer.Stop(); try { this.ServersSynchStates = new Dictionary <string, bool>(); // Get server state of self. bool serverState = GetServerSynchState( ConfigurationManager.AppSettings["ServerIP"] ); /*if (!serverState) * { * SessionSynchTimer.Start(); * return; * }*/ string physicalApplicationPath = HttpRuntime.AppDomainAppPath; ClientManager clientManager = new ClientManager(); foreach (string clientName in Global.AllSessions.Keys) { Client client = clientManager.GetSingle(clientName); if (client == null) { continue; } if (client.SynchServers.Length == 0) { continue; } foreach (Guid idUser in Global.AllSessions[clientName].Keys) { string sessionId = Global.AllSessions[clientName][idUser].SessionID; if (!this.SessionSynchLog.ContainsKey(sessionId)) { this.SessionSynchLog.Add(sessionId, new Dictionary <string, string>()); } StringBuilder xmlBuilder = new StringBuilder(); if (Global.AllSessions[clientName][idUser]["User"] == null) { continue; } foreach (string key in Global.AllSessions[clientName][idUser].Keys) { try { if (Global.AllSessions[clientName][idUser][key] == null) { continue; } //byte[] bytes = HttpContext.Current.Session[key].ToByteArray(); string valueStr = Global.AllSessions[clientName][idUser][key].ToString(); string typeName = Global.AllSessions[clientName][idUser][key].GetType().Name; switch (typeName) { case "Guid": case "Language": case "Int16": case "Int32": case "Int64": break; case "String": if (File.Exists(valueStr)) { typeName = "Path"; valueStr = valueStr.Replace( physicalApplicationPath, "" ); } break; default: continue; } if (!this.SessionSynchLog[sessionId].ContainsKey(key)) { this.SessionSynchLog[sessionId].Add(key, ""); } if (this.SessionSynchLog[sessionId][key] == valueStr) { continue; } xmlBuilder.Append(string.Format( "<Value Key=\"{0}\" Type=\"{2}\"><![CDATA[{1}]]></Value>", key, valueStr,//System.Text.Encoding.UTF8.GetString(bytes), typeName )); this.SessionSynchLog[sessionId][key] = valueStr; } catch { } } if (xmlBuilder.Length == 0) { continue; } foreach (string server in client.SynchServers) { // Check if the server is online. /*if (!GetServerSynchState(server)) * { * this.SessionSynchLog[sessionId].Clear(); * continue; * }*/ try { Dictionary <string, string> cookies = new Dictionary <string, string>(); cookies.Add("ASP.NET_SessionId", sessionId); ServiceLink service = new ServiceLink(string.Format( "http://{0}/Handlers/Synch.ashx", server )); service.HostHeader = client.Host; service.Request(new string[] { "Method=SetSessionUpdates" }, System.Text.Encoding.UTF8.GetBytes(string.Format( "<Session Id=\"{0}\" Client=\"{2}\" IdUser=\"{3}\">{1}</Session>", sessionId, xmlBuilder.ToString(), clientName, idUser )), cookies); } catch (Exception ex) { this.SessionSynchLog[sessionId].Clear(); } } } } } catch { } SessionSynchTimer.Start(); }
private void CheckDeletedFiles() { return; string fileName; foreach (string file in this.FileStates.Keys) { fileName = Path.Combine( ConfigurationManager.AppSettings["InstanceRoot"], file.Remove(0, 1) ); InstanceCollection instances = new InstanceCollection( ConfigurationManager.AppSettings["InstanceRoot"] ); List <string> servers = new List <string>(); foreach (Instance instance in instances.Instances.Values) { foreach (Client client in instance.GetClients()) { if (client.SynchServers.Length == 0) { continue; } foreach (string server in client.SynchServers) { // TEST: //string server = "127.0.0.1"; if (servers.Contains(server)) { continue; } servers.Add(server); } } } if (!File.Exists(fileName)) { if (long.Parse(DateTime.UtcNow.ToString("yyyyMMddHHmmssfff")) - long.Parse(this.FileStates[file]) > 10000) { foreach (string server in servers) { //File.Delete(fileName); ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", server )); string result = service.Request( service.Address + "?Method=DeleteFile&Path=" + file.Remove(0, 1), new byte[0] ); } } } } }