Beispiel #1
0
        protected override void CreateChildControls()
        {
            try
            {
                foreach (SINCycleReceiver receiver in SINCycleReceivers)
                {
                    SINCycleContext scContext = new SINCycleContext();
                    receiver.BeforeContextLoad(scContext);
                }

                SPContext   currentcontext = SPContext.Current;
                HttpContext httpContext    = HttpContext.Current;

                foreach (SINCycleReceiver receiver in SINCycleReceivers)
                {
                    SINCycleContext scContext = new SINCycleContext();
                    scContext.SPContext   = currentcontext;
                    scContext.HttpContext = httpContext;
                    receiver.AfterContextLoad(scContext);
                }

                foreach (SINCycleReceiver receiver in SINCycleReceivers)
                {
                    SINCycleContext scContext = new SINCycleContext();
                    scContext.SPContext   = currentcontext;
                    scContext.HttpContext = httpContext;
                    receiver.BeforeResourceItemsLoad(scContext);
                }

                List <SPListItem> allItems = Utilities.GetAllItemsForContext(currentcontext, SINCycleReceivers);

                foreach (SINCycleReceiver receiver in SINCycleReceivers)
                {
                    SINCycleContext scContext = new SINCycleContext();
                    scContext.SPContext   = currentcontext;
                    scContext.HttpContext = httpContext;
                    receiver.AfterResourceItemsLoad(scContext, allItems);
                }

                StringBuilder sb = new StringBuilder();

                foreach (SPListItem item in allItems)
                {
                    SPContentType ct = item.ContentType;
                    string        ctResourceConfiguration = ct.XmlDocuments["http://schemas.spsin.com/Resource"];
                    XmlDocument   xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(ctResourceConfiguration);
                    string               receiverAssembly = xmlDoc["ScriptResourceReceiver"]["ReceiverAssembly"].InnerText;
                    string               receiverClass    = xmlDoc["ScriptResourceReceiver"]["ReceiverClass"].InnerText;
                    Assembly             assembly         = Assembly.Load(receiverAssembly);
                    SPSINResourceHandler resourceItem     = (SPSINResourceHandler)assembly.CreateInstance(receiverClass);
                    SPSINContext         context          = new SPSINContext();
                    context.Context     = currentcontext;
                    context.Item        = item;
                    context.HttpContext = httpContext;

                    string resourceString = "";

                    foreach (SINCycleReceiver receiver in SINCycleReceivers)
                    {
                        SINCycleContext scContext = new SINCycleContext();
                        scContext.SPContext           = currentcontext;
                        scContext.HttpContext         = httpContext;
                        scContext.AllResourceItems    = allItems;
                        scContext.CurrentResourceItem = item;
                        resourceString += receiver.BeforeResourceItemGetResourceStringEvaluation(scContext, item);
                    }

                    resourceString += resourceItem.GetResourceString(context);

                    foreach (SINCycleReceiver receiver in SINCycleReceivers)
                    {
                        SINCycleContext scContext = new SINCycleContext();
                        scContext.SPContext           = currentcontext;
                        scContext.HttpContext         = httpContext;
                        scContext.AllResourceItems    = allItems;
                        scContext.CurrentResourceItem = item;
                        resourceString = receiver.AfterResourceItemGetResourceStringEvaluation(scContext, item, resourceString);
                    }

                    sb.Append(resourceString);
                    sb.Append(Environment.NewLine);
                }

                string output = sb.ToString();
                foreach (SINCycleReceiver receiver in SINCycleReceivers)
                {
                    SINCycleContext scContext = new SINCycleContext();
                    scContext.SPContext        = currentcontext;
                    scContext.HttpContext      = httpContext;
                    scContext.AllResourceItems = allItems;
                    output = receiver.AfterProcessingComplete(scContext, output);
                }

                Controls.Add(new LiteralControl(output));
            }
            catch (Exception e)
            {
                Controls.Add(new LiteralControl(string.Format(@"<!-- SP SIN Encountered an exception while processing: {0} -->", e.ToString())));
            }
        }
Beispiel #2
0
 public virtual void BeforeContextLoad(SINCycleContext context)
 {
 }
Beispiel #3
0
        internal static List <SPListItem> GetAllItemsForContext(SPContext context, List <SINCycleReceiver> receivers)
        {
            HttpContext httpContext  = HttpContext.Current;
            SPWeb       web          = context.Web;
            SPList      resourceList = web.Lists[GetResourceListID(context)];

            SPView defaultView = resourceList.DefaultView;

            SPListItemCollection allResourceItemsRaw = resourceList.GetItems(defaultView);
            List <SPListItem>    allResourceItems    = new List <SPListItem>();

            List <SPListItem> returnItems = new List <SPListItem>();

            foreach (SPListItem rawItem in allResourceItemsRaw)
            {
                SPListItem item = resourceList.GetItemById(rawItem.ID);
                allResourceItems.Add(item);
            }

            foreach (SPListItem item in allResourceItems)
            {
                SPContentType ct = item.ContentType;
                string        ctResourceConfiguration = ct.XmlDocuments["http://schemas.spsin.com/Resource"];
                XmlDocument   xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(ctResourceConfiguration);
                string               receiverAssembly = xmlDoc["ScriptResourceReceiver"]["ReceiverAssembly"].InnerText;
                string               receiverClass    = xmlDoc["ScriptResourceReceiver"]["ReceiverClass"].InnerText;
                Assembly             assembly         = Assembly.Load(receiverAssembly);
                SPSINResourceHandler resourceItem     = (SPSINResourceHandler)assembly.CreateInstance(receiverClass);
                SPSINContext         newcontext       = new SPSINContext();
                newcontext.Context     = context;
                newcontext.Item        = item;
                newcontext.HttpContext = httpContext;

                Boolean shouldEvaluate = true;

                foreach (SINCycleReceiver receiver in receivers)
                {
                    SINCycleContext scContext = new SINCycleContext();
                    scContext.CurrentResourceItem = item;
                    scContext.HttpContext         = newcontext.HttpContext;
                    scContext.SPContext           = newcontext.Context;
                    scContext.AllResourceItems    = allResourceItems;

                    shouldEvaluate = receiver.BeforeResourceItemShouldLoadEvaluation(scContext, item, shouldEvaluate);
                }


                if (shouldEvaluate)
                {
                    Boolean shouldLoad = resourceItem.ShouldLoad(newcontext);

                    foreach (SINCycleReceiver receiver in receivers)
                    {
                        SINCycleContext scContext = new SINCycleContext();
                        scContext.CurrentResourceItem = item;
                        scContext.HttpContext         = newcontext.HttpContext;
                        scContext.SPContext           = newcontext.Context;
                        scContext.AllResourceItems    = allResourceItems;

                        shouldLoad = receiver.AfterResourceItemShouldLoadEvaluation(scContext, item, shouldLoad);
                    }
                    if (shouldLoad)
                    {
                        returnItems.Add(item);
                    }
                }
            }

            return(returnItems);
        }
Beispiel #4
0
 public virtual string AfterResourceItemGetResourceStringEvaluation(SINCycleContext context, SPListItem resourceItem, string ResourceString)
 {
     return(ResourceString);
 }
Beispiel #5
0
 public virtual string AfterProcessingComplete(SINCycleContext context, string Output)
 {
     return(Output);
 }
Beispiel #6
0
 public virtual string BeforeResourceItemGetResourceStringEvaluation(SINCycleContext context, SPListItem resourceItem)
 {
     return(string.Empty);
 }
Beispiel #7
0
 public virtual Boolean AfterResourceItemShouldLoadEvaluation(SINCycleContext context, SPListItem resourceItem, Boolean ShouldLoadThisResource)
 {
     return(ShouldLoadThisResource);
 }
Beispiel #8
0
 public virtual void AfterResourceItemsLoad(SINCycleContext context, List <SPListItem> ResourceItems)
 {
 }
Beispiel #9
0
 public virtual void BeforeResourceItemsLoad(SINCycleContext context)
 {
 }
Beispiel #10
0
 public virtual void AfterContextLoad(SINCycleContext context)
 {
 }