示例#1
0
        protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

      #warning first we have to setup connection info and create a session
            string instanceUrl = "http://myinstance.com/";

            using (var credentials = new SecureStringPasswordProvider("login", "password"))
                using (
                    var session =
                        SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(instanceUrl)
                        .Credentials(credentials)
                        .DefaultDatabase("web")
                        .DefaultLanguage("en")
                        .BuildReadonlySession())
                {
                    var request =
                        ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/content/home")
                        .AddScope(ScopeType.Self)
                        .Payload(PayloadType.Content)
                        .Build();

                    ScItemsResponse items = await session.ReadItemAsync(request);

                    string fieldContent = items[0]["Text"].RawValue;

                    string itemName = "Home Item Text";

                    var dialogBuilder = new AlertDialog.Builder(this);
                    dialogBuilder.SetTitle(itemName);
                    dialogBuilder.SetMessage(fieldContent);
                    dialogBuilder.SetPositiveButton("OK", (object sender, DialogClickEventArgs e) =>
                    {
                    });

                    dialogBuilder.Create().Show();
                }
        }
示例#2
0
        public override async void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            // first we have to setup connection info and create a session
            var instanceUrl = "http://mobiledev1ua1.dk.sitecore.net:722";

            using (var credentials = new SecureStringPasswordProvider("admin", "b"))
                using (
                    var session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(instanceUrl)
                                  .Credentials(credentials)
                                  .WebApiVersion("v1")
                                  .DefaultDatabase("web")
                                  .DefaultLanguage("en")
                                  .MediaLibraryRoot("/sitecore/media library")
                                  .MediaPrefix("~/media/")
                                  .DefaultMediaResourceExtension("ashx")
                                  .BuildSession())
                {
                    // In order to fetch some data we have to build a request
                    var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/content/home")
                                  .AddFieldsToRead("text")
                                  .AddScope(ScopeType.Self)
                                  .Build();

                    // And execute it on a session asynchronously
                    var response = await session.ReadItemAsync(request);

                    // Now that it has succeeded we are able to access downloaded items
                    ISitecoreItem item = response[0];

                    // And content stored it its fields
                    string fieldContent = item["text"].RawValue;

                    UIAlertView alert = new UIAlertView("Sitecore SDK Demo", fieldContent, null, "Ok", null);
                    alert.Show();
                }
        }
        public void TestCreateItemByIdWithUserWithoutCreateAccessReturnsException()
        {
            var anonymousSession = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(testData.InstanceUrl)
                                   .Credentials(testData.Users.NoCreateAccess)
                                   .Site(testData.ShellSite)
                                   .BuildSession();
            var request = ItemWebApiRequestBuilder.CreateItemRequestWithParentPath(this.testData.Items.CreateItemsHere.Path)
                          .ItemTemplatePath(testData.Items.Home.Template)
                          .ItemName("item created with nocreate user")
                          .Database("master")
                          .Build();

            TestDelegate testCode = async() =>
            {
                var   task = anonymousSession.CreateItemAsync(request);
                await task;
            };
            Exception exception = Assert.Throws <ParserException>(testCode);

            Assert.AreEqual("[Sitecore Mobile SDK] Data from the internet has unexpected format", exception.Message);
            Assert.AreEqual("Sitecore.MobileSDK.API.Exceptions.WebApiJsonErrorException", exception.InnerException.GetType().ToString());
            Assert.True(exception.InnerException.Message.Contains("AddFromTemplate - Add access required"));
        }
        public void TestGetItemAsAnonymousWithoutReadAccessReturnsError()
        {
            using
            (
                var session = SitecoreWebApiSessionBuilder.AnonymousSessionWithHost(testData.InstanceUrl)
                              .DefaultDatabase("web")
                              .DefaultLanguage("en")
                              .Site(testData.ShellSite)
                              .BuildReadonlySession()
            )
            {
                TestDelegate testCode = async() =>
                {
                    var   task = session.ReadItemAsync(this.requestWithItemId);
                    await task;
                };
                Exception exception = Assert.Throws <ParserException>(testCode);

                Assert.AreEqual("[Sitecore Mobile SDK] Data from the internet has unexpected format", exception.Message);
                Assert.AreEqual("Sitecore.MobileSDK.API.Exceptions.WebApiJsonErrorException", exception.InnerException.GetType().ToString());
                Assert.True(exception.InnerException.Message.Contains("Access to site is not granted."));
            }
        }
        public void TestHashingFlagCanBeSet()
        {
            using (var session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost("sitecore.net")
                                 .Credentials(this.adminCredentials)
                                 .MediaResizingStrategy(DownloadStrategy.Plain)
                                 .BuildSession())
            {
                Assert.IsNotNull(session);
                Assert.IsNotNull(session.MediaLibrarySettings);
                Assert.AreEqual(DownloadStrategy.Plain, session.MediaLibrarySettings.MediaDownloadStrategy);
            }


            using (var otherSession = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost("sitecore.net")
                                      .Credentials(this.adminCredentials)
                                      .MediaResizingStrategy(DownloadStrategy.Hashed)
                                      .BuildSession())
            {
                Assert.IsNotNull(otherSession);
                Assert.IsNotNull(otherSession.MediaLibrarySettings);
                Assert.AreEqual(DownloadStrategy.Hashed, otherSession.MediaLibrarySettings.MediaDownloadStrategy);
            }
        }
示例#6
0
 private IBaseSessionBuilder NewSession()
 {
     return(SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(this.testData.InstanceUrl)
            .Credentials(new WebApiCredentialsPOD("username", "password")));
 }