Esempio n. 1
0
        public RedirectToRouteResult CreateEvent(EventModel responseEventModel)
        {
            var excelFilePath = "";
            var imageFilePath = "";

            //Save Excel File
            if (responseEventModel.excelFile.ContentLength > 0 && responseEventModel.excelFile.ContentType.Contains("spreadsheetml"))
            {
                //Excel File

                excelFilePath = System.Web.HttpContext.Current.Server.MapPath($@"~/StudentExcel/{DateTime.Now.ToFileTime()}{responseEventModel.excelFile.FileName}");
                responseEventModel.excelFile.SaveAs(excelFilePath);
            }

            //Save Poster Image
            if (responseEventModel.posterImage.ContentLength > 0 && responseEventModel.posterImage.ContentType.Contains("image"))
            {
                //Poster Image File

                imageFilePath = System.Web.HttpContext.Current.Server.MapPath($@"~/PosterImage/{DateTime.Now.ToFileTime()}{responseEventModel.posterImage.FileName}");
                responseEventModel.posterImage.SaveAs(imageFilePath);
            }

            //Get the Datatable After Parsing
            var parsedDataTable = new ParseExcel().InsertTblRegisteredStudents(excelFilePath);


            //To Delete the file
            if (System.IO.File.Exists(excelFilePath))
            {
                System.IO.File.Delete(excelFilePath);
            }


            //Request Config
            var request = new RestRequest("api/User/CreateEvent");

            request.Method = Method.POST;

            //Adding JSON Body

            //TODO:
            //Add Volunteer Reference

            var requestedData = new
            {
                Name               = responseEventModel.name,
                Venue              = responseEventModel.venue,
                Description        = responseEventModel.description,
                EventDate          = Convert.ToDateTime(responseEventModel.eventDate),
                StartTime          = responseEventModel.startTime,
                EndTime            = responseEventModel.endTime,
                PosterImagePath    = imageFilePath,
                AttendeesDataTable = parsedDataTable
            };

            request.AddJsonBody(JsonConvert.SerializeObject(requestedData, Formatting.Indented));

            var response = client.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                Debug.Print(response.Content);
            }
            return(RedirectToAction("CreateEvent"));
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            /*
             * TwoKeyDictionary<string, string, string> readconf = new TwoKeyDictionary<string, string, string>();
             * MISC.readconfig_2kdict("conf\\GCF_BI_IRAT_TC.conf",readconf);
             * Debug.Print(readconf.ToString());
             * Dictionary<
             *  string,string> ab = readconf["36.523-1"];
             * _Dictionary<string,string> abc = new _Dictionary<string, string>(ab);
             * Debug.Print(abc.ToString());
             * Dictionary<string, List<string>> t1 = MISC.readconfiglist("conf\\PTCRB_IRAT_band.conf",'\t');
             * foreach (KeyValuePair<string , List<string>> kvp in t1)
             * {
             *  Debug.Print(kvp.Key);
             *  Debug.Print("\t\t"+string.Join(",",kvp.Value));
             * }
             */
            Logging lg = new Logging("log.log", 0);

            MISC.lgstr = lg;
            _Dictionary <string, string> configdic = MISC.readconfig(@"conf\\config.conf");

            string[] excelfilearr_env          = configdic["ecfile"].Split(',');
            string[] sheetnamearr_env          = configdic["ecsheet"].Split(',');
            string   printlevelforenvcondition = configdic["envdebprint"];
            string   bandsupportfile           = configdic["bandsupportfile"];
            string   bandsupportproject        = configdic["bandsupportproject"];
            bool     sheetspecwise             = Convert.ToBoolean(configdic["sheetspecwise"]);

            string[] gcfsheetarr  = configdic["gcfsheetarr"].Split(',');
            string[] gcfarrBI     = configdic["gcfbandlistforBI"].Split(',');
            string[] gcfarrBIM    = configdic["gcfbandlistforBIM"].Split(',');
            string[] gcfarrBIW    = configdic["gcfbandlistforBIW"].Split(',');
            string[] ptcrbspecarr = configdic["ptcrbspecarr"].Trim().Split(',');
            string[] ptcrbarrBI   = configdic["ptcrbbandlistforBI"].Trim().Split(',');
            string[] ptcrbarrBIW  = configdic["ptcrbbandlistforBIW"].Trim().Split(',');

            _Dictionary <string, string> bandlistdic = MISC.readconfig(bandsupportfile);

            Debug.Print(bandlistdic.ToString());
            Dictionary <string, string[]> prjsupbandlist = MISC.prjsupbl(bandlistdic, bandsupportproject);
            _List <string> allband  = new _List <string>();
            _List <string> ulcaband = new _List <string>();

            foreach (KeyValuePair <string, string[]> kvp in prjsupbandlist)
            {
                if (kvp.Key.ToUpper() == "ULCA")
                {
                    ulcaband.AddRange(kvp.Value);
                }
                else
                {
                    allband.AddRange(kvp.Value);
                }
                lg.deb("key: " + kvp.Key + "  val: " + String.Join("   ", kvp.Value));
            }
            lg.inf("All together" + allband.ToString());
            MISC.PICSBandSupportList = allband;
            Dictionary <string, List <string> > spec_tc_env = new Dictionary <string, List <string> >();

            for (int xl = 0; xl < excelfilearr_env.Count(); xl++)
            {
                string   excelfile_env = excelfilearr_env[xl];
                string   sheetname_env = sheetnamearr_env[xl];
                string[] filenamepart  = excelfile_env.Split('_');
                string   spec          = filenamepart[0];// +"."+ filenamepart[1];
                Debug.Print("spec:" + spec + ":");
                spec_tc_env.Add(spec, new List <string>());
                ParseExcel envpe = new ParseExcel(excelfile_env);
                envpe.lgx = lg;
                DataTable dt_env = envpe.GetExcelData(sheetname_env + "$");
                envpe.processenv(dt_env, spec_tc_env, printlevelforenvcondition);
            }
            foreach (KeyValuePair <string, List <string> > kvp in spec_tc_env)
            {
                lg.war("spec: " + kvp.Key);
                lg.war("bandlist extreme" + String.Join("#", kvp.Value.ToArray()));
            }


            //ParseExcel envcond = new ParseExcel(excelfile_env);

            Console.WriteLine("This program will parse and process GCF/PTCRB file.");
            Console.WriteLine("First argument is g/p g=> GCF, p=> PTCRB.");
            Console.WriteLine("Second argument is file name");
            Console.WriteLine("========================================================\n\n");
            if (args.Length != 2)
            {
                Console.WriteLine("Please add exactly two argument ");
            }
            else
            {
                string file = args[1];
                if (File.Exists(file))
                {
                    if (args[0].ToLower() == "g")
                    {
                        //code for gcf here.
                        Console.WriteLine("Now GCF file processing ...");
                        ParseExcel.BIlist  = gcfarrBI;
                        ParseExcel.BIlistW = gcfarrBIW;
                        ParseExcel.BIlistM = gcfarrBIM;
                        ParseExcel pex = new ParseExcel(file, "g");

                        pex.lgx = lg;
                        pex.cleanupfolder();
                        //List<string> sheetlist = pex.GetExcelsheetslist();

                        foreach (string sh in gcfsheetarr)
                        {
                            lg.inf("processing Sheet: " + sh);
                            DataTable dt = pex.GetExcelData(sh + "$");
                            pex.processgcffile(dt, spec_tc_env);
                        }
                        pex.writeoutput();
                        Console.WriteLine("Processing done");
                    }
                    else if (args[0].ToLower() == "p")
                    {
                        //code for ptcrb here.
                        Console.WriteLine("Now PTCRB file processing ...");
                        ParseExcel.BIlist  = ptcrbarrBI;
                        ParseExcel.BIlistW = ptcrbarrBIW;
                        ParseExcel pex = new ParseExcel(file, "p");
                        pex.lgx = lg;
                        pex.cleanupfolder();
                        DataTable dt = pex.GetExcelData("Sheet$");
                        pex.processptcrbfile(dt, spec_tc_env, ptcrbspecarr);
                        pex.writeoutput();
                        Console.WriteLine("Processing done");
                    }
                    else
                    {
                        Console.WriteLine("Please use letter g/p as the first argument ");
                    }
                }
                else
                {
                    Console.WriteLine("The file path is invalid");
                    Debug.Print("file not found");
                    lg.cri("file not found");
                }
            }
        }
        private void Execute(CreateChecksumsExecute execute)
        {
            // set up hashing
            StreamWriter output = null;

            if (!execute.Request.Preview)
            {
                output = File.CreateText(execute.OutputFileUri);
            }

            // set up reporting
            ParseExcel report = null;

            if (execute.Request.Report)
            {
                report = new ParseExcel();
                report.StartFileSheet();
            }

            long totalDataProcessed = 0;
            var  hasher             = execute.Request.HashType.ToString();

            using (var algorithm = HashCalc.GetHashAlgorithm(execute.Request.HashType))
            {
                output?.WriteLine($"# Generated {hasher} with Expedition at {DateTime.Now}");
                output?.WriteLine($"# https://github.com/DesignedSimplicity/Expedition/");
                output?.WriteLine("");

                // query file system
                var query = new QueryFileSystem();
                //TODO attach event handler here
                execute.Request.Silent = true;
                var queryResult = query.Execute(execute.Request);

                // enumerate and hash files
                int count = 0;
                var files = new List <FileInfo>();
                foreach (var file in queryResult.Files)
                {
                    string hash     = null;
                    var    fileName = file.FullName;

                    // exclude/skip output file
                    if (String.Compare(execute.OutputFileUri, fileName, true) == 0)
                    {
                        continue;
                    }

                    try
                    {
                        count++;
                        files.Add(file);
                        execute.SetState(new BaseFileSytemState(file));
                        execute.Log($"{count}. {fileName} -> {file.Length:###,###,###,###,##0}");
                        if (execute.Request.Preview)
                        {
                            execute.LogLine($" LOG");
                        }
                        else
                        {
                            // calculate hash and output hash to log
                            var s = new Stopwatch();
                            s.Start();
                            hash = HashCalc.GetHash(fileName, algorithm);
                            var rate = file.Length / (s.ElapsedMilliseconds + 1);
                            s.Stop();
                            execute.LogLine($" {hasher} = {hash} @ {rate:###,###,###,###,##0} b/ms");
                        }

                        // format and write checksum to stream
                        var path = execute.GetOuputPath(fileName);
                        output?.WriteLine($"{hash} {path}");

                        // update file data state
                        totalDataProcessed += file.Length;
                        execute.SetState(new BaseFileSytemState(file, hash));

                        // write report data if requested
                        report?.AddFileInfo(file, null, hash);
                    }
                    catch (Exception ex)
                    {
                        execute.LogError(fileName, ex);
                        execute.SetState(new BaseFileSytemState(file, ex));
                        report?.AddFileInfo(file, null, hash, ex.Message);
                    }
                }

                // gather output files
                execute.Files = files.ToArray();

                // show output
                var time = DateTime.Now.Subtract(execute.Request.Started);
                var mb   = totalDataProcessed / 1024.0 / 1024.0;
                var gb   = mb / 1024;
                var tb   = gb / 1024;
                var gbh  = gb / time.TotalHours;
                var mbs  = mb / time.TotalMinutes;
                execute.LogLine($"==================================================");
                execute.LogLine($"FILES: {files.Count:###,###,###,###,###,##0}");
                execute.LogLine($"BYTES: {totalDataProcessed:###,###,###,###,###,##0} = {gb:###,###,###,###,###,##0} GB = {tb:###,###,###,###,###,##0} TB");
                execute.LogLine($"TIME: {time:hh\\:mm\\:ss} H:M:S = {time.TotalSeconds:###,###,###,###,##0} SEC");
                execute.LogLine($"--------------------------------------------------");
                execute.LogLine($"RATE: {gbh:##,##0.0} GB/HOUR = {mbs:##,##0.0} MB/SEC");

                if (queryResult.Errors.Count > 0)
                {
                    execute.LogLine($"##################################################");
                    execute.LogLine($"QUERY ERRORS: {queryResult.Errors.Count}");
                }
                if (execute.Exceptions.Count > 0)
                {
                    execute.LogLine($"##################################################");
                    execute.LogLine($"EXCEPTIONS: {execute.Exceptions.Count()}");
                }

                // clean up output file
                if (output != null)
                {
                    execute.LogLine($"==================================================");
                    execute.LogLine($"SAVING HASHES: {execute.OutputFileUri}");
                    output?.Flush();
                    output?.Close();
                    output?.Dispose();
                }

                // close out report
                if (report != null)
                {
                    execute.LogLine($"--------------------------------------------------");
                    execute.LogLine($"SAVING REPORT: {execute.ReportFileUri}");
                    report.SaveAs(execute.ReportFileUri);
                }
            }
        }
Esempio n. 4
0
        private void Execute(VerifyChecksumsExecute execute)
        {
            // set up reporting
            ParseExcel report = null;

            if (execute.Request.Report)
            {
                report = new ParseExcel();
                report.StartFileSheet();
            }

            var hasher = execute.HashType.ToString();

            using (var algorithm = HashCalc.GetHashAlgorithm(execute.HashType))
            {
                // query file system
                var query       = new QueryHashSystem();
                var queryResult = query.Execute(execute.InputFileUri);

                // enumerate and hash files
                int  fileCount          = 0;
                long totalDataProcessed = 0;
                var  files = new List <FileInfo>();
                foreach (var entry in queryResult.Entries)
                {
                    var fileName = entry.Key;
                    var file     = new FileInfo(fileName);
                    files.Add(file);

                    var status = "PREVIEW";
                    //execute.AddState(execute.Request, )
                    //UpdateState(execute.Request, )

                    try
                    {
                        fileCount++;
                        var log = new StringBuilder();
                        log.Append($"{fileCount}. {fileName} -> {hasher} = ");

                        // calculate hash and output hash to log
                        var    hash  = hasher;
                        string error = null;
                        if (!execute.Request.Preview)
                        {
                            try
                            {
                                hash = HashCalc.GetHash(fileName, algorithm);
                                var match = (String.Compare(hash, entry.Value, true) == 0);
                                if (match)
                                {
                                    status = "VALID";
                                }
                                else
                                {
                                    error  = "Hash Invalid";
                                    status = "INVALID";
                                    execute.LogError(entry.Key, new Exception(error));
                                }
                            }
                            catch (DirectoryNotFoundException)
                            {
                                status = "MISSING";
                                error  = "Not Found";
                            }
                            catch (FileNotFoundException)
                            {
                                status = "MISSING";
                                error  = "Not Found";
                            }
                            catch (Exception ex)
                            {
                                status = "ERROR";
                                error  = ex.Message;
                            }
                        }

                        // write report data if requested
                        report?.AddFileInfo(file, status, hash, error);

                        // display to output
                        log.Append($"{hash} {status}");
                        execute.LogLine(log.ToString());

                        // update totals
                        totalDataProcessed += file.Length;
                    }
                    catch (Exception ex)
                    {
                        execute.LogError(entry.Key, ex);
                    }
                }

                // show output
                var time = DateTime.Now.Subtract(execute.Request.Started);
                var mb   = totalDataProcessed / 1024.0 / 1024.0;
                var gb   = mb / 1024;
                var tb   = gb / 1024;
                var gbh  = gb / time.TotalHours;
                var mbs  = mb / time.TotalMinutes;
                execute.LogLine($"==================================================");
                execute.LogLine($"FILES: {files.Count:###,###,###,###,###,##0}");
                execute.LogLine($"BYTES: {totalDataProcessed:###,###,###,###,###,##0} = {gb:###,###,###,###,###,##0} GB = {tb:###,###,###,###,###,##0} TB");
                execute.LogLine($"TIME: {time:hh\\:mm\\:ss} H:M:S = {time.TotalSeconds:###,###,###,###,##0} SEC");
                execute.LogLine($"--------------------------------------------------");
                execute.LogLine($"RATE: {gbh:##,##0.0} GB/HOUR = {mbs:##,##0.0} MB/SEC");

                if (execute.Exceptions.Count > 0)
                {
                    execute.LogLine($"##################################################");
                    execute.LogLine($"EXCEPTIONS: {execute.Exceptions.Count()}");
                }

                // close out report
                if (report != null)
                {
                    execute.LogLine($"--------------------------------------------------");
                    execute.LogLine($"SAVING REPORT: {execute.ReportFileUri}");
                    report.SaveAs(execute.ReportFileUri);
                }
            }
        }
Esempio n. 5
0
        public ActionResult CreateEvent(EventModel responseEventModel)
        {
            var excelFilePath = "";
            var imageFilePath = "";

            //Save Excel File
            if (responseEventModel.excelFile.ContentLength > 0 && responseEventModel.excelFile.ContentType.Contains("spreadsheetml"))
            {
                //Excel File

                excelFilePath = System.Web.HttpContext.Current.Server.MapPath($@"~/StudentExcel/{DateTime.Now.ToFileTime()}{responseEventModel.excelFile.FileName}");
                responseEventModel.excelFile.SaveAs(excelFilePath);
            }

            //Save Poster Image
            if (responseEventModel.posterImage.ContentLength > 0 && responseEventModel.posterImage.ContentType.Contains("image"))
            {
                //Poster Image File
                //TODO:
                //Change it to the relative Path
                imageFilePath = System.Web.HttpContext.Current.Server.MapPath($@"~/PosterImage/{DateTime.Now.ToFileTime()}{responseEventModel.posterImage.FileName}");
                responseEventModel.posterImage.SaveAs(imageFilePath);
            }

            //Get the Datatable After Parsing
            var parsedDataTable = new ParseExcel().InsertTblRegisteredStudents(excelFilePath);


            //To Delete the file
            //if (System.IO.File.Exists(excelFilePath))
            //{
            //    System.IO.File.Delete(excelFilePath);
            //}


            //Request Config
            var request = new RestRequest("api/User/CreateEvent");

            request.Method = Method.POST;

            //Adding JSON Body

            //TODO:
            //Add Volunteer Reference

            var requestedData = new
            {
                Name               = responseEventModel.name,
                Venue              = responseEventModel.venue,
                Description        = responseEventModel.description,
                EventDate          = Convert.ToDateTime(responseEventModel.eventDate),
                StartTime          = responseEventModel.startTime,
                EndTime            = responseEventModel.endTime,
                PosterImagePath    = imageFilePath,
                AttendeesDataTable = parsedDataTable,
                CreatedBy          = Convert.ToInt32(Session["userId"])
            };

            request.AddJsonBody(JsonConvert.SerializeObject(requestedData, Formatting.Indented));

            var response = client.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                Debug.Print(response.Content);
            }
            if (response.Content != null)
            {
                if (response.Content.Length > 2)
                {
                    Dictionary <string, string> stuDictionary =
                        JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Content);
                    ExcelInvalidRows.InvalidRows(excelFilePath, stuDictionary);
                    string FilePath  = System.Web.HttpContext.Current.Server.MapPath($@"~/OutputExcel/");
                    byte[] fileBytes = System.IO.File.ReadAllBytes(FilePath + "LogExcel" + ".xlsx");
                    string fileName  = "LogExcel" + ".xlsx";
                    //To Delete the file
                    if (System.IO.File.Exists(excelFilePath))
                    {
                        System.IO.File.Delete(excelFilePath);
                    }
                    //To Delete the file
                    if (System.IO.File.Exists(FilePath + "LogExcel" + ".xlsx"))
                    {
                        System.IO.File.Delete(FilePath + "LogExcel" + ".xlsx");
                    }
                    return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
                }
                else
                {
                    return(Redirect("Dashboard"));
                }
            }
            return(View());
        }