public void TestSiteMapCacheRequest()
        {
            IOrganizationService service = new OrganizationService(new CrmConnection("CRM"));

            StringWriter mapJson = new StringWriter();
            SiteMapLoader loader = new SiteMapLoader(1033);
            ITracingService tace = new debugTrace();
            loader.ParseSiteMapToJson(service,tace, mapJson);
            Console.WriteLine(mapJson.ToString());
        }
        public void TestSiteMapCacheRequest()
        {
            IOrganizationService service = new OrganizationService(new CrmConnection("CRM"));

            StringWriter    mapJson = new StringWriter();
            SiteMapLoader   loader  = new SiteMapLoader(1033);
            ITracingService tace    = new debugTrace();

            loader.ParseSiteMapToJson(service, tace, mapJson);
            Console.WriteLine(mapJson.ToString());
        }
Esempio n. 3
0
        /// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
        /// <see cref="IPluginExecutionContext"/>,
        /// <see cref="IOrganizationService"/>
        /// and <see cref="ITracingService"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
        /// The plug-in's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the plug-in. Also, multiple system threads
        /// could execute the plug-in at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in plug-ins.
        /// </remarks>
        protected void ExecuteGetSiteMap(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            Entity output = new Entity("webresource");

            IOrganizationService service = localContext.OrganizationService;
            ITracingService trace = localContext.TracingService;

            // Exract the search criteria 
            QueryBase query = (QueryBase)localContext.PluginExecutionContext.InputParameters["Query"];
            Type queryType = query.GetType();
            if (queryType == typeof(QueryExpression))
            {
                trace.Trace("Found QueryExpression");
                // Get condition
                QueryExpression queryExpression = (QueryExpression)query;
                if (queryExpression.EntityName != "webresource")
                    return;

                if (queryExpression.Criteria == null || queryExpression.Criteria.Conditions.Count != 1 || queryExpression.Criteria.Conditions[0].AttributeName != "name")
                    return;

                string webresourceName = (string)queryExpression.Criteria.Conditions[0].Values[0];
                if ((webresourceName.Length > SiteMapResourceName.Length + 3) && webresourceName.StartsWith(SiteMapResourceName) && webresourceName.EndsWith(".js"))
                {

                    string lcid = webresourceName.Substring(16);
                    lcid = lcid.Substring(0, lcid.Length - 3);
                    trace.Trace("LCID={0}",lcid);
                    var outputCollection = (EntityCollection)localContext.PluginExecutionContext.OutputParameters["BusinessEntityCollection"];
                    SiteMapLoader siteMap = new SiteMapLoader(int.Parse(lcid));
                    StringWriter json = new StringWriter();

                    siteMap.ParseSiteMapToJson(service, trace, json);

                    var scriptBytes = System.Text.Encoding.UTF8.GetBytes(json.ToString());
                    trace.Trace("Parsed Sit Map OK");

                    output["name"] = webresourceName;
                    output["content"] = System.Convert.ToBase64String(scriptBytes);
                    output["webresourcetype"] = new OptionSetValue(3);
                    outputCollection.Entities.Clear();
                    outputCollection.Entities.Add(output);
                }
            }
        }