Exemplo n.º 1
0
 private void RefreshConnections(object sender, EventArgs e)
 {
     Dialog.IsOpen        = false;
     Dialog.DialogContent = null;
     Task.Run(async() => {
         var connections = await Globals.CloudManager.InvokeAsync(x => x.GetConnectedServices(Globals.PersonalCloud.Value))
                           .ConfigureAwait(false);
         Dispatcher.Invoke(() => {
             Connections.Clear();
             foreach (var item in connections)
             {
                 var model = new StorageConnectionItem {
                     IsSelected = false,
                     Name       = item,
                     Type       = "Cloud Storage"
                 };
                 Connections.Add(model);
             }
         });
     });
 }
Exemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            if (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName == "zh")
            {
                FontFamily = new FontFamily("Microsoft YaHei UI");
            }
            SharingPathBox.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            var letters = new List <char> {
                '—'
            };

            letters.AddRange(Enumerable.Range(68, 23).Select(x => (char)x));
            DriveLetters = letters.AsReadOnly();

            MountedCloudDrive.ItemsSource   = DriveLetters;
            MountedCloudDrive.SelectedIndex = 0;

            Connections = new ObservableCollection <StorageConnectionItem>();
            ConnectionList.ItemsSource = Connections;
            Albums = new ObservableCollection <PhotoAlbumItem>();
            AlbumList.ItemsSource = Albums;

            Task.Run(async() => {
                try
                {
                    var sharingEnabled = await Globals.CloudManager.InvokeAsync(x => x.IsFileSharingEnabled(null))
                                         .ConfigureAwait(false);
                    var sharingPath = await Globals.CloudManager.InvokeAsync(x => x.GetFileSharingRoot())
                                      .ConfigureAwait(false);

                    var deviceName = await Globals.CloudManager.InvokeAsync(x => x.GetDeviceName(null))
                                     .ConfigureAwait(false);
                    var cloudName = await Globals.CloudManager.InvokeAsync(x => x.GetPersonalCloudName(Globals.PersonalCloud.Value))
                                    .ConfigureAwait(false);

                    var mounted = await Globals.CloudManager.InvokeAsync(x => x.IsExplorerIntegrationEnabled())
                                  .ConfigureAwait(false);
                    var mountPoint = await Globals.CloudManager.InvokeAsync(x => x.GetMountPointForPersonalCloud(Globals.PersonalCloud.Value))
                                     .ConfigureAwait(false);

                    var connections = await Globals.CloudManager.InvokeAsync(x => x.GetConnectedServices(Globals.PersonalCloud.Value))
                                      .ConfigureAwait(false);
                    var albums = await Globals.CloudManager.InvokeAsync(x => x.GetAlbumSettings(Globals.PersonalCloud.Value))
                                 .ConfigureAwait(false);

                    await Dispatcher.InvokeAsync(() => {
                        SharingSwitch.IsChecked = sharingEnabled;
                        if (!string.IsNullOrEmpty(sharingPath))
                        {
                            SharingPathBox.Text = sharingPath;
                        }

                        DeviceNameBox.Text    = deviceName;
                        CloudNameBox.Text     = cloudName;
                        MountedCloudName.Text = cloudName;
                        MountSwitch.IsChecked = mounted;

                        if (mountPoint?.Length != 3)
                        {
                            MountedCloudDrive.SelectedIndex = 0;
                        }
                        else
                        {
                            var letterIndex = mountPoint[0] - 68 + 1;
                            MountedCloudDrive.SelectedIndex = letterIndex;
                        }

                        foreach (var item in connections)
                        {
                            var model = new StorageConnectionItem {
                                IsSelected = false,
                                Name       = item,
                                Type       = "Cloud Storage"
                            };
                            Connections.Add(model);
                        }
                        foreach (var item in albums)
                        {
                            var model = new PhotoAlbumItem {
                                IsSelected = false,
                                Name       = item.Name,
                                Path       = item.MediaFolder
                            };
                            Albums.Add(model);
                        }
                    });
                }
                catch
                {
                    // Todo
                }

                initialized = true;
            });
        }