Example #1
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (DownloadedString != null)
            {
                FileDownloadingData.FileName = FileName.Text;

                if (ValidateData())
                {
                    FileNameProvider.Invoke(FileDownloadingData.FileName, DownloadedString);
                }
                return;
            }

            FileDownloadingData.Url = WebsiteUrl.Text;
            if (ValidateData())
            {
                await Task.Run(async() =>
                {
                    var webClient = new WebClient();

                    var downloadString = await webClient.DownloadStringTaskAsync(FileDownloadingData.Url);

                    StringDownloaded.Invoke(downloadString);
                });
            }
        }
        private void AddExistingWebResource()
        {
            if ((SelectedWebResource != null) && !string.IsNullOrEmpty(SelectedWebResource.Uri))
            {
                dynamic fileData = FileNameProvider.GetFileName();

                if (!fileData.HasError)
                {
                    string localPath = fileData.LocalFilePath;
                    string fileName  = fileData.FileName;
                    if (!string.IsNullOrEmpty(localPath))
                    {
                        var newWebResource = new WebResourceViewModel(null);
                        newWebResource.Name       = fileName;
                        newWebResource.Base64Data = Convert.ToBase64String(File.ReadAllBytes(localPath));
                        newWebResource.Uri        = SelectedWebResource.Uri;

                        newWebResource.SetParent(SelectedWebResource.Parent ?? SelectedWebResource);

                        string fullName            = string.Format("/{0}/{1}", newWebResource.Uri, newWebResource.Name);
                        var    existingWebResource = newWebResource.Parent.Children.FirstOrDefault(c => c.Name.Equals(fullName, StringComparison.InvariantCultureIgnoreCase));
                        if (existingWebResource != null)
                        {
                            UserMessageProvider.ShowUserErrorMessage(StringResources.Error_Website_Resource_Exists);
                            return;
                        }

                        try
                        {
                            _webResources.Save(newWebResource);

                            newWebResource.IsSelected        = true;
                            newWebResource.Parent.IsExpanded = true;

                            SelectedWebResource = newWebResource;

                            base.OnPropertyChanged("RootWebResource");
                        }
                        catch (WebResourceUploadFailedException)
                        {
                        }
                    }
                }
            }
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (DownloadedString != null)
            {
                FileNameProvider.Invoke(FileName.Text, DownloadedString);
                return;
            }

            var currentUrl = WebsiteUrl.Text;

            await Task.Run(async() =>
            {
                var webClient = new WebClient();

                var downloadString = await webClient.DownloadStringTaskAsync(currentUrl);

                StringDownloaded.Invoke(downloadString);
            });
        }
 public WeekResult FindByWeek(string weekKey)
 {
     return(ResultSerializer.Deserialize <WeekResult>(File.ReadAllText(FileNameProvider.GetWeekFileName(weekKey))));
 }
 public bool HasWeekData(string weekKey)
 {
     return(File.Exists(FileNameProvider.GetWeekFileName(weekKey)));
 }
 public void Save(Year year, WeekResult weekResult)
 {
     using (var sw = new StreamWriter(FileNameProvider.GetWeekFileName(year.WeekKey(weekResult.Week))))
         sw.Write(Serialize(weekResult));
 }