public void CleanDir_CleanTmpdir()
        {
            if (Directory.Exists("test"))
            {
                Directory.Delete("test", true);
            }
            Directory.CreateDirectory("test");

            string[] messages = new string[] { };
            string[] errors   = new string[] { };

            File.Create("test\\test1.txt").Dispose();
            File.SetLastWriteTime("test\\test1.txt", DateTime.Now.AddDays(-5));
            File.Create("test\\test2.txt").Dispose();
            File.SetLastWriteTime("test\\test2.txt", DateTime.Now.AddDays(-5));
            File.Create("test\\test3.txt").Dispose();
            Assert.IsTrue(File.Exists("test\\test1.txt"));
            Assert.IsTrue(File.Exists("test\\test2.txt"));
            Assert.IsTrue(File.Exists("test\\test3.txt"));
            CleanDir.CleanTmpdir("test", false, null, ref messages, ref errors);
            Assert.That(messages.Length, Is.Not.EqualTo(0));
            Assert.That(errors.Length, Is.EqualTo(0));
            Assert.IsFalse(File.Exists("test\\test1.txt"));
            Assert.IsFalse(File.Exists("test\\test2.txt"));
            Assert.IsFalse(File.Exists("test\\test3.txt"));
            File.Delete("test\\test3.txt");

            //for other methods call test, look at FileHelper.PurgeFolder

            Directory.Delete("test");
        }
Esempio n. 2
0
        /// <summary>
        /// Load handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormMain_Load(object sender, EventArgs e)
        {
            //perform the first connection
            try
            {
                DentneDModel dentnedModel = new DentneDModel();
                dentnedModel.Doctors.Find(-1);
            }
            catch
            {
                MessageBox.Show("Database connection error. This application will be closed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }

            //clean temporary folder
            if (Convert.ToBoolean(ConfigurationManager.AppSettings["cleanTmpdirAtStartup"]))
            {
                string[] messages = new string[] { };
                string[] errors   = new string[] { };
                try
                {
                    CleanDir.CleanTmpdir(ConfigurationManager.AppSettings["tmpdir"], false, -4, ref messages, ref errors);
                }
                catch { }
            }

            //set startup size
            try
            {
                Match sizeOnStartup = Regex.Match(ConfigurationManager.AppSettings["sizeOnStartup"], @"^(?<w>\d*)x(?<h>\d*)(?<m>M*)$");
                if (sizeOnStartup.Success)
                {
                    int width  = Convert.ToInt16(sizeOnStartup.Groups[1].Value);
                    int height = Convert.ToInt16(sizeOnStartup.Groups[2].Value);
                    if (width > Screen.PrimaryScreen.WorkingArea.Width)
                    {
                        width = Screen.PrimaryScreen.WorkingArea.Width - 5;
                    }
                    if (height > Screen.PrimaryScreen.WorkingArea.Height)
                    {
                        height = Screen.PrimaryScreen.WorkingArea.Height - 5;
                    }
                    this.Size = new Size(width, height);
                    this.CenterToScreen();
                    if (!String.IsNullOrEmpty(sizeOnStartup.Groups[3].Value))
                    {
                        this.WindowState = FormWindowState.Maximized;
                    }
                }
            }
            catch { }

            //set AdvancedDataGridView translations
            AdvancedDataGridView.SetTranslations(AdvancedDataGridView.LoadTranslationsFromFile(Program.uighfApplication.LanguageFilename));
            AdvancedDataGridViewSearchToolBar.SetTranslations(AdvancedDataGridViewSearchToolBar.LoadTranslationsFromFile(Program.uighfApplication.LanguageFilename));
        }
        /// <summary>
        /// Clean temporary folder
        /// </summary>
        private void CleanTmpdir()
        {
            try
            {
                string[] messages = new string[] { };
                string[] errors   = new string[] { };

                //clean the tmpdir
                log.Info("Cleaning Temporary folder \"" + tmpdir + "\"...");
                CleanDir.CleanTmpdir(tmpdir, doSecureDelete, -2, ref messages, ref errors);
                foreach (string message in messages)
                {
                    log.Info(message);
                }
                foreach (string error in errors)
                {
                    log.Error(error);
                }
            }
            catch
            {
                log.Error("Exception happened running CleanTmpdir");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Clean data dirs
        /// </summary>
        private void CleanDataDir()
        {
            try
            {
                string[] messages = new string[] { };
                string[] errors   = new string[] { };

                //clean the patient datadir
                log.Info("Cleaning Patient Data folder \"" + patientsDatadir + "\"...");
                CleanDir.CleanPatientDir(patientsDatadir, doSecureDelete, ref messages, ref errors);
                foreach (string message in messages)
                {
                    log.Info(message);
                }
                foreach (string error in errors)
                {
                    log.Error(error);
                }

                //clean the patient attachment dir
                log.Info("Cleaning Patient Attachments folder \"" + patientsAttachmentsdir + "\"...");
                CleanDir.CleanPatientAttachmentsDir(patientsAttachmentsdir, doSecureDelete, ref messages, ref errors);
                foreach (string message in messages)
                {
                    log.Info(message);
                }
                foreach (string error in errors)
                {
                    log.Error(error);
                }
            }
            catch
            {
                log.Error("Exception happened running CleanDataDir");
            }
        }
        public void CleanDir_CleanPatientDir()
        {
            if (Directory.Exists("test"))
            {
                Directory.Delete("test", true);
            }
            Directory.CreateDirectory("test");

            string[] messages = new string[] { };
            string[] errors   = new string[] { };

            patients t_patients1 = null;
            patients t_patients2 = null;

            _dentnedModel.Patients.Remove(_dentnedModel.Patients.List(r => r.patients_name == "XX1" && r.patients_surname == "XX1").ToArray());
            _dentnedModel.Patients.Remove(_dentnedModel.Patients.List(r => r.patients_name == "XX2" && r.patients_surname == "XX2").ToArray());

            t_patients1 = new patients()
            {
                patients_name      = "XX1",
                patients_surname   = "XX1",
                patients_birthdate = DateTime.Now,
                patients_birthcity = "xxx",
                patients_doctext   = "xxx",
                patients_sex       = "M",
                patients_username  = "******",
                patients_password  = "******"
            };
            _dentnedModel.Patients.Add(t_patients1);

            Directory.CreateDirectory("test\\" + t_patients1.patients_id);
            Directory.CreateDirectory("test\\" + t_patients1.patients_id + "\\test");
            File.Create("test\\" + t_patients1.patients_id + "\\test1.txt").Dispose();
            File.Create("test\\" + t_patients1.patients_id + "\\test\\test1.txt").Dispose();

            t_patients2 = new patients()
            {
                patients_name      = "XX2",
                patients_surname   = "XX2",
                patients_birthdate = DateTime.Now,
                patients_birthcity = "xxx",
                patients_doctext   = "xxx",
                patients_sex       = "M",
                patients_username  = "******",
                patients_password  = "******"
            };
            _dentnedModel.Patients.Add(t_patients2);

            Directory.CreateDirectory("test\\" + t_patients2.patients_id);
            Directory.CreateDirectory("test\\" + t_patients2.patients_id + "\\test");
            File.Create("test\\" + t_patients2.patients_id + "\\test1.txt").Dispose();
            File.Create("test\\" + t_patients2.patients_id + "\\test\\test1.txt").Dispose();

            Assert.IsTrue(Directory.Exists("test\\" + t_patients1.patients_id));
            Assert.IsTrue(File.Exists("test\\" + t_patients1.patients_id + "\\test1.txt"));
            Assert.IsTrue(File.Exists("test\\" + t_patients1.patients_id + "\\test\\test1.txt"));
            Assert.IsTrue(Directory.Exists("test\\" + t_patients2.patients_id));
            Assert.IsTrue(File.Exists("test\\" + t_patients2.patients_id + "\\test1.txt"));
            Assert.IsTrue(File.Exists("test\\" + t_patients2.patients_id + "\\test\\test1.txt"));

            CleanDir.CleanPatientDir("test", false, ref messages, ref errors);
            Assert.That(messages.Length, Is.EqualTo(0));
            Assert.That(errors.Length, Is.EqualTo(0));

            _dentnedModel.Patients.Remove(_dentnedModel.Patients.List(r => r.patients_name == "XX2" && r.patients_surname == "XX2").ToArray());

            CleanDir.CleanPatientDir("test", false, ref messages, ref errors);
            Assert.That(messages.Length, Is.Not.EqualTo(0));
            Assert.That(errors.Length, Is.EqualTo(0));

            Assert.IsTrue(Directory.Exists("test\\" + t_patients1.patients_id));
            Assert.IsTrue(File.Exists("test\\" + t_patients1.patients_id + "\\test1.txt"));
            Assert.IsTrue(File.Exists("test\\" + t_patients1.patients_id + "\\test\\test1.txt"));
            Assert.IsFalse(Directory.Exists("test\\" + t_patients2.patients_id));
            Assert.IsFalse(File.Exists("test\\" + t_patients2.patients_id + "\\test1.txt"));
            Assert.IsFalse(File.Exists("test\\" + t_patients2.patients_id + "\\test\\test1.txt"));

            _dentnedModel.Patients.Remove(_dentnedModel.Patients.List(r => r.patients_name == "XX1" && r.patients_surname == "XX1").ToArray());
            _dentnedModel.Patients.Remove(_dentnedModel.Patients.List(r => r.patients_name == "XX2" && r.patients_surname == "XX2").ToArray());

            CleanDir.CleanPatientDir("test", true, ref messages, ref errors);
            Assert.That(messages.Length, Is.Not.EqualTo(0));
            Assert.That(errors.Length, Is.EqualTo(0));

            Assert.IsFalse(Directory.Exists("test\\" + t_patients1.patients_id));
            Assert.IsFalse(File.Exists("test\\" + t_patients1.patients_id + "\\test1.txt"));
            Assert.IsFalse(File.Exists("test\\" + t_patients1.patients_id + "\\test\\test1.txt"));
            Assert.IsFalse(Directory.Exists("test\\" + t_patients2.patients_id));
            Assert.IsFalse(File.Exists("test\\" + t_patients2.patients_id + "\\test1.txt"));
            Assert.IsFalse(File.Exists("test\\" + t_patients2.patients_id + "\\test\\test1.txt"));

            Directory.Delete("test", true);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            bool   showhelp = false;
            bool   defaultlanguagerebuild  = false;
            bool   languagerebuild         = false;
            bool   cleandatadir            = false;
            string formprotectedpassword   = null;
            string reportprotectedpassword = null;

            var p = new OptionSet()
            {
                { "l|languagerebuilt", "rebuild the loaded language file against default values",
                  v => languagerebuild = v != null },
                { "r|defaultlanguagerebuild", "rebuild the default language file",
                  v => defaultlanguagerebuild = v != null },
                { "d|cleandatadir", "clean patients data and temporary directories",
                  v => cleandatadir = v != null },
                { "f|formprotectedpassword="******"get entrypted password for protected forms",
                  v => formprotectedpassword = v },
                { "t|reportprotectedpassword="******"get entrypted password for protected reports",
                  v => reportprotectedpassword = v },
                { "h|help", "show help",
                  v => showhelp = v != null }
            };

            //attach the console
            if (args.Length > 0)
            {
                AttachConsole(ATTACH_PARENT_PROCESS);

                try
                {
                    p.Parse(args);
                }
                catch (OptionException e)
                {
                    Console.WriteLine();
                    Console.WriteLine(Assembly.GetExecutingAssembly().GetName().Name);
                    Console.WriteLine(e.Message);
                    Console.WriteLine("Try `--help' for more information.");
                    return;
                }

                if (
                    (languagerebuild ? 1 : 0) + (defaultlanguagerebuild ? 1 : 0) + (cleandatadir ? 1 : 0) +
                    (!String.IsNullOrEmpty(formprotectedpassword) || !String.IsNullOrEmpty(reportprotectedpassword) ? 1 : 0) > 1 ||
                    !defaultlanguagerebuild && !languagerebuild && !cleandatadir && String.IsNullOrEmpty(formprotectedpassword) && String.IsNullOrEmpty(reportprotectedpassword))
                {
                    showhelp = true;
                }

                Console.WriteLine();

                if (showhelp)
                {
                    //show help
                    Console.WriteLine("Usage: " + Assembly.GetExecutingAssembly().GetName().Name + " [OPTIONS]");
                    Console.WriteLine();
                    Console.WriteLine("Options:");
                    p.WriteOptionDescriptions(Console.Out);
                }
                else if (defaultlanguagerebuild)
                {
                    //rebuilt the default language
                    Console.WriteLine("Rebuilding the default language file to \"" + DGUIGHFLanguageHelper.DefaultLanguageFilename + "\"...");
                    if (DGUIGHFLanguageHelper.RebuiltDefaultLanguage(DGUIGHFLanguageHelper.DefaultLanguageFilename))
                    {
                        Console.WriteLine("File successfully rebuilt.");
                    }
                    else
                    {
                        Console.WriteLine("Rebuild ends with errors.");
                    }
                }
                else if (languagerebuild)
                {
                    //rebuilt the loaded language
                    string[] messages = new string[] { };
                    Console.WriteLine("Rebuilt the current language file to \"" + Program.uighfApplication.LanguageFilename + "\"...");
                    if (DGUIGHFLanguageHelper.RebuiltLanguage(Program.uighfApplication.LanguageFilename, false, ref messages))
                    {
                        foreach (string message in messages)
                        {
                            Console.WriteLine("  " + message);
                        }
                        Console.WriteLine("File successfully rebuilt.");
                    }
                    else
                    {
                        Console.WriteLine("Rebuild ends with errors.");
                    }
                }
                else if (cleandatadir)
                {
                    string[] messages = new string[] { };
                    string[] errors   = new string[] { };

                    string tmpdir                 = ConfigurationManager.AppSettings["tmpdir"];
                    string patientsDatadir        = ConfigurationManager.AppSettings["patientsDatadir"];
                    string patientsAttachmentsdir = ConfigurationManager.AppSettings["patientsAttachmentsdir"];
                    bool   doSecureDelete         = Convert.ToBoolean(ConfigurationManager.AppSettings["doSecureDelete"]);

                    //clean the tmpdir
                    Console.WriteLine("Cleaning Temporary folder \"" + tmpdir + "\"...");
                    CleanDir.CleanTmpdir(tmpdir, doSecureDelete, null, ref messages, ref errors);
                    foreach (string message in messages)
                    {
                        Console.WriteLine("  " + message);
                    }
                    foreach (string error in errors)
                    {
                        Console.WriteLine("  " + error);
                    }
                    Console.WriteLine("Folder processed.");

                    Console.WriteLine();

                    //clean the patient datadir
                    Console.WriteLine("Cleaning Patient Data folder \"" + patientsDatadir + "\"...");
                    CleanDir.CleanPatientDir(patientsDatadir, doSecureDelete, ref messages, ref errors);
                    foreach (string message in messages)
                    {
                        Console.WriteLine("  " + message);
                    }
                    foreach (string error in errors)
                    {
                        Console.WriteLine("  " + error);
                    }
                    Console.WriteLine("Folder processed.");

                    Console.WriteLine();

                    //clean the patient attachment dir
                    Console.WriteLine("Cleaning Patient Attachments folder \"" + patientsAttachmentsdir + "\"...");
                    CleanDir.CleanPatientAttachmentsDir(patientsAttachmentsdir, doSecureDelete, ref messages, ref errors);
                    foreach (string message in messages)
                    {
                        Console.WriteLine("  " + message);
                    }
                    foreach (string error in errors)
                    {
                        Console.WriteLine("  " + error);
                    }
                    Console.WriteLine("Folder processed.");
                }
                else if (!String.IsNullOrEmpty(formprotectedpassword) && !String.IsNullOrEmpty(reportprotectedpassword))
                {
                    //Build encrypted passwords
                    Console.WriteLine("Building the encrypted passwords for protected forms and reports...");
                    Console.WriteLine(String.Format("Your form entrypted password is: {0} ", PasswordHelper.EncryptPassword(formprotectedpassword)));
                    Console.WriteLine(String.Format("Your check for proteted form list is: {0} ", PasswordHelper.EncryptPassword(String.Join(",", ConfigurationManager.AppSettings["passwordProtectedForms"].Split(',')))));
                    Console.WriteLine(String.Format("Your report entrypted password is: {0} ", PasswordHelper.EncryptPassword(reportprotectedpassword)));
                }
                else if (!String.IsNullOrEmpty(formprotectedpassword))
                {
                    //Build encrypted password
                    Console.WriteLine("Building the encrypted password for protected forms...");
                    Console.WriteLine(String.Format("Your form entrypted password is: {0} ", PasswordHelper.EncryptPassword(formprotectedpassword)));
                    Console.WriteLine(String.Format("Your check for proteted form list is: {0} ", PasswordHelper.EncryptPassword(String.Join(",", ConfigurationManager.AppSettings["passwordProtectedForms"].Split(',')))));
                }
                else if (!String.IsNullOrEmpty(reportprotectedpassword))
                {
                    //Build encrypted password
                    Console.WriteLine("Building the encrypted password for protected reports...");
                    Console.WriteLine(String.Format("Your report entrypted password is: {0} ", PasswordHelper.EncryptPassword(reportprotectedpassword)));
                }

                Console.WriteLine();
                SendKeys.SendWait("{ENTER}");
                Application.Exit();
            }
            else
            {
                //show main form
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                DGUIGHFApplication.Run(Program.uighfApplication);
            }
        }