コード例 #1
0
 public void RemoveAndDisposeRange(IEnumerable <IWuEndpoint> endpoints)
 {
     if (endpoints == null)
     {
         throw new ArgumentNullException(nameof(endpoints));
     }
     // To prevent a InvalidOperationException like "Collection was modified;
     // enumeration operation may not execute.",
     // create a separate enumeration to allow to remove items from the endpoint list.
     endpoints = endpoints.ToList();
     foreach (var endpoint in endpoints)
     {
         _endpoints.Remove(endpoint);
         endpoint?.Dispose();
     }
 }
コード例 #2
0
            public void It_returns_false_when_collection_does_not_contain_item()
            {
                var collection = new SynchronizedObservableCollection <string>(new List <string> {
                    "1", "2", "3"
                });

                Assert.That(collection.Remove("4"), Is.False);
                Assert.That(collection.Count, Is.EqualTo(3));
            }
コード例 #3
0
        public bool Remove(WuRemoteCallContext item)
        {
            var result = _callHistory.Remove(item);

            if (result)
            {
                item.PropertyChanged -= PropChangedHandler;
            }
            return(result);
        }
コード例 #4
0
            public void It_returns_true_when_collection_contains_item()
            {
                var collection = new SynchronizedObservableCollection <string>(new List <string> {
                    "1", "2", "3", "3"
                });

                Assert.That(collection.Remove("3"), Is.True);
                Assert.That(collection.Count, Is.EqualTo(3));
                Assert.That(collection[0], Is.EqualTo("1"));
                Assert.That(collection[1], Is.EqualTo("2"));
                Assert.That(collection[2], Is.EqualTo("3"));
            }
コード例 #5
0
            public void It_invokes_PropertyChanged_when_collection_contains_item()
            {
                var collection = new SynchronizedObservableCollection <string>(new List <string> {
                    "1", "2", "3", "3"
                });
                var propertyChangedEventArgs = new List <PropertyChangedEventArgs>();

                ((INotifyPropertyChanged)collection).PropertyChanged += (sender, args) => { propertyChangedEventArgs.Add(args); };
                collection.Remove("3");

                Assert.That(propertyChangedEventArgs.Count, Is.EqualTo(2));
                Assert.That(propertyChangedEventArgs.Any(p => p.PropertyName.Equals("Count")), Is.True);
                Assert.That(propertyChangedEventArgs.Any(p => p.PropertyName.Equals("Item[]")), Is.True);
            }
コード例 #6
0
            public void It_invokes_CollectionChanged_when_collection_contains_item()
            {
                var collection = new SynchronizedObservableCollection <string>(new List <string> {
                    "1", "2", "3", "3"
                });
                NotifyCollectionChangedEventArgs collectionChangedEventArgs = null;

                collection.CollectionChanged += (sender, args) => { collectionChangedEventArgs = args; };
                collection.Remove("3");

                Assert.That(collectionChangedEventArgs.Action, Is.EqualTo(NotifyCollectionChangedAction.Remove));
                Assert.That(collectionChangedEventArgs.OldItems[0], Is.EqualTo("3"));
                Assert.That(collectionChangedEventArgs.OldStartingIndex, Is.EqualTo(2));
            }
コード例 #7
0
        private async void AddToFavourites(object param)
        {
            if (m_selectedResult == null)
            {
                return;
            }

            if (m_selectedResult.State == PartDatasheetState.Saved)
            {
                if (Global.MessageBox(this, Global.GetStringResource("StringDoYouWantToRemoveFromFavourites"), MessageBoxExPredefinedButtons.YesNo) != MessageBoxExButton.Yes)
                {
                    return;
                }
                m_selectedResult.RemovePdf();
                m_savedParts.Remove(m_selectedResult);
                if (IsFavouritesMode)
                {
                    m_searchResults.Remove(m_selectedResult);
                    Global.SaveSavedParts();
                }
                return;
            }

            try
            {
                ActionsCount++;
                PartViewModel part = m_selectedResult;
                await part.SavePdf();

                m_savedParts.Add(part);
                Global.SaveSavedParts();
            }
            catch
            {
                Global.MessageBox(this, Global.GetStringResource("StringDownloadError"), MessageBoxExPredefinedButtons.Ok);
            }
            finally
            {
                ActionsCount--;
            }
        }
コード例 #8
0
        //public ConcurrentDictionary<string, ServerListing> Servers
        //{
        //    get { return servers; }
        //} private ConcurrentDictionary<string, ServerListing> servers = new ConcurrentDictionary<string, ServerListing>();

        #endregion

        public void Query(string[] metaservers = null)
        {
            l.Info("[META] Querying metaservers.");

            if (metaservers == null)
            {
                metaservers = DefaultMetaservers;
            }

            foreach (var metaserver in DefaultMetaservers)
            {
                IPHostEntry host = Dns.GetHostEntry(metaserver);

                if (host == null)
                {
                    l.Error("Host DNS lookup failed for metaserver: " + metaserver);
                    continue;
                }

                Socket socket = null;

                try
                {
                    try
                    {
                        socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.IP);
                        socket.Connect(host.AddressList, NetConstants.MetaserverPort);
                    }
                    catch (Exception ex)
                    {
                        l.Warn("Failed to connect to: " + host.HostName + ".  Exception: " + ex.ToString());
                        continue;
                    }

                    if (!socket.Connected)
                    {
                        socket.Dispose();
                        continue;
                    }

                    byte[] sendBytes = ASCIIEncoding.ASCII.GetBytes("?version=_");

                    try
                    {
                        socket.Send(sendBytes);
                    }
                    catch (Exception ex)
                    {
                        l.Warn("Error sending to metaserver '" + metaserver + "': " + ex.ToString());
                        continue;
                    }

                    int packetsReceived = 0;

receive:
                    if (packetsReceived > 1)
                    {
                        l.Trace("packetsReceived > 1");
                    }

                    byte[] recvBuffer = new byte[8192];
                    int    bytesRead  = 0;
                    try
                    {
                        if (packetsReceived == 0 || socket.Poll(250, SelectMode.SelectRead))
                        {
                            socket.ReceiveTimeout = 5000; // HARDTIME TIMEOUT
                            bytesRead             = socket.Receive(recvBuffer);
                        }
                    }
                    catch (Exception ex)
                    {
                        l.Warn("Error receiving from metaserver: " + ex.ToString());
                        continue;
                    }

                    if (bytesRead == 0)
                    {
                        if (packetsReceived == 0)
                        {
                            l.Warn("Received nothing from metaserver'" + metaserver + "'");
                        }
                        continue;
                    }

                    packetsReceived++;

                    string result = ASCIIEncoding.ASCII.GetString(recvBuffer);

                    string[] lines = result.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                    int    lineCount    = 0;
                    string protocolType = null;
                    string protocolUnknown2;
                    foreach (var line in lines)
                    {
                        if (line.StartsWith(((char)0).ToString()))
                        {
                            break;
                        }

                        string[] cells = line.Split(',');

                        if (lineCount++ == 0)
                        {
                            protocolType = cells[0];
                            if (protocolType.Equals("r"))
                            {
                                protocolUnknown2 = cells[1];
                            }
                            continue;
                        }

                        ServerListing listing = null;
                        if (protocolType.Equals("r"))
                        {
                            listing         = new ServerListing(cells[0]);
                            listing.Source  = protocolType;
                            listing.Port    = Convert.ToInt32(cells[1]);
                            listing.Status  = cells[2];
                            listing.Age     = Convert.ToInt32(cells[3]);
                            listing.Players = Convert.ToInt32(cells[4]);
                            listing.Queue   = Convert.ToInt32(cells[5]);
                            listing.Type    = cells[6];
                            listing.Comment = String.Empty;
                        }
                        else if (protocolType.Equals("s"))
                        {
                            listing         = new ServerListing(cells[0]);
                            listing.Source  = protocolType;
                            listing.Type    = cells[1];
                            listing.Comment = cells[2];
                            listing.Port    = Convert.ToInt32(cells[4]);
                            listing.Players = Convert.ToInt32(cells[5]);
                            listing.Queue   = Convert.ToInt32(cells[6].Trim());
                            listing.Status  = "2"; // TODO  REVIEW
                            if (listing.Type.Equals("unknown"))
                            {
                                listing.Status = "3";                                 // TODO  REVIEW
                            }
                            listing.Age = 0;
                        }
                        else
                        {
                            l.Warn("Unknown metaserver protocol: " + protocolType);
                        }

                        if (listing != null && listing.IsSupported)
                        {
                            l.Debug("[meta] " + listing.ToString());
                            if (ServerListings.Contains(listing))
                            {
                                ServerListings.Remove(listing);
                            }
                            ServerListings.Add(listing);
                            servers.Set(listing.Key, listing);
                        }
                    }
                    goto receive;
                }
                finally
                {
                    try
                    {
                        if (socket != null)
                        {
                            socket.Dispose();
                            socket = null;
                        }
                    }
                    catch (Exception ex) { l.Trace(ex.ToString()); }
                }
            }
        }