Beispiel #1
0
        public void CopyFromTempFolderMultiple(int?boardId)
        {
            var sourcePath = UploadsFolder.GetUploadsSubPath(UploadsFolder.TempFolderMultiple);

            var destPath = UploadsFolder.GetUploadsSubPath(boardId.ToString());

            if (!Directory.Exists(destPath))
            {
                Directory.CreateDirectory(destPath);
            }

            CopyFiles(sourcePath, destPath);

            //Delete unrelated vsn
            DirectoryInfo thisDirectory = new DirectoryInfo(destPath);

            FileInfo[] vsnFiles = thisDirectory.GetFiles("board*.vsn"); //Files start with 'board'
            foreach (var vsn in vsnFiles)
            {
                string vsnToKeep = "board" + boardId.ToString() + ".vsn";
                if (vsn.Name != vsnToKeep)
                {
                    vsn.Delete();
                }
            }
        }
        public async Task AutoUpdateRandDynamicData(int id)
        {
            //generate random eta
            Random rndETA1 = new Random();
            int    etaint1 = rndETA1.Next(1, 60); // creates a number between 1 and 60
            string eta1    = etaint1.ToString() + "min";
            Random rndETA2 = new Random();
            int    etaint2 = rndETA2.Next(1, 60); // creates a number between 1 and 60
            string eta2    = etaint2.ToString() + "min";

            //call traveltimeService to update the values into postgresql database
            traveltimeService.updateTravelTime(id, "1", "mvalley", "Mid Valley",
                                               DateTime.Now.ToString(), eta1);
            traveltimeService.updateTravelTime(id, "1", "tsquare", "Times Square",
                                               DateTime.Now.ToString(), eta2);

            //call parkingService to update the values into postgresql database
            //--------

            //call weatherService to update the values into postgresql database

            /*Random rand1 = new Random();
             * int diceNum1 = rand1.Next(0, 2);
             * Random rand2 = new Random();
             * int diceNum2 = rand2.Next(0, 2);
             * Random rand3 = new Random();
             * int diceNum3 = rand3.Next(0, 2);
             * string[] weatherStatus = new string[] { "rain", "no rain", "thunderstorm" };
             *
             * string morning = weatherStatus[diceNum1];
             * string afternoon = weatherStatus[diceNum2];
             * string night = weatherStatus[diceNum3];
             *
             * weatherService.updateWeather(id, "Selayang", morning, afternoon,
             *  night, DateTime.Now.ToString());*/


            //delete tempfoldersingle, recreate tempfilersingle, copy from board folder
            var folderPath = UploadsFolder.GetUploadsSubPath(UploadsFolder.TempFolderSingle);

            if (Directory.Exists(folderPath))
            {
                Directory.Delete(folderPath, true);                               //delete old folder
            }
            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);                                //create new folder
            }
            var sourcePathToCopy = UploadsFolder.GetUploadsSubPath(id.ToString());

            if (Directory.Exists(sourcePathToCopy))
            {
                _fileManagement.CopyFiles(sourcePathToCopy, folderPath);                                     //make a copy from board folder
            }
            //call createvsn to re-create the vsn file
            _createVsnService.createVSN(id, false);
            //update physical board
            await _colorlightServices.SendProgramAsync(id, false);
        }
Beispiel #3
0
        public void CopyClientUploadedFiles(string destPath)
        {
            var sourcePath = UploadsFolder.GetUploadsSubPath(UploadsFolder.TempFolderClient);

            if (!Directory.Exists(sourcePath))
            {
                Directory.CreateDirectory(sourcePath);
            }
            CopyFiles(sourcePath, destPath);
        }
Beispiel #4
0
        public async Task UpdateHistory(int boardId)
        {
            var user = await _userManager.GetUserAsync(User);

            var userName = await _userManager.GetUserNameAsync(user);

            //var userName = "******";

            var board = await _context.Boards
                        .Include(b => b.Location)
                        .Include(b => b.Display)
                        .ThenInclude(d => d.MessageAssignments)
                        .FirstOrDefaultAsync(m => m.ID == boardId);

            //Save images - copy from <board> folder to history folder
            string sourcePath;
            string destPath;
            string sourceFile;
            string destFile;

            var thisBoardName     = board.Name;
            var thisBoardMessages = board.Display.MessageAssignments.ToList();

            //Board Folder
            sourcePath = Path.Combine(UploadsFolder.GetUploadsSubPath(boardId.ToString()));
            //History Folder
            string subFolderName = thisBoardName + "_" + DateTime.Now.ToString("ddMMyyyy-HHmm");

            destPath = Path.Combine(UploadsFolder.GetUploadsSubPath(UploadsFolder.History), subFolderName);
            if (!Directory.Exists(destPath))
            {
                Directory.CreateDirectory(destPath);
            }

            foreach (var message in thisBoardMessages)
            {
                string fileName = message.ImageFileName + fileExtension;
                sourceFile = System.IO.Path.Combine(sourcePath, fileName);
                destFile   = System.IO.Path.Combine(destPath, fileName);
                System.IO.File.Copy(sourceFile, destFile, true);
            }

            _context.Histories.Add( //Add
                new History
            {
                H_Name        = board.Name,
                H_Address     = board.Location.Address,
                H_NowDateTime = DateTime.Now,
                H_User        = userName,
                Object        = destPath
            });
            await _context.SaveChangesAsync();

            Message = "Successfully Edited. Please check history. Please check board.";
        }
Beispiel #5
0
        public void CopyFromTempFolderSingle(int?boardId)
        {
            var sourcePath = UploadsFolder.GetUploadsSubPath(UploadsFolder.TempFolderSingle);

            var destPath = UploadsFolder.GetUploadsSubPath(boardId.ToString());

            if (!Directory.Exists(destPath))
            {
                Directory.CreateDirectory(destPath);
            }

            CopyFiles(sourcePath, destPath);
        }
Beispiel #6
0
        public void UploadFile(string fileName, IFormFile file)
        {
            string uploadFolderPath;
            string filePath;

            uploadFolderPath = UploadsFolder.GetUploadsSubPath(UploadsFolder.TempFolderClient);
            filePath         = Path.Combine(uploadFolderPath, fileName);

            // If file with same name exists delete it
            if (System.IO.File.Exists(fileName))
            {
                System.IO.File.Delete(fileName);
            }

            // Create new local file and copy contents of uploaded file
            using (var localFile = System.IO.File.OpenWrite(filePath))
                using (var uploadedFile = file.OpenReadStream())
                {
                    uploadedFile.CopyTo(localFile);
                }
        }
        public async Task AutoUpdateDynamicData(int id)
        {
            //delete tempfoldersingle, recreate tempfilersingle, copy from board folder
            var folderPath = UploadsFolder.GetUploadsSubPath(UploadsFolder.TempFolderSingle);

            if (Directory.Exists(folderPath))
            {
                Directory.Delete(folderPath, true);                               //delete old folder
            }
            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);                                //create new folder
            }
            var sourcePathToCopy = UploadsFolder.GetUploadsSubPath(id.ToString());

            if (Directory.Exists(sourcePathToCopy))
            {
                _fileManagement.CopyFiles(sourcePathToCopy, folderPath);                                     //make a copy from board folder
            }
            //call createvsn to re-create the vsn file
            _createVsnService.createVSN(id, false);
            //update physical board
            await _colorlightServices.SendProgramAsync(id, false);
        }
Beispiel #8
0
        public async Task <bool> SendProgramAsync(int boardId, bool isMultiple)
        {
            ThisBoard = await _context.Boards
                        .Include(b => b.Display)
                        .AsNoTracking()
                        .FirstOrDefaultAsync(m => m.ID == boardId);

            string c4_IPAddress = ThisBoard.Display.C4_IP;
            string vsnFilename  = "board" + boardId.ToString() + ".vsn";

            Client         = new RestClient("http://" + c4_IPAddress + "/api/program/" + vsnFilename);
            Client.Timeout = -1;

            Request = new RestRequest(Method.POST);
            Request.AddHeader("Content-Type", "multipart/form-data;bounda6ry=;");

            //Manage post directory and the program (+files) to be sent
            string postDirectory;
            string defaultDirectory = Directory.GetCurrentDirectory();

            this.logger.LogDebug("Current Directory: " + defaultDirectory);
            if (!isMultiple)
            {
                postDirectory = UploadsFolder.GetUploadsSubPath(UploadsFolder.TempFolderSingle);
            }
            else
            {
                postDirectory = UploadsFolder.GetUploadsSubPath(UploadsFolder.TempFolderMultiple);
            }
            Directory.SetCurrentDirectory(postDirectory);
            this.logger.LogDebug("New Directory: " + postDirectory);
            List <string> filenameList = GetAllFilenames(postDirectory);

            int key = 0;

            foreach (var file in filenameList)
            {
                Request.AddFile("f" + key.ToString(), file);
                key++;
            }

            Response = Client.Execute(Request);

            /*string content = response.Content;
             * string contentType = response.ContentType;
             * IList<Parameter> headers = response.Headers;
             * string errorMessage = response.ErrorMessage;
             * Exception errorException = response.ErrorException;*/
            NumericStatusCode = (int)Response.StatusCode;

            //Reset default directory after request execution
            Directory.SetCurrentDirectory(defaultDirectory);
            this.logger.LogDebug("Directory is reset to " + Directory.GetCurrentDirectory());

            if (Response.IsSuccessful || Response.ResponseStatus.ToString() == "Completed")
            {
                if (NumericStatusCode == 200)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #9
0
        public async Task CombineHistory(int boardId)
        {
            var board = await _context.Boards
                        .Include(b => b.Location)
                        .Include(b => b.Display)
                        .ThenInclude(d => d.MessageAssignments)
                        .FirstOrDefaultAsync(m => m.ID == boardId);


            string sourcePath;
            string destComebineHistory;

            var thisBoardName = board.Name;

            //Board Folder
            sourcePath = Path.Combine(UploadsFolder.GetUploadsSubPath(boardId.ToString()));


            //CombineHistory Folder
            string subCombineHistory = thisBoardName;

            destComebineHistory = Path.Combine(UploadsFolder.GetUploadsSubPath(UploadsFolder.CombineHistory), subCombineHistory);
            if (!Directory.Exists(destComebineHistory))
            {
                Directory.CreateDirectory(destComebineHistory);
            }

            Bitmap newImg = new Bitmap(790, 1024);

            Graphics g = Graphics.FromImage(newImg);



            g.DrawImage(Image.FromFile(Path.Combine(sourcePath, "message1.jpg")), new Point(10, 10));
            newImg.Save(Path.Combine(destComebineHistory, "output.jpg"), ImageFormat.Jpeg);

            g.DrawImage(Image.FromFile(Path.Combine(sourcePath, "message2.jpg")), new Point(10, 200));
            newImg.Save(Path.Combine(destComebineHistory, "output.jpg"), ImageFormat.Jpeg);

            g.DrawImage(Image.FromFile(Path.Combine(sourcePath, "message3.jpg")), new Point(10, 400));
            newImg.Save(Path.Combine(destComebineHistory, "output.jpg"), ImageFormat.Jpeg);

            g.DrawImage(Image.FromFile(Path.Combine(sourcePath, "message4.jpg")), new Point(10, 600));
            newImg.Save(Path.Combine(destComebineHistory, "output.jpg"), ImageFormat.Jpeg);

            g.DrawImage(Image.FromFile(Path.Combine(sourcePath, "message5.jpg")), new Point(10, 800));
            newImg.Save(Path.Combine(destComebineHistory, "output.jpg"), ImageFormat.Jpeg);

            //g.DrawImage(Image.FromFile(@"wwwroot\uploads\" + boardID + "\\message1.jpg"), new Point(10, 10));
            //newImg.Save(@"wwwroot\uploads\CombineHistory\" + subCombineHistory + "\\output.jpg", ImageFormat.Jpeg);

            //g.DrawImage(Image.FromFile(@"wwwroot\uploads\" + boardID + "\\message2.jpg"), new Point(10, 200));
            //newImg.Save(@"wwwroot\uploads\CombineHistory\" + subCombineHistory + "\\output.jpg", ImageFormat.Jpeg);

            //g.DrawImage(Image.FromFile(@"wwwroot\uploads\" + boardID + "\\message3.jpg"), new Point(10, 400));
            //newImg.Save(@"wwwroot\uploads\CombineHistory\" + subCombineHistory + "\\output.jpg", ImageFormat.Jpeg);

            //g.DrawImage(Image.FromFile(@"wwwroot\uploads\" + boardID + "\\message4.jpg"), new Point(10, 600));
            //newImg.Save(@"wwwroot\uploads\CombineHistory\" + subCombineHistory + "\\output.jpg", ImageFormat.Jpeg);

            //g.DrawImage(Image.FromFile(@"wwwroot\uploads\" + boardID + "\\message5.jpg"), new Point(10, 800));
            //newImg.Save(@"wwwroot\uploads\CombineHistory\" + subCombineHistory + "\\output.jpg", ImageFormat.Jpeg);

            ///////////
            //g.DrawImage(Image.FromFile(@"wwwroot/uploads/" + boardID + "/message1.jpg"), new Point(10, 10));
            //newImg.Save(@"wwwroot/uploads/CombineHistory/" + subCombineHistory + "/output.jpg", ImageFormat.Jpeg);

            //g.DrawImage(Image.FromFile(@"wwwroot/uploads/" + boardID + "/message2.jpg"), new Point(10, 200));
            //newImg.Save(@"wwwroot/uploads/CombineHistory/" + subCombineHistory + "/output.jpg", ImageFormat.Jpeg);

            //g.DrawImage(Image.FromFile(@"wwwroot/uploads/" + boardID + "/message3.jpg"), new Point(10, 400));
            //newImg.Save(@"wwwroot/uploads/CombineHistory/" + subCombineHistory + "/output.jpg", ImageFormat.Jpeg);

            //g.DrawImage(Image.FromFile(@"wwwroot/uploads/" + boardID + "/message4.jpg"), new Point(10, 600));
            //newImg.Save(@"wwwroot/uploads/CombineHistory/" + subCombineHistory + "/output.jpg", ImageFormat.Jpeg);

            //g.DrawImage(Image.FromFile(@"wwwroot/uploads/" + boardID + "/message5.jpg"), new Point(10, 800));
            //newImg.Save(@"wwwroot/uploads/CombineHistory/" + subCombineHistory + "/output.jpg", ImageFormat.Jpeg);
        }
        public void ImageDataBase64([FromBody] PostModel clientInput)
        {
            string[] imgDataArray =
            {
                clientInput.Message1,
                clientInput.Message2,
                clientInput.Message3,
                clientInput.Message4,
                clientInput.Message5
            };

            const string fileExtension = ".jpg";  //Image file type
            int          thisBoard     = clientInput.BoardId;

            string folderPath;

            if (thisBoard != 0) //Single id
            {
                folderPath = UploadsFolder.GetUploadsSubPath(UploadsFolder.TempFolderSingle);
                if (Directory.Exists(folderPath))
                {
                    Directory.Delete(folderPath, true);                               //delete old folder
                }
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);                                    //create new folder
                }
                var sourcePathToCopy = UploadsFolder.GetUploadsSubPath(thisBoard.ToString()); //board folder
                if (Directory.Exists(sourcePathToCopy))
                {
                    _fileManagement.CopyFiles(sourcePathToCopy, folderPath); //make a copy from board folder to temp folder
                }
                Directory.Delete(sourcePathToCopy, true);                    //delete board folder (to create a new one from scratch)
            }
            else //0 = Multiple ids
            {
                folderPath = UploadsFolder.GetUploadsSubPath(UploadsFolder.TempFolderMultiple);
                if (Directory.Exists(folderPath))
                {
                    Directory.Delete(folderPath, true);                               //delete old folder
                }
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);                                //create new folder
                }
                var sourcePathToCopy = UploadsFolder.GetUploadsSubPath(thisBoard.ToString());
                if (Directory.Exists(sourcePathToCopy))
                {
                    _fileManagement.CopyFiles(sourcePathToCopy, folderPath);
                }
            }

            //Save messages 1,2,3,4,5 - convert client base64 back to image, save in server
            int count = 1;

            foreach (var item in imgDataArray)
            {
                string filename     = "message" + count.ToString() + fileExtension; //Image filename to be saved
                string absolutePath = Path.Combine(folderPath, filename);

                byte[] imageBytes = Convert.FromBase64String(item);
                System.IO.File.WriteAllBytes(absolutePath, imageBytes);

                count++;
            }

            _fileManagement.CopyClientUploadedFiles(folderPath);
            _fileManagement.CopyParkingLogos(folderPath);

            string clientTempPath = UploadsFolder.GetUploadsSubPath(UploadsFolder.TempFolderClient);

            if (Directory.Exists(clientTempPath))
            {
                Directory.Delete(clientTempPath, true);                                   //delete TempFolderClient, subfolders, files
            }
        }