//#################################################################################################
        public IActionResult LoadSessionFromFile(Models.SessionModel sessionModel)
        {
            Program.sessionModel.validationMessage = String.Empty;
            Program.sessionModel.valError          = false;

            if ((sessionModel.file != null && !sessionModel.file.FileName.EndsWith(".xml")) ||
                (!String.IsNullOrEmpty(sessionModel.fileName) && !sessionModel.fileName.EndsWith(".xml")))
            {
                Program.sessionModel.validationMessage = HelperController.GetMessage("Session.Err.WrongType").txt;
                Program.sessionModel.valError          = true;
                return(Session());
            }


            if (sessionModel.file != null)
            {
                try
                {
                    var result = new StringBuilder();
                    using (var reader = new StreamReader(sessionModel.file.OpenReadStream()))
                    {
                        while (reader.Peek() >= 0)
                        {
                            result.AppendLine(reader.ReadLine());
                        }
                    }

                    var filestring = result.ToString();
                    Program.indexModel.FilterList = GetFiltersFromXml(Controllers.XmlController.GetXml(filestring));
                }
                catch (Exception ex)
                {
                    LogController.LogError(String.Format(HelperController.GetMessage("SessionController.Err.LoadSessionFromFile(Model)1").txt, ex.ToString()));
                    Program.sessionModel.validationMessage = HelperController.GetMessage("SessionController.Err.LoadSessionFromFile(Model)1").ext;
                    Program.sessionModel.valError          = true;
                    return(Session());
                }
            }
            else
            {
                try
                {
                    Program.indexModel.FilterList = GetFiltersFromXml(Controllers.XmlController.GetXml(HelperController.ConvertBase64ToUtf8(sessionModel.fileString)));
                }
                catch (Exception ex)
                {
                    LogController.LogError(String.Format(HelperController.GetMessage("SessionController.Err.LoadSessionFromFile(Model)2").txt, ex.ToString()));
                    Program.sessionModel.validationMessage = HelperController.GetMessage("SessionController.Err.LoadSessionFromFile(Model)2").ext;
                    Program.sessionModel.valError          = true;
                    return(Session());
                }
            }

            Program.sessionModel.validationMessage = HelperController.GetMessage("SessionController.Inf.LoadSessionFromFile(Model)").txt;

            return(Session());
        }
Example #2
0
        //#################################################################################################
        public static XmlDocument GetXml(string str)
        {
            XmlDocument xDoc = new XmlDocument();

            try
            {
                xDoc.LoadXml(str);
            }
            catch (Exception ex)
            {
                LogController.LogError(String.Format(HelperController.GetMessage("XmlController.Err.GetXml").txt, ex.ToString()));
                throw;
            }
            return(xDoc);
        }
Example #3
0
        public static bool IsValid(string str)
        {
            if (!String.IsNullOrEmpty(str))
            {
                try
                {
                    XmlDocument xDoc = GetXml(str);
                }
                catch (Exception ex)
                {
                    LogController.LogError(String.Format(HelperController.GetMessage("XmlController.Err.IsValid").txt, ex.ToString()));
                    throw;
                }
            }

            return(true);
        }
Example #4
0
        public IActionResult Start(Models.IndexModel model, string action)
        {
            LogController.Begin();
            if (model.FilterList == null | (model.FilterList != null && model.FilterList.flist == null))
            {
                var msg = HelperController.GetMessage("Index.Err.NoFilter");
                LogController.LogError(msg.txt);
                Program.indexModel.ExceptionMessage = msg.txt;
                return(RedirectToAction("Index", "Home"));
            }

            SessionController.SaveSession(model.FilterList);

            Program.indexModel.ExceptionMessage = model.ExceptionMessage;
            Program.indexModel.ErrorFilterList  = model.ErrorFilterList;
            if (!String.IsNullOrEmpty(action) && action != "Start")
            {
                Program.indexModel.FilterList.Remove(action);
                return(RedirectToAction("Index", "Home"));
            }


            Program.indexModel.FilterList = new Classes.FList(model.FilterList);

            //da "GetContent" nicht statisch
            try
            {
                queryController qController = new queryController();
                Program.indexModel.ContentList = new List <Classes.Content>();
                Program.indexModel.ContentList = qController.GetContent(Program.indexModel.FilterList.flist);
            }
            catch (Exception ex)
            {
                LogController.LogError(String.Format(HelperController.GetMessage("Helper.Err.QueryController").txt, ex.ToString()));
                Program.indexModel.ExceptionMessage = HelperController.GetMessage("Helper.Err.QueryController").ext;
            }


            return(RedirectToAction("Index", "Home"));
        }
        //#################################################################################################
        public static Classes.FList LoadSessionFromFile(string file, bool usedef)
        {
            XmlDocument doc = new XmlDocument();

            try
            {
                doc = Controllers.FileController.LoadXmlFromFile(file);
                if (doc.ChildNodes.Count == 0 && usedef)
                {
                    return(LoadSessionFromFile("DefaultFilters.xml", false));
                }
            }
            catch (Exception ex)
            {
                LogController.LogError(String.Format(HelperController.GetMessage("SessionController.Err.LoadSessionFromFile(string,bool)").txt, ex.ToString()));
                throw;
            }



            return(GetFiltersFromXml(doc));
        }
Example #6
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"));
        }
Example #7
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());
            }
        }
Example #8
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
        }