Advertisement
EdGr87

Untitled

Oct 24th, 2022
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.42 KB | None | 0 0
  1. public string? FilePath { get; set; }
  2.  
  3.         public Dictionary<int, Languages>? LanguagesDictionary { get; set; }
  4.  
  5.         public string? DocumentPath { get; set; }
  6.  
  7.         public Visibility CanShow { get; set; } = Visibility.Collapsed;
  8.  
  9.         public DialogHelper DialogHelper { get; }
  10.  
  11.         public FolderHelper FolderHelper { get; }
  12.  
  13.         public AudioHelper AudioHelper { get; }
  14.  
  15.         public bool CanBePressed { get; set; }
  16.  
  17.         public AzureTranscriptionService AzureTranscription { get; }
  18.  
  19.         public Command PickFileCommad { get; set; }
  20.  
  21.         public Command CopyDocumentPathCommand { get; set; }
  22.  
  23.         public AsyncCommand StartCommand { get; set; }
  24.  
  25.         private string? _SelectedLanguage;
  26.  
  27.         public string SelectedLanguage {
  28.             get => _SelectedLanguage!;
  29.             set {
  30.                 if (_SelectedLanguage != value) {
  31.                     _SelectedLanguage = value;
  32.                     StartCommand.RaiseCanExecuteChanged();
  33.                 }
  34.             }
  35.         }
  36.  
  37.  
  38.         private bool _IsBusy;
  39.         public bool IsBusy {
  40.             get { return _IsBusy; }
  41.             set {
  42.                 if (_IsBusy != value) {
  43.                     _IsBusy = value;
  44.                     StartCommand.RaiseCanExecuteChanged();
  45.                 }
  46.             }
  47.         }
  48.  
  49.  
  50.         public AudioPageViewModel() {
  51.             InitListLanguages();
  52.             CanBePressed = true;
  53.             AzureTranscription = new AzureTranscriptionService();
  54.             DialogHelper = new DialogHelper();
  55.             FolderHelper = new FolderHelper();
  56.             AudioHelper = new AudioHelper();
  57.             CanShow = Visibility.Hidden;
  58.             PickFileCommad = new Command(PickFileAction);
  59.             StartCommand = new AsyncCommand(StartAction, CanStartAction);
  60.             CopyDocumentPathCommand = new Command(CopyDocumentPathAction);
  61.         }
  62.  
  63.         private void CopyDocumentPathAction() {
  64.             throw new NotImplementedException();
  65.         }
  66.  
  67.         private async Task StartAction() {
  68.             IsBusy = true;
  69.             CanShow = Visibility.Visible;
  70.             CanBePressed = false;
  71.  
  72.             var FileWithoutExtension = Path.GetFileNameWithoutExtension
  73.                 (FilePath);
  74.  
  75.             var AudioPath = FolderHelper.CreateFolder(ConstantsHelpers.AUDIO);
  76.  
  77.             var DocumentPath = FolderHelper.CreateFolder();
  78.  
  79.             var AudioFileNamePath = Path.Combine(AudioPath, $"{FileWithoutExtension}{ConstantsHelpers.WAV}");
  80.  
  81.             var ConvertedAudioPath = AudioHelper.Converter(FilePath!, AudioFileNamePath);
  82.  
  83.             var DocumentName = Path.Combine(DocumentPath, $"{FileWithoutExtension}{ConstantsHelpers.DOCX}");
  84.  
  85.             //await AzureTranscription.ConvertToTextAsync(ConvertedAudioPath,
  86.             //FileWithoutExtension!, SelectedItem);
  87.  
  88.             await Task.Delay(10000);
  89.  
  90.             IsBusy = false;
  91.             CanShow = Visibility.Hidden;
  92.             CanBePressed = true;
  93.         }
  94.  
  95.         private bool CanStartAction(object arg) {
  96.             return !string.IsNullOrEmpty(SelectedLanguage) &&
  97.                    !string.IsNullOrEmpty(FilePath) &&
  98.                    !IsBusy;
  99.         }
  100.  
  101.  
  102.         private void PickFileAction() {
  103.             var FullPath = DialogHelper.GetFilePath(ConstantsHelpers.AUDIO);
  104.             FilePath = FullPath;
  105.  
  106.             StartCommand?.RaiseCanExecuteChanged();
  107.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement