Exemplo n.º 1
0
        public static void LoadConfiguration(this IConfiguration target, ConfigurationRequest request)
        {
            ArgumentValidation.NotNull("configuration", target);
            ArgumentValidation.NotNull("request", request);
            IVsHierarchy hier          = VsHelper.GetCurrentHierarchy(request.ServiceProvider);
            Project      proj          = VsHelper.ToDteProject(hier);
            string       filename      = proj.FileName;
            string       fullname      = proj.FullName;
            string       webConfigPath = null;

            foreach (var item in proj.ProjectItems)
            {
                var pItem = ((ProjectItem)item);
                if (pItem.Name == "Web.config" /* || pItem.Name == "App.config"*/)
                {
                    for (short i = 0; i < pItem.FileCount; i++)
                    {
                        var ifilename = pItem.FileNames[i];
                        webConfigPath = ifilename;
                        break;
                    }
                }
                if (webConfigPath != null)
                {
                    break;
                }
            }

            try
            {
                if (webConfigPath != null)
                {
                    string root = webConfigPath.Substring(0, webConfigPath.LastIndexOf(Path.DirectorySeparatorChar));
                    WebConfigurationFileMap fileMap = CreateFileMap(root);
                    var config = System.Web.Configuration.WebConfigurationManager.OpenMappedWebConfiguration(fileMap, "/web.config");

                    if ((target.Dependencies & ConfigurationDependency.ConnectionString) == ConfigurationDependency.ConnectionString)
                    {
                        var connectionString = config.ConnectionStrings.ConnectionStrings[request.ConnectionStringName];
                        if (connectionString != null)
                        {
                            target.ConnectionString = connectionString.ConnectionString;
                        }
                        else
                        {
                            MessageBox.Show($"Connection String not found {request.ConnectionStringName}");
                        }
                    }

                    if ((target.Dependencies & ConfigurationDependency.StyleSheets) == ConfigurationDependency.StyleSheets)
                    {
                        var section = (Configuration.WebSection)config.GetSection("webpx/web");
                        target.StyleSheets = WebResourceManagement.GetStyleSheets(section);
                    }
                }
                else
                {
                    MessageBox.Show("Web Config Not Found!");
                }
            }
            catch (System.Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("{0}{1}", ex.Message, Environment.NewLine);
                sb.AppendFormat("{0}{1}", ex.StackTrace, Environment.NewLine);
                MessageBox.Show(sb.ToString(), ex.GetType().FullName);
            }
        }
Exemplo n.º 2
0
        protected override void Render(HtmlTextWriter writer)
        {
            var context  = StyleSheetManager.GetCurrentContext(this.Page);
            var controls = context?.GetAll();

            if (controls != null)
            {
                foreach (var control in controls)
                {
                    var styleSheets = control.GetStyleSheets();
                    if (styleSheets != null)
                    {
                        //StyleSheetManager styleSheetManager = GetStyleSheetManager();
                        //if (styleSheetManager != null)
                        {
                            foreach (var styleSheet in styleSheets)
                            {
                                this.Add(styleSheet);
                            }
                        }
                    }
                }
            }
            //writer.Write($"controls: {controls!=null} {controls?.Count()??-1}");

            int c = 0;

            //writer.Write($"<!-- Use CDN {NetworkSegmentation.GetIPSegmentType(this.GetIPAddress())} -->\r\n");
            using (var designScope = new Design.DesignScope(this))
            {
                if (this.DesignMode)
                {
                    WebResourceManagement.Init();
                }
                foreach (var styleSheet in this.References)
                {
                    string name    = styleSheet.Name;
                    bool   isDebug = HttpContext.Current?.IsDebuggingEnabled ?? false;
                    bool   isCDN   = EnableCDN && ShouldUseCDN();
                    string url     = styleSheet.Url;
                    if (!string.IsNullOrEmpty(name))
                    {
                        var reference = WebResourceManagement.StyleSheets?[name];
                        if (reference != null)
                        {
                            if (isCDN)
                            {
                                url = isDebug ? reference.CdnDebugPath : reference.CdnPath;
                                if (isDebug && string.IsNullOrEmpty(url))
                                {
                                    url = reference.CdnPath;
                                }
                            }
                            else
                            {
                                url = isDebug ? reference.DebugPath : reference.Path;
                                if (isDebug && string.IsNullOrEmpty(url))
                                {
                                    url = reference.Path;
                                }
                            }
                            if (string.IsNullOrEmpty(url))
                            {
                                url = reference.Path;
                            }

                            //if (reference!=null)
                            //{
                            //    throw new System.Exception($"{name} Path: {reference.Path} url '{url}' isCDN: {isCDN} isDebug: {isDebug}");
                            //}
                        }
                        else
                        if (!DesignMode)
                        {
                            throw new StyleSheetReferenceException($"The StyleSheet Definition for '{name}' has not been configured!");
                        }
                    }
                    else
                    {
                        url = isCDN ? (isDebug ? styleSheet.CdnDebugUrl : styleSheet.CdnUrl) : (isDebug ? styleSheet.DebugUrl : styleSheet.Url);
                    }
                    if (!string.IsNullOrEmpty(url))
                    {
                        writer.AddAttribute(HtmlTextWriterAttribute.Rel, "stylesheet");
                        writer.AddAttribute(HtmlTextWriterAttribute.Href, this.Page.ResolveClientUrl(url));
                        writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
                        writer.RenderBeginTag(HtmlTextWriterTag.Link);
                        writer.RenderEndTag();
                        c++;
                    }
                    //else
                    //{
                    //    writer.Write($"<!-- Not found Url from {name} -->\r\n");
                    //}
                }
            }
            //if (DesignMode)
            //    writer.Write($"{{{this.GetType().Name}: {this.ID}. StyleSheets:{c} of {this.References.Count}}} in {WebResourceManagement.ResourcesProvider?.Name??"Not Loaded"}");
        }