protected override void Execute(ThreadPool owner) { bool deliveredAsms = false; bool connectionClosed = false; try { lock (_ListLock) { bool initComplete = true; List <string> listContent = _ClientList.Descriptions.Select(j => STEM.Sys.IO.Path.AdjustPath(j.Filename).ToUpper()).ToList(); List <string> localContent; while (true) { try { localContent = _MasterList.Descriptions.Select(j => STEM.Sys.IO.Path.AdjustPath(j.Filename).ToUpper()).ToList(); break; } catch { } } string platform = ""; if (_ClientList.IsWindows) { platform = "win-x86"; if (_ClientList.IsX64) { platform = "win-x64"; } } else { platform = "linux-x86"; if (_ClientList.IsX64) { platform = "linux-x64"; } } foreach (string name in localContent.ToList()) { STEM.Sys.IO.FileDescription f = null; while (true) { try { f = _MasterList.Descriptions.FirstOrDefault(i => i.Filename.Equals(name, StringComparison.InvariantCultureIgnoreCase)); break; } catch { } } string fullPath = System.IO.Path.Combine(f.Filepath, f.Filename); if (fullPath.IndexOf("win-x86", StringComparison.InvariantCultureIgnoreCase) >= 0 && !platform.Equals("win-x86", StringComparison.InvariantCultureIgnoreCase)) { localContent.Remove(name); } if (fullPath.IndexOf("win-x64", StringComparison.InvariantCultureIgnoreCase) >= 0 && !platform.Equals("win-x64", StringComparison.InvariantCultureIgnoreCase)) { localContent.Remove(name); } if (fullPath.IndexOf("linux-x86", StringComparison.InvariantCultureIgnoreCase) >= 0 && !platform.Equals("linux-x86", StringComparison.InvariantCultureIgnoreCase)) { localContent.Remove(name); } if (fullPath.IndexOf("linux-x64", StringComparison.InvariantCultureIgnoreCase) >= 0 && !platform.Equals("linux-x64", StringComparison.InvariantCultureIgnoreCase)) { localContent.Remove(name); } } initComplete = localContent.Except(listContent).Count() == 0; if (initComplete) { if (!_ClientList.MessageConnection.Send(new AssemblyInitializationComplete())) { STEM.Sys.EventLog.WriteEntry("AssemblySync.DeliverDelta", "SendAssemblyList: Forced disconnect, " + _ClientList.MessageConnection.RemoteAddress, STEM.Sys.EventLog.EventLogEntryType.Information); _ClientList.MessageConnection.Close(); connectionClosed = true; } ExecutionInterval = TimeSpan.FromSeconds(30); return; } AssemblyList send = new AssemblyList(); send.Path = _ClientList.Path; foreach (string name in localContent.Except(listContent).ToList()) { STEM.Sys.IO.FileDescription f = null; while (true) { try { f = _MasterList.Descriptions.FirstOrDefault(i => i.Filename.Equals(name, StringComparison.InvariantCultureIgnoreCase)); break; } catch { } } send.Descriptions.Add(f); _ClientList.Descriptions.Add(new STEM.Sys.IO.FileDescription(f.Filepath, f.Filename, false)); if (!_ClientList.MessageConnection.Send(send)) { try { STEM.Sys.EventLog.WriteEntry("AssemblySync.DeliverDelta", "SendAssemblyList: Forced disconnect, " + _ClientList.MessageConnection.RemoteAddress, STEM.Sys.EventLog.EventLogEntryType.Information); _ClientList.MessageConnection.Close(); connectionClosed = true; } catch { } return; } send.Descriptions.Clear(); deliveredAsms = true; } if (send.Descriptions.Count > 0) { if (!_ClientList.MessageConnection.Send(send)) { try { STEM.Sys.EventLog.WriteEntry("AssemblySync.DeliverDelta", "SendAssemblyList: Forced disconnect, " + _ClientList.MessageConnection.RemoteAddress, STEM.Sys.EventLog.EventLogEntryType.Information); _ClientList.MessageConnection.Close(); connectionClosed = true; } catch { } return; } send.Descriptions.Clear(); deliveredAsms = true; } if (deliveredAsms) { _ClientList.MessageConnection.Send(send); } } } catch { } finally { if (connectionClosed) { owner.EndAsync(this); } } }
void DeliverDelta(object o) { MessageConnection connection = o as MessageConnection; AssemblyList list = null; lock (_AssemblyLists) { list = _AssemblyLists.FirstOrDefault(i => i.MessageConnection == connection); if (list == null) { _Pool.EndAsync(new System.Threading.ParameterizedThreadStart(DeliverDelta), o); return; } } bool deliveredAsms = false; bool connectionClosed = false; try { lock (list) { bool initComplete = true; List <string> listContent = list.Descriptions.Select(j => STEM.Sys.IO.Path.AdjustPath(j.Filename).ToUpper()).ToList(); List <string> localContent; while (true) { try { localContent = AssemblyList.Descriptions.Select(j => STEM.Sys.IO.Path.AdjustPath(j.Filename).ToUpper()).ToList(); break; } catch { } } string platform = ""; if (list.IsWindows) { platform = "win-x86"; if (list.IsX64) { platform = "win-x64"; } } else { platform = "linux-x86"; if (list.IsX64) { platform = "linux-x64"; } } foreach (string name in localContent.ToList()) { STEM.Sys.IO.FileDescription f = null; while (true) { try { f = AssemblyList.Descriptions.FirstOrDefault(i => i.Filename.Equals(name, StringComparison.InvariantCultureIgnoreCase)); break; } catch { } } string fullPath = System.IO.Path.Combine(f.Filepath, f.Filename); if (fullPath.IndexOf("win-x86", StringComparison.InvariantCultureIgnoreCase) >= 0 && !platform.Equals("win-x86", StringComparison.InvariantCultureIgnoreCase)) { localContent.Remove(name); } if (fullPath.IndexOf("win-x64", StringComparison.InvariantCultureIgnoreCase) >= 0 && !platform.Equals("win-x64", StringComparison.InvariantCultureIgnoreCase)) { localContent.Remove(name); } if (fullPath.IndexOf("linux-x86", StringComparison.InvariantCultureIgnoreCase) >= 0 && !platform.Equals("linux-x86", StringComparison.InvariantCultureIgnoreCase)) { localContent.Remove(name); } if (fullPath.IndexOf("linux-x64", StringComparison.InvariantCultureIgnoreCase) >= 0 && !platform.Equals("linux-x64", StringComparison.InvariantCultureIgnoreCase)) { localContent.Remove(name); } } initComplete = localContent.Except(listContent).Count() == 0; if (initComplete) { if (!list.MessageConnection.Send(new AssemblyInitializationComplete())) { if (!list.MessageConnection.Send(new AssemblyInitializationComplete())) { list.MessageConnection.Close(); connectionClosed = true; return; } } } AssemblyList send = new AssemblyList(); send.Path = list.Path; foreach (string name in localContent.Except(listContent).ToList()) { STEM.Sys.IO.FileDescription f = AssemblyList.Descriptions.FirstOrDefault(i => i.Filename.Equals(name, StringComparison.InvariantCultureIgnoreCase)); string fullPath = System.IO.Path.Combine(f.Filepath, f.Filename); send.Descriptions.Add(f); list.Descriptions.Add(new STEM.Sys.IO.FileDescription(f.Filepath, f.Filename, false)); if (!list.MessageConnection.Send(send)) { try { STEM.Sys.EventLog.WriteEntry("AssemblySync.DeliverDelta", "SendAssemblyList: Forced disconnect, " + list.MessageConnection.RemoteAddress, STEM.Sys.EventLog.EventLogEntryType.Information); list.MessageConnection.Close(); connectionClosed = true; } catch { } return; } send.Descriptions.Clear(); deliveredAsms = true; } if (send.Descriptions.Count > 0) { if (!list.MessageConnection.Send(send)) { try { list.MessageConnection.Close(); connectionClosed = true; } catch { } return; } send.Descriptions.Clear(); deliveredAsms = true; } if (deliveredAsms) { list.MessageConnection.Send(send); } } } catch { } finally { if (connectionClosed) { Dispose(connection); } } }