コード例 #1
0
        private async void SendRequest()
        {
            try
            {
                using (ISitecoreWebApiSession session = this.instanceSettings.GetSession())
                {
                    var request = ItemWebApiRequestBuilder.RenderingHtmlRequestWithSourceAndRenderingId(sourceIdTextField.Text, renderingIdTextField.Text)
                                  .Build();

                    this.ShowLoader();

                    Stream response = await session.ReadRenderingHtmlAsync(request);

                    response.Position = 0;
                    string htmlText = "";
                    using (StreamReader reader = new StreamReader(response))
                    {
                        htmlText = await reader.ReadToEndAsync();
                    }

                    this.resultWebView.LoadHtmlString(htmlText, null);
                }
            }
            catch (Exception e)
            {
                AlertHelper.ShowLocalizedAlertWithOkOption("Error", e.Message);
            }
            finally
            {
                BeginInvokeOnMainThread(delegate
                {
                    this.HideLoader();
                });
            }
        }
コード例 #2
0
        private async void GetRenderingHtml()
        {
            var sourceIdField    = this.FindViewById <EditText>(Resource.Id.field_source_id);
            var renderingIdField = this.FindViewById <EditText>(Resource.Id.field_rendering_id);

            var sourceId    = sourceIdField.Text;
            var renderingId = renderingIdField.Text;

            if (string.IsNullOrWhiteSpace(sourceId))
            {
                Toast.MakeText(this, "Please enter source ID", ToastLength.Long).Show();
                return;
            }

            if (string.IsNullOrWhiteSpace(renderingId))
            {
                Toast.MakeText(this, "Please enter rendering ID", ToastLength.Long).Show();
                return;
            }

            try
            {
                this.SetProgressBarIndeterminateVisibility(true);

                using (ISitecoreWebApiSession session = Prefs.From(this).Session)
                {
                    var request = ItemWebApiRequestBuilder.RenderingHtmlRequestWithSourceAndRenderingId(sourceId, renderingId)
                                  .Build();

                    var response = await session.ReadRenderingHtmlAsync(request);

                    if (response != null)
                    {
                        var    reader = new StreamReader(response);
                        string html   = await reader.ReadToEndAsync();

                        this.webview.LoadDataWithBaseURL(null, html, null, null, null);
                    }
                    else
                    {
                        var title = this.GetString(Resource.String.text_error);
                        DialogHelper.ShowSimpleDialog(this, title, "Failed load rendering html");
                    }
                }
                this.SetProgressBarIndeterminateVisibility(false);
            }
            catch (System.Exception exception)
            {
                this.SetProgressBarIndeterminateVisibility(false);

                var title = this.GetString(Resource.String.text_error);
                DialogHelper.ShowSimpleDialog(this, title, exception.Message);
            }
        }