예제 #1
0
        public string GetFile(string directory)
        {
            Json      checkfile  = new Json();
            CheckPath check_path = new CheckPath();

            DirectoryInfo dir = new DirectoryInfo(@"C:\COSMOS");


            ////If the File being downloaded exsits.. Delete the file//////
            if (System.IO.File.Exists(@"C:\COSMOS\" + directory))
            {
                System.IO.File.Delete(@"C:\COSMOS\" + directory);
            }



            if (directory.Contains(" "))
            {
                response = "File Directory Contains Space!";
            }
            else if (check_path.directoryexists(@"C:\COSMOS") == false || directory == "/" || directory == @"\")//check if destination exist
            {
                response = "The Directory Doesn't Exist!";
            }
            else if (checkfile.checkfile(directory) == false || directory == "." || directory == @"\" || directory == "/")//check if file exists
            {
                response = "File Not found";
            }
            else if (checkfile.isfileCorrupt(directory))
            {
                response = "File is Corrupted!";
            }
            else
            {
                Process.Start("cmd", @"/c cd C:\hadoop-2.7.2\bin && hdfs dfs -copyToLocal /" + directory + @" C:\COSMOS").WaitForExit();


                if (check_path.local_file_incomplete(directory, @"C:\COSMOS"))
                {
                    response = "File Download was cancelled upon download!";
                }
                else
                {
                    response = "File downloaded";
                }
            }



            return(response);
        }
예제 #2
0
        public string EditFile(string directory)
        {
            Json      checkfile             = new Json();
            CheckPath check_path            = new CheckPath();
            Boolean   file_downloaded_check = false;


            /////////////Delete All Files inside EDITFILES folder///////////////

            DirectoryInfo dir = new DirectoryInfo(@"C:\COSMOS\EDITFILES");

            foreach (FileInfo fi in dir.GetFiles())
            {
                fi.Delete();
            }

            ////////////Create Folder For Files to be Edited////////
            Boolean folderExists = Directory.Exists(@"C:\COSMOS\EDITFILES");

            if (folderExists == false)
            {
                Directory.CreateDirectory(@"C:\COSMOS\EDITFILES");
            }


            ///////////DOWNLOADS FILE FIRST//////////////
            if (directory.Contains(" "))
            {
                response = "File Directory Contains Space!";
            }
            else if (checkfile.checkfile(directory) == false || directory == "." || directory == @"\" || directory == "/")//check if file exists
            {
                response = "File Not found";
            }
            else if (checkfile.isfileCorrupt(directory))
            {
                response = "File is Corrupted!";
            }
            else
            {   //////////////Download from HDFS/////////////////
                Process.Start("cmd", @"/c cd C:\hadoop-2.7.2\bin && hdfs dfs -copyToLocal /" + directory + @" C:\COSMOS\EDITFILES").WaitForExit();


                if (check_path.local_file_incomplete(directory, @"C:\COSMOS\EDITFILES"))
                {
                    response = "File Download was cancelled upon Loading!";
                }
                else
                {
                    //////////////Delete from HDFS once finished Downloading/////////
                    //response = "File downloaded";
                    //Process.Start("cmd", @"/c cd C:\hadoop-2.3.0\bin && hdfs dfs -rm /" + directory ).WaitForExit();
                    SaveFile_Delete       = directory;
                    file_downloaded_check = true;
                }
            }

            if (file_downloaded_check == true)
            {
                Process.Start(@"C:\COSMOS\EDITFILES");
            }

            return(null);
        }