private async void Button_Click_2(object sender, RoutedEventArgs e) { byte[] data = System.Text.Encoding.UTF8.GetBytes(txb_word.Text.Trim()); AVFile file = new AVFile("mytxtFile.txt", data, new Dictionary<string, object>() { {"author","AVOSCloud"} }); await file.SaveAsync().ContinueWith( t => { if (!t.IsFaulted) { MessageBox.Show(file.ObjectId); } else { } }, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext()); #region 以下代码可以实现将本地文件上传到AVOS Cloud 的服务端,进行保存,并且可以跟踪上传进度。 AVFile localFile = AVFile.CreateFileWithLocalPath("screenshot.PNG", Path.Combine("<Local Folder Path>", "screenshot.PNG")); await localFile.SaveAsync(new Progress<AVUploadProgressEventArgs>(p => { var progress = p.Progress; })); #endregion }
internal IDictionary <string, object> GetMetaData(FileState state, Stream data) { IDictionary <string, object> rtn = new Dictionary <string, object>(); if (state.MetaData != null) { foreach (var meta in state.MetaData) { rtn.Add(meta.Key, meta.Value); } } MergeDic(rtn, "mime_type", AVFile.GetMIMEType(state.Name)); MergeDic(rtn, "size", data.Length); MergeDic(rtn, "_checksum", GetMD5Code(data)); if (AVUser.CurrentUser != null) { if (AVUser.CurrentUser.ObjectId != null) { MergeDic(rtn, "owner", AVUser.CurrentUser.ObjectId); } } return(rtn); }
static public async Task <bool> Feeds(bool Silent, bool EnableUI) { try { if (!Silent) { await EventProgressDisableUI("Downloading latest feeds...", true); } System.Diagnostics.Debug.WriteLine("Downloading latest feeds..."); string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } }; string DownloadString = await AVDownloader.DownloadStringAsync(10000, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "subscription/list?output=json")); JObject WebJObject = JObject.Parse(DownloadString); if (WebJObject["subscriptions"] != null && WebJObject["subscriptions"].HasValues) { if (!Silent) { await EventProgressDisableUI("Processing " + WebJObject["subscriptions"].Count() + " feeds...", true); } System.Diagnostics.Debug.WriteLine("Processing " + WebJObject["subscriptions"].Count() + " feeds..."); List <string> ApiFeedIdList = new List <string>(); IReadOnlyList <IStorageItem> LocalFileList = await ApplicationData.Current.LocalFolder.GetItemsAsync(); List <TableFeeds> TableUpdatedFeeds = new List <TableFeeds>(); List <TableFeeds> TableCurrentFeeds = await SQLConnection.Table <TableFeeds>().ToListAsync(); foreach (JToken JTokenRoot in WebJObject["subscriptions"]) { string FeedId = JTokenRoot["sortid"].ToString(); string FeedTitle = JTokenRoot["title"].ToString(); string HtmlUrl = WebUtility.HtmlDecode(JTokenRoot["htmlUrl"].ToString()); HtmlUrl = WebUtility.UrlDecode(HtmlUrl); Uri FullUrl = new Uri(HtmlUrl); ApiFeedIdList.Add(FeedId); TableFeeds TableResult = TableCurrentFeeds.Where(x => x.feed_id == FeedId).FirstOrDefault(); if (TableResult == null) { //System.Diagnostics.Debug.WriteLine("Adding feed: " + FeedTitle); TableFeeds AddFeed = new TableFeeds(); AddFeed.feed_id = FeedId; AddFeed.feed_title = FeedTitle; AddFeed.feed_link = FullUrl.Scheme + "://" + FullUrl.Host; AddFeed.feed_ignore_status = false; if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues) { AddFeed.feed_folder = JTokenRoot["categories"][0]["label"].ToString(); } TableUpdatedFeeds.Add(AddFeed); } else { //System.Diagnostics.Debug.WriteLine("Updating feed: " + FeedTitle); TableResult.feed_title = FeedTitle; TableResult.feed_link = FullUrl.Scheme + "://" + FullUrl.Host; if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues) { TableResult.feed_folder = JTokenRoot["categories"][0]["label"].ToString(); } TableUpdatedFeeds.Add(TableResult); } //Check and download feed logo if (!LocalFileList.Any(x => x.Name == FeedId + ".png")) { try { if (!Silent) { await EventProgressDisableUI("Downloading " + FeedTitle + " icon...", true); } Uri IconUrl = new Uri("https://s2.googleusercontent.com/s2/favicons?domain=" + FullUrl.Host); byte[] HttpFeedIcon = await AVDownloader.DownloadByteAsync(3000, "News Scroll", null, IconUrl); if (HttpFeedIcon != null && HttpFeedIcon.Length > 75) { await AVFile.SaveBytes(FeedId + ".png", HttpFeedIcon); System.Diagnostics.Debug.WriteLine("Downloaded transparent logo: " + HttpFeedIcon.Length + "bytes/" + IconUrl); } else { System.Diagnostics.Debug.WriteLine("No logo found for: " + IconUrl); } } catch { } } } //Update the feeds in database if (TableUpdatedFeeds.Any()) { await SQLConnection.InsertAllAsync(TableUpdatedFeeds, "OR REPLACE"); } //Delete removed feeds from the database List <string> DeletedFeeds = TableCurrentFeeds.Select(x => x.feed_id).Except(ApiFeedIdList).ToList(); System.Diagnostics.Debug.WriteLine("Found deleted feeds: " + DeletedFeeds.Count()); foreach (string DeleteFeedId in DeletedFeeds) { await DeleteFeed(DeleteFeedId); } } if (EnableUI) { await EventProgressEnableUI(); } return(true); } catch { await EventProgressEnableUI(); return(false); } }
void photoChooserTask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { //MessageBox.Show(e.ChosenPhoto.Length.ToString()); AVFile file = new AVFile("WPSelected.png", e.ChosenPhoto); file.SaveAsync().ContinueWith( t => { if (!t.IsFaulted) { MessageBox.Show(file.ObjectId); } else { } }, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext()); //Code to display the photo on the page in an image control named myImage. //System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(); //bmp.SetSource(e.ChosenPhoto); //myImage.Source = bmp; } }
//Download Bing wallpaper async Task DownloadBingWallpaper() { try { Debug.WriteLine("Downloading Bing update."); //Check for internet connection if (!DownloadInternetCheck()) { BackgroundStatusUpdateSettings(null, null, "Never", null, "NoWifiEthernet"); return; } //Load and set Download Information string DownloadBingRegion = "en-US"; switch (setDownloadBingRegion) { case 0: { DownloadBingRegion = vCultureInfoReg.Name; break; } case 2: { DownloadBingRegion = "en-GB"; break; } case 3: { DownloadBingRegion = "en-AU"; break; } case 4: { DownloadBingRegion = "de-DE"; break; } case 5: { DownloadBingRegion = "en-CA"; break; } case 6: { DownloadBingRegion = "ja-JP"; break; } case 7: { DownloadBingRegion = "zh-CN"; break; } case 8: { DownloadBingRegion = "fr-FR"; break; } case 9: { DownloadBingRegion = "pt-BR"; break; } case 10: { DownloadBingRegion = "nz-NZ"; break; } } string DownloadBingResolution = "1920x1080"; switch (setDownloadBingResolution) { case 1: { DownloadBingResolution = "1280x720"; break; } case 2: { DownloadBingResolution = "1080x1920"; break; } case 3: { DownloadBingResolution = "720x1280"; break; } case 4: { DownloadBingResolution = "1024x768"; break; } } //Download and read Bing Wallpaper XML XDocument XDocumentBing = XDocument.Parse(await AVDownloader.DownloadStringAsync(5000, "TimeMe", null, new Uri("https://www.bing.com/HPImageArchive.aspx?format=xml&n=1&mkt=" + DownloadBingRegion))); //Read and check current Bing wallpaper XElement XElement = XDocumentBing.Descendants("image").First(); string BingUrlName = XElement.Element("urlBase").Value + "_" + DownloadBingResolution + ".jpg"; string BingDescription = XElement.Element("copyright").Value; if (BgStatusBingDescription != BingDescription) { //Download and Save Bing Wallpaper image IBuffer BingWallpaperFile = await AVDownloader.DownloadBufferAsync(5000, "TimeMe", new Uri("https://www.bing.com" + BingUrlName)); if (BingWallpaperFile != null) { //Save the Bing wallpaper image StorageFile BingSaveFile = await AVFile.SaveBuffer("TimeMeTilePhoto.png" + new String(' ', new Random().Next(1, 50)), BingWallpaperFile); //Set background photo as device wallpaper try { if (setDeviceWallpaper) { await UserProfilePersonalizationSettings.Current.TrySetWallpaperImageAsync(BingSaveFile); } } catch { Debug.WriteLine("Failed to update Device wallpaper."); } //Set background photo as lockscreen wallpaper try { if (setLockWallpaper) { if (setDevStatusMobile) { await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Tiles/TimeMeTileColor.png"))); } await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(BingSaveFile); } } catch { Debug.WriteLine("Failed to update Lock screen wallpaper."); } //Save Bing photo name BgStatusPhotoName = BingUrlName; vApplicationSettings["BgStatusPhotoName"] = BgStatusPhotoName; //Save Bing description status BgStatusBingDescription = BingDescription; vApplicationSettings["BgStatusBingDescription"] = BgStatusBingDescription; //Notification - Bing description ShowNotiBingDescription(); //Force live tile update TileLive_ForceUpdate = true; } else { Debug.WriteLine("Failed downloading the Bing wallpaper."); BackgroundStatusUpdateSettings(null, null, "Never", null, "FailedDownloadBingWallpaper"); return; } } //Save Bing update status BgStatusDownloadBing = DateTimeNow.ToString(vCultureInfoEng); vApplicationSettings["BgStatusDownloadBing"] = BgStatusDownloadBing; } catch (Exception ex) { Debug.WriteLine("Failed updating the Bing wallpaper."); BackgroundStatusUpdateSettings(null, null, "Never", null, "CatchDownloadBingWallpaper" + ex.Message); } }
private async void Button_Click_4(object sender, RoutedEventArgs e) { string filePath = Path.Combine("Shared", "Media", "GuoJiGe.mp3"); AVFile file = AVFile.CreateFileWithLocalPath("GuoJiGe.mp3", filePath); await file.SaveAsync(); }
//Download weather and forecast async Task DownloadWeather() { try { Debug.WriteLine("Downloading Weather update."); //Check for internet connection if (!DownloadInternetCheck()) { BackgroundStatusUpdateSettings("Never", null, null, null, "NoWifiEthernet"); return; } //Check if location is available if (String.IsNullOrEmpty(DownloadWeatherLocation)) { BackgroundStatusUpdateSettings("Never", null, null, null, "NoWeatherLocation"); return; } //Download and save weather summary string WeatherSummaryResult = await AVDownloader.DownloadStringAsync(5000, "TimeMe", null, new Uri("https://service.weather.microsoft.com/" + DownloadWeatherLanguage + "/weather/summary/" + DownloadWeatherLocation + DownloadWeatherUnits)); if (!String.IsNullOrEmpty(WeatherSummaryResult)) { //Update weather summary status UpdateWeatherSummaryStatus(WeatherSummaryResult); //Notification - Current Weather ShowNotiWeatherCurrent(); //Save weather summary data await AVFile.SaveText("TimeMeWeatherSummary.js", WeatherSummaryResult); } else { Debug.WriteLine("Failed no weather summary found."); BackgroundStatusUpdateSettings("Failed", null, null, null, "NoWeatherSummary"); return; } //Download and save weather forecast string WeatherForecastResult = await AVDownloader.DownloadStringAsync(5000, "TimeMe", null, new Uri("https://service.weather.microsoft.com/" + DownloadWeatherLanguage + "/weather/forecast/daily/" + DownloadWeatherLocation + DownloadWeatherUnits)); if (!String.IsNullOrEmpty(WeatherForecastResult)) { //Save weather forecast data await AVFile.SaveText("TimeMeWeatherForecast.js", WeatherForecastResult); } else { Debug.WriteLine("Failed no weather forecast found."); BackgroundStatusUpdateSettings("Failed", null, null, null, "NoWeatherForecast"); return; } //Save Weather status BgStatusDownloadWeather = DateTimeNow.ToString(vCultureInfoEng); vApplicationSettings["BgStatusDownloadWeather"] = BgStatusDownloadWeather; BgStatusDownloadWeatherTime = BgStatusDownloadWeather; vApplicationSettings["BgStatusDownloadWeatherTime"] = BgStatusDownloadWeather; } catch (Exception ex) { Debug.WriteLine("Failed updating the weather info."); BackgroundStatusUpdateSettings("Failed", null, null, null, "CatchDownloadWeather" + ex.Message); } //Update weather summary status void UpdateWeatherSummaryStatus(string WeatherSummaryResult) { try { //Check if there is summary data available JObject SummaryJObject = JObject.Parse(WeatherSummaryResult); if (SummaryJObject["responses"][0]["weather"] != null) { //Set Weather Provider Information JToken HttpJTokenProvider = SummaryJObject["responses"][0]["weather"][0]["provider"]; if (HttpJTokenProvider["name"] != null) { string Provider = HttpJTokenProvider["name"].ToString(); if (!String.IsNullOrEmpty(Provider)) { BgStatusWeatherProvider = Provider; vApplicationSettings["BgStatusWeatherProvider"] = BgStatusWeatherProvider; } else { BgStatusWeatherProvider = "N/A"; vApplicationSettings["BgStatusWeatherProvider"] = BgStatusWeatherProvider; } } //Set Weather Current Conditions string Icon = ""; string Condition = ""; string Temperature = ""; string WindSpeedDirection = ""; JToken UnitsJToken = SummaryJObject["units"]; JToken HttpJTokenCurrent = SummaryJObject["responses"][0]["weather"][0]["current"]; if (HttpJTokenCurrent["icon"] != null) { Icon = HttpJTokenCurrent["icon"].ToString(); } if (HttpJTokenCurrent["cap"] != null) { Condition = HttpJTokenCurrent["cap"].ToString(); } if (HttpJTokenCurrent["temp"] != null) { Temperature = HttpJTokenCurrent["temp"].ToString() + "°"; } if (HttpJTokenCurrent["windSpd"] != null && HttpJTokenCurrent["windDir"] != null) { WindSpeedDirection = HttpJTokenCurrent["windSpd"].ToString() + " " + UnitsJToken["speed"].ToString() + " " + AVFunctions.DegreesToCardinal(Convert.ToDouble((HttpJTokenCurrent["windDir"].ToString()))); } //Set Weather Forecast Conditions string RainChance = ""; string TemperatureLow = ""; string TemperatureHigh = ""; JToken HttpJTokenForecast = SummaryJObject["responses"][0]["weather"][0]["forecast"]["days"][0]; if (HttpJTokenForecast["precip"] != null) { RainChance = HttpJTokenForecast["precip"].ToString() + "%"; } if (HttpJTokenForecast["tempLo"] != null) { TemperatureLow = HttpJTokenForecast["tempLo"].ToString() + "°"; } if (HttpJTokenForecast["tempHi"] != null) { TemperatureHigh = HttpJTokenForecast["tempHi"].ToString() + "°"; } //Set Weather Icon if (!String.IsNullOrEmpty(Icon)) { BgStatusWeatherCurrentIcon = Icon; vApplicationSettings["BgStatusWeatherCurrentIcon"] = BgStatusWeatherCurrentIcon; } else { BgStatusWeatherCurrentIcon = "0"; vApplicationSettings["BgStatusWeatherCurrentIcon"] = BgStatusWeatherCurrentIcon; } //Set Weather Temperature and Condition if (!String.IsNullOrEmpty(Temperature) && !String.IsNullOrEmpty(Condition)) { BgStatusWeatherCurrent = AVFunctions.ToTitleCase(Condition) + ", " + Temperature; vApplicationSettings["BgStatusWeatherCurrent"] = BgStatusWeatherCurrent; } else { BgStatusWeatherCurrent = "N/A"; vApplicationSettings["BgStatusWeatherCurrent"] = BgStatusWeatherCurrent; } //Set Weather Temperature if (!String.IsNullOrEmpty(Temperature)) { BgStatusWeatherCurrentTemp = Temperature; vApplicationSettings["BgStatusWeatherCurrentTemp"] = BgStatusWeatherCurrentTemp; } else { BgStatusWeatherCurrentTemp = "N/A"; vApplicationSettings["BgStatusWeatherCurrentTemp"] = BgStatusWeatherCurrentTemp; } //Set Weather Condition if (!String.IsNullOrEmpty(Condition)) { BgStatusWeatherCurrentText = AVFunctions.ToTitleCase(Condition); vApplicationSettings["BgStatusWeatherCurrentText"] = BgStatusWeatherCurrentText; } else { BgStatusWeatherCurrentText = "N/A"; vApplicationSettings["BgStatusWeatherCurrentText"] = BgStatusWeatherCurrentText; } //Set Weather Wind Speed and Direction if (!String.IsNullOrEmpty(WindSpeedDirection)) { BgStatusWeatherCurrentWindSpeed = WindSpeedDirection; vApplicationSettings["BgStatusWeatherCurrentWindSpeed"] = BgStatusWeatherCurrentWindSpeed; } else { BgStatusWeatherCurrentWindSpeed = "N/A"; vApplicationSettings["BgStatusWeatherCurrentWindSpeed"] = BgStatusWeatherCurrentWindSpeed; } //Set Weather Rain Chance if (!String.IsNullOrEmpty(RainChance)) { BgStatusWeatherCurrentRainChance = RainChance; vApplicationSettings["BgStatusWeatherCurrentRainChance"] = BgStatusWeatherCurrentRainChance; } else { BgStatusWeatherCurrentRainChance = "N/A"; vApplicationSettings["BgStatusWeatherCurrentRainChance"] = BgStatusWeatherCurrentRainChance; } //Set Weather Temp Low if (!String.IsNullOrEmpty(TemperatureLow)) { BgStatusWeatherCurrentTempLow = TemperatureLow; vApplicationSettings["BgStatusWeatherCurrentTempLow"] = BgStatusWeatherCurrentTempLow; } else { BgStatusWeatherCurrentTempLow = "N/A"; vApplicationSettings["BgStatusWeatherCurrentTempLow"] = BgStatusWeatherCurrentTempLow; } //Set Weather Temp High if (!String.IsNullOrEmpty(TemperatureHigh)) { BgStatusWeatherCurrentTempHigh = TemperatureHigh; vApplicationSettings["BgStatusWeatherCurrentTempHigh"] = BgStatusWeatherCurrentTempHigh; } else { BgStatusWeatherCurrentTempHigh = "N/A"; vApplicationSettings["BgStatusWeatherCurrentTempHigh"] = BgStatusWeatherCurrentTempHigh; } } } catch { } } }