#pragma warning disable AvoidAsyncVoid private async void DeleteFolder_Clicked(object sender, EventArgs e) { bool result = await DisplayAlert(AppResources.RemoveFolderTitle, AppResources.RemoveFolder, AppResources.Continue, AppResources.Cancel); if (result) { Track t = FindTrack((View)sender); if (t.CloudProvider != CloudStorage.CloudProviders.NULL) { ProviderInfo pi = await ProviderInfo.GetCloudProviderAsync(t.CloudProvider); if (await pi.CheckAuthenitcationAsync()) { bool removeWorked = await pi.RemoveFolder(t.CloudRoot, t.Project, UpdateStatus); if (removeWorked) { // Are we goint to remove a song that is playing? if (this.tvm.SelectedSong.Project == t.Project) { this.tvm.StopPlayer(); this.tvm.ResetPlayer(); } string projectPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), t.Project); Directory.Delete(projectPath, true); t.CloudProvider = CloudStorage.CloudProviders.NULL; t.CloudRoot = null; if (selectedTrack?.Project == t.Project) { selectedTrack = null; } // Remove folder from current list for (int i = LoadedTracks.Count - 1; i >= 0; i--) { if (LoadedTracks[i].Project == t.Project) { LoadedTracks.RemoveAt(i); } } // If part of playlist, remove from there for (int i = this.tvm.Playlist.Count - 1; i >= 0; i--) { if (t.Project == this.tvm.Playlist[i].Project) { this.tvm.Playlist.RemoveAt(i); } } } else { await DisplayAlert(AppResources.RemoveFolderRemoteFailedTitle, AppResources.RemoveFolderRemoteFailed, AppResources.OK); } } } else { Analytics.TrackEvent("Cloud Provider for folder invalid"); await DisplayAlert("Cloud Provider incorrect", "The cloud provider saved in local storage is missing or incorrect. This is not an expected error, contact the developer.", "OK"); } } }
public async static Task <ProviderInfo> GetCloudProviderAsync(CloudProviders cp) { ICloudStore cs = null; if (!providers.ContainsKey(cp)) { ProviderInfo newProvider = null; switch (cp) { case CloudProviders.OneDrive: cs = CloudStoreFactory.CreateCloudStore(CloudStorage.CloudProviders.OneDrive); Dictionary <string, object> onedriveparams = new Dictionary <string, object>(); onedriveparams[CloudParams.ClientID.ToString()] = "7ba22c7f-29be-4dc7-a274-4209fe0b8b72"; onedriveparams[CloudParams.UIParent.ToString()] = App.UiParent; if (cs.Initialize(onedriveparams)) { bool worked = await cs.AuthenticateAsync(); if (worked) { newProvider = new ProviderInfo(cp, cs); } } break; case CloudProviders.GoogleDrive: cs = CloudStoreFactory.CreateCloudStore(CloudStorage.CloudProviders.GoogleDrive); Dictionary <string, object> googledriveparams = new Dictionary <string, object>(); googledriveparams[CloudParams.ClientID.ToString()] = GetGoogleClientID(); // 133589155347-gj93njepme6jp96nh1erjmdi4q4c7d9k.apps.googleusercontent.com // 133589155347-2he14os3etg7evt97pcu5jil1udh1klk.apps.googleusercontent.com googledriveparams[CloudParams.RedirectURL.ToString()] = GetGoogleAuthRedirect(); googledriveparams[CloudParams.AppName.ToString()] = "MyMixes"; googledriveparams[CloudParams.UIParent.ToString()] = App.UiParent; googledriveparams[CloudParams.GoogleToken.ToString()] = null; if (cs.Initialize(googledriveparams)) { bool worked = await cs.AuthenticateAsync(); AuthenticationState.Authenticator = cs.GetAuthenticator(); bool authCompletWorked = await cs.CompleteAuthenticateAsync(AuthenticationState.Authenticator); if (authCompletWorked) { newProvider = new ProviderInfo(cp, cs); } } break; default: return(null); } if (newProvider != null) { providers[cp] = newProvider; return(newProvider); } } else { return(providers[cp]); } return(null); }
private async Task SyncProjectsAsync() { Dictionary <string, List <string> > AllSongs = new Dictionary <string, List <string> >(); foreach (MixLocation ml in PersistentData.MixLocationList) { UpdateStatus(ml.Provider.ToString() + " " + ml.Path); ProviderInfo pi = await ProviderInfo.GetCloudProviderAsync(ml.Provider); if (await pi.CheckAuthenitcationAsync()) { List <string> l = await pi.GetFoldersAsync(ml.Path); if (l != null) { foreach (string f in l) { UpdateStatus(ml.Provider.ToString() + " " + ml.Path + " " + f); var retList = await pi.UpdateProjectAsync(ml.Path, f, UpdateStatus); if (AllSongs.ContainsKey(f)) { AllSongs[f].AddRange(retList); } else { AllSongs[f] = retList; } } } } } string rootPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); foreach (string p in Directory.GetDirectories(rootPath)) { if (!AllSongs.ContainsKey(Path.GetFileName(p))) { Debug.Print("Remove dir " + p + "\n"); UpdateStatus("Removing " + p); Directory.Delete(p, true); } else { foreach (string s in Directory.GetDirectories(p)) { if (AllSongs[p].Contains(Path.GetFileName(s))) { UpdateStatus("Removing " + s); Debug.Print("Remove file " + s + "\n"); File.Delete(s); } } } } foreach (string p in AllSongs.Keys) { foreach (string f in AllSongs[p]) { UpdateStatus(p + " " + f); } } PersistentData.Save(); }