当前位置: 首页>>代码示例>>C#>>正文


C# IMansionContext.Cast方法代码示例

本文整理汇总了C#中IMansionContext.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# IMansionContext.Cast方法的具体用法?C# IMansionContext.Cast怎么用?C# IMansionContext.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMansionContext的用法示例。


在下文中一共展示了IMansionContext.Cast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoExecute

        /// <summary>
        /// Executes this tag.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        protected override void DoExecute(IMansionContext context)
        {
            // get the web context
            var webContext = context.Cast<IMansionWebContext>();

            // check if there is exactly one uploaded file
            if (webContext.Request.Files.Count != 1)
                throw new InvalidOperationException(string.Format("There were {0} uploaded files instead of 1", webContext.Request.Files.Count));

            // get the uploaded file
            var uploadedFile = webContext.Request.Files.Values.ToArray()[0];

            // store the file
            var resourcePath = contentResourceService.ParsePath(context, new PropertyBag
                                                                         {
                                                                         	{"fileName", uploadedFile.FileName},
                                                                         	{"category", GetAttribute(context, "category", "Uploads")}
                                                                         });
            var resource = contentResourceService.GetResource(context, resourcePath);
            using (var pipe = resource.OpenForWriting())
                uploadedFile.InputStream.CopyTo(pipe.RawStream);

            // set the path to the file as the value of the property
            var uploadedFilePath = contentResourceService.GetFirstRelativePath(context, resourcePath);

            // create the properties
            var uploadedFileProperties = new PropertyBag
                                         {
                                         	{"fileName", Path.GetFileName(uploadedFilePath)},
                                         	{"relativePath", uploadedFilePath}
                                         };
            using (context.Stack.Push(GetRequiredAttribute<string>(context, "target"), uploadedFileProperties, GetAttribute(context, "global", false)))
                ExecuteChildTags(context);
        }
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:38,代码来源:SaveUploadedFileTag.cs

示例2: GetUrl

		/// <summary>
		/// Builds the folder url of the specified <paramref name="folderNode"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="assetTypeNode">The asset type node.</param>
		/// <param name="folderNode">The asset folder node.</param>
		/// <returns>Returns the <see cref="Url"/>.</returns>
		public static Url GetUrl(IMansionContext context, Node assetTypeNode, Node folderNode)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (assetTypeNode == null)
				throw new ArgumentNullException("assetTypeNode");
			if (folderNode == null)
				throw new ArgumentNullException("folderNode");

			// get the web context
			var webContext = context.Cast<IMansionWebContext>();

			// get the path
			var folderPath = GetPath(assetTypeNode, folderNode);

			// create an url
			var url = Url.CreateUrl(webContext);

			// create the relative path
			url.PathSegments = WebUtilities.CombineIntoRelativeUrl(StaticContentRequestHandler.Prefix, folderPath);
			url.CanHaveExtension = true;

			// create the url
			return url;
		}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:33,代码来源:AssetUtil.cs

示例3: Evaluate

		/// <summary>
		/// Gets the label of a particular <paramref name="typeName"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="typeName">The <see cref="ITypeDefinition"/> for which to get the label.</param>
		public string Evaluate(IMansionContext context, string typeName)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (string.IsNullOrEmpty(typeName))
				throw new ArgumentNullException("typeName");

			// try to find the type
			ITypeDefinition type;
			if (!typeService.TryLoad(context, typeName, out type))
				return string.Empty;

			// find the descriptor
			CmsBehaviorDescriptor cmsDescriptor;
			if (!type.TryFindDescriptorInHierarchy(candidate => candidate.GetBehavior(context).HasIcon, out cmsDescriptor))
				return string.Empty;

			// get the behavior
			var behavior = cmsDescriptor.GetBehavior(context);

			// get the url
			var webContext = context.Cast<IMansionWebContext>();
			var url = Url.CreateUrl(webContext);
			url.PathSegments = WebUtilities.CombineIntoRelativeUrl(StaticResourceRequestHandler.Prefix, behavior.PathToIcon);
			url.CanHaveExtension = true;

			// build the icon html
			return string.Format("<i><img class=\"icon\" src=\"{0}\" alt=\"{1}\"></i>", url, behavior.Label ?? string.Empty);
		}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:35,代码来源:GetTypeDefinitionIcon.cs

示例4: DoExecute

        /// <summary>
        /// Executes this tag.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        protected override void DoExecute(IMansionContext context)
        {
            // get the web request
            var webRequest = context.Cast<IMansionWebContext>();

            var outputPipe = (WebOutputPipe) context.OutputPipeStack.FirstOrDefault(x => x is WebOutputPipe);
            if (outputPipe == null)
                throw new InvalidOperationException("No web output pipe was found on thet stack.");

            // set the properties of the output pipe
            outputPipe.Response.ContentType = GetAttribute(webRequest, "contentType", "text/html");
            outputPipe.Encoding = GetAttribute(webRequest, "encoding", Encoding.UTF8);
            outputPipe.Response.CacheSettings.OutputCacheEnabled = GetAttribute(webRequest, "cache", false);

            // set the file name
            outputPipe.Response.Headers.Add("Content-Disposition", "attachment; filename=" + GetRequiredAttribute<string>(context, "fileName"));

            // optionally set size
            var sizeInBytes = GetAttribute(context, "fileSize", -1);
            if (sizeInBytes != -1)
                outputPipe.Response.Headers.Add("Content-Length", sizeInBytes.ToString(CultureInfo.InvariantCulture));

            // push the repsonse pipe to the stack and execute child tags)
            using (webRequest.OutputPipeStack.Push(outputPipe))
                ExecuteChildTags(webRequest);
        }
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:30,代码来源:RespondDownloadTag.cs

示例5: DoExecute

			/// <summary>
			/// Executes this tag.
			/// </summary>
			/// <param name="context">The <see cref="IMansionContext"/>.</param>
			protected override void DoExecute(IMansionContext context)
			{
				// get the web context
				var webContext = context.Cast<IMansionWebContext>();

				// get the column
				Column column;
				if (!webContext.TryPeekControl(out column))
					throw new InvalidOperationException(string.Format("'{0}' must be added to a '{1}'", GetType(), typeof (Column)));

				// get the property names on which to sort
				var propertyName = GetRequiredAttribute<string>(context, "on");

				// create the filter
				var sort = new ColumnSort
				           {
				           	PropertyName = propertyName
				           };

				// allow facets
				using (webContext.ControlStack.Push(sort))
					ExecuteChildTags(webContext);

				// set the sort to the column
				column.Sort = sort;
			}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:30,代码来源:ColumnSort.cs

示例6: Retrieve

        /// <summary>
        /// Builds and executes the query.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="arguments">The arguments from which to build the query.</param>
        /// <param name="repository">The <see cref="IRepository"/>.</param>
        /// <param name="parser">The <see cref="IQueryParser"/>.</param>
        /// <returns>Returns the result.</returns>
        protected override Record Retrieve(IMansionContext context, IPropertyBag arguments, IRepository repository, IQueryParser parser)
        {
            // get the url
            Url url;
            if (!arguments.TryGet(context, "url", out url))
                url = context.Cast<IMansionWebContext>().Request.RequestUrl;

            // parse the URL for identifiers
            IPropertyBag queryAttributes;
            if (!nodeUrlService.TryExtractQueryParameters(context.Cast<IMansionWebContext>(), url, out queryAttributes))
                return null;

            // parse the query
            var query = parser.Parse(context, queryAttributes);

            // execute the query
            return repository.RetrieveSingleNode(context, query);
        }
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:26,代码来源:RetrieveNodeByUrlTag.cs

示例7: Get

        /// <summary>
        /// Gets the row.
        /// </summary>
        /// <param name="context">The request context.</param>
        /// <param name="attributes">The attributes of this tag.</param>
        /// <returns>Returns the result.</returns>
        protected override IPropertyBag Get(IMansionContext context, IPropertyBag attributes)
        {
            // get the url
            Url url;
            if (!attributes.TryGet(context, "url", out url))
                url = context.Cast<IMansionWebContext>().Request.RequestUrl;

            // return the property bag representation
            return url.ToPropertyBag();
        }
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:16,代码来源:ParseApplicationUrlTag.cs

示例8: Evaluate

        /// <summary>
        /// Generates an absulute url from the <see cref="Uri"/>.
        /// </summary>
        /// <param name="context">The request context.</param>
        /// <param name="relativeUrl">The <see cref="Uri"/> which to make absolute.</param>
        /// <returns>The <see cref="Url"/>.</returns>
        public Url Evaluate(IMansionContext context, string relativeUrl)
        {
            // validate arguments
            if (context == null)
                throw new ArgumentNullException("context");
            if (relativeUrl == null)
                throw new ArgumentNullException("relativeUrl");

            return Url.ParseUrl(context.Cast<IMansionWebContext>(), relativeUrl);
        }
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:16,代码来源:MakeUrl.cs

示例9: Evaluate

        /// <summary>
        /// Generates a URL for the node.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="node">The <see cref="Node"/> for which to generate the URL.</param>
        /// <returns>The <see cref="Uri"/> generated for the <paramref name="node"/>.</returns>
        public Url Evaluate(IMansionContext context, Node node)
        {
            // validate arguments
            if (context == null)
                throw new ArgumentNullException("context");
            if (node == null)
                throw new ArgumentNullException("node");

            // return the url
            return nodeUrlService.Generate(context.Cast<IMansionWebContext>(), node);
        }
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:17,代码来源:NodeURL.cs

示例10: Evaluate

        /// <summary>
        /// Gets the value of a cookie.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="cookieName">The string which to encode.</param>
        /// <param name="defaultValue">The default value.</param>
        public string Evaluate(IMansionContext context, string cookieName, string defaultValue)
        {
            // validate arguments
            if (context == null)
                throw new ArgumentNullException("context");
            if (string.IsNullOrEmpty(cookieName))
                throw new ArgumentNullException("context");

            // get the cookie
            WebCookie cookie;
            return context.Cast<IMansionWebContext>().Request.Cookies.TryGetValue(cookieName, out cookie) ? cookie.Value : defaultValue;
        }
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:18,代码来源:GetCookieValue.cs

示例11: Evaluate

		/// <summary>
		/// Generates a route URL.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="controller">The name of the controller.</param>
		/// <param name="action">The action of the controller.</param>
		/// <param name="parameters">The parameters for the route URL.</param>
		/// <returns>Return the relative URL.</returns>
		public Url Evaluate(IMansionContext context, string controller, string action, params string[] parameters)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (string.IsNullOrEmpty(controller))
				throw new ArgumentNullException("controller");
			if (string.IsNullOrEmpty(action))
				throw new ArgumentNullException("action");

			return RouteUrlBuilder.BuildRoute(context.Cast<IMansionWebContext>(), controller, action, parameters);
		}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:20,代码来源:CommandRouteUrl.cs

示例12: Evaluate

		/// <summary>
		/// Generates a route URL.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="controller">The name of the controller.</param>
		/// <param name="action">The action of the controller.</param>
		/// <returns>Return the relative URL.</returns>
		public Url Evaluate(IMansionContext context, string controller, string action)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (string.IsNullOrEmpty(controller))
				throw new ArgumentNullException("controller");
			if (string.IsNullOrEmpty(action))
				throw new ArgumentNullException("action");

			return RouteUrlBuilder.BuildBackofficeRouteWithArea(context.Cast<IMansionWebContext>(), "Cms", controller, action);
		}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:19,代码来源:CmsRouteUrl.cs

示例13: DoAuthenticate

        /// <summary>
        /// Authenticates the user.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="authenicationProvider">The authentication provider which to use.</param>
        /// <param name="parameters">The parameters used for authentication.</param>
        /// <returns>Returns the <see cref="AuthenticationResult"/>.</returns>
        protected override AuthenticationResult DoAuthenticate(IMansionContext context, AuthenticationProvider authenicationProvider, IPropertyBag parameters)
        {
            // authenticate
            var result = authenicationProvider.Authenticate(context, parameters);
            if (!result.WasSuccesful)
                return result;
            var user = result.UserState;

            // get the web request context
            var webContext = context.Cast<IMansionWebContext>();

            // check session
            if (!webContext.Session.IsWritable)
                throw new InvalidOperationException("Could not authenticate user because the session is not writeable");

            // store this user in the session
            webContext.Session[GetRevivalCookieName(context)] = user;

            // check if the authentication provider support user revival and the rememberMe flag was set
            var revivalCookieName = GetRevivalCookieName(context);
            if (authenicationProvider.SupportsRevival && parameters.Get(context, "allowRevival", false))
            {
                // get the revival data for this user
                var revivalData = authenicationProvider.GetRevivalProperties(context, user, parameters);
                if (revivalData != null)
                {
                    // add additional revival properties
                    revivalData.Set("authenticationProviderName", authenicationProvider.Name);
                    revivalData.Set("userSignature", GetUserSignatureHash(webContext));

                    // encrypt it
                    var serializedRevivalData = conversionService.Convert<byte[]>(context, revivalData);
                    var encryptedRevivalData = encryptionService.Encrypt(context, cookieSalt, serializedRevivalData);
                    var revivalDataString = conversionService.Convert<string>(context, encryptedRevivalData);

                    // store it in a cookie
                    var revivalCookie = new WebCookie {
                        Name = revivalCookieName,
                        Value = revivalDataString,
                        Expires = DateTime.Now.AddDays(14),
                        HttpOnly = true
                    };
                    context.SetCookie(revivalCookie);
                }
            }
            else
                context.DeleteCookie(revivalCookieName);

            // authentication was successful
            return result;
        }
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:58,代码来源:WebSecurityService.cs

示例14: Evaluate

		/// <summary>
		/// Gets the property of a control.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="propertyName">The name of the control property which to get.</param>
		/// <param name="defaultValue">The default page number.</param>
		/// <returns>Returns the page number.</returns>
		public object Evaluate(IMansionContext context, string propertyName, object defaultValue)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");

			// get the control
			Control control;
			if (!context.Cast<IMansionWebContext>().TryFindControl(out control))
				throw new InvalidOperationException("No control is found on the stack.");

			// return the value
			return Evaluate(context, control.Definition.Id, propertyName, defaultValue);
		}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:21,代码来源:GetControlPropertyValue.cs

示例15: Evaluate

		/// <summary>
		/// Generates a route URL.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="area">The name of the area.</param>
		/// <param name="controller">The name of the controller.</param>
		/// <param name="action">The action of the controller.</param>
		/// <param name="nodeId">The ID of the node.</param>
		/// <returns>Return the relative URL.</returns>
		public Url Evaluate(IMansionContext context, string area, string controller, string action, int nodeId)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (string.IsNullOrEmpty(area))
				throw new ArgumentNullException("area");
			if (string.IsNullOrEmpty(controller))
				throw new ArgumentNullException("controller");
			if (string.IsNullOrEmpty(action))
				throw new ArgumentNullException("action");

			return RouteUrlBuilder.BuildRouteWithArea(context.Cast<IMansionWebContext>(), area, controller, action, nodeId);
		}
开发者ID:Erikvl87,项目名称:Premotion-Mansion,代码行数:23,代码来源:RouteUrlWithArea.cs


注:本文中的IMansionContext.Cast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。