Example #1
0
        private Task <LoadMetadataResults> LoadMetadata_Execute(string rootProps)
        {
            var viewModel       = ViewModel;
            var busyPickingFile = MainResources.Busy_PickingFile;
            var busySavingTheme = MainResources.Busy_SavingTheme;

            string[] splProps = (rootProps ?? String.Empty).Split('.');
            var      task     = new Task <LoadMetadataResults>(() =>
            {
                BusyText = busyPickingFile;

                var result = new LoadMetadataResults()
                {
                    Loaded = false,
                    Data   = new Dictionary <string, string>()
                };

                var opfl = new OpenFileDialog
                {
                    Filter = "Metadata File|*.meta",
                };
                var dlg = opfl.ShowDialog();
                if (dlg.HasValue && !dlg.Value)
                {
                    return(result);
                }
                var dataFile = opfl.FileName;

                BusyText = busySavingTheme;

                try
                {
                    using (var fs = File.OpenText(dataFile))
                    {
                        while (!fs.EndOfStream)
                        {
                            string s = fs.ReadLine();
                            if (s.StartsWith(";"))
                            {
                                continue;
                            }
                            var kv = s.Split(':');
                            result.Data.Add(kv[0].Trim(), kv[1].Trim());
                        }
                    }
                    result.Loaded = true;
                }
                catch
                {
                    //...
                }

                return(result);
            },
                                                               TaskCreationOptions.LongRunning);

            task.Start();
            return(task);
        }
Example #2
0
 private void ImportMetadata_PostExecute(LoadMetadataResults r)
 {
     ViewModel.Rules.Pause();
     ViewModel.SetMetadata(r.Data);
     ViewModel.Rules.Apply(ViewModel.Flags);
     ViewModel.Rules.Apply(ViewModel.Colors);
     ViewModel.Rules.Resume();
     IsBusy = false;
 }