Ejemplo n.º 1
0
        //#################################################################################################
        public IActionResult SaveView()
        {
            Directory.CreateDirectory(exportZipPath);
            Directory.CreateDirectory(exportPath);
            for (int k = 0; k < Program.uploadModel.FileList.Count; k++)
            {
                if (Program.uploadModel.ArrayList[k] == null)
                {
                    continue;
                }
                var csv = new StringBuilder();

                for (int i = 0; i < Program.uploadModel.ArrayList[k].Length; i++)
                {
                    string line = null;
                    for (int j = 0; j < Program.uploadModel.ArrayList[k][i].Length; j++)
                    {
                        if (line == null)
                        {
                            line = Program.uploadModel.ArrayList[k][i][j];
                        }
                        else
                        {
                            line = line + ";" + Program.uploadModel.ArrayList[k][i][j];
                        }
                    }
                    csv.AppendLine(line);
                }
                var name = Program.uploadModel.FileList[k].ID + "_" + Program.uploadModel.FileList[k].Name + ".csv";
                System.IO.File.WriteAllText(Path.Combine(exportPath, name), csv.ToString());
            }

            var zipname = Path.Combine(exportZipPath, "export.zip");

            ZipFile.CreateFromDirectory(exportPath, zipname);

            const string contentType = "application/zip";

            HttpContext.Response.ContentType = contentType;
            var result = new FileContentResult(System.IO.File.ReadAllBytes(zipname), contentType)
            {
                FileDownloadName = "export.zip"
            };

            FileController.ClearDirectory(exportPath);
            FileController.ClearDirectory(exportZipPath);

            return(result);
        }
Ejemplo n.º 2
0
        public IActionResult SaveToCsv(Models.IndexModel indexModel, int newSite = -1, int newCps = -1)
        {
            LogController.Begin();
            Program.indexModel.ErrorFilterList  = indexModel.ErrorFilterList;
            Program.indexModel.ExceptionMessage = indexModel.ExceptionMessage;
            int num = 0;

            //change only the actual shown part of the contentlist
            for (int i = 0 + Program.indexModel.cps * Program.indexModel.actSite; i < Program.indexModel.ContentList.Count && i < Program.indexModel.cps * (Program.indexModel.actSite + 1); i++)
            {
                int j = i % Program.indexModel.cps;
                Program.indexModel.ContentList[i].download = indexModel.PartialContentList[j].download;

                if (Program.indexModel.ContentList[i].download)
                {
                    num++;
                }
            }
            if (num > 5)
            {
                Program.indexModel.ExceptionMessage = HelperController.GetMessage("Index.Err.ToManyFiles").txt;
                return(RedirectToAction("Index", "Home"));
            }

            if (newSite >= 0)
            {
                return(SetActSite(newSite));
            }
            if (newCps >= 0)
            {
                return(SetCps(newCps));
            }



            switch (Program.indexModel.database.KeyName)
            {
            case ("geoprofiles"):

                var zipFile = FileController.DownloadAndProcessGEOProfiles(Program.indexModel.ContentList);

                if (zipFile != null && System.IO.File.Exists(zipFile))
                {
                    var bArray = System.IO.File.ReadAllBytes(zipFile);
                    return(File(bArray, "application/octet-stream", "export.zip"));
                }
                else
                {
                    Controllers.LogController.LogError($"Zipfile could not be accessed at {zipFile}");
                }
                //break;
                var csv = FileController.WriteListToCsv(Program.indexModel.ContentList);
                if (csv != null)
                {
                    var bArray = System.Text.Encoding.UTF8.GetBytes(csv.ToString());
                    return(File(bArray, "application/octet-stream", "export.csv"));
                }
                break;

            case ("gds"):
                var processedPath = FileController.DowloadAndProcessGDS(Program.indexModel.ContentList);
                if (processedPath != null)
                {
                    return(RedirectToAction("Upload", "Upload"));
                }
                break;
            }

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 3
0
        //#################################################################################################
        public IActionResult UploadFile(Models.UploadModel uploadModel)
        {
            try
            {
                Controllers.LogController.Begin();
                StartZeit = DateTime.Now;

                Program.uploadModel.ExceptionMessage = null;
                Program.uploadModel.Step             = 1;

                Directory.CreateDirectory(tmpPath);
                Directory.CreateDirectory(dataPath);
                Directory.CreateDirectory(csvPath);
                Directory.CreateDirectory(processedPath);

                if (uploadModel.file != null)
                {
                    try
                    {
                        using (var stream = System.IO.File.Create(Path.Combine(dataPath, uploadModel.file.FileName)))
                        {
                            uploadModel.file.CopyTo(stream);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogController.LogError(String.Format(HelperController.GetMessage("UploadController.Err.UploadFile1").txt, ex.ToString()));
                        Program.uploadModel.ExceptionMessage = HelperController.GetMessage("UploadController.Err.UploadFile1").ext;
                        return(Upload());
                    }
                }
                else
                {
                    try
                    {
                        if (uploadModel.fileString.IndexOf("data:") >= 0)
                        {
                            uploadModel.fileString = Regex.Replace(uploadModel.fileString, "data:([^,]+)", String.Empty);
                            uploadModel.fileString = uploadModel.fileString.Remove(0, 1);
                        }
                        System.IO.File.WriteAllBytesAsync(Path.Combine(dataPath, uploadModel.fileName), Convert.FromBase64String(uploadModel.fileString));
                    }
                    catch (Exception ex)
                    {
                        LogController.LogError(String.Format(HelperController.GetMessage("UploadController.Err.UploadFile2").txt, ex.ToString()));
                        Program.uploadModel.ExceptionMessage = HelperController.GetMessage("UploadController.Err.UploadFile2").ext;
                        return(Upload());
                    }
                }

                Program.uploadModel.FileList = new List <Classes.File>();
                FileController.MoveAndExtractFiles(dataPath, csvPath);



                FileController.MoveAndExtractFiles(csvPath, processedPath);
                LogController.End(String.Format("verstrichene Zeit: {0}", DateTime.Now - StartZeit));
                return(Preview(processedPath));
            }
            catch (Exception ex)
            {
                LogController.LogError(String.Format(HelperController.GetMessage("UploadController.Err.Total").txt, ex.ToString()));
                Program.uploadModel.ExceptionMessage = HelperController.GetMessage("UploadController.Err.Total").ext;
                FileController.ClearDirectory(@"C:\temp\tmp_upload_" + Program.GuidString);
                Program.uploadModel.FileList = null;
                return(Upload());
            }
        }
Ejemplo n.º 4
0
        //#################################################################################################

        public void _Preview(string processedPath, bool UseUpload = false, int?ID = null)
        {
            bool HasData = false;

            foreach (FileInfo fi in new DirectoryInfo(processedPath).GetFiles())
            {
                HasData = true;
                // in release mode, Files get deleted, in _DEBUG mode this statement ignores duplicates
                #if _DEBUG
                if (Program.uploadModel.FileList.Select(file => file.Name).Contains(fi.Name))
                {
                    continue;
                }
                #endif

                Classes.File file = new Classes.File();
                file.ID      = ID;
                file.Name    = fi.Name;
                file.Length  = fi.Length;
                file.content = new Classes.Content();



                if (fi.Extension == ".csv")
                {
                    string[] lines = System.IO.File.ReadAllLines(fi.FullName);

                    string[][] parts = new string[lines.Length][];

                    for (int i = 0; i < lines.Length; i++)
                    {
                        lines[i].Replace("\"", "");
                        parts[i] = lines[i].Split(';');
                        if (parts[i].Length != parts[0].Length)
                        {
                            file.ExceptionMessage = HelperController.GetMessage("UploadController.Err.ColumnMismatch").txt;
                        }
                    }

                    List <int> li = new List <int>();
                    for (int i = 0; parts.Length > 0 && i < parts[0].GetLength(0); i++)
                    {
                        li.Add(0);
                    }
                    Program.uploadModel.FileList.Add(file);
                    Program.uploadModel.ArrayList.Add(parts);
                    Program.uploadModel.Offset.Add(0);
                    Program.uploadModel.IntegerList.Add(li);
                    continue;
                }

                Program.uploadModel.FileList.Add(file);
                Program.uploadModel.ArrayList.Add(null);
                Program.uploadModel.Offset.Add(0);
                Program.uploadModel.IntegerList.Add(null);
            }
            if (!UseUpload && !HasData)
            {
                Classes.File file = new Classes.File();
                file.ID = ID;
                file.ExceptionMessage = HelperController.GetMessage("UploadController.Err.NoDataFound").txt;
                Program.uploadModel.FileList.Add(file);
                Program.uploadModel.ArrayList.Add(null);
                Program.uploadModel.Offset.Add(0);
                Program.uploadModel.IntegerList.Add(null);
            }
            #if !_DEBUG
            FileController.ClearDirectory(processedPath, false, false);
            #endif
        }