public IHttpActionResult GetImages(int id, int catid)
        {
            List <COMimage> list;

            //if the call was made to get the users image
            if (catid != -1)
            {
                list = BLLimage.Getimages().FindAll(img => img.CategoryID == catid);
            }
            else
            {
                //time is current page number in this category images
                list = BLLimage.Getimages().FindAll(img => img.UserId == id);
            }
            if (list == null)
            {
                return(BadRequest("fail to load images"));
            }
            if (list.Count > 0)
            {
                return(Ok(ImageMat.CreateMat(list, true)));
            }
            else
            {
                return(BadRequest("no more pictures for this category."));
            }
        }
Ejemplo n.º 2
0
        public void Load()
        {
            int x = 0;

            foreach (COMCategory cat in BLLcategory.GetCategories())
            {
                x = BLLimage.Getimages().FindAll(img => img.CategoryID == cat.CategoryId).Count();
                categoriesCounter.Add(cat.CategoryName, x);
            }
            foreach (COMCategory cat in BLLcategory.GetCategories())
            {
                List <COMimageObject> objects = new List <COMimageObject>();
                BLLimage.Getimages().FindAll(img => img.CategoryID == cat.CategoryId).ForEach(img => objects.AddRange(BLLobject.GetObjects().FindAll(obj => obj.ImageID == img.ImageID)));
                x = objects.Count;
                voicesCounter.Add(cat.CategoryName, x);
            }
        }
    public static string VoiceStorage(int userId,int catId, string URL, Dictionary<string, int> voicesCounter)
    {
        Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS",  @"C:\keys\wordproject -29b2e0d3e0d5.json");
        // upload the image storage
        string voiceName;
        if(voicesCounter.Count>0)
        //voicesCounter[BLLcategory.GetCategoryById(catId).CategoryName]++
        voiceName = "voice" + BLLcategory.GetCategoryById(catId).CategoryName + voicesCounter[BLLcategory.GetCategoryById(catId).CategoryName]++ + ".mp3";
        else
        {
            List<COMimageObject> objs = new List<COMimageObject>();
            foreach (COMimage img in BLLimage.Getimages().FindAll(img => img.UserId == userId))
            {
                objs.AddRange(BLLobject.GetObjects().FindAll(obj => obj.ImageID == img.ImageID));
            }

            string add = catId == 6 ? BLLuser.GetUserById(userId).CategoryName : BLLcategory.GetCategoryById(catId).CategoryName;
            voiceName = "voice" + add + objs.Count + ".mp3";

        }
        string bucketName = "objectsound";
        var storage = StorageClient.Create();
        using (var f = File.OpenRead(URL))
        {
            try
            {
                var res = storage.UploadObject(bucketName, voiceName, null, f);
                URL = "https://storage.googleapis.com/" + bucketName + "/" + voiceName;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        return URL;
    }