Beispiel #1
0
        public FFmpegLogItem(string name, IClipboardService clipboardService)
        {
            Name = name;

            CopyToClipboardCommand = new DelegateCommand(() =>
            {
                clipboardService.SetText(_complete.ToString());
            });

            RemoveCommand = new DelegateCommand(() => RemoveRequested?.Invoke());
        }
Beispiel #2
0
        protected override void OnInitialized()
        {
            IMessageBoxService messageBoxService = Container.Resolve <IMessageBoxService>();
            IClipboardService  clipboardService  = Container.Resolve <IClipboardService>();

            ViewBind.AppViewLocator = Container.Resolve <IViewLocator>();
            // have no idea if it makes sense, but works
            MainWindow?mainWindow = Container.Resolve <MainWindow>();

            IEventAggregator?eventAggregator = Container.Resolve <IEventAggregator>();

            eventAggregator.GetEvent <AllModulesLoaded>().Publish();

            mainWindow.ContentRendered += MainWindowOnContentRendered;

            #if DEBUG
            mainWindow.ShowDialog();
            #else
            try
            {
                mainWindow.ShowDialog();
            }
            catch (Exception e)
            {
                var commitHash = File.Exists("COMMIT_HASH") ? File.ReadAllText("COMMIT_HASH") : "unknown";
                Console.WriteLine(e.ToString());
                var logPath = Path.GetTempFileName() + ".WDE.log.txt";
                File.WriteAllText(logPath, "Commit: " + commitHash + "\n\n" + e.ToString());

                var choice = messageBoxService.ShowDialog(new MessageBoxFactory <int>().SetIcon(MessageBoxIcon.Error)
                                                          .SetTitle("Fatal error")
                                                          .SetMainInstruction("Sorry, fatal error has occured and the program had to stop")
                                                          .SetContent("You are welcome to report the bug at github. Reason: " + e.Message)
                                                          .SetFooter("Log file saved at: " + logPath)
                                                          .WithButton("Copy log path to clipboard", 2)
                                                          .WithButton("Open log file", 1)
                                                          .WithButton("Close", 0)
                                                          .Build());
                if (choice == 2)
                {
                    clipboardService.SetText(logPath);
                }
                else if (choice == 1)
                {
                    Process.Start("explorer", logPath);
                }
            }
            #endif

            Current.Shutdown();
        }
Beispiel #3
0
        public YouTubeUploaderViewModel(YouTubeUploader Uploader,
                                        IMessageProvider MessageProvider,
                                        IClipboardService ClipboardService)
        {
            _uploader                = Uploader;
            _messageProvider         = MessageProvider;
            _cancellationTokenSource = new CancellationTokenSource();

            UploadCommand = new DelegateCommand(() => _uploadTask = OnUpload(), false);

            OpenVideoCommand = new DelegateCommand(() => Process.Start(Link), false);

            CopyLinkCommand = new DelegateCommand(() => ClipboardService.SetText(Link), false);
        }
 public RowPickerViewModel(ViewModelBase baseViewModel,
                           ITaskRunner taskRunner,
                           ISolutionItemSqlGeneratorRegistry queryGeneratorRegistry,
                           IClipboardService clipboardService,
                           IWindowManager windowManager,
                           IEventAggregator eventAggregator,
                           ISolutionItemEditorRegistry solutionItemEditorRegistry,
                           ISessionService sessionService,
                           IMessageBoxService messageBoxService,
                           ISolutionTasksService solutionTasksService,
                           bool noSaveMode = false)
 {
     this.baseViewModel = baseViewModel;
     this.solutionItemEditorRegistry = solutionItemEditorRegistry;
     this.sessionService             = sessionService;
     this.messageBoxService          = messageBoxService;
     this.noSaveMode = noSaveMode;
     Watch(baseViewModel, o => o.IsModified, nameof(Title));
     ExecuteChangedCommand = noSaveMode ? AlwaysDisabledCommand.Command : new AsyncAutoCommand(async() =>
     {
         baseViewModel.Save.Execute(null);
         eventAggregator.GetEvent <DatabaseTableChanged>().Publish(baseViewModel.TableDefinition.TableName);
         await taskRunner.ScheduleTask("Update session", async() => await sessionService.UpdateQuery(baseViewModel));
         if (solutionTasksService.CanReloadRemotely)
         {
             await solutionTasksService.ReloadSolutionRemotelyTask(baseViewModel.SolutionItem);
         }
     });
     CopyCurrentSqlCommand = new AsyncAutoCommand(async() =>
     {
         await taskRunner.ScheduleTask("Generating SQL",
                                       async() => { clipboardService.SetText((await baseViewModel.GenerateQuery()).QueryString); });
     });
     GenerateCurrentSqlCommand = new AsyncAutoCommand(async() =>
     {
         var sql    = await baseViewModel.GenerateQuery();
         var item   = new MetaSolutionSQL(new JustQuerySolutionItem(sql.QueryString));
         var editor = solutionItemEditorRegistry.GetEditor(item);
         await windowManager.ShowDialog((IDialog)editor);
     });
     PickSelected = new AsyncAutoCommand(async() =>
     {
         await AskIfSave(false);
     });
     Cancel = new DelegateCommand(() =>
     {
         CloseCancel?.Invoke();
     });
     Accept = PickSelected;
 }
Beispiel #5
0
    public QuickCommands(Lazy <IQuickAccessService> service,
                         Lazy <IQuickAccessViewModel> viewModel,
                         IClipboardService clipboardService,
                         IStatusBar statusBar)
    {
        CopyCommand = new DelegateCommand <object>(o =>
        {
            var text = o.ToString() ?? "";
            clipboardService.SetText(text);
            statusBar.PublishNotification(new PlainNotification(NotificationType.Info, "Copied " + text));
            viewModel.Value.CloseSearch();
        });

        SetSearchCommand = new DelegateCommand <object>(o =>
        {
            viewModel.Value.OpenSearch(o.ToString());
        });

        NoCommand = new DelegateCommand(() => { });
    }
Beispiel #6
0
        public FFmpegLogViewModel(IClipboardService ClipboardService,
                                  FFmpegLog FFmpegLog)
        {
            LogItems = FFmpegLog
                       .LogItems
                       .ToReadOnlyReactiveCollection();

            LogItems
            .ObserveAddChanged()
            .Subscribe(M => SelectedLogItem = M);

            LogItems
            .ObserveRemoveChanged()
            .Subscribe(M =>
            {
                if (LogItems.Count > 0)
                {
                    SelectedLogItem = LogItems[0];
                }
            });

            if (LogItems.Count > 0)
            {
                SelectedLogItem = LogItems[0];
            }

            CopyToClipboardCommand = this
                                     .ObserveProperty(M => M.SelectedLogItem)
                                     .Select(M => M != null)
                                     .ToReactiveCommand()
                                     .WithSubscribe(() =>
            {
                ClipboardService.SetText(SelectedLogItem.GetCompleteLog());
            });

            RemoveCommand = this
                            .ObserveProperty(M => M.SelectedLogItem)
                            .Select(M => M != null)
                            .ToReactiveCommand()
                            .WithSubscribe(() => FFmpegLog.Remove(SelectedLogItem));
        }
Beispiel #7
0
        public FFmpegLogItem(string Name,
                             string Args,
                             IClipboardService ClipboardService)
        {
            this.Name = Name;
            this.Args = Args;

            _complete.AppendLine("ARGS:");
            _complete.AppendLine("-------------");
            _complete.AppendLine(Args);
            _complete.AppendLine();
            _complete.AppendLine("OUTPUT:");
            _complete.AppendLine("-------------");

            CopyToClipboardCommand = new DelegateCommand(() =>
            {
                ClipboardService.SetText(_complete.ToString());
            });

            RemoveCommand = new DelegateCommand(() => RemoveRequested?.Invoke());
        }
        private Result Create(Link link, string arg)
        {
            var description = string.IsNullOrEmpty(link.Description)
                ? ""
                : FormatDescription(link.Description, arg);
            var title = $"[{link.Shortcut}] {description}";

            var canOpenLink   = !ArgumentIsMissing(link.Path, arg);
            var formattedData = FormatDescription(link.Path, arg);
            var subTitle      = link.Type == LinkType.Path
                ? formattedData
                : formattedData.Replace(Environment.NewLine, " ↵ ");

            return(new Result {
                Title = title,
                SubTitle = subTitle,
                IcoPath = @"images/icon.png",
                Action = context => {
                    if (context.SpecialKeyState?.CtrlPressed == true)
                    {
                        var dialogResult = MessageBox.Show($"Delete shortcut: '{link.Shortcut}'?", "Confirmation",
                                                           MessageBoxButtons.YesNo);
                        if (dialogResult == DialogResult.Yes)
                        {
                            _storage.Delete(link.Shortcut);
                        }
                        return true;
                    }

                    if (context.SpecialKeyState.AltPressed || link.Type == LinkType.ClipboardTemplate)
                    {
                        _clipboardService.SetText(formattedData);
                        return true;
                    }

                    return canOpenLink && _linkProcess.Open(formattedData);
                }
            });
        }
Beispiel #9
0
        public PacketFilterDialogViewModel(IClipboardService clipboardService,
                                           IReadOnlyFilterData?filterData)
        {
            this.clipboardService = clipboardService;
            Accept = new DelegateCommand(() => CloseOk?.Invoke());
            Cancel = new DelegateCommand(() => CloseCancel?.Invoke());

            ClearFiltersCommand = new AsyncAutoCommand(async() =>
            {
                ExcludedEntries = "";
                IncludedEntries = "";
                ExcludedOpcodes = "";
                IncludedOpcodes = "";
                ExcludedGuids.Clear();
                IncludedGuids.Clear();
                CommaSeparatedPackets = "";
                HasMaxPacketNumber    = false;
                HasMinPacketNumber    = false;
                MinPacketNumber       = 0;
                MaxPacketNumber       = 0;
            });
            CopyFiltersCommand = new AsyncAutoCommand(async() =>
            {
                var data = new SerializedClipboardData()
                {
                    ExcludedEntries      = GenerateList(excludedEntries, s => uint.TryParse(s, out _), uint.Parse),
                    IncludedEntries      = GenerateList(includedOpcodes, s => uint.TryParse(s, out _), uint.Parse),
                    ExcludedGuids        = ExcludedGuids.Count == 0 ? null : ExcludedGuids.Select(s => s.ToHexWithTypeString()).ToList(),
                    IncludedGuids        = IncludedGuids.Count == 0 ? null : IncludedGuids.Select(s => s.ToHexWithTypeString()).ToList(),
                    ExcludedOpcodes      = GenerateList(excludedOpcodes, _ => true, s => s.ToUpper()),
                    IncludedOpcodes      = GenerateList(includedOpcodes, _ => true, s => s.ToUpper()),
                    ForceIncludedNumbers = GenerateList(commaSeparatedPackets, s => int.TryParse(s, out var x) && x >= 0, int.Parse),
                    MinPacket            = HasMinPacketNumber ? MinPacketNumber : null,
                    MaxPacket            = HasMaxPacketNumber ? MaxPacketNumber : null,
                };
                var serialized = JsonConvert.SerializeObject(data, Formatting.Indented, new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                });
                clipboardService.SetText(serialized);
            });
            PasteFiltersCommand = new AsyncAutoCommand(async() =>
            {
                var text = await clipboardService.GetText();
                if (string.IsNullOrEmpty(text))
                {
                    return;
                }

                SerializedClipboardData?serialized = null;
                try
                {
                    serialized = JsonConvert.DeserializeObject <SerializedClipboardData>(text);
                }
                catch (Exception _)
                {
                    // ignored
                }

                if (!serialized.HasValue)
                {
                    return;
                }

                HasMinPacketNumber = serialized.Value.MinPacket.HasValue;
                HasMaxPacketNumber = serialized.Value.MaxPacket.HasValue;
                MinPacketNumber    = serialized.Value.MinPacket ?? 0;
                MaxPacketNumber    = serialized.Value.MaxPacket ?? 0;

                if (serialized.Value.ExcludedEntries != null)
                {
                    ExcludedEntries = string.Join(", ", serialized.Value.ExcludedEntries);
                }
                if (serialized.Value.IncludedEntries != null)
                {
                    IncludedEntries = string.Join(", ", serialized.Value.IncludedEntries);
                }
                if (serialized.Value.ExcludedGuids != null)
                {
                    ExcludedGuids.AddRange(serialized.Value.ExcludedGuids.StringToGuids());
                }
                if (serialized.Value.IncludedGuids != null)
                {
                    IncludedGuids.AddRange(serialized.Value.IncludedGuids.StringToGuids());
                }
                if (serialized.Value.ExcludedOpcodes != null)
                {
                    ExcludedOpcodes = string.Join(", ", serialized.Value.ExcludedOpcodes);
                }
                if (serialized.Value.IncludedOpcodes != null)
                {
                    IncludedOpcodes = string.Join(", ", serialized.Value.IncludedOpcodes);
                }
                if (serialized.Value.ForceIncludedNumbers != null)
                {
                    CommaSeparatedPackets = string.Join(", ", serialized.Value.ForceIncludedNumbers);
                }
            });

            if (filterData != null)
            {
                HasMinPacketNumber = filterData.MinPacketNumber.HasValue;
                HasMaxPacketNumber = filterData.MaxPacketNumber.HasValue;
                MinPacketNumber    = filterData.MinPacketNumber ?? 0;
                MaxPacketNumber    = filterData.MaxPacketNumber ?? 0;

                if (filterData.ExcludedEntries != null)
                {
                    ExcludedEntries = string.Join(", ", filterData.ExcludedEntries);
                }
                if (filterData.IncludedEntries != null)
                {
                    IncludedEntries = string.Join(", ", filterData.IncludedEntries);
                }
                if (filterData.ExcludedGuids != null)
                {
                    ExcludedGuids.AddRange(filterData.ExcludedGuids);
                }
                if (filterData.IncludedGuids != null)
                {
                    IncludedGuids.AddRange(filterData.IncludedGuids);
                }
                if (filterData.ExcludedOpcodes != null)
                {
                    ExcludedOpcodes = string.Join(", ", filterData.ExcludedOpcodes);
                }
                if (filterData.IncludedOpcodes != null)
                {
                    IncludedOpcodes = string.Join(", ", filterData.IncludedOpcodes);
                }
                if (filterData.ForceIncludePacketNumbers != null)
                {
                    CommaSeparatedPackets = string.Join(", ", filterData.ForceIncludePacketNumbers);
                }
            }

            DeleteIncludedGuid = new DelegateCommand <UniversalGuid?>(guid =>
            {
                if (guid != null)
                {
                    IncludedGuids.Remove(guid);
                }
            });

            DeleteExcludedGuid = new DelegateCommand <UniversalGuid?>(guid =>
            {
                if (guid != null)
                {
                    ExcludedGuids.Remove(guid);
                }
            });

            AutoDispose(this.ToObservable(o => o.ExcludedEntries).SubscribeAction(_ => RaisePropertyChanged(nameof(EntriesHeader))));
            AutoDispose(this.ToObservable(o => o.IncludedEntries).SubscribeAction(_ => RaisePropertyChanged(nameof(EntriesHeader))));
            AutoDispose(ExcludedGuids.ToCountChangedObservable().SubscribeAction(_ => RaisePropertyChanged(nameof(GuidsHeader))));
            AutoDispose(IncludedGuids.ToCountChangedObservable().SubscribeAction(_ => RaisePropertyChanged(nameof(GuidsHeader))));
            AutoDispose(this.ToObservable(o => o.ExcludedOpcodes).SubscribeAction(_ => RaisePropertyChanged(nameof(OpcodesHeader))));
            AutoDispose(this.ToObservable(o => o.IncludedOpcodes).SubscribeAction(_ => RaisePropertyChanged(nameof(OpcodesHeader))));
        }
        public MainViewModel(IMainModel model, ICttObjectTrackingService cttObjectTrackingService, INavigationService navigationService, ISystemTrayService systemTrayService, IMessageBoxService messageBoxService, IClipboardService clipboardService, IEmailComposeService emailComposeService, ISmsComposeService smsComposeService)
        {
            _model = model;
            _cttObjectTrackingService = cttObjectTrackingService;
            _navigationService        = navigationService;
            _systemTrayService        = systemTrayService;
            _messageBoxService        = messageBoxService;
            _clipboardService         = clipboardService;
            _emailComposeService      = emailComposeService;
            _smsComposeService        = smsComposeService;

            TrackedObjects = _model.TrackedObjects
                             .Select(x => new ObjectDetailsViewModel(x))
                             .ToObservableCollection();

            ShowObjectDetailsCommand = new RelayCommand <ObjectDetailsViewModel>(item =>
            {
                var objectId = item.Model.ObjectId;

                _navigationService.NavigateTo(new Uri("/View/ObjectDetailsPage.xaml?" + objectId, UriKind.Relative));
            });

            NewObjectCommand = new RelayCommand(() =>
            {
                _navigationService.NavigateTo(new Uri("/View/NewObjectPage.xaml", UriKind.Relative));
            }, () => !IsBusy);

            EnableSelectionCommand = new RelayCommand(() =>
            {
                IsSelectionEnabled = true;
            }, () => !IsTrackedObjectsEmpty && !IsBusy);

            RefreshCommand = new RelayCommand(() =>
            {
                var enumerator = TrackedObjects.GetEnumerator();

                RefreshNext(enumerator);
            }, () => !IsTrackedObjectsEmpty && !IsBusy);

            DeleteObjectsCommand = new RelayCommand <IList>(items =>
            {
                if (items == null || items.Count == 0)
                {
                    return;
                }

                _messageBoxService.Show("Está prestes a apagar os objectos seleccionados", "Tem a certeza?", new string[] { "eliminar", "cancelar" }, button =>
                {
                    if (button != 0)
                    {
                        return;
                    }

                    var itemsToRemove = items
                                        .Cast <ObjectDetailsViewModel>()
                                        .ToArray();

                    foreach (var item in itemsToRemove)
                    {
                        _model.TrackedObjects.Remove(item.Model);

                        TrackedObjects.Remove(item);
                    }

                    IsTrackedObjectsEmpty = (TrackedObjects.Count == 0);

                    _model.Save();
                });
            }, items => !IsBusy);

            ShowAboutCommand = new RelayCommand(() =>
            {
                _navigationService.NavigateTo(new Uri("/View/AboutPage.xaml", UriKind.Relative));
            });

            BackKeyPressCommand = new RelayCommand <CancelEventArgs>(e =>
            {
                if (IsSelectionEnabled)
                {
                    IsSelectionEnabled = false;

                    e.Cancel = true;
                }
            });

            CopyCodeCommand = new RelayCommand <ObjectDetailsViewModel>(item =>
            {
                _clipboardService.SetText(item.Model.ObjectId);
            });

            MailCodeCommand = new RelayCommand <ObjectDetailsViewModel>(item =>
            {
                _emailComposeService.Show("CTT Objectos", string.Format("\nO seu código de tracking: {0}\n\nPode consultar o estado entrando em http://www.ctt.pt e utilizando a opção \"Pesquisa de Objectos\".\n\nEnviado por CTT Objectos (http://bit.ly/cttobjectos)", item.Model.ObjectId));
            });

            TextCodeCommand = new RelayCommand <ObjectDetailsViewModel>(item =>
            {
                _smsComposeService.Show(string.Empty, item.Model.ObjectId);
            });

            MessengerInstance.Register <AddObjectMessage>(this, message =>
            {
                var objectViewModel = TrackedObjects.FirstOrDefault(x => x.Model.ObjectId == message.Model.ObjectId);

                if (objectViewModel == null)
                {
                    var objectModel = new ObjectModel(message.Description, message.ETag, message.Model);

                    _model.TrackedObjects.Add(objectModel);

                    TrackedObjects.Add(new ObjectDetailsViewModel(objectModel));

                    IsTrackedObjectsEmpty = false;
                }
                else
                {
                    objectViewModel.Model.Description = message.Description;
                    objectViewModel.Model.State       = message.Model;
                }

                _model.Save();
            });

            IsTrackedObjectsEmpty = (TrackedObjects.Count == 0);
        }
Beispiel #11
0
 private void CopyError()
 {
     clipboardService.SetText(SelectedErrorListItem.Description);
 }