Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string templateFileName = string.Concat(ImageProcessingManager.TemplatePath, txtTemplateName.Text, ".bin");

            if (Directory.Exists(ImageProcessingManager.TemplatePath) == false)
            {
                Directory.CreateDirectory(ImageProcessingManager.TemplatePath);
            }

            try
            {
                if (File.Exists(templateFileName))
                {
                    var result = MessageBox.Show("Template Name already present. Do you want to overwrite it?", "Save Template", MessageBoxButtons.YesNoCancel);
                    if (result != System.Windows.Forms.DialogResult.OK)
                    {
                        return;
                    }
                }
                var masterTemplate = ImageProcessingManager.FillMasterTemplate(ChessBoard, Padding, IsWhiteFirst);
                ImageProcessingManager.SaveTemplate(ChessBoard, templateFileName, masterTemplate, Intensity);
                AddEntryToTemplateCatalog(txtTemplateName.Text, lbl.Text, templateFileName);

                MessageBox.Show("Template saved successfully!", "Save Template", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            this.Close();
        }
Example #2
0
        public async Task <ActionResult> UploadCoverImage(string artistId)
        {
            try
            {
                PikchaUser pikchaUser = await _userManager.GetUserAsync(this.User);

                if (pikchaUser == null)
                {
                    return(StatusCode(StatusCodes.Status404NotFound, PikchaMessages.MESS_Status404_UserNotFound));
                }

                /* bool isArtist = await _userManager.IsInRoleAsync(pikchaUser, PikchaConstants.PIKCHA_ROLES_ARTIST_NAME);
                 * if(! isArtist)
                 * {
                 *   return StatusCode(StatusCodes.Status404NotFound, PikchaMessages.MESS_Status404_ArtistNotFound);
                 * } */
                using (var streamReader = new HttpRequestStreamReader(Request.Body, Encoding.UTF8))
                    using (var jsonReader = new JsonTextReader(streamReader))
                    {
                        var json = await JObject.LoadAsync(jsonReader);

                        string coverContent = (string)json["coverContent"];
                        if (coverContent.Contains(','))
                        {
                            coverContent = coverContent.Split(",")[1];
                        }

                        //string tmp = (string)json["signatureContent"]["data"];
                        ImageProcessingManager manager = new ImageProcessingManager(_hostingEnvironment, _configuration);
                        // = "";
                        string filePath = string.Empty;
                        manager.ProcessCoverImage(coverContent, ref filePath);
                        // get the PikchaUser from ClaimsPrincipal {{this.User}} and save the file location

                        if (!string.IsNullOrEmpty(filePath))
                        {
                            pikchaUser.Cover = filePath;
                            await _pikchDbContext.SaveChangesAsync();

                            //var pikchaUserQuery = _pikchDbContext.PikchaUsers.Include("Images.Views").Include("Following").Include("Following.PikchaUser").Include("Following.Artist").Where(u => u.Id == artistId);
                            // var userDTO = await _mapper.ProjectTo<ArtistDTO>(pikchaUserQuery).FirstAsync();
                            var pikchaUserDb = await _pikchDbContext.PikchaUsers.Include("Images.Views").Include("Following.Artist").Include("Followers.PikchaUser").FirstAsync(u => u.Id == pikchaUser.Id);

                            var userDTO = _mapper.Map <ArtistDTO>(pikchaUserDb);
                            return(ReturnOkOrErrorStatus(userDTO));
                        }
                        else
                        {
                            Log.Error(" Profile, UploadCoverImage, userId ={userId}, filePath={filePath}", artistId, filePath);
                            return(StatusCode(StatusCodes.Status500InternalServerError, PikchaMessages.MESS_Status500InternalServerError));
                        }
                    }
            }
            catch (Exception ex)
            {
                Log.Error(ex, " Profile, UploadCoverImage, userId ={userId}", artistId);
                return(StatusCode(StatusCodes.Status500InternalServerError, PikchaMessages.MESS_Status404ImageNotFound));
            }
        }
Example #3
0
        private void btnCaptureScreen_Click(object sender, EventArgs e)
        {
            ImageProcessingManager.TakeScreenShot();
            CaptureChessBoard chessBoard = new CaptureChessBoard();

            chessBoard.CapturedScreen = Image.FromFile("screen.jpg");
            chessBoard.Show();
            //pictureBox1.Image = img;
        }
Example #4
0
        public async Task <ActionResult> UploadAvatarImage(string userId)
        {
            try
            {
                using (var streamReader = new HttpRequestStreamReader(Request.Body, Encoding.UTF8))
                    using (var jsonReader = new JsonTextReader(streamReader))
                    {
                        var json = await JObject.LoadAsync(jsonReader);

                        string avatarContent = (string)json["avatarContent"];
                        if (avatarContent.Contains(','))
                        {
                            avatarContent = avatarContent.Split(",")[1];
                        }

                        //string tmp = (string)json["signatureContent"]["data"];
                        ImageProcessingManager manager = new ImageProcessingManager(_hostingEnvironment, _configuration);
                        // = "";
                        string filePath = string.Empty;
                        manager.ProcessAvatarFile(avatarContent, ref filePath);
                        // get the PikchaUser from ClaimsPrincipal {{this.User}} and save the file location
                        PikchaUser pikchaUser = await _userManager.GetUserAsync(this.User);

                        if (pikchaUser == null)
                        {
                            return(StatusCode(StatusCodes.Status404NotFound, PikchaMessages.MESS_Status404_UserNotFound));
                        }

                        if (!string.IsNullOrEmpty(filePath))
                        {
                            pikchaUser.Avatar = filePath;
                            await _pikchDbContext.SaveChangesAsync();

                            var lgUSer = _mapper.Map <AuthenticatedUserDTO>(pikchaUser);
                            var roles  = await _userManager.GetRolesAsync(pikchaUser);

                            if (roles != null)
                            {
                                lgUSer.Roles = roles.ToList();
                            }
                            return(Ok(lgUSer));
                        }
                        else
                        {
                            Log.Error(" Profile, UploadAvatarImage, userId ={userId}, filePath={filePath}", userId, filePath);
                            return(StatusCode(StatusCodes.Status500InternalServerError, PikchaMessages.MESS_Status500InternalServerError));
                        }
                    }
            }
            catch (Exception ex)
            {
                Log.Error(ex, " Profile, UploadAvatarImage, userId ={userId}", userId);
                return(StatusCode(StatusCodes.Status500InternalServerError, PikchaMessages.MESS_Status404ImageNotFound));
            }
        }
Example #5
0
        public ActionResult Create(HttpPostedFileBase[] file, Events events)
        {
            try
            {
                var check = 0;
                foreach (var item in file)
                {
                    if (item != null && item.ContentLength > 0)
                    {
                        var fileName   = "";
                        var randomFile = "";
                        var uploadDir  = "~/Content/Images/EventsPictures";

                        System.IO.Directory.CreateDirectory(Server.MapPath(uploadDir));

                        fileName = item.FileName;
                        string extension = Path.GetExtension(item.FileName);
                        randomFile = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + Guid.NewGuid().ToString("N") +
                                     extension;

                        var filePath = Path.Combine(Server.MapPath(uploadDir), randomFile);


                        //code to compress n save image
                        Image i = Image.FromStream(item.InputStream);
                        ImageProcessingManager imgprocess = new ImageProcessingManager(filePath);
                        imgprocess.SaveCompressedImage(i);

                        if (check != 0)
                        {
                            events.Images = events.Images + "," + randomFile;
                        }
                        else
                        {
                            events.Images = randomFile;
                        }
                        check = 1;
                    }
                }

                events.CreatedBy = User.Identity.GetUserId();
                events.CreatedOn = DateTime.UtcNow.AddHours(5);

                db.Events.Add(events);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(RedirectToAction("Index"));
        }
Example #6
0
        private void btnLoadTemplate_Click(object sender, EventArgs e)
        {
            TemplateEntity selectedEntity = allLoadedTemplates[cmbTemplates.SelectedIndex];

            if (selectedEntity != null)
            {
                //Console.WriteLine("Reading template " + selectedEntity.TemplateName);
                ImageProcessingManager.ReadTemplate(selectedEntity.TemplateFileName);

                MessageBox.Show("Template successfully loaded..", "Chess Master", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //Console.WriteLine("Reading template DONE!");
            }
        }
Example #7
0
 private void Awake()
 {
     #region Singleton implementation
     if (instance == null)
     {
         instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         DestroyImmediate(gameObject);
         return;
     }
     #endregion
 }
Example #8
0
        private void btnSplitImae_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            //Console.WriteLine("Reading current Chess position...");
            int paddingPixel = int.Parse(txtPadding.Text);

            if (rbtnWhite.Checked)
            {
                ImageProcessingManager.PrintChessBoard(rbtnWhite.Checked);
                ImageProcessingManager.PrepareFenString(rbtnWhite.Checked);
            }
            else
            {
                ImageProcessingManager.PrintChessBoard(rbtnWhite.Checked);
                ImageProcessingManager.PrepareFenString(rbtnWhite.Checked);
            }
            Cursor = Cursors.Default;
        }
Example #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            Image <Gray, Byte> template = new Image <Gray, byte>("A-1.jpg");
            //Image<Gray, Byte> template = new Image<Gray, byte>("1.jpg");
            Image <Gray, Byte> input_Image = new Image <Gray, byte>("after.jpg");
            bool result = ImageProcessingManager.AreImagesSame(template, input_Image, ImageProcessingManager.StandardMatchingFactor);

            //long matchTime = 0;
            //Image<Bgr, Byte> resultImage = ImageProcessingManager.Draw(template, input_Image, out matchTime);
            //int i = 0;
            if (result)
            {
                MessageBox.Show("matched");
            }
            else
            {
                MessageBox.Show("not matched");
            }
        }
Example #10
0
        private void btnReadMasterTemplate_Click(object sender, EventArgs e)
        {
            //this.SetDesktopLocation(Left+20, this.Top);

            Cursor = Cursors.WaitCursor;
            //Console.WriteLine("Reading master template...");
            int paddingPixel = int.Parse(txtPadding.Text);

            if (rbtnWhite.Checked)
            {
                //ImageProcessingManager.FillMasterTemplate(Image.FromFile("white.png"), paddingPixel, rbtnWhite.Checked);
                ImageProcessingManager.FillMasterTemplate(Image.FromFile("croppedTemplate.png"), paddingPixel, rbtnWhite.Checked);
                //ImageProcessingManager.FillMasterTemplate(Image.FromFile("test.jpg"), paddingPixel, rbtnWhite.Checked);
                //ImageProcessingManager.PrintChessBoard();
            }
            else
            {
                ImageProcessingManager.FillMasterTemplate(Image.FromFile("black.png"), 5, rbtnWhite.Checked);
            }
            Cursor = Cursors.Default;
            //Console.WriteLine("Done!");
        }
Example #11
0
        public async Task <ActionResult> UploadImage([FromForm] ImageViewModel imgViewModel)
        {
            try
            {  //
                PikchaUser loggedinUser = await _userManager.GetUserAsync(this.User);

                if (loggedinUser == null)
                {
                    return(StatusCode(StatusCodes.Status404NotFound, PikchaMessages.MESS_Status404_UserNotFound));
                }

                if (string.IsNullOrEmpty(imgViewModel.Signature) || !System.IO.File.Exists(PikchaConstants.PIKCHA_IMAGE_UPLOAD_ROOT_FOLDER + imgViewModel.Signature))
                {
                    return(StatusCode(StatusCodes.Status404NotFound, PikchaMessages.MESS_Status404SignatureNotFound));
                }
                if (imgViewModel.ImageFile == null)
                {
                    return(StatusCode(StatusCodes.Status404NotFound, PikchaMessages.MESS_Status404ImageNotFound));
                }

                string      imageId = Guid.NewGuid().ToString();
                PikchaImage pkImg   = new PikchaImage()
                {
                    Id = imageId
                };
                pkImg.CopyPropertiesFrom(imgViewModel);

                ImageProcessingManager imgManager = new ImageProcessingManager(_hostingEnvironment, _configuration);

                bool status = await imgManager.ProcessAndUploadImageAsync(imageId, imgViewModel.ImageFile, imgViewModel.Signature, ref pkImg);

                if (status)
                {
                    try
                    {
                        pkImg.Artist = loggedinUser;
                        await _pikchDbContext.PikchaImages.AddAsync(pkImg);

                        await _pikchDbContext.SaveChangesAsync();

                        // add image tags
                        await AddImageTags(pkImg, imgViewModel.Tags);

                        // add new product owned by owner of the image
                        decimal price = 0;
                        decimal.TryParse(imgViewModel.Price, out price);
                        ImageProduct imgPrd = new ImageProduct()
                        {
                            IsSale   = true,
                            FinPrice = price,
                            Type     = PikchaConstants.PIKCHA_PRODUCT_TYPE_OWNER,
                            Image    = pkImg,
                            Seller   = loggedinUser
                        };

                        await _pikchDbContext.ImageProducts.AddAsync(imgPrd);

                        await _pikchDbContext.SaveChangesAsync();

                        return(StatusCode(StatusCodes.Status201Created));
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, " Image, UploadImage, parameters: viewmodel={imgViewModel}, fileName={fileName}", imgViewModel != null ? "Not null" : "Null", (imgViewModel != null && imgViewModel.ImageFile != null)? imgViewModel.ImageFile.FileName : "Null");
                        return(StatusCode(StatusCodes.Status500InternalServerError, PikchaMessages.MESS_Status500InternalServerError));
                    }
                }
                else
                {
                    Log.Error(" Image, UploadImage, Image processing is failed., parameters: viewmodel={imgViewModel}, fileName={fileName}", imgViewModel != null ? "Not null" : "Null", (imgViewModel != null && imgViewModel.ImageFile != null) ? imgViewModel.ImageFile.FileName : "Null");
                    return(StatusCode(StatusCodes.Status500InternalServerError, PikchaMessages.MESS_Status500ImageProcessingError));
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, " Image, UploadImage, ");
                return(StatusCode(StatusCodes.Status500InternalServerError, PikchaMessages.MESS_Status500InternalServerError));
            }
        }
Example #12
0
        public async Task <ActionResult> PromoteUserToArtist(string userId)
        {
            try
            {
                var pikchaUser = await _userManager.GetUserAsync(this.User);

                if (pikchaUser == null)
                {
                    return(StatusCode(StatusCodes.Status404NotFound, PikchaMessages.MESS_Status404_UserNotFound));
                }
                bool isInAlready = await _userManager.IsInRoleAsync(pikchaUser, PikchaConstants.PIKCHA_ROLES_ARTIST_NAME);

                if (isInAlready)
                {
                    return(StatusCode(StatusCodes.Status404NotFound, PikchaMessages.MESS_Status404_UserAlreadyPromoted));
                }

                using (var streamReader = new HttpRequestStreamReader(Request.Body, Encoding.UTF8))
                    using (var jsonReader = new JsonTextReader(streamReader))
                    {
                        var json = await JObject.LoadAsync(jsonReader);

                        string signatureContent = (string)json["signatureContent"];
                        if (signatureContent.Contains(','))
                        {
                            signatureContent = signatureContent.Split(",")[1];
                        }
                        // upload signature file
                        ImageProcessingManager manager = new ImageProcessingManager(_hostingEnvironment, _configuration);
                        //string filePath = await manager.UploadToLocalDirectory(signatureFile, Guid.NewGuid().ToString(), ".jpg", StorageManager.FileCategory.Sign);
                        string orgFName = string.Empty;
                        string invFName = string.Empty;

                        await manager.ProcessSignatureFileAsync(signatureContent, ref orgFName, ref invFName);

                        pikchaUser.Sign    = orgFName;
                        pikchaUser.InvSign = invFName;
                        await _pikchDbContext.SaveChangesAsync();

                        var result = await _userManager.AddToRoleAsync(pikchaUser, PikchaConstants.PIKCHA_ROLES_ARTIST_NAME);

                        if (result.Succeeded)
                        {
                            var pkUsr = _mapper.Map <AuthenticatedUserDTO>(pikchaUser);
                            var roles = await _userManager.GetRolesAsync(pikchaUser);

                            if (roles != null)
                            {
                                pkUsr.Roles = roles.ToList();
                            }
                            return(Ok(pkUsr));
                        }
                        return(StatusCode(StatusCodes.Status500InternalServerError, "Error in promoting the user "));
                    }
            }
            catch (Exception ex)
            {
                Log.Error(ex, " Profile, PromoteUserToArtist, userId ={userId}", userId);
                return(StatusCode(StatusCodes.Status500InternalServerError, PikchaMessages.MESS_Status500InternalServerError));
            }
        }