Esempio n. 1
0
        public static Type GetModule(HttpApplicationStateBase appState, string moduleName, bool ignoreCase = false)
        {
            if (string.IsNullOrEmpty(moduleName))
            {
                return(null);
            }

            object qname = null;

            if (appState != null)
            {
                if (appState.AllKeys.Contains(MakeAliasViewDataKey(moduleName)))
                {
                    qname = appState[MakeAliasViewDataKey(moduleName)];
                }
            }
            else
            {
                qname = moduleName;
            }

            if (qname != null)
            {
                return(Type.GetType(qname.ToString(), false, ignoreCase));
            }

            return(null);
        }
        public void DynamicTest()
        {
            HttpApplicationStateBase appState = CreateAppStateInstance();
            dynamic d = new DynamicHttpApplicationState(appState);

            d["x"] = "y";
            Assert.Equal("y", d.x);
            Assert.Equal("y", d[0]);
            d.a = "b";
            Assert.Equal("b", d["a"]);
            d.Foo = "bar";
            Assert.Equal("bar", d.Foo);
            Assert.Null(d.XYZ);
            Assert.Null(d["xyz"]);
            Assert.Throws <ArgumentOutOfRangeException>(
                () =>
            {
                var x = d[5];
            }
                );
            var a = d.Baz = 42;

            Assert.Equal(42, a);
            var b = d["test"] = 666;

            Assert.Equal(666, b);
        }
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);

            string sitePath = CmsRoute.GetSitePath();

            isPreviewRequest  = requestContext.HttpContext.Request.QueryString["_previewAsset_"] == "true";
            isPreviewRequest |= Reference.Reference.IsDesignTime(sitePath);

            if (isPreviewRequest)
            {
                HttpApplicationStateBase application = requestContext.HttpContext.Application;
                _GetContentStore(requestContext, application);
            }

            //check if the asset followed with querystring "previewAsset"
            AssetBasePath = (isPreviewRequest) ?
                            ConfigurationManager.AppSettings["DesignTimeAssetsLocation"] :
                            sitePath;

            if (string.IsNullOrEmpty(AssetBasePath))
            {
                AssetBasePath = sitePath;
            }

            Authman = AuthenticationManager.Get(sitePath);
        }
        public static void SetValueOf <T>([NotNull] this HttpApplicationStateBase thisValue, [NotNull] string name, T value)
        {
            if (name.Length == 0)
            {
                throw new ArgumentNullException(nameof(name));
            }
            thisValue.Lock();

            string key = thisValue.AllKeys.FirstOrDefault(k => k.IsSame(name));

            if (value == null || value.Equals(default(T)))
            {
                if (key != null)
                {
                    thisValue.Remove(key);
                }
            }
            else
            {
                key ??= name;
                thisValue[key] = value;
            }

            thisValue.UnLock();
        }
Esempio n. 5
0
        /// <summary>
        /// The get or set.
        /// </summary>
        /// <param name="httpApplicationState">
        /// The http application state.
        /// </param>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="getValue">
        /// The get value.
        /// </param>
        /// <typeparam name="T">
        /// </typeparam>
        /// <returns>
        /// </returns>
        public static T GetOrSet <T>(
            [NotNull] this HttpApplicationStateBase httpApplicationState, [NotNull] string key, [NotNull] Func <T> getValue)
        {
            CodeContracts.VerifyNotNull(httpApplicationState, "httpApplicationState");
            CodeContracts.VerifyNotNull(key, "key");
            CodeContracts.VerifyNotNull(getValue, "getValue");

            var item = httpApplicationState[key];

            if (!Equals(item, default(T)))
            {
                return((T)item);
            }

            try
            {
                httpApplicationState.Lock();

                item = httpApplicationState[key];

                if (Equals(item, default(T)))
                {
                    item = getValue();
                    httpApplicationState[key] = item;
                }
            }
            finally
            {
                httpApplicationState.UnLock();
            }

            return((T)item);
        }
        /// <summary>
        /// Extension method to get all view models stored in HttpApplicationStateBase for the specified type.
        /// </summary>
        /// <typeparam name="TEntity">The type of entities that should be retrieved.</typeparam>
        /// <param name="appState">The application state to get the view models from.</param>
        /// <returns>The view models stored in the ApplicationState as a dictionary of key => view model.</returns>
        internal static Dictionary <string, TEntity> GetEntities <TEntity>(this HttpApplicationStateBase appState)
        {
            var appStateKey = typeof(TEntity).FullName;

            return(appState[appStateKey] != null
                ? (Dictionary <string, TEntity>)appState[appStateKey]
                : new Dictionary <string, TEntity>());
        }
Esempio n. 7
0
 public static void ReleaseUsernameFromReservedUsernamesCollection(HttpApplicationStateBase application, HttpSessionStateBase session, string username)
 {
     if (session != null)
     {
         session[RESERVED_USERNAME_INSESSION_KEY] = null;
     }
     ((HashSet <string>)application[RESERVED_USERNAMES_COLLECTION_KEY]).Remove(username);
 }
Esempio n. 8
0
 // Methods
 public HttpApplicationStateBaseWrapper(HttpApplicationStateBase httpApplicationState)
 {
     if (httpApplicationState == null)
     {
         throw new ArgumentNullException("httpApplicationState");
     }
     this._application = httpApplicationState;
 }
Esempio n. 9
0
        public Type GetDependencyType(HttpApplicationStateBase appState = null)
        {
            if (_type != null)
            {
                return(_type);
            }

            return(ModulesCatalog.GetModule(appState, _moduleName, _ignoreCase));
        }
Esempio n. 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GlobalMap"/> class.
        /// </summary>
        /// <param name="appState">An instance of <see cref="HttpApplicationStateBase"/></param>
        public GlobalMap(HttpApplicationStateBase appState)
        {
            if (appState == null)
            {
                throw new ArgumentNullException("appState");
            }

            _application = appState;
        }
 public void InvalidTypeWhenGetting()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         HttpApplicationStateBase appState = CreateAppStateInstance();
         dynamic d = new DynamicHttpApplicationState(appState);
         var x     = d[new object()];
     }, WebPageResources.DynamicHttpApplicationState_UseOnlyStringOrIntToGet);
 }
Esempio n. 12
0
 public static void StoreUsernameInReservedUsernamesCollection(HttpApplicationStateBase application, HttpSessionStateBase session, string username)
 {
     if (IsUsernameReserved(application, session, username))
     {
         throw new InvalidOperationException("This username is already reserved");
     }
     ((HashSet <string>)application[RESERVED_USERNAMES_COLLECTION_KEY]).Add(username);
     session[RESERVED_USERNAME_INSESSION_KEY] = username;
 }
        public void PrintCommands(string sid)
        {
            if (WebClientPrint.ProcessPrintJob(System.Web.HttpContext.Current.Request.Url.Query))
            {
                HttpApplicationStateBase app = HttpContext.Application;

                //Create a ClientPrintJob obj that will be processed at the client side by the WCPP
                ClientPrintJob cpj = new ClientPrintJob();

                //get printer commands for this user id
                object printerCommands = app[sid + PRINTER_COMMANDS];
                if (printerCommands != null)
                {
                    cpj.PrinterCommands = printerCommands.ToString();
                    cpj.FormatHexValues = true;
                }

                //get printer settings for this user id
                int printerTypeId = (int)app[sid + PRINTER_ID];

                if (printerTypeId == 0) //use default printer
                {
                    cpj.ClientPrinter = new DefaultPrinter();
                }
                else if (printerTypeId == 1) //show print dialog
                {
                    cpj.ClientPrinter = new UserSelectedPrinter();
                }
                else if (printerTypeId == 2) //use specified installed printer
                {
                    cpj.ClientPrinter = new InstalledPrinter(app[sid + INSTALLED_PRINTER_NAME].ToString());
                }
                else if (printerTypeId == 3) //use IP-Ethernet printer
                {
                    cpj.ClientPrinter = new NetworkPrinter(app[sid + NET_PRINTER_HOST].ToString(), int.Parse(app[sid + NET_PRINTER_PORT].ToString()));
                }
                else if (printerTypeId == 4) //use Parallel Port printer
                {
                    cpj.ClientPrinter = new ParallelPortPrinter(app[sid + PARALLEL_PORT].ToString());
                }
                else if (printerTypeId == 5) //use Serial Port printer
                {
                    cpj.ClientPrinter = new SerialPortPrinter(app[sid + SERIAL_PORT].ToString(),
                                                              int.Parse(app[sid + SERIAL_PORT_BAUDS].ToString()),
                                                              (SerialPortParity)Enum.Parse(typeof(SerialPortParity), app[sid + SERIAL_PORT_PARITY].ToString()),
                                                              (SerialPortStopBits)Enum.Parse(typeof(SerialPortStopBits), app[sid + SERIAL_PORT_STOP_BITS].ToString()),
                                                              int.Parse(app[sid + SERIAL_PORT_DATA_BITS].ToString()),
                                                              (SerialPortHandshake)Enum.Parse(typeof(SerialPortHandshake), app[sid + SERIAL_PORT_FLOW_CONTROL].ToString()));
                }

                //Send ClientPrintJob back to the client
                System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
                System.Web.HttpContext.Current.Response.BinaryWrite(cpj.GetContent());
                System.Web.HttpContext.Current.Response.End();
            }
        }
Esempio n. 14
0
        // GET: SMSTest
        public ActionResult Index()
        {
            //SMSHelper.SendMessage("18514502514");
            HttpApplicationStateBase state = this.HttpContext.Application;

            state.Add("phone", "123456789");
            return(Json(state, JsonRequestBehavior.AllowGet));

            //return Json(SMSHelper.SendMessage("18514502514",""),JsonRequestBehavior.AllowGet);
        }
        public void ClientPrinterSettings(string sid,
                                          string pid,
                                          string installedPrinterName,
                                          string netPrinterHost,
                                          string netPrinterPort,
                                          string parallelPort,
                                          string serialPort,
                                          string serialPortBauds,
                                          string serialPortDataBits,
                                          string serialPortStopBits,
                                          string serialPortParity,
                                          string serialPortFlowControl,
                                          string printerCommands)
        {
            try
            {
                HttpApplicationStateBase app = HttpContext.Application;

                //save settings in the global Application obj

                //save the type of printer selected by the user
                int i = int.Parse(pid);
                app[sid + PRINTER_ID] = i;

                if (i == 2)
                {
                    app[sid + INSTALLED_PRINTER_NAME] = installedPrinterName;
                }
                else if (i == 3)
                {
                    app[sid + NET_PRINTER_HOST] = netPrinterHost;
                    app[sid + NET_PRINTER_PORT] = netPrinterPort;
                }
                else if (i == 4)
                {
                    app[sid + PARALLEL_PORT] = parallelPort;
                }
                else if (i == 5)
                {
                    app[sid + SERIAL_PORT]              = serialPort;
                    app[sid + SERIAL_PORT_BAUDS]        = serialPortBauds;
                    app[sid + SERIAL_PORT_DATA_BITS]    = serialPortDataBits;
                    app[sid + SERIAL_PORT_FLOW_CONTROL] = serialPortFlowControl;
                    app[sid + SERIAL_PORT_PARITY]       = serialPortParity;
                    app[sid + SERIAL_PORT_STOP_BITS]    = serialPortStopBits;
                }

                //save the printer commands specified by the user
                app[sid + PRINTER_COMMANDS] = printerCommands;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static T GetValueOf <T>([NotNull] this HttpApplicationStateBase thisValue, int index, T defaultValue = default(T))
        {
            T result = defaultValue;

            thisValue.Lock();
            if (thisValue.Keys.Count > 0 && index.InRangeRx(0, thisValue.Keys.Count))
            {
                result = thisValue.Get(index).To(result);
            }
            thisValue.UnLock();
            return(result);
        }
Esempio n. 17
0
 public void SetPrintCommand(string sid, string printerCommands)
 {
     try
     {
         HttpApplicationStateBase app = HttpContext.Application;
         app[sid + PRINTER_COMMANDS] = printerCommands;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 18
0
        public static void LoadModules(HttpApplicationStateBase appState, IDictionary storage, params object[] args)
        {
            var modules = appState[ModulesCatalog._webexInternalModuleTypes] as IEnumerable <Type>;

            if (modules != null)
            {
                foreach (var module in modules)
                {
                    LoadModule(storage, module, args);
                }
            }
        }
Esempio n. 19
0
        public ActionResult ForgotPassword(string username)
        {
            string subdomain = UtilityHelper.GetSubdomain(HttpContext.Request.Headers["HOST"]);
            string password  = Guid.NewGuid().ToString().Substring(0, 8);

            DataModel.User           user        = UserBL.ResetPassword(subdomain, username, password);
            HttpApplicationStateBase application = HttpContext.Application;
            string body = application[ConstantsUtil.ConfigForgotPasswordEmailBody].ToString().Replace("*password*", password);

            UtilityHelper.SendEmail(user.Email, application[ConstantsUtil.ConfigForgotPasswordEmailSubject].ToString(), body);
            ViewBag.Email = user.Email;
            return(View());
        }
Esempio n. 20
0
        public static IEnumerable <Type> GetModuleDependencies(this IModule module, HttpApplicationStateBase appState = null)
        {
            if (module == null)
            {
                return new Type[] { }
            }
            ;

            var md  = module as IModuleDependency;
            var dep = new List <Type>();

            if (md != null)
            {
                var depStrings = md.GetDependencyByName();

                if (depStrings != null)
                {
                    foreach (var item in depStrings)
                    {
                        var t = Type.GetType(item, false, false);
                        if (t != null && !dep.Contains(t))
                        {
                            dep.Add(t);
                        }
                    }
                }

                var depTypes = md.GetDependency();
                if (depTypes != null)
                {
                    foreach (var t in depTypes)
                    {
                        if (t != null && !dep.Contains(t))
                        {
                            dep.Add(t);
                        }
                    }
                }
            }

            foreach (DependencyAttribute item in module.GetType().GetCustomAttributes(typeof(DependencyAttribute), false))
            {
                var t = item.GetDependencyType(appState);
                if (t != null && !dep.Contains(t))
                {
                    dep.Add(t);
                }
            }

            return(dep);
        }
        public static Dictionary <string, string> Convert(HttpApplicationStateBase coll)
        {
            var keyValues = new Dictionary <string, string>();
            var keys      = coll.Keys;

            foreach (var key in keys)
            {
                var strKey = key.ToString();
                var value  = coll.Get(strKey).ToString();
                keyValues.Add(strKey, value);
            }

            return(keyValues);
        }
Esempio n. 22
0
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);

            SitePath          = CmsRoute.GetSitePath();
            isPreviewRequest  = requestContext.HttpContext.Request.QueryString["_previewAsset_"] == "true";
            isPreviewRequest |= Reference.Reference.IsDesignTime(SitePath);

            if (isPreviewRequest)
            {
                HttpApplicationStateBase application = requestContext.HttpContext.Application;
                _GetContentStore(requestContext, application);
            }
        }
        public static void Set(IDocumentStore documentStore, HttpApplicationStateBase application = null)
        {
            if (documentStore == null)
            {
                throw new ArgumentNullException("documentStore");
            }

            application = application ?? TryGetApplication();
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            application[DocumentStoreKey] = documentStore;
        }
Esempio n. 24
0
        public static void Set(this HttpApplicationStateBase state, string name, object data)
        {
            Debug.Assert(state != null);
            Debug.Assert(name != null);

            try
            {
                state.Lock();
                state[name] = data;
            }
            finally
            {
                state.UnLock();
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CurrentBoardSettings"/> class.
        /// </summary>
        /// <param name="applicationStateBase">
        /// The application state base.
        /// </param>
        /// <param name="injectServices">
        /// The inject services.
        /// </param>
        /// <param name="haveBoardId">
        /// The have board id.
        /// </param>
        /// <param name="treatCacheKey">
        /// </param>
        /// <param name="boardRepository">
        /// The board Repository.
        /// </param>
        public CurrentBoardSettings(
            [NotNull] HttpApplicationStateBase applicationStateBase,
            [NotNull] IInjectServices injectServices,
            [NotNull] IHaveBoardID haveBoardId,
            [NotNull] ITreatCacheKey treatCacheKey)
        {
            CodeContracts.VerifyNotNull(applicationStateBase, "applicationStateBase");
            CodeContracts.VerifyNotNull(injectServices, "injectServices");
            CodeContracts.VerifyNotNull(haveBoardId, "haveBoardId");
            CodeContracts.VerifyNotNull(treatCacheKey, "treatCacheKey");

            this._applicationStateBase = applicationStateBase;
            this._injectServices       = injectServices;
            this._haveBoardId          = haveBoardId;
            this._treatCacheKey        = treatCacheKey;
        }
        /// <summary>
        /// Gets the webpack instance.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <returns>
        /// The webpack instance.
        /// </returns>
        /// <exception cref="System.InvalidOperationException">Webpack has not been configured, have you called HttpApplication.ConfigureWebpack()?</exception>
        internal static IWebpack GetWebpack(this HttpApplicationStateBase application)
        {
            if (application == null)
            {
                throw new ArgumentNullException(nameof(application));
            }

            var webpack = application[WebpackApplicationKey] as IWebpack;

            if (webpack == null)
            {
                throw new InvalidOperationException("Webpack has not been configured, have you called HttpApplication.ConfigureWebpack()?");
            }

            return(webpack);
        }
Esempio n. 27
0
        /// <summary>
        /// The set.
        /// </summary>
        /// <param name="httpApplicationState">
        /// The http application state.
        /// </param>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <typeparam name="T">
        /// </typeparam>
        public static void Set <T>(
            [NotNull] this HttpApplicationStateBase httpApplicationState, [NotNull] string key, [NotNull] T value)
        {
            CodeContracts.VerifyNotNull(httpApplicationState, "httpApplicationState");
            CodeContracts.VerifyNotNull(key, "key");

            try
            {
                httpApplicationState.Lock();
                httpApplicationState[key] = value;
            }
            finally
            {
                httpApplicationState.UnLock();
            }
        }
        public void InvalidNumberOfIndexes()
        {
            Assert.Throws <ArgumentException>(() =>
            {
                HttpApplicationStateBase appState = CreateAppStateInstance();
                dynamic d = new DynamicHttpApplicationState(appState);
                d[1, 2]   = 3;
            }, WebPageResources.DynamicDictionary_InvalidNumberOfIndexes);

            Assert.Throws <ArgumentException>(() =>
            {
                HttpApplicationStateBase appState = CreateAppStateInstance();
                dynamic d = new DynamicHttpApplicationState(appState);
                var x     = d[1, 2];
            }, WebPageResources.DynamicDictionary_InvalidNumberOfIndexes);
        }
        public static IDocumentStore Get(HttpApplicationStateBase application = null)
        {
            application = application ?? TryGetApplication();
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            var documentStore = application[DocumentStoreKey] as IDocumentStore;

            if (documentStore == null)
            {
                throw new KeyNotFoundException("Could not find WikiDown IDocumentStore in Application-state.");
            }

            return(documentStore);
        }
Esempio n. 30
0
        public static IEnumerable <T> LoadModules <T>(HttpApplicationStateBase appState, IDictionary storage, params object[] args)
        {
            var modules = appState[ModulesCatalog._webexInternalModuleTypes] as IEnumerable <Type>;
            var l       = new List <T>();

            if (modules != null)
            {
                foreach (var module in modules)
                {
                    if (typeof(T).IsAssignableFrom(module))
                    {
                        l.Add((T)LoadModule(storage, module, args));
                    }
                }
            }

            return(l);
        }
 public DynamicHttpApplicationState(HttpApplicationStateBase state)
 {
     _state = state;
 }