Пример #1
0
        public virtual bool Close()
        {
            lock (_ObjectLock)
            {
                if (!ControlOpen)
                {
                    return(false);
                }

                ControlOpen = false;
                ThreadPool.EndAsync(new System.Threading.ThreadStart(CheckInstall));
            }

            return(true);
        }
Пример #2
0
            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);
                    }
                }
            }