示例#1
0
文件: Simple.cs 项目: 2sic/2sxc
        internal static IHtmlString Render(IContentBlock parentCb, IEntity entity)
        {
            // if not the expected content-type, just output a hidden html placeholder
            if (entity.Type.Name != Settings.AttributeSetStaticNameContentBlockTypeName)
                return new HtmlString(string.Format(EmptyMessage, entity.EntityId));

            // render it
            var cb = new EntityContentBlock(parentCb, entity);
            return cb.SxcInstance.Render();
        }
示例#2
0
 public HtmlString Render()
 {
     if (Entity.Type.Name == Settings.AttributeSetStaticNameContentBlockTypeName)
     {
         var cb = new EntityContentBlock(SxcInstance.ContentBlock, Entity);
         return(cb.SxcInstance.Render());
     }
     else
     {
         return(new HtmlString("<!-- auto-render of item " + EntityId + " -->"));
     }
 }
示例#3
0
        internal static IHtmlString Render(IContentBlock parentCb, IEntity entity)
        {
            // if not the expected content-type, just output a hidden html placeholder
            if (entity.Type.Name != Settings.AttributeSetStaticNameContentBlockTypeName)
            {
                return(new HtmlString(string.Format(EmptyMessage, entity.EntityId)));
            }

            // render it
            var cb = new EntityContentBlock(parentCb, entity);

            return(cb.SxcInstance.Render());
        }
示例#4
0
        internal static SxcInstance GetSxcOfApiRequest(HttpRequestMessage request)
        {
            string cbidHeader = "ContentBlockId";
            var    moduleInfo = request.FindModuleInfo();

            // get url parameters and provide override values to ensure all configuration is
            // preserved in AJAX calls
            List <KeyValuePair <string, string> > urlParams = null;
            var requestParams = request.GetQueryNameValuePairs();
            var origParams    = requestParams.Where(p => p.Key == "originalparameters").ToList();

            if (origParams.Any())
            {
                var paramSet = origParams.First().Value;

                // Workaround for deserializing KeyValuePair -it requires lowercase properties(case sensitive), which seems to be a bug in some Newtonsoft.Json versions: http://stackoverflow.com/questions/11266695/json-net-case-insensitive-property-deserialization
                var items = Json.Deserialize <List <UpperCaseStringKeyValuePair> >(paramSet);
                urlParams = items.Select(a => new KeyValuePair <string, string>(a.Key, a.Value)).ToList();

                //urlParams = requestParams
                //    .Where(keyValuePair => keyValuePair.Key.IndexOf("orig", StringComparison.Ordinal) == 0)
                //    .Select(pair => new KeyValuePair<string, string>(pair.Key.Substring(4), pair.Value))
                //    .ToList();
            }
            // first, check the special overrides
            //var origparams = requestParams.Select(np => np.Key == "urlparameters").ToList();
            //if (origparams.Any())
            //{
            //    var paramSet = origparams.First();
            //}

            // then add remaining params


            IContentBlock contentBlock = new ModuleContentBlock(moduleInfo, urlParams);

            // check if we need an inner block
            if (request.Headers.Contains(cbidHeader))
            {
                var cbidh = request.Headers.GetValues(cbidHeader).FirstOrDefault();
                int cbid;
                Int32.TryParse(cbidh, out cbid);
                if (cbid < 0)   // negative id, so it's an inner block
                {
                    contentBlock = new EntityContentBlock(contentBlock, cbid);
                }
            }

            return(contentBlock.SxcInstance);
        }
示例#5
0
        internal static SxcInstance GetSxcOfApiRequest(HttpRequestMessage request)
        {
            string cbidHeader = "ContentBlockId";
            var    moduleInfo = request.FindModuleInfo();

            // get url parameters and provide override values to ensure all configuration is
            // preserved in AJAX calls
            List <KeyValuePair <string, string> > urlParams = null;
            var requestParams = request.GetQueryNameValuePairs();
            var origParams    = requestParams.Where(p => p.Key == "originalparameters").ToList();

            if (origParams.Any())
            {
                var paramSet = origParams.First().Value;
                var items    = Json.Deserialize <List <KeyValuePair <string, string> > >(paramSet);
                urlParams = items.ToList();
                //urlParams = requestParams
                //    .Where(keyValuePair => keyValuePair.Key.IndexOf("orig", StringComparison.Ordinal) == 0)
                //    .Select(pair => new KeyValuePair<string, string>(pair.Key.Substring(4), pair.Value))
                //    .ToList();
            }
            // first, check the special overrides
            //var origparams = requestParams.Select(np => np.Key == "urlparameters").ToList();
            //if (origparams.Any())
            //{
            //    var paramSet = origparams.First();
            //}

            // then add remaining params


            IContentBlock contentBlock = new ModuleContentBlock(moduleInfo, urlParams);

            // check if we need an inner block
            if (request.Headers.Contains(cbidHeader))
            {
                var cbidh = request.Headers.GetValues(cbidHeader).FirstOrDefault();
                int cbid;
                int.TryParse(cbidh, out cbid);
                if (cbid < 0)   // negative id, so it's an inner block
                {
                    contentBlock = new EntityContentBlock(contentBlock, cbid);
                }
            }

            return(contentBlock.SxcInstance);
        }
示例#6
0
        internal static IHtmlString Render(IContentBlock parentCb, Eav.Interfaces.IEntity entity, Log parentLog)
        {
            var log = new Log("Htm.Render", parentLog, "simple");

            // if not the expected content-type, just output a hidden html placeholder
            if (entity.Type.Name != Settings.AttributeSetStaticNameContentBlockTypeName)
            {
                log.Add("empty, will return hidden html placeholder");
                return(new HtmlString(string.Format(EmptyMessage, entity.EntityId)));
            }

            // render it
            log.Add("found, will render");
            var cb = new EntityContentBlock(parentCb, entity, log);

            return(cb.SxcInstance.Render());
        }
示例#7
0
        public string GenerateContentBlock(int parentId, string field, int sortOrder, string app = "", Guid?guid = null)
        {
            var contentTypeName = Settings.AttributeSetStaticNameContentBlockTypeName;
            var values          = new Dictionary <string, object>
            {
                { EntityContentBlock.CbPropertyTitle, "" },
                { EntityContentBlock.CbPropertyApp, app },
                { EntityContentBlock.CbPropertyShowChooser, true },
            };

            var entityId = CreateItemAndAddToList(parentId, field, sortOrder, contentTypeName, values, guid);

            // now return a rendered instance
            var newContentBlock = new EntityContentBlock(SxcContext.ContentBlock, entityId);

            return(newContentBlock.SxcInstance.Render().ToString());
        }
示例#8
0
        internal static SxcInstance GetSxcOfApiRequest(HttpRequestMessage request, bool allowNoContextFound = false, Log log = null)
        {
            var cbidHeader = "ContentBlockId";
            var moduleInfo = request.FindModuleInfo();


            // get url parameters and provide override values to ensure all configuration is
            // preserved in AJAX calls
            List <KeyValuePair <string, string> > urlParams = null;
            var requestParams = request.GetQueryNameValuePairs();
            var origParams    = requestParams.Where(p => p.Key == "originalparameters").ToList();

            if (origParams.Any())
            {
                var paramSet = origParams.First().Value;

                // Workaround for deserializing KeyValuePair -it requires lowercase properties(case sensitive), which seems to be a bug in some Newtonsoft.Json versions: http://stackoverflow.com/questions/11266695/json-net-case-insensitive-property-deserialization
                var items = Json.Deserialize <List <UpperCaseStringKeyValuePair> >(paramSet);
                urlParams = items.Select(a => new KeyValuePair <string, string>(a.Key, a.Value)).ToList();
            }

            if (allowNoContextFound & moduleInfo == null)
            {
                return(null);
            }

            var tenant = moduleInfo == null
                ? new DnnTenant(null)
                : new DnnTenant(new PortalSettings(moduleInfo.OwnerPortalID));
            IContentBlock contentBlock = new ModuleContentBlock(new DnnInstanceInfo(moduleInfo), log, tenant, urlParams);

            // check if we need an inner block
            if (request.Headers.Contains(cbidHeader))
            {
                var cbidh = request.Headers.GetValues(cbidHeader).FirstOrDefault();
                int.TryParse(cbidh, out var cbid);
                if (cbid < 0)   // negative id, so it's an inner block
                {
                    contentBlock = new EntityContentBlock(contentBlock, cbid, log);
                }
            }

            return(contentBlock.SxcInstance);
        }
示例#9
0
        internal static SxcInstance GetSxcOfModuleContext(this HttpRequestMessage request)
        {
            string        cbidHeader   = "ContentBlockId";
            var           moduleInfo   = request.FindModuleInfo();
            IContentBlock contentBlock = new ModuleContentBlock(moduleInfo);

            // check if we need an inner block
            if (request.Headers.Contains(cbidHeader))
            {
                var cbidh = request.Headers.GetValues(cbidHeader).FirstOrDefault();
                int cbid;
                int.TryParse(cbidh, out cbid);
                if (cbid < 0)   // negative id, so it's an inner block
                {
                    contentBlock = new EntityContentBlock(contentBlock, cbid);
                }
            }

            return(contentBlock.SxcInstance);
        }