public async Task PutContainer() { var url = _serverUrlForContainer + "?restype=container"; var now = SystemTime.UtcNow; var content = new EmptyContent { Headers = { { "x-ms-date", now.ToString("R") }, { "x-ms-version", AzureStorageVersion } } }; var client = GetClient(); client.DefaultRequestHeaders.Authorization = CalculateAuthorizationHeaderValue(HttpMethods.Put, url, content.Headers); var response = await client.PutAsync(url, content, CancellationToken); if (response.IsSuccessStatusCode) { return; } if (response.StatusCode == HttpStatusCode.Conflict) { return; } throw StorageException.FromResponseMessage(response); }
public void PutContainer(string containerName) { var url = GetUrl(containerName) + "?restype=container"; var now = SystemTime.UtcNow; var content = new EmptyContent { Headers = { {"x-ms-date", now.ToString("R") }, {"x-ms-version", "2011-08-18" }, } }; var client = GetClient(); client.DefaultRequestHeaders.Authorization = CalculateAuthorizationHeaderValue("PUT", url, content.Headers); var response = AsyncHelpers.RunSync(() => client.PutAsync(url, content)); if (response.IsSuccessStatusCode) return; if (response.StatusCode == HttpStatusCode.Conflict) return; throw ErrorResponseException.FromResponseMessage(response); }
public void PutContainer(string containerName) { var url = GetUrl(containerName) + "?restype=container"; var now = SystemTime.UtcNow; var content = new EmptyContent { Headers = { { "x-ms-date", now.ToString("R") }, { "x-ms-version", "2011-08-18" }, } }; var client = GetClient(); client.DefaultRequestHeaders.Authorization = CalculateAuthorizationHeaderValue("PUT", url, content.Headers); var response = AsyncHelpers.RunSync(() => client.PutAsync(url, content)); if (response.IsSuccessStatusCode) { return; } if (response.StatusCode == HttpStatusCode.Conflict) { return; } throw ErrorResponseException.FromResponseMessage(response); }
public void PutContainer() { var url = GetUrl(_serverUrlForContainer, "restype=container"); var now = SystemTime.UtcNow; var content = new EmptyContent { Headers = { { "x-ms-date", now.ToString("R") }, { "x-ms-version", AzureStorageVersion } } }; var client = GetClient(); SetAuthorizationHeader(client, HttpMethods.Put, url, content.Headers); var response = client.PutAsync(url, content, CancellationToken).Result; if (response.IsSuccessStatusCode) { return; } if (response.StatusCode == HttpStatusCode.Conflict) { return; } throw StorageException.FromResponseMessage(response); }
public async Task PutContainer() { var url = azureServerUrl + "?restype=container"; var now = SystemTime.UtcNow; var content = new EmptyContent { Headers = { {"x-ms-date", now.ToString("R") }, {"x-ms-version", AzureStorageVersion }, } }; var client = GetClient(); client.DefaultRequestHeaders.Authorization = CalculateAuthorizationHeaderValue("PUT", url, content.Headers); var response = await client.PutAsync(url, content).ConfigureAwait(false); if (response.IsSuccessStatusCode) return; if (response.StatusCode == HttpStatusCode.Conflict) return; throw ErrorResponseException.FromResponseMessage(response); }
public void ConstructorSetsCorrectEmptyContentProperties() { var empty = new EmptyContent(); Assert.AreEqual(ContentType.Empty, empty.ContentType); Assert.AreEqual(default(int), empty.Value); }
/// <summary> /// DownloadFile /// </summary> /// <param name="url"></param> /// <param name="method"></param> /// <param name="formData"></param> /// <param name="saveFileName"></param> /// <param name="call"></param> /// <returns></returns> public EmptyContent DownloadFile(string url, string method, FormData formData, string saveFileName, ProgressCall call) { EmptyContent result = new EmptyContent(); try { HttpWebRequest request = this.CreateRequest(url, method); this.SetFormData(request, formData); using (HttpWebResponse response = this.GetResponse(request)) { using (var responseStream = this.GetResponseStream(response)) { long length = response.ContentLength > 0 ? response.ContentLength : responseStream.Length; long position = 0; this.OnProgressCall(call, length, position); using (var fs = File.Create(saveFileName)) { byte[] buffer = new byte[8 * 1024]; int count = 0; int trycount = 0; do { count = responseStream.Read(buffer, 0, buffer.Length); if (count > 0) { fs.Write(buffer, 0, count); fs.Flush(); position = position + count; trycount = 0; this.OnProgressCall(call, length, position); } else if ((response.ContentLength == 0 || response.ContentLength > position) && trycount < 3) { System.Threading.Thread.Sleep(50); trycount++; count = 1; } }while (count > 0); } this.SetContent(response, result); } } } catch (Exception ex) { result.Error = ex; } return(result); }
private static void SetNames() { Thing.SetName("thing"); Link.SetName("link"); IsA.SetName("is a"); IsNotA.SetName("is not a"); Of.SetName("of"); And.SetName("and"); ThatConsistsOf.SetName("that consists of"); Has.SetName("has"); Contains.SetName("contains"); ContainedBy.SetName("contained by"); One.SetName("one"); Zero.SetName("zero"); Character.SetName("character"); Sum.SetName("sum"); String.SetName("string"); Name.SetName("name"); Set.SetName("set"); Group.SetName("group"); ParsedFrom.SetName("parsed from"); ThatIs.SetName("that is"); ThatIsBefore.SetName("that is before"); ThatIsAfter.SetName("that is after"); ThatIsBetween.SetName("that is between"); ThatIsRepresentedBy.SetName("that is represented by"); ThatHas.SetName("that has"); Text.SetName("text"); Path.SetName("path"); Content.SetName("content"); Empty.SetName("empty"); EmptyContent.SetName("empty content"); Alphabet.SetName("alphabet"); Letter.SetName("letter"); Case.SetName("case"); Upper.SetName("upper"); Lower.SetName("lower"); Code.SetName("code"); }
/// <summary> /// DownloadFile /// </summary> /// <param name="url"></param> /// <param name="method"></param> /// <param name="formData"></param> /// <param name="saveFileName"></param> /// <returns></returns> public EmptyContent DownloadFile(string url, string method, FormData formData, string saveFileName) { EmptyContent result = new EmptyContent(); try { HttpWebRequest request = this.CreateRequest(url, method); this.SetFormData(request, formData); using (HttpWebResponse response = this.GetResponse(request)) { using (var responseStream = this.GetResponseStream(response)) { using (var fs = File.Create(saveFileName)) { #if NET20 var buffer = new byte[8 * 1024]; int count = 0; while ((count = responseStream.Read(buffer, 0, buffer.Length)) > 0 || response.ContentLength > fs.Position) { if (count > 0) { fs.Write(buffer, 0, count); } else { System.Threading.Thread.SpinWait(10); } } #else responseStream.CopyTo(fs); #endif } this.SetContent(response, result); } } } catch (Exception ex) { result.Error = ex; } return(result); }
public void TestSetup() { content = new EmptyContent(); }
public MasterSamplePageWP(MasterSample sampleList) { if (Device.OS == TargetPlatform.Windows && Device.Idiom == TargetIdiom.Phone) { NavigationPage.SetHasNavigationBar(this, false); } Title = Device.OS == TargetPlatform.Android ? " " + sampleList.Title : sampleList.Title; //if (sampleList.Samples.Count == 1) //{ // var type = Type.GetType(sampleList.Samples[0].Type); // if (type == null) // { // Detail = new EmptyContent(); // } // else // { // var samplePage = Activator.CreateInstance(type) as SamplePage; // Detail = samplePage; // } //} //else if (sampleList.Samples.Count > 1) { var listView = new ListView { ItemsSource = sampleList.Samples, ItemTemplate = new DataTemplate(typeof(SampleListCell)), RowHeight = 45 }; var contentLayout = new StackLayout { Children = { listView } }; if (Device.OS == TargetPlatform.Windows && Device.Idiom == TargetIdiom.Phone) { contentLayout.Padding = new Thickness(0, 0, 0, 60); } var master = new ContentPage { Title = "Sample List", Content = contentLayout }; Master = master; Master.Icon = (Device.OS == TargetPlatform.Windows && Device.Idiom == TargetIdiom.Phone)? "Assets/Controls.png" : "Controls.png"; Detail = Activator.CreateInstance(Type.GetType(sampleList.Samples[0].Type)) as SamplePage; listView.ItemSelected += (sender, args) => { IsPresented = false; if (listView.SelectedItem == null) { return; } var sampleDetails = args.SelectedItem as SampleDetails; var type = Type.GetType(sampleDetails.Type); if (type == null) { Detail = new EmptyContent(); } else { var samplePage = Activator.CreateInstance(type) as SamplePage; Detail = samplePage; } //listView.SelectedItem = null; }; if (sampleList.Samples.Count > 0) { listView.SelectedItem = sampleList.Samples[0]; } } }
public MasterSamplePageWP(MasterSample sampleList) { if (Device.OS == TargetPlatform.Windows && Device.Idiom == TargetIdiom.Phone) NavigationPage.SetHasNavigationBar(this, false); Title = Device.OS == TargetPlatform.Android ? " " + sampleList.Title : sampleList.Title; //if (sampleList.Samples.Count == 1) //{ // var type = Type.GetType(sampleList.Samples[0].Type); // if (type == null) // { // Detail = new EmptyContent(); // } // else // { // var samplePage = Activator.CreateInstance(type) as SamplePage; // Detail = samplePage; // } //} //else if (sampleList.Samples.Count > 1) { var listView = new ListView { ItemsSource = sampleList.Samples, ItemTemplate = new DataTemplate(typeof (SampleListCell)), RowHeight = 45 }; var contentLayout = new StackLayout { Children = { listView } }; if (Device.OS == TargetPlatform.Windows && Device.Idiom == TargetIdiom.Phone) contentLayout.Padding = new Thickness(0, 0, 0, 60); var master = new ContentPage {Title = "Sample List", Content = contentLayout }; Master = master; Master.Icon = (Device.OS == TargetPlatform.Windows && Device.Idiom == TargetIdiom.Phone)? "Assets/Controls.png" : "Controls.png"; Detail = Activator.CreateInstance(Type.GetType(sampleList.Samples[0].Type)) as SamplePage; listView.ItemSelected += (sender, args) => { IsPresented = false; if (listView.SelectedItem == null) return; var sampleDetails = args.SelectedItem as SampleDetails; var type = Type.GetType(sampleDetails.Type); if (type == null) { Detail = new EmptyContent(); } else { var samplePage = Activator.CreateInstance(type) as SamplePage; Detail = samplePage; } //listView.SelectedItem = null; }; if (sampleList.Samples.Count > 0) { listView.SelectedItem = sampleList.Samples[0]; } } }