//[Authorize]
        public ActionResult LogOff()
        {
            //WebSecurity.Logout();
            try
            {
                MSession s = MSession.Get(Session["ctx"] as Ctx);
                s.Logout();
            }
            catch
            {
            }


            FormsAuthentication.SignOut();
            if (Session != null)
            {
                Session.Abandon();
            }
            return(RedirectToAction("Index", "Home"));
        }
        // [ValidateAntiForgeryToken]
        //[Authorize]
        public ActionResult LogOff()
        {
            //WebSecurity.Logout();
            try
            {
                Ctx ctx = Session["ctx"] as Ctx;
                //VAdvantage.Logging.VLogMgt.Shutdown(ctx);
                MSession s = MSession.Get(ctx);
                s.Logout();
            }
            catch
            {
            }


            FormsAuthentication.SignOut();
            //if (Session != null)
            //    Session.Abandon();
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 3
0
        /// <summary>
        /// Return the Form pointer of WindowNo - or null
        /// </summary>
        /// <param name="WindowNo"></param>
        /// <returns></returns>



        /// <summary>
        ///    Exit System
        /// </summary>
        /// <param name="status"></param>
        public static void ExitEnv(int status)
        {
            //	End Session
            MSession session = MSession.Get(Env.GetContext(), false);   //	finish

            if (session != null)
            {
                session.Logout();
            }
            //
            Reset(true);        // final cache reset
            _log.Info("");
            //
            VLogMgt.Shutdown();
            //

            if (VAdvantage.DataBase.Ini.IsClient())
            {
                Environment.Exit(status);
            }
        }       //	close
Esempio n. 4
0
        }       //	getCtx

        private bool StartEnvironment(bool doTrace)
        {
            //Program.StartUp(false, "ServerMgr");    //start up the ServerMgr class (Loads the initial value to run the application)
            if (doTrace)
            {
                VLogMgt.SetLevel(Level.ALL);    //in case of server side, we will always open the trace to ALL
            }
            else
            {
                VLogMgt.SetLevel(Level.OFF);
            }
            log.Info("");

            String Remote_Addr = "Unknown";
            String Remote_Host = null;

            try
            {
                IPAddress[] ips = Dns.GetHostAddresses(Dns.GetHostName());
                if (ips.Length > 0)
                {
                    Remote_Addr = ips[0].ToString();    //pick the one tht comes first (in case of multiple IP's)
                }
                Remote_Host = Dns.GetHostName();
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, "No Local Host", e);
            }


            //	Set Session
            MSession session = MSession.Get(GetCtx(), "Z", true, Remote_Addr, Remote_Host, "Server");

            //
            return(session != null);
        }       //	startEnvironment
Esempio n. 5
0
        public static FormDataOut GetFormInfo(int AD_Form_ID, Ctx ctx)
        {
            FormDataOut outt = new FormDataOut();

            String className = null;

            String sql = "SELECT Name, Description, Classname, Help , IsReport, DisplayName FROM AD_Form WHERE AD_Form_ID=" + AD_Form_ID;  //jz ClassName, AD?
            bool   trl = !Env.IsBaseLanguage(ctx, "AD_Form");

            if (trl)
            {
                sql = " SELECT f.Name, t.Description, f.Classname, t.Help ,f.IsReport,t.Name " //jz
                      + " FROM AD_Form f INNER JOIN AD_Form_Trl t"
                      + " ON (f.AD_Form_ID=t.AD_Form_ID AND AD_Language='" + Env.GetAD_Language(ctx) + "')"
                      + " WHERE f.AD_Form_ID=" + AD_Form_ID;
            }

            IDataReader idr = null;
            DataTable   dt  = null;

            try
            {
                idr = DB.ExecuteReader(sql, null, null);
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    outt.Name        = Util.GetValueOfString(dr[0]);
                    outt.Description = Util.GetValueOfString(dr[1]);
                    if (dr["IsReport"].ToString().Equals("Y", StringComparison.OrdinalIgnoreCase))
                    {
                        className     = "VAdvantage.Report.ReportLoader";
                        outt.IsReport = true;
                    }
                    else
                    {
                        className = dr[2].ToString();
                        string prefix = "";
                        string nSpace = "";

                        try
                        {
                            //Tuple<String, String> aInfo = null;
                            if (Env.GetModulePrefix(outt.Name, out prefix, out nSpace))
                            {
                                className = className.Replace(nSpace, prefix.Substring(0, prefix.Length - 1));
                            }
                            //else if (!string.IsNullOrEmpty(className) && Env.GetModulePrefix(className.Substring(, out prefix,out nSpace))
                            //{

                            //}
                            else
                            {
                                if (prefix.Length == 0)
                                {
                                    prefix = "VIS_";
                                }


                                nSpace = "VAdvantage";
                                if (className.Contains(nSpace))
                                {
                                    className = className.Replace(nSpace, prefix.Substring(0, prefix.Length - 1));
                                }
                                nSpace = "ViennaAdvantage";
                                if (className.Contains(nSpace))
                                {
                                    className = className.Replace(nSpace, prefix.Substring(0, prefix.Length - 1));
                                }
                            }
                        }
                        catch
                        {
                            // blank
                        }
                        outt.Prefix = "";
                    }


                    outt.ClassName = className;
                    //className = Util.GetValueOfString(dr[2]);
                    outt.Help = Util.GetValueOfString(dr[3]);
                    // if (!trl)
                    // {
                    outt.DisplayName = Util.GetValueOfString(dr[5]);
                    // }
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                outt.IsError = true;
                outt.Message = e.Message;
            }
            if (className == null)
            {
                //return false;
            }
            else
            {
                // bool success = OpenForm(AD_Form_ID, className, name);
                //	Log
                MSession session = MSession.Get(ctx, true);
                session.WindowLog(ctx.GetAD_Client_ID(), ctx.GetAD_Org_ID(), 0, AD_Form_ID);
            }

            return(outt);
        }
Esempio n. 6
0
        //[MethodImpl(MethodImplOptions.Synchronized)]
        //[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
        /// <summary>
        /// Entry Point of Framework
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        public ActionResult Index(FormCollection form)
        {
            //if (!User.Identity.IsAuthenticated)
            //{
            //    // Required to allow javascript redirection through to browser
            //    this.Response.TrySkipIisCustomErrors = true;
            //    this.Response.Status = "401 Unauthorized";
            //    this.Response.StatusCode = 401;
            //    // note that the following line is .NET 4.5 or later only
            //    // otherwise you have to suppress the return URL etc manually!
            //    this.Response.SuppressFormsAuthenticationRedirect = true;
            //    // If we got this far, something failed

            //}


            var url = CloudLogin.IsAllowedToLogin(Request.Url.ToString());

            if (!string.IsNullOrEmpty(url))
            {
                return(RedirectPermanent(url));
            }

            VAdvantage.DataBase.DBConn.SetConnectionString();//Init database conection
            LoginModel model = null;

            if (User.Identity.IsAuthenticated)
            {
                try
                {
                    //var conf = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
                    //  SessionStateSection section = (SessionStateSection) conf.GetSection("system.web/sessionState");
                    // int timeout = (int) section.Timeout.TotalMinutes;
                    Session.Timeout = 20; // ideal timout
                }
                catch
                {
                }


                //AccountController a = new AccountController();
                //a.LogOff();
                FormsIdentity ident = User.Identity as FormsIdentity;
                Ctx           ctx   = null;
                if (ident != null)
                {
                    FormsAuthenticationTicket ticket = ident.Ticket;
                    string       loginContextString  = ticket.UserData;// get login context string from Form Ticket
                    LoginContext lCtx = JsonHelper.Deserialize(loginContextString, typeof(LoginContext)) as LoginContext;
                    IDataReader  dr   = null;



                    //create class from string
                    string key = "";
                    if (Session["ctx"] != null)
                    {
                        ctx = Session["ctx"] as Ctx;

                        //Update Old Session
                        MSession session = MSession.Get(ctx, false);
                        if (session != null)
                        {
                            session.Logout();
                        }

                        key = ctx.GetSecureKey();

                        //if (Session.Timeout < 2)
                        //{
                        SessionEventHandler.SessionEnd(ctx);
                        Session.Timeout = 17;
                        //}
                        Session["ctx"] = null;
                    }
                    ctx = new Ctx(lCtx.ctxMap); //cretae new context
                    if (key != "")
                    {
                        ctx.SetSecureKey(key);
                    }
                    Session["ctx"] = ctx;

                    //get login Language object on server
                    var loginLang = ctx.GetAD_Language();

                    Language l = Language.GetLanguage(ctx.GetAD_Language()); //Language.GetLoginLanguage();
                    l = VAdvantage.Utility.Env.VerifyLanguage(ctx, l);

                    ctx.SetContext(VAdvantage.Utility.Env.LANGUAGE, l.GetAD_Language());
                    ctx.SetContext(VAdvantage.Utility.Env.ISRIGHTTOLEFT, VAdvantage.Utility.Env.IsRightToLeft(loginLang) ? "Y" : "N");
                    new VAdvantage.Login.LoginProcess(ctx).LoadSysConfig();


                    ViewBag.culture   = ctx.GetAD_Language();
                    ViewBag.direction = ctx.GetIsRightToLeft() ? "rtl" : "ltr";

                    //Change Authentication
                    model                           = new LoginModel();
                    model.Login1Model               = new Login1Model();
                    model.Login2Model               = new Login2Model();
                    model.Login1Model.UserName      = User.Identity.Name;
                    model.Login1Model.LoginLanguage = ctx.GetAD_Language();

                    model.Login2Model.Role      = ctx.GetAD_Role_ID().ToString();
                    model.Login2Model.Client    = ctx.GetAD_Client_ID().ToString();
                    model.Login2Model.Org       = ctx.GetAD_Org_ID().ToString();
                    model.Login2Model.Warehouse = ctx.GetAD_Warehouse_ID().ToString();


                    var RoleList      = new List <KeyNamePair>();
                    var ClientList    = new List <KeyNamePair>();
                    var OrgList       = new List <KeyNamePair>();
                    var WareHouseList = new List <KeyNamePair>();

                    LoginHelper.Login(model, out RoleList);

                    //string diableMenu = ctx.GetContext("#DisableMenu");
                    Helpers.MenuHelper mnuHelper = new Helpers.MenuHelper(ctx); // inilitilize menu class

                    bool disableMenu = MRole.GetDefault(ctx).IsDisableMenu();
                    ctx.SetIsBasicDB(mnuHelper.GetIsBasicDB());


                    // If Home page not linked OR home page Linked BUT Menu is not disabled , then show home page.
                    // If Home is linked as well as menu is disabled then don't load Default Home Page Settings
                    if (MRole.GetDefault(ctx).GetHomePage_ID() == 0 || (MRole.GetDefault(ctx).GetHomePage_ID() > 0 && !disableMenu))
                    {
                        HomeModels hm = new HomeModels();
                        objHomeHelp     = new HomeHelper();
                        hm              = objHomeHelp.getLoginUserInfo(ctx, 32, 32);
                        ViewBag.UserPic = hm.UsrImage;
                    }

                    if (!disableMenu) // if menu is not disabled, only then load menu.
                    {
                        //get current user info
                        ViewBag.Menu        = mnuHelper.GetMenuTree();    // create tree
                        Session["barNodes"] = ViewBag.Menu.GetBarNodes(); /* add is session to get it in favourite call */

                        ViewBag.TreeHtml = mnuHelper.GetMenuTreeUI(ViewBag.Menu.GetRootNode(), @Url.Content("~/"));
                    }

                    ViewBag.disableMenu = disableMenu;

                    mnuHelper.dispose();

                    //  LoginHelper.GetClients(id)

                    ClientList    = LoginHelper.GetClients(ctx.GetAD_Role_ID());                                          // .Add(new KeyNamePair(ctx.GetAD_Client_ID(), ctx.GetAD_Client_Name()));
                    OrgList       = LoginHelper.GetOrgs(ctx.GetAD_Role_ID(), ctx.GetAD_User_ID(), ctx.GetAD_Client_ID()); // .Add(new KeyNamePair(ctx.GetAD_Org_ID(), ctx.GetAD_Org_Name()));
                    WareHouseList = LoginHelper.GetWarehouse(ctx.GetAD_Org_ID());                                         // .Add(new KeyNamePair(ctx.GetAD_Warehouse_ID(), ctx.GetContext("#M_Warehouse_Name")));


                    ViewBag.RoleList      = RoleList;
                    ViewBag.ClientList    = ClientList;
                    ViewBag.OrgList       = OrgList;
                    ViewBag.WarehouseList = WareHouseList;
                    lock (_lock)    // Locked bundle Object and session Creation to handle concurrent requests.
                    {
                        //Cretae new Sessin
                        MSession sessionNew = MSession.Get(ctx, true, GetVisitorIPAddress(true));


                        var lst = VAdvantage.ModuleBundles.GetStyleBundles(); //Get All Style Bundle
                        foreach (var b in lst)
                        {
                            if (!BundleTable.Bundles.Contains(b))
                            {
                                BundleTable.Bundles.Add(b); //Add in Mvc Bundle Table
                            }
                        }

                        var lstRTLStyle = VAdvantage.ModuleBundles.GetRTLStyleBundles(); //Get All Script Bundle

                        foreach (var b in lstRTLStyle)
                        {
                            if (!BundleTable.Bundles.Contains(b))
                            {
                                BundleTable.Bundles.Add(b); //Add in Mvc Bundlw Table
                            }
                        }

                        var lstScript = VAdvantage.ModuleBundles.GetScriptBundles(); //Get All Script Bundle

                        foreach (var b in lstScript)
                        {
                            if (!BundleTable.Bundles.Contains(b))
                            {
                                BundleTable.Bundles.Add(b); //Add in Mvc Bundlw Table
                            }
                        }

                        ViewBag.LibSuffix   = "";
                        ViewBag.FrameSuffix = "_v1";
                        int libFound = 0;
                        foreach (Bundle b in BundleTable.Bundles)
                        {
                            if (b.Path.Contains("ViennaBase") && b.Path.Contains("_v") && ViewBag.LibSuffix == "")
                            {
                                ViewBag.LibSuffix = Util.GetValueOfInt(ctx.GetContext("#FRONTEND_LIB_VERSION")) > 2
                                                      ? "_v3" : "_v2";
                                libFound++;
                            }

                            if (b.Path.Contains("VIS") && b.Path.Contains("_v"))
                            {
                                ViewBag.FrameSuffix = Util.GetValueOfInt(ctx.GetContext("#FRAMEWORK_VERSION")) > 1
                                                      ? "_v2" : "_v1";
                                libFound++;
                            }
                            if (libFound >= 2)
                            {
                                break;
                            }
                        }
                        //check system setting// set to skipped lib
                    }
                }
            }

            else
            {
                model             = new LoginModel();
                model.Login1Model = new Login1Model();
                //model.Login1Model.UserName = "******";
                //model.Login1Model.Password = "******";
                model.Login1Model.LoginLanguage = "en_US";
                model.Login2Model = new Login2Model();

                ViewBag.RoleList      = new List <KeyNamePair>();
                ViewBag.OrgList       = new List <KeyNamePair>();
                ViewBag.WarehouseList = new List <KeyNamePair>();
                ViewBag.ClientList    = new List <KeyNamePair>();

                ViewBag.Languages = Language.GetLanguages();

                Session["ctx"]    = null;
                ViewBag.direction = "ltr";

                ViewBag.LibSuffix = "";
                foreach (Bundle b in BundleTable.Bundles)
                {
                    if (b.Path.Contains("ViennaBase") && b.Path.Contains("_v"))
                    {
                        ViewBag.LibSuffix = "_v2";
                        break;
                    }
                }
            }
            return(View(model));
        }
Esempio n. 7
0
        //[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
        public ActionResult Index(FormCollection form)
        {
            LoginModel model = null;

            if (User.Identity.IsAuthenticated)
            {
                VAdvantage.DataBase.DBConn.SetConnectionString();//Init database conection


                //AccountController a = new AccountController();
                //a.LogOff();
                FormsIdentity ident = User.Identity as FormsIdentity;
                Ctx           ctx   = null;
                if (ident != null)
                {
                    FormsAuthenticationTicket ticket = ident.Ticket;
                    string       loginContextString  = ticket.UserData;// get login context string from Form Ticket
                    LoginContext lCtx = JsonHelper.Deserialize(loginContextString, typeof(LoginContext)) as LoginContext;



                    //create class from string
                    string key = "";
                    if (Session["ctx"] != null)
                    {
                        ctx            = Session["ctx"] as Ctx;
                        key            = ctx.GetSecureKey();
                        Session["ctx"] = null;
                    }
                    ctx = new Ctx(lCtx.ctxMap); //cretae new context
                    if (key != "")
                    {
                        ctx.SetSecureKey(key);
                    }
                    Session["ctx"] = ctx;

                    //get login Language object on server
                    var loginLang = ctx.GetAD_Language();

                    Language l = Language.GetLanguage(ctx.GetAD_Language()); //Language.GetLoginLanguage();
                    l = VAdvantage.Utility.Env.VerifyLanguage(ctx, l);

                    ctx.SetContext(VAdvantage.Utility.Env.LANGUAGE, l.GetAD_Language());
                    ctx.SetContext(VAdvantage.Utility.Env.ISRIGHTTOLEFT, VAdvantage.Utility.Env.IsRightToLeft(loginLang) ? "Y" : "N");

                    //get current user info
                    HomeModels hm = new HomeModels();
                    objHomeHelp     = new HomeHelper();
                    hm              = objHomeHelp.getLoginUserInfo(ctx, 32, 32);
                    ViewBag.UserPic = hm.UsrImage;

                    Helpers.MenuHelper mnuHelper = new Helpers.MenuHelper(ctx); // inilitilize menu class

                    ViewBag.Menu        = mnuHelper.GetMenuTree();              // create tree
                    Session["barNodes"] = ViewBag.Menu.GetBarNodes();           /* add is session to get it in favourite call */

                    ViewBag.TreeHtml = mnuHelper.GetMenuTreeUI(ViewBag.Menu.GetRootNode(), @Url.Content("~/"));
                    // create tree html

                    ViewBag.culture   = ctx.GetAD_Language();
                    ViewBag.direction = ctx.GetIsRightToLeft() ? "rtl" : "ltr";
                    ctx.SetIsBasicDB(mnuHelper.GetIsBasicDB());

                    mnuHelper.dispose();



                    //Change Authentication
                    model                           = new LoginModel();
                    model.Login1Model               = new Login1Model();
                    model.Login2Model               = new Login2Model();
                    model.Login1Model.UserName      = User.Identity.Name;
                    model.Login1Model.LoginLanguage = ctx.GetAD_Language();

                    model.Login2Model.Role      = ctx.GetAD_Role_ID().ToString();
                    model.Login2Model.Client    = ctx.GetAD_Client_ID().ToString();
                    model.Login2Model.Org       = ctx.GetAD_Org_ID().ToString();
                    model.Login2Model.Warehouse = ctx.GetAD_Warehouse_ID().ToString();


                    var RoleList      = new List <KeyNamePair>();
                    var ClientList    = new List <KeyNamePair>();
                    var OrgList       = new List <KeyNamePair>();
                    var WareHouseList = new List <KeyNamePair>();

                    LoginHelper.Login(model, out RoleList);

                    //  LoginHelper.GetClients(id)

                    ClientList    = LoginHelper.GetClients(ctx.GetAD_Role_ID());                                          // .Add(new KeyNamePair(ctx.GetAD_Client_ID(), ctx.GetAD_Client_Name()));
                    OrgList       = LoginHelper.GetOrgs(ctx.GetAD_Role_ID(), ctx.GetAD_User_ID(), ctx.GetAD_Client_ID()); // .Add(new KeyNamePair(ctx.GetAD_Org_ID(), ctx.GetAD_Org_Name()));
                    WareHouseList = LoginHelper.GetWarehouse(ctx.GetAD_Org_ID());                                         // .Add(new KeyNamePair(ctx.GetAD_Warehouse_ID(), ctx.GetContext("#M_Warehouse_Name")));


                    ViewBag.RoleList      = RoleList;
                    ViewBag.ClientList    = ClientList;
                    ViewBag.OrgList       = OrgList;
                    ViewBag.WarehouseList = WareHouseList;
                    MSession session = MSession.Get(ctx, true);
                }
            }

            else
            {
                model             = new LoginModel();
                model.Login1Model = new Login1Model();
                //model.Login1Model.UserName = "******";
                //model.Login1Model.Password = "******";
                model.Login1Model.LoginLanguage = "en_US";
                model.Login2Model = new Login2Model();

                ViewBag.RoleList      = new List <KeyNamePair>();
                ViewBag.OrgList       = new List <KeyNamePair>();
                ViewBag.WarehouseList = new List <KeyNamePair>();
                ViewBag.ClientList    = new List <KeyNamePair>();
                Session["ctx"]        = null;
                ViewBag.direction     = "ltr";
            }
            return(View(model));
        }
Esempio n. 8
0
        }       //	getActive

        public bool StopAll()
        {
            log.Info("Stop All log================================>" + DateTime.Now.Millisecond.ToString());
            ViennaServer[] servers = GetActive();
            //	Interrupt
            for (int i = 0; i < servers.Length; i++)
            {
                ViennaServer server = servers[i];
                try
                {
                    if (server.GetServerThread().IsAlive)
                    {
                        server.SetPriority(ThreadPriority.Highest);
                        server.Interrupt();
                    }
                }
                catch (Exception e)
                {
                    log.Log(Level.SEVERE, "(Interrupting) - " + server, e);
                }
            }                //	for all servers
            Thread.Sleep(0); //yielding

            //	Wait for death
            for (int i = 0; i < servers.Length; i++)
            {
                ViennaServer server = servers[i];
                try
                {
                    int maxWait = 10;   //	10 iterations = 1 sec
                    while (server.GetServerThread().IsAlive)
                    {
                        if (maxWait-- == 0)
                        {
                            log.Severe("Wait timeout for interruped " + server);
                            break;
                        }
                        Thread.Sleep(100);              //	1/10
                    }
                }
                catch (Exception e)
                {
                    log.Log(Level.SEVERE, "(Waiting) - " + server, e);
                }
            }   //	for all servers

            //	Final Check
            int noRunning = 0;
            int noStopped = 0;

            for (int i = 0; i < servers.Length; i++)
            {
                ViennaServer server = servers[i];
                try
                {
                    if (server.GetServerThread().IsAlive)
                    {
                        log.Warning("Alive: " + server);
                        noRunning++;
                    }
                    else
                    {
                        log.Info("Stopped: " + server);
                        noStopped++;
                    }
                }
                catch (Exception e)
                {
                    log.Log(Level.SEVERE, "(Checking) - " + server, e);
                    noRunning++;
                }
            }

            //	End Session
            MSession session = MSession.Get(Env.GetContext(), false);   //	finish

            if (session != null)
            {
                session.Logout();
            }
            m_servers.Clear();
            log.Fine("Running=" + noRunning + ", Stopped=" + noStopped);
            //ViennaServerGroup.Get().Dump();
            return(noRunning == 0);
        }       //	stopAll