Inheritance: AcManager.Tools.AcObjectsNew.AcObjectNew, IComparer
        public void OnUri(Uri uri) {
            _type = uri.GetQueryParamEnum<OnlineManagerType>("Mode");
            _manager = BaseOnlineManager.ManagerByMode(_type);

            var id = uri.GetQueryParam("Id");
            if (id == null) {
                throw new Exception(ToolsStrings.Common_IdIsMissing);
            }

            _entry = _manager.GetById(id);
            if (_entry == null) {
                throw new Exception(string.Format(AppStrings.Online_ServerWithIdIsMissing, id));
            }
        }
Beispiel #2
0
        private async Task ScanDefferedAsync() {
            BackgroundLoading = true;
            Pinged = 0;

            await Task.Run(() => {
                KunosApiProvider.TryToGetLanList(async i => {
                    try {
                        var entry = new ServerEntry(this, i, true);
                        InnerWrappersList.Add(new AcItemWrapper(this, entry));
                        if (entry.Status == ServerStatus.Unloaded) {
                            await entry.Update(ServerEntry.UpdateMode.Lite); // BUG: Wait?
                        }
                        Pinged++;
                    } catch (Exception e) {
                        Logging.Warning("Cannot create ServerEntry: " + e);
                    }
                });
            });

            BackgroundLoading = false;
        }
 public ViewModel(ServerEntry entry) {
     Entry = entry;
     FancyBackgroundManager.Instance.ChangeBackground(Entry.Track?.PreviewImage);
 }
Beispiel #4
0
 public IEnumerable <string> GetSourceKeys(ServerEntry entry)
 {
     return(_sources.Where(x => x.Value.Contains(entry)).Select(x => x.Key));
 }
Beispiel #5
0
 public static void RemoveFromList(string key, ServerEntry server)
 {
     Instance.GetInternalSource(key).Remove(server);
 }
Beispiel #6
0
 public static void AddToList(string key, ServerEntry server)
 {
     Instance.GetInternalSource(key).Add(server);
 }
Beispiel #7
0
 public void Remove(ServerEntry entry)
 {
     Remove(entry.Id);
 }
Beispiel #8
0
 internal bool Contains(ServerEntry entry)
 {
     return(_entries?.GetByIdOrDefault(entry.Id) != null);
 }
Beispiel #9
0
 public void AvoidRemoval(ServerEntry entry)
 {
     _removeWhenReleased.Remove(entry);
 }
Beispiel #10
0
 public void RemoveWhenReleased(ServerEntry entry)
 {
     _removeWhenReleased.Add(entry);
 }
Beispiel #11
0
 public bool IsHolded(ServerEntry entry)
 {
     return(_holdedList.Contains(entry));
 }
Beispiel #12
0
        public void Show(ServerEntry server) {
            ServerEntry = server;

            if (!ReferenceEquals(DataContext, this)) {
                DataContext = this;
                InitializeComponent();
                Show();

                Owner = Application.Current.MainWindow;

                _timer = new DispatcherTimer {
                    Interval = TimeSpan.FromSeconds(1),
                    IsEnabled = true
                };
                _timer.Tick += OnTick;
            }

            Car = server.SelectedCarEntry?.CarObject;
            Track = server.Track;

            try {
                _ignoreSkinChange = true;
                Skin = server.GetSelectedCarSkin();
            } finally {
                _ignoreSkinChange = false;
            }

            Buttons = new[] {
                CreateExtraStyledDialogButton("Go.Button", AppStrings.Common_Go, () => ServerEntry?.JoinCommand.Execute(ServerEntry.ActualJoin), () => Ready),
                CancelButton
            };
        }
Beispiel #13
0
        private void Add([NotNull] IEnumerable <ServerInformation> informations)
        {
            if (_first)
            {
                _first = false;

                var newEntries = new List <ServerEntry>((informations as IReadOnlyList <ServerInformation>)?.Count ?? 300);
                foreach (var information in informations)
                {
                    var existing = _list.GetByIdOrDefault(information.Id);
                    if (existing == null)
                    {
                        var entry = new ServerEntry(information);
                        entry.SetOrigin(Key);
                        entry.SetReferences(FileBasedOnlineSources.Instance.GetSourceKeys(entry));
                        newEntries.Add(entry);
                    }
                    else
                    {
                        existing.SetOrigin(Key);
                        existing.UpdateValues(information);
                        OnlineManager.Instance.AvoidRemoval(existing);
                    }
                }

                var target = _list as ChangeableObservableCollection <ServerEntry>;
                if (target == null || newEntries.Count < 10)
                {
                    foreach (var entry in newEntries)
                    {
                        _list.Add(entry);
                    }
                }
                else
                {
                    target.AddRange_Direct(newEntries);
                }
            }
            else
            {
                var list = informations.ToIReadOnlyListIfItIsNot();

                foreach (var information in list)
                {
                    var existing = _list.GetByIdOrDefault(information.Id);
                    if (existing == null)
                    {
                        var entry = new ServerEntry(information);
                        entry.SetOrigin(Key);
                        _list.Add(entry);
                    }
                    else
                    {
                        existing.SetOrigin(Key);
                        existing.UpdateValues(information);
                        OnlineManager.Instance.AvoidRemoval(existing);
                    }
                }

                for (var i = _list.Count - 1; i >= 0; i--)
                {
                    if (list.GetByIdOrDefault(_list[i].Id) == null)
                    {
                        var serverEntry = _list[i];
                        var empty       = serverEntry.RemoveOrigin(_source.Id);

                        if (empty)
                        {
                            if (OnlineManager.Instance.IsHolded(serverEntry))
                            {
                                OnlineManager.Instance.RemoveWhenReleased(serverEntry);
                            }
                            else
                            {
                                _list.RemoveAt(i);
                            }
                        }
                    }
                }
            }
        }