public async void UploadGifFileToMasterDatabaseAsSitecoreAdminForParentPath()
        {
            await this.RemoveAll();

            using (var image = GetStreamFromUrl(TestEnvironment.Images.Gif.Pictures_2))
            {
                const string ItemName = "testGif";
                const string Database = "master";

                var request = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath(testData.Items.UploadMediaHere.Path)
                              .ItemDataStream(image)
                              .Database(Database)
                              .ItemName(ItemName)
                              .FileName("test.gif")
                              .ContentType("image/jpg")
                              .ItemTemplatePath("System/Media/Unversioned/Jpeg")
                              .Build();

                var response = await this.session.UploadMediaResourceAsync(request);

                Assert.AreEqual(1, response.ResultCount);
                Assert.AreEqual(ItemName, response[0].DisplayName);
                Assert.AreEqual(Database, response[0].Source.Database);
                this.AssertImageUploaded(response[0].Path, Database);
            }
        }
Esempio n. 2
0
        public void TestCorrectParamsForParentPath()
        {
            Stream stream = this.GenerateFakeStream();
            IMediaResourceUploadRequest request = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath("/some folder/path")
                                                  .ContentType("image/jpg")
                                                  .ItemName("name1")
                                                  .FileName("bugaga.jpg")
                                                  .ItemTemplatePath("System/Media/Unversioned/Image")
                                                  .ItemDataStream(stream)
                                                  .Build();

            IMediaResourceUploadRequest autocompletedRequest = this.requestMerger.FillUploadMediaGaps(request);

            string result   = this.builder.GetUrlForRequest(autocompletedRequest);
            string expected = "http://mobiledev1ua1.dk.sitecore.net:7119/" +
                              "-/item/v234%2f" +
                              "sitecore%2fshell" +
                              "%2fsome%20folder%2fpath" +
                              "?" +
                              "sc_database=web&" +
                              "name=name1&" +
                              "template=System%2fMedia%2fUnversioned%2fImage";

            Assert.AreEqual(expected, result);
        }
        public async void UploadJpgFileWithInternationalItemNameAndParentPath()
        {
            await this.RemoveAll();

            //create international parent
            var createRequest = ItemWebApiRequestBuilder.CreateItemRequestWithParentId(this.testData.Items.UploadMediaHere.Id)
                                .ItemTemplatePath(testData.Items.Home.Template)
                                .ItemName("युक्रेन")
                                .Database("master")
                                .Build();
            var createResponse = await session.CreateItemAsync(createRequest);

            //Assert.AreEqual(1, createResponse.ResultCount);
            using (var image = GetStreamFromUrl(TestEnvironment.Images.Jpeg._30x30))
            {
                const string ItemName   = "International Слава Україні ウクライナへの栄光";
                const string Database   = "master";
                string       parentPath = createResponse[0].Path.Remove(0, 23);
                var          request    = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath(parentPath)
                                          .ItemDataStream(image)
                                          .Database(Database)
                                          .ItemName(ItemName)
                                          .FileName("ク.gif")
                                          .Build();
                var response = await this.session.UploadMediaResourceAsync(request);

                Assert.AreEqual(1, response.ResultCount);
                Assert.AreEqual(ItemName, response[0].DisplayName);
                this.AssertImageUploaded(response[0].Path, Database);
            }
        }
        private async void UploadImage(Android.Net.Uri data)
        {
            var imageNameField = this.FindViewById <EditText>(Resource.Id.field_media_item_name);
            var imagePathField = this.FindViewById <EditText>(Resource.Id.field_media_item_path);

            var imageName = imageNameField.Text;
            var imagePath = imagePathField.Text;

            if (string.IsNullOrWhiteSpace(imageName))
            {
                Toast.MakeText(this, "Please select image name before upload", ToastLength.Long).Show();
                return;
            }

            if (data == null)
            {
                Toast.MakeText(this, "Please select image before upload", ToastLength.Long).Show();
                return;
            }

            try
            {
                this.SetProgressBarIndeterminateVisibility(true);

                using (ISitecoreWebApiSession session = Prefs.From(this).Session)
                {
                    using (Stream stream = ContentResolver.OpenInputStream(this.imageUri))
                    {
                        var builder = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath(imagePath)
                                      .ItemDataStream(stream)
                                      .ContentType("image/jpg")
                                      .ItemName(imageName)
                                      .FileName("bugaga.jpg");

                        var response = await session.UploadMediaResourceAsync(builder.Build());

                        if (response != null && response.ResultCount > 0)
                        {
                            DialogHelper.ShowSimpleDialog(this, "Image uploaded", "Image path : " + response[0].Path);
                        }
                        else
                        {
                            var title = this.GetString(Resource.String.text_error);
                            DialogHelper.ShowSimpleDialog(this, title, "Failed to upload image");
                        }
                    }
                }
                this.SetProgressBarIndeterminateVisibility(false);
            }
            catch (System.Exception exception)
            {
                this.SetProgressBarIndeterminateVisibility(false);

                var title = this.GetString(Resource.String.text_error);
                DialogHelper.ShowSimpleDialog(this, title, exception.Message);
            }
        }
Esempio n. 5
0
        public void TestItemNameRequired()
        {
            Stream stream  = this.GenerateFakeStream();
            var    builder = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath("/some folder/path")
                             .ContentType("image/jpg")
                             .FileName("bugaga.jpg")
                             .ItemDataStream(stream);

            Assert.Throws <ArgumentNullException>(() => builder.Build());
        }
Esempio n. 6
0
        public void TestItemDataStreamRequired()
        {
            var builder = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath("/some folder/path")
                          .ContentType("image/jpg")
                          .ItemName("name1")
                          .FileName("bugaga.jpg")
                          .ItemTemplatePath("System/Media/Unversioned/Image");

            Assert.Throws <ArgumentNullException>(() => builder.Build());
        }
Esempio n. 7
0
        public void TestContentTypeIsNotRequired()
        {
            Stream stream  = this.GenerateFakeStream();
            var    request = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath("/some folder/path")
                             .ItemName("name1")
                             .FileName("bugaga.jpg")
                             .ItemDataStream(stream)
                             .Build();

            Assert.NotNull(request, "null Content type should be available");
        }
        public async void UploadImageToEmptyParentPathDoesNotReturnException()
        {
            await this.RemoveAll();

            using (var image = GetStreamFromUrl(TestEnvironment.Images.Gif.Pictures_2))
            {
                var request = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath("")
                              .ItemDataStream(image)
                              .ItemName("test")
                              .FileName("test.png")
                              .Build();
                Assert.NotNull(request);
            }
        }
        public async void UploadImageToWith2ItemNamesReturnsInvalidOperationException()
        {
            await this.RemoveAll();

            using (var image = GetStreamFromUrl(TestEnvironment.Images.Gif.Pictures_2))
            {
                var exception = Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath(this.testData.Items.UploadMediaHere.Path)
                                                                          .ItemDataStream(image)
                                                                          .ItemName("test")
                                                                          .ItemName("test2")
                                                                          .FileName("test.png")
                                                                          .Build());
                Assert.AreEqual("UploadMediaItemByParentPathRequestBuilder.ItemName : Property cannot be assigned twice.", exception.Message);
            }
        }
        private async Task <ScItemsResponse> UploadLargeImage()
        {
            var    resourceUrl = NSBundle.MainBundle.PathForResource("IMG_0994", "MOV");
            string host        = "http://cms71u3.test24dk1.dk.sitecore.net";



            // iOS hardware : FileStream constructor throws
            // Access to the path "/var/mobile/Applications/2CD1D07E-26DD-43CC-AF52-F24368FB4676/LargeUploadTestiOS.app/IMG_0994.MOV" is denied.


            using (NSData movieContents = NSData.FromFile(resourceUrl))
                using (Stream videoOnFileSystem = movieContents.AsStream())
                    using (IWebApiCredentials auth = new SecureStringPasswordProvider.iOS.SecureStringPasswordProvider("sitecore\\admin", "b"))
                        using (var session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(host)
                                             .Credentials(auth)
                                             .Site("/sitecore/shell")
                                             .BuildSession())

                        {
                            // TODO : dispose properly
                            //        NSData movieContents = NSData.FromFile(resourceUrl);
                            //        Stream videoOnFileSystem = movieContents.AsStream();


//        byte[] tmp = System.Text.Encoding.UTF8.GetBytes("Hello World");
//        Stream videoOnFileSystem = new MemoryStream(tmp);

                            var request = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath("/")
                                          .ItemDataStream(videoOnFileSystem)
                                          .Database("master")
                                          .ItemName("NewLargeMedia for adk")
                                          .FileName("IMG_0997.MOV")
                                          .ContentType("video/quicktime")
                                          .ItemTemplatePath("System/Media/Unversioned/Movie")
                                          .Build();

                            var response = await session.UploadMediaResourceAsync(request);

                            return(response);
                        }
        }
        private async void SendImage(UIImage image)
        {
            try
            {
                using (ISitecoreWebApiSession session = this.instanceSettings.GetSession())
                {
                    Stream stream = image.AsJPEG().AsStream();

                    var request = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath(itemPathTextField.Text)
                                  .ItemDataStream(stream)
                                  .ContentType("image/jpg")
                                  .ItemName(this.itemNameTextField.Text)
                                  .FileName("imageFile.jpg")
                                  .Build();

                    this.ShowLoader();

                    var response = await session.UploadMediaResourceAsync(request);

                    if (response != null)
                    {
                        AlertHelper.ShowAlertWithOkOption("upload image result", "The image uploaded successfuly");
                    }
                    else
                    {
                        AlertHelper.ShowAlertWithOkOption("upload image result", "something wrong");
                    }
                }
            }
            catch (Exception e)
            {
                AlertHelper.ShowLocalizedAlertWithOkOption("Error", e.Message);
            }
            finally
            {
                BeginInvokeOnMainThread(delegate
                {
                    this.HideLoader();
                });
            }
        }
        public async void UploadImageToNotExistentFolder()
        {
            await this.RemoveAll();

            using (var image = GetStreamFromUrl(TestEnvironment.Images.Gif.Pictures_2))
            {
                var request = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath("/not existent/folder")
                              .ItemDataStream(image)
                              .ItemName("test")
                              .FileName("test.png")
                              .Build();

                TestDelegate testCode = async() =>
                {
                    var   task = this.session.UploadMediaResourceAsync(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.AreEqual("The specified location not found.", exception.InnerException.Message);
            }
        }
Esempio n. 13
0
        public void TestNullParentPath()
        {
            var builder = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath(null);

            Assert.NotNull(builder, "null path should be available");
        }
Esempio n. 14
0
        public void TestEmptyContentType()
        {
            var builder = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath("/some folder/path");

            Assert.Throws <ArgumentException>(() => builder.ContentType(""));
        }