/// <summary>
        /// Raises an event related to a session.
        /// </summary>
        protected virtual void RaiseSessionEvent(Session session, SessionEventReason reason)
        {
            lock (m_eventLock)
            {
                SessionEventHandler handler = null;

                switch (reason)
                {
                case SessionEventReason.Created: { handler = m_SessionCreated; break; }

                case SessionEventReason.Activated: { handler = m_SessionActivated; break; }

                case SessionEventReason.Closing: { handler = m_SessionClosing; break; }
                }

                if (handler != null)
                {
                    try
                    {
                        handler(session, reason);
                    }
                    catch (Exception e)
                    {
                        Utils.Trace(e, "Session event handler raised an exception.");
                    }
                }
            }
        }
 protected override void WndProc(ref System.Windows.Forms.Message m)
 {
     if (m.Msg == Cliver.WinApi.Messages.WM_WTSSESSION_CHANGE)
     {
         //SessionEventHandler?.BeginInvoke(m.WParam.ToInt32(), null, null);
         SessionEventHandler?.Invoke(m.WParam.ToInt32());
     }
     base.WndProc(ref m);
 }
Example #3
0
        public static sp_error WaitForLoginComplete(this ISession session)
        {
            var result = sp_error.OK;
            var reset  = new ManualResetEvent(false);
            SessionEventHandler handler = (a, e) =>
            {
                result = e.Status;
                reset.Set();
            };

            session.LoginComplete += handler;
            reset.WaitOne();
            session.LoginComplete -= handler;
            return(result);
        }
Example #4
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   A Session extension method that plays a single track and notifies it's completion. </summary>
        ///
        /// <remarks>   <para>This single extension-method takes care of unloading (in case there are any other tracks
        ///             playing), loading, and starting playback of a single track. Then, when the track is complete,
        ///             it signals the task. This enables for easy programming of behaviour such as playing through an
        ///             entire playlist, or simply playing random songs non-stop. Queueing is also easily implemented
        ///             with this method. However, this method is not meant to be used in combinations with the ability
        ///             to change what track you are currently listening to. If your application (one way or another)
        ///             allows the user (or some AI) to select a new song, whilst there is one playing, you SHOULD not
        ///             use this method, as it can have un-wanted sideeffects (in the magnitude of your application
        ///             crashing and dying horribly).</para>
        ///
        ///              <para>The inner workings of this method is implemented using the <see cref="Session.EndOfTrack"/>
        ///              event. Every time you call this method an event-handler is attatched to the <see cref="Session.EndOfTrack"/>
        ///              event. This means that if you call this method again (before the song is finished),
        ///              it will attatch a second event-handler, and then a third, and so forth. This can probably
        ///              be resolved (one way or another), but for now, this functionality is <strong><u>not supported</u></strong>.</para> </remarks>
        ///
        /// <param name="session">  The session to act on. </param>
        /// <param name="track">    The track. </param>
        ///
        /// <returns>   A task that is signalled when the track completes. </returns>
        ///
        /// <example>
        ///          Play through an enumerable of tracks:
        ///          <code>
        ///             <code lang="cs"><![CDATA[
        /// private async Task PlayAll(Session session, IEnumerable<Track> tracks)
        /// {
        ///     foreach(var t in tracks)
        ///         await session.Play(t);
        /// }
        ///             ]]></code>
        ///          </code>
        /// </example>
        ///-------------------------------------------------------------------------------------------------
        public static Task Play(this Session session, Track track)
        {
            TaskCompletionSource <object> tcs     = new TaskCompletionSource <object>();
            SessionEventHandler           handler = null;

            handler = (s, e) =>
            {
                session.EndOfTrack -= handler;
                tcs.SetResult(null);
            };

            session.PlayerUnload();
            session.EndOfTrack += handler;
            session.PlayerLoad(track);
            session.PlayerPlay();

            return(tcs.Task);
        }
        //-----------------------------------------------------------------------------
        public SilkroadServer(IPEndPoint bind_addr, IPEndPoint module_addr, ServerType srv_type, bool blowfish, bool sec_bytes, bool handshake, PacketDispatcher packetProcessor, DelayedPacketDispatcher delayedPacketDispatcher, List<RedirectRule> redirs = null)
        {
            m_listener_sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            m_sessions = new List<RelaySession>();
            m_bind_addr = bind_addr;
            m_module_addr = module_addr;
            m_srv_type = srv_type;
            m_class_lock = new object();
            m_session_create_handler = new SessionEventHandler(OnContextCreate);
            m_session_destroy_handler = new SessionEventHandler(OnContextDestroy);

            m_blowfish = blowfish;
            m_sec_bytes = sec_bytes;
            m_handshake = handshake;

            m_redirect_rules = redirs;
            m_pck_processor = packetProcessor;
            m_delayed_pck_dispatcher = delayedPacketDispatcher;
        }
Example #6
0
        //-----------------------------------------------------------------------------

        public SilkroadServer(IPEndPoint bind_addr, IPEndPoint module_addr, ServerType srv_type, bool blowfish, bool sec_bytes, bool handshake, PacketDispatcher packetProcessor, DelayedPacketDispatcher delayedPacketDispatcher, List <RedirectRule> redirs = null)
        {
            m_listener_sock           = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            m_sessions                = new List <RelaySession>();
            m_bind_addr               = bind_addr;
            m_module_addr             = module_addr;
            m_srv_type                = srv_type;
            m_class_lock              = new object();
            m_session_create_handler  = new SessionEventHandler(OnContextCreate);
            m_session_destroy_handler = new SessionEventHandler(OnContextDestroy);

            m_blowfish  = blowfish;
            m_sec_bytes = sec_bytes;
            m_handshake = handshake;



            m_redirect_rules         = redirs;
            m_pck_processor          = packetProcessor;
            m_delayed_pck_dispatcher = delayedPacketDispatcher;
        }
Example #7
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));
        }