private static void CheckForValidResponse(PictureResponse response)
 {
     Assert.IsNotNull(response);
     Assert.AreEqual(response.data.Length, 16);
     Assert.IsTrue(response.data.All(p => !p.favorited));
     Assert.IsTrue(response.data.All(p => { int t; return(int.TryParse(p.id, out t)); }));
 }
        public async Task TestIndexRequestWithWarnings()
        {
            // Request: http://walldash.net/backend/main_page/get_images.php?resolution=all&sort_by=r&also_find=l&color=+&show_nsfw=false&show_sketchy=false&show_sfw=true&tags=&username=&password=&session_id=&imgs_to_show=16&imgs_shown=0&_=1432239046438
            PictureResponse response = await GetResponseFor("get_images_index_with_warnings.json");

            CheckForValidResponse(response);
        }
Ejemplo n.º 3
0
        public async Task <PictureResponse> SetPicture(PictureForm form)
        {
            var response = new PictureResponse();

            var(system, error) = await GetPrepare(form.Id);

            if (error != null)
            {
                response.Error = error;
                return(response);
            }
            response.Picture = system.Picture;

            if (form.Picture != null)
            {
                if (form.Picture.Length > 5 * 1024 * 1024)
                {
                    response.Error = "Картинка слишком большая";
                    return(response);
                }
                var path = "/systems/" + form.Id;
                switch (form.Picture.ContentType)
                {
                case "image/gif":
                    path += ".gif";
                    break;

                case "image/jpeg":
                    path += ".jpg";
                    break;

                case "image/png":
                    path += ".png";
                    break;

                default:
                    response.Error = "Картинка неизвестного формата";
                    return(response);
                }
                using (var stream = new FileStream(_hostingEnvironment.WebRootPath + path, FileMode.Create))
                {
                    await form.Picture.CopyToAsync(stream);
                }
                var oldPath = system.Picture.Split("?").First();
                if (oldPath != path && !oldPath.StartsWith("/default/"))
                {
                    System.IO.File.Delete(_hostingEnvironment.WebRootPath + oldPath);
                }
                path          += "?d=" + DateTimeOffset.Now.ToUnixTimeMilliseconds();
                system.Picture = path;
            }

            response.Succeded = true;
            response.Picture  = system.Picture;

            await _db.SaveChangesAsync();

            return(response);
        }
Ejemplo n.º 4
0
 private void AssertAllPropertiesHaveValues(PictureResponse response)
 {
     Assert.IsFalse(string.IsNullOrWhiteSpace(response.Id));
     Assert.IsFalse(string.IsNullOrWhiteSpace(response.Name));
     Assert.IsFalse(string.IsNullOrWhiteSpace(response.AppPath));
     Assert.IsFalse(string.IsNullOrWhiteSpace(response.OriginalPath));
     Assert.IsFalse(string.IsNullOrWhiteSpace(response.FolderName));
     Assert.IsFalse(string.IsNullOrWhiteSpace(response.FolderId));
     Assert.IsTrue(response.FolderSortOrder > 0);
     Assert.IsTrue(response.Size > 0);
     Assert.IsNotNull(response.Tags);
     Assert.IsTrue(response.Tags.Count() > 0);
     Assert.IsNotNull(response.CreateTimestamp);
 }
Ejemplo n.º 5
0
        public async Task <ActionResult <PictureResponse> > GetPicture(Guid id)
        {
            var pic = await _context.Pictures.FindAsync(id);

            if (pic == null)
            {
                return(NotFound());
            }
            var response = new PictureResponse {
                AnswerLength = pic.AnswerLength, Category = pic.Category, Id = pic.Id, URL = pic.URL
            };

            return(Ok(response));
        }
        public async Task <List <string> > GetImages(string query, string sort, int startFrom, string additional)
        {
            if (string.IsNullOrWhiteSpace(additional))
            {
                // HACK: Because WwwFormUrlDecoder does not want empty strings...
                additional = "dummy=dummy";
            }

            WwwFormUrlDecoder decoder = new WwwFormUrlDecoder(additional);

            sort = GetCorrectOrderBy(sort);

            // Additional configuration.
            int    imagesPerPage = GetInteger(decoder, "imagesPerPage", 16);
            string resolution    = GetValue(decoder, "resolution", "all");
            string alsoFind      = GetValue(decoder, "also_find", "l");
            string color         = GetValue(decoder, "color", "+");
            string showSfw       = GetValue(decoder, "show_sfw", "true");
            string showSketchy   = GetValue(decoder, "show_sketchy", "false");
            string showNsfw      = GetValue(decoder, "show_nsfw", "false");
            string username      = GetValue(decoder, "username", string.Empty);
            string password      = GetValue(decoder, "password", string.Empty);
            string sessionId     = GetValue(decoder, "session_id", string.Empty);
            string _             = GetValue(decoder, "_", "1432239046438");

            int startIndex = imagesPerPage * startFrom;

            query = WebUtility.UrlEncode(query);
            string url = "http://walldash.net/backend/main_page/get_images.php?";

            url += $"resolution={resolution}&sort_by={sort}&also_find={alsoFind}&";
            url += $"color={color}&show_nsfw={showNsfw}&show_sketchy={showSketchy}&";
            url += $"show_sfw={showSfw}&tags={query}&username={username}&";
            url += $"password={password}&session_id={sessionId}&imgs_to_show={imagesPerPage}&";
            url += $"imgs_shown={startIndex}&_={_}";

            HttpClient client = new HttpClient();
            string     json   = await client.GetStringAsync(new Uri(url));

            // Parse JSON
            PictureResponse images = ParseImages(json);

            // Get just links
            return(images.data.Select(img => $"http://walldash.net/imgs/{img.id}.jpg").ToList());
        }
Ejemplo n.º 7
0
        public static void Run()
        {
            // ExStart:1
            CellsApi   cellsApi   = new CellsApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);
            StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            String fileName     = "Sample_Test_Book.xls";
            String sheetName    = "Sheet6";
            int    pictureIndex = 0;
            String storage      = "";
            String folder       = "";

            Picture body = new Picture();

            body.Name          = "aspose-cloud-logo";
            body.RotationAngle = 90.0;

            try
            {
                // Upload source file to aspose cloud storage
                storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName));

                // Invoke Aspose.Cells Cloud SDK API to update specific picture from excel worksheet
                PictureResponse apiResponse = cellsApi.PostWorkSheetPicture(fileName, sheetName, pictureIndex, storage, folder, body);

                if (apiResponse != null && apiResponse.Status.Equals("OK"))
                {
                    Console.WriteLine("Update a specific Picture from Excel Worksheet , Done!");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
            // ExEnd:1
        }
        public async Task TestIndexRequest()
        {
            PictureResponse response = await GetResponseFor("get_images_index.json");

            CheckForValidResponse(response);
        }