예제 #1
0
        private void GoToApplication(Models.Core.User user)
        {
            Common.Session.CurrentUser = user;
            BusinessLayer.General.Logging.Log("Password correct", BusinessLayer.General.Logging.LogLevel.Info);

            BusinessLayer.General.Logging.Log("Creating session for user", BusinessLayer.General.Logging.LogLevel.Debug);
            Models.Core.Session sess = new Models.Core.Session();
            sess.HostName     = Environment.MachineName;
            sess.User         = user;
            sess.SessionStart = DateTime.Now;
            sess.SessionEnd   = DateTime.Now.AddHours(1);
            Crud.Add(sess);
            Common.Session.CurrentSession = sess;

            BusinessLayer.General.Logging.Log("Creating MainForm object", BusinessLayer.General.Logging.LogLevel.Debug);
            MainForm mainForm = new MainForm();

            Common.Session.MainForm = mainForm;
            Common.MenuBuilder.Build();
            Context.Transfer(mainForm);

            BusinessLayer.General.Logging.Log("MainForm loaded", BusinessLayer.General.Logging.LogLevel.Debug);
            BusinessLayer.General.Logging.Log("Login form closed", BusinessLayer.General.Logging.LogLevel.Debug);

            Dispose();
        }
        public void CrudTest()
        {
            //act
            Crud <RestaurantDataAccessLayer.Restaurant> crud = new Crud <RestaurantDataAccessLayer.Restaurant>();

            //arrange
            RestaurantDataAccessLayer.Restaurant rest1 = crud.Retrieve(1);
            bool test = crud.Add(new RestaurantDataAccessLayer.Restaurant());

            //assert
            Assert.AreEqual(rest1.RestaurantID, 1);
            Assert.IsTrue(test);
        }
예제 #3
0
        public static MessageTranslation Translate(string message, string language, string group = "*")
        {
            Logging.Log("Translate message '" + message + "' for messagegroup " + group + ", language=" + language, Logging.LogLevel.Debug);

            group    = group.ToUpper();
            language = language.ToLower();

            DefineLanguage(language);

            var session           = DataConnector.NHibernateConnector.OpenSession();
            MessageTranslation ft = session.CreateCriteria(typeof(MessageTranslation))
                                    .Add(Expression.Eq("Language", language))
                                    .Add(Expression.Eq("MessageGroup", group))
                                    .Add(Expression.Eq("Message", message))
                                    .UniqueResult <MessageTranslation>();

            if (!(string.IsNullOrEmpty(ft?.Translation)))
            {
                Logging.Log("Translation found: '" + ft.Translation + "'", Logging.LogLevel.Debug);
                return(ft);
            }
            else
            {
                Logging.Log("Translation not found, looking for English translation", Logging.LogLevel.Debug);
                MessageTranslation fte = session.CreateCriteria(typeof(MessageTranslation))
                                         .Add(Expression.Eq("Language", "en"))
                                         .Add(Expression.Eq("MessageGroup", group))
                                         .Add(Expression.Eq("Message", message))
                                         .UniqueResult <MessageTranslation>();
                if (!(string.IsNullOrEmpty(fte?.Translation)))
                {
                    Logging.Log("Translation found: '" + fte.Translation + "'", Logging.LogLevel.Debug);
                    return(fte);
                }
                else
                {
                    Logging.Log("Translation not found, creating new translation record", Logging.LogLevel.Debug);
                    ft = new MessageTranslation();
                    ft.MessageGroup = group;
                    ft.Message      = message;
                    ft.Language     = "en";
                    ft.Translation  = message;
                    ft.Translated   = false;
                    Crud.Add(ft);
                    Logging.Log("Translation record added", Logging.LogLevel.Debug);
                    return(ft);
                }
            }
        }
예제 #4
0
        public static FormTranslation TranslateCpt(string form, string cpt, string language, string currentLbl = "")
        {
            Logging.Log("Translate component '" + cpt + "' for form " + form + ", language=" + language, Logging.LogLevel.Debug);

            language = language.ToLower();

            DefineLanguage(language);

            var             session = DataConnector.NHibernateConnector.OpenSession();
            FormTranslation ft      = session.CreateCriteria(typeof(FormTranslation))
                                      .Add(Expression.Eq("Language", language))
                                      .Add(Expression.Eq("Form", form))
                                      .Add(Expression.Eq("Component", cpt))
                                      .UniqueResult <FormTranslation>();

            if (!(string.IsNullOrEmpty(ft?.Translation)))
            {
                Logging.Log("Translation found: '" + ft.Translation + "'", Logging.LogLevel.Debug);
                return(ft);
            }
            else
            {
                Logging.Log("Translation not found, looking for English translation", Logging.LogLevel.Debug);
                FormTranslation fte = session.CreateCriteria(typeof(FormTranslation))
                                      .Add(Expression.Eq("Language", "en"))
                                      .Add(Expression.Eq("Form", form))
                                      .Add(Expression.Eq("Component", cpt))
                                      .UniqueResult <FormTranslation>();
                if (!(string.IsNullOrEmpty(fte?.Translation)))
                {
                    Logging.Log("Translation found: '" + fte.Translation + "'", Logging.LogLevel.Debug);
                    return(fte);
                }
                else
                {
                    Logging.Log("Translation not found, creating new translation record", Logging.LogLevel.Debug);
                    ft             = new FormTranslation();
                    ft.Form        = form;
                    ft.Component   = cpt;
                    ft.Language    = "en";
                    ft.Translation = currentLbl;
                    ft.Translated  = false;
                    Crud.Add(ft);
                    Logging.Log("Translation record added", Logging.LogLevel.Debug);
                    return(ft);
                }
            }
        }
예제 #5
0
        public static void Log(string text, LogLevel level, Models.Core.User user = null)
        {
            int logLevel = Convert.ToInt16(Crud.GetById <Models.Core.Property, string>("DebugLevel")?.Value ?? "0");

            if ((int)level >= logLevel)
            {
                Models.Core.Logging log = new Models.Core.Logging();
                log.Text      = text;
                log.Timestamp = DateTime.Now;
                log.User      = user;
                log.Hostname  = Environment.MachineName;
                log.Level     = (int)level;
                Crud.Add(log);
                Debug.WriteLine("(" + log.Timestamp.ToString("yyyy-MM-dd HH:mm:ss.fff") + ") " +
                                level.ToString().ToUpper() + ": " + text);
            }
        }
예제 #6
0
        public static void DefineLanguage(string language)
        {
            var session = DataConnector.NHibernateConnector.OpenSession();

            Logging.Log("Checking if language '" + language + "' is defined in MessageTranslation", Logging.LogLevel.Debug);

            MessageTranslation trl = session.CreateCriteria(typeof(MessageTranslation))
                                     .Add(Expression.Eq("MessageGroup", "*"))
                                     .Add(Expression.Eq("Message", "_name"))
                                     .Add(Expression.Eq("Language", language))
                                     .UniqueResult <MessageTranslation>();

            if (trl == null)
            {
                Logging.Log("Language '" + language + "' is not defined, creating record in MessageTranslation", Logging.LogLevel.Debug);
                trl = new MessageTranslation();
                trl.MessageGroup = "*";
                trl.Message      = "_name";
                trl.Language     = language;
                trl.Translation  = language;
                Crud.Add(trl);
                Logging.Log("Record for language '" + language + "' is created in MessageTranslation", Logging.LogLevel.Debug);
            }
        }
        public static void AddReview(Reviews.Review rev)
        {
            Crud <RestaurantDataAccessLayer.Review> crud = new Crud <RestaurantDataAccessLayer.Review>();

            crud.Add(LibraryConverter.RevLibToDataConverion(rev));
        }
예제 #8
0
        private static void ThrowException(Assembly asm, Exception ex)
        {
            string     msg           = null;
            string     errornr       = Guid.NewGuid().ToString();
            StackTrace st            = new StackTrace(ex, true);
            MethodBase method        = st.GetFrame(0).GetMethod();
            string     customMessage = ex.Message;

            msg = string.Empty;
            while (!(ex == null))
            {
                msg += "" + "\r\n";
                msg += ex.ToString() + "\r\n";
                ex   = ex.InnerException;
            }
            string classn = method.ReflectedType.Name;
            string box    = null;

            box  = string.Empty;
            box += "Assembly: " + "\t" + Path.GetFileName(asm.Location) + "\r\n";
            box += "Directory: " + "\t" + "\t" + Environment.CurrentDirectory.ToString() + "\r\n";
            box += "Version: " + "\t" + "\t" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + "\r\n";
            box += "Time: " + "\t" + "\t" + DateTime.Now + "\r\n";
            box += "Method: " + "\t" + "\t" + method.Name + "\r\n";
            box += "Class: " + "\t" + "\t" + classn + "\r\n";
            box += "Line: " + "\t" + "\t" + st.GetFrame(0).GetFileLineNumber().ToString() + "\t" + "Column: " + "\t" + st.GetFrame(0).GetFileColumnNumber().ToString() + "\r\n";
            box += "Error: " + "\t" + "\t" + customMessage + "\r\n" + "\r\n" + "Show detailed error information?";
            BusinessLayer.General.Logging.Log("Error: " + customMessage, BusinessLayer.General.Logging.LogLevel.Error);
            try
            {
                Error  errordb = new Error();
                string os      = Environment.OSVersion.ToString();
                if (Environment.Is64BitOperatingSystem == true)
                {
                    os += " (x64)";
                }
                User username = null;
                User userWs   = Session.CurrentSession.User;
                if (userWs != null)
                {
                    username = userWs;
                }
                errordb.ClassName        = classn;
                errordb.ErrorDescription = customMessage;
                errordb.Host             = Environment.MachineName.ToString();
                errordb.LongError        = msg;
                errordb.Method           = method.Name;
                errordb.OS        = os;
                errordb.Place     = st.GetFrame(0).GetFileLineNumber().ToString() + " : " + st.GetFrame(0).GetFileColumnNumber().ToString();
                errordb.StackInfo = st.ToString();
                errordb.User      = username;
                errordb.Version   = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                errordb.ErrorTime = DateTime.Now;
                Crud.Add(errordb);
            }
            catch (Exception errdb)
            {
                ThrowException(asm, errdb);
            }
            DialogResult ch = MessageBox.Show(box, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

            if (ch == DialogResult.Yes)
            {
                MessageBox.Show(msg, "Error", MessageBoxButtons.OK);
            }
        }