Beispiel #1
0
        /// <summary>
        /// Use to generate a database export and return it as a stream
        /// </summary>
        /// <returns>Response containing the stream of the file</returns>
        public DatabaseExportResponse ExportDatabaseManual()
        {
            var response = new DatabaseExportResponse();

            try
            {
                response = ExportDatabase();

                if (response.Status != HttpStatusCode.OK)
                {
                    return(response);
                }

                response.File = FileToBytes(response.Path);
            }
            catch (Exception ex)
            {
                s_logger.Error(ex, "Unable to perform database export");
                response.Status = HttpStatusCode.InternalServerError;
            }

            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// Used to get a Zip file of all of the database tables as CSVs
        /// </summary>
        public DatabaseExportResponse ExportDatabase()
        {
            var response = new DatabaseExportResponse();

            try
            {
                FileProccessing proccessing = new FileProccessing();

                DateTime now = DateTime.Now;

                string exportName = $"databaseexport_{now.ToString("yyyyddMM_HHmmss")}";

                string fullZipPath = proccessing.CreateZip(_appSettings.DatabaseBackupDestination, exportName);

                if (string.IsNullOrEmpty(fullZipPath))
                {
                    s_logger.Error("Unable to create empty zip");
                    response.Status = HttpStatusCode.InternalServerError;
                    return(response);
                }
                else
                {
                    var helpdeskDataLayer = new HelpdeskDataLayer();
                    var unitDataLayer     = new UnitsDataLayer();
                    var usersDataLayer    = new UsersDataLayer();
                    var topicsDataLayer   = new TopicsDataLayer();
                    var studentDataLayer  = new StudentDatalayer();
                    var queueDataLayer    = new QueueDataLayer();
                    var checkInDataLayer  = new CheckInDataLayer();

                    DataTable helpdesks = helpdeskDataLayer.GetHelpdesksAsDataTable();
                    proccessing.SaveToZIPAsCSV(fullZipPath, "helpdesks", helpdesks);

                    DataTable timespans = helpdeskDataLayer.GetTimeSpansAsDataTable();
                    proccessing.SaveToZIPAsCSV(fullZipPath, "timespans", timespans);

                    DataTable helpdeskUnits = helpdeskDataLayer.GetHelpdeskUnitsAsDataTable();
                    proccessing.SaveToZIPAsCSV(fullZipPath, "helpdeskunits", helpdeskUnits);

                    DataTable users = usersDataLayer.GetUsersAsDataTable();
                    proccessing.SaveToZIPAsCSV(fullZipPath, "users", users);

                    DataTable units = unitDataLayer.GetUnitsAsDataTable();
                    proccessing.SaveToZIPAsCSV(fullZipPath, "units", units);

                    DataTable topics = topicsDataLayer.GetTopicsAsDataTable();
                    proccessing.SaveToZIPAsCSV(fullZipPath, "topics", topics);

                    DataTable students = studentDataLayer.GetStudentsAsDataTable();
                    proccessing.SaveToZIPAsCSV(fullZipPath, "students", students);

                    DataTable queuesItems = queueDataLayer.GetQueueItemsAsDataTable();
                    proccessing.SaveToZIPAsCSV(fullZipPath, "queueItems", queuesItems);

                    DataTable checkIns = checkInDataLayer.GetCheckInsAsDataTable();
                    proccessing.SaveToZIPAsCSV(fullZipPath, "checkInHistory", checkIns);

                    DataTable checkInQueueItems = checkInDataLayer.GetCheckInQueueItemsAsDataTable();
                    proccessing.SaveToZIPAsCSV(fullZipPath, "checkinqueueitem", checkInQueueItems);

                    response.Path   = fullZipPath;
                    response.Status = HttpStatusCode.OK;
                }
            }
            catch (Exception ex)
            {
                s_logger.Error(ex, "Unable to generate database export");
                response.Status = HttpStatusCode.InternalServerError;
            }
            return(response);
        }