Esempio n. 1
0
        public AcError(AcCommonObject target, AcErrorType type, params object[] args)
        {
            Target   = target;
            Type     = type;
            Category = CategoryFromType(type);

            try {
                Message = string.Format(MessageFromType(type), args.Select(x => (x as Exception)?.Message ?? x).ToArray());
            } catch (FormatException) {
                Message = Regex.Replace(MessageFromType(type), @"\{\d+\}", "?");
            }

            BaseException = args.OfType <Exception>().FirstOrDefault();

            if (Category != AcErrorCategory.CarSkin &&
                (type != AcErrorType.Data_JsonIsMissing || !Equals(args.FirstOrDefault(), @"ui_skin.json")) &&
                type != AcErrorType.Car_ParentIsMissing &&
                type != AcErrorType.Track_PreviewIsMissing &&
                type != AcErrorType.Track_OutlineIsMissing &&
                type != AcErrorType.Track_MapIsMissing)
            {
                Logging.Write(Message);
            }

            foreach (var exception in args.OfType <Exception>())
            {
                Logging.Warning(exception);
            }
        }
Esempio n. 2
0
        public WrapperContentObject(AcCommonObject acObject, string contentDirectory)
        {
            _contentDirectory = contentDirectory;
            CanBePacked       = acObject.CanBePacked();

            AcObject = acObject;
            Version  = ContentVersion = (acObject as IAcObjectVersionInformation)?.Version;

            AcObject.SubscribeWeak((sender, args) => {
                switch (args.PropertyName)
                {
                case nameof(AcCommonObject.DisplayName):
                    UpdateDisplayName();
                    break;

                case nameof(IAcObjectVersionInformation.Version):
                    var updated = (acObject as IAcObjectVersionInformation)?.Version;
                    if (Version == ContentVersion)
                    {
                        Version = updated;
                    }

                    ContentVersion = updated;
                    break;
                }
            });

            UpdateDisplayName();
            _sizeLazy          = Lazier.Create(GetSize);
            _fileIsMissingLazy = Lazier.Create(() => ShareMode == ShareMode.Directly && Filename != null && !File.Exists(Filename));
        }
Esempio n. 3
0
        protected void InitializeAcObjectPage([NotNull] ISelectedAcObjectViewModel model)
        {
            SelectedAcObject = model.SelectedAcObject;
            InputBindings.Clear();
            InputBindings.AddRange(new[] {
                new InputBinding(SelectedAcObject.ToggleFavouriteCommand, new KeyGesture(Key.B, ModifierKeys.Control)),
                new InputBinding(SelectedAcObject.CopyIdCommand, new KeyGesture(Key.C, ModifierKeys.Control)), // TODO: why doesn’t work after quick switching?
                new InputBinding(SelectedAcObject.CopyIdCommand, new KeyGesture(Key.C, ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)),
                new InputBinding(SelectedAcObject.CopyIdCommand, new KeyGesture(Key.C, ModifierKeys.Control | ModifierKeys.Shift))
                {
                    CommandParameter = @"name"
                },
                new InputBinding(SelectedAcObject.CopyIdCommand, new KeyGesture(Key.C, ModifierKeys.Control | ModifierKeys.Alt))
                {
                    CommandParameter = @"path"
                },
                new InputBinding(SelectedAcObject.ViewInExplorerCommand, new KeyGesture(Key.F, ModifierKeys.Control)),
                new InputBinding(SelectedAcObject.ReloadCommand, new KeyGesture(Key.R, ModifierKeys.Control))
                {
                    CommandParameter = @"full"
                },
                // new InputBinding(SelectedAcObject.ToggleCommand, new KeyGesture(Key.D, ModifierKeys.Control)),
                new InputBinding(new DelegateCommand(ToggleObject), new KeyGesture(Key.D, ModifierKeys.Control)),
                new InputBinding(SelectedAcObject.SaveCommand, new KeyGesture(Key.S, ModifierKeys.Control)),
                new InputBinding(model.ChangeIdCommand, new KeyGesture(Key.F2, ModifierKeys.Control | ModifierKeys.Shift)),
                new InputBinding(model.CloneCommand, new KeyGesture(Key.D, ModifierKeys.Control | ModifierKeys.Shift)),
                new InputBinding(model.FindInformationCommand, new KeyGesture(Key.I, ModifierKeys.Control)),
                new InputBinding(SelectedAcObject.DeleteCommand, new KeyGesture(Key.Delete, ModifierKeys.Control))
            });
            DataContext = model;

            if (!_set)
            {
                _set      = true;
                Loaded   += OnLoaded;
                Unloaded += OnUnloaded;
            }
            else
            {
                model.Load();
            }

            UpdateBindingsLaterAsync().Forget();
        }
Esempio n. 4
0
 public AcErrorException(AcCommonObject target, AcErrorType type, params object[] args)
 {
     AcError = new AcError(target, type, args);
 }
 private static string GetSearchAddress(AcCommonObject obj)
 {
     return(SettingsHolder.Content.SearchEngine?.GetUri(obj.Name ?? obj.Id, true) ??
            $"https://duckduckgo.com/?q=site%3Awikipedia.org+{Uri.EscapeDataString(obj.Name ?? obj.Id)}&ia=web");
 }