internal WebConfigManager(ISite site)
        {
            Debug.Assert(site != null);
            _site = site;

            IWebApplication webApplicationService = (IWebApplication)_site.GetService(typeof(IWebApplication));

            if (webApplicationService != null)
            {
                IProjectItem dataFileProjectItem = webApplicationService.GetProjectItemFromUrl("~/web.config");
                if (dataFileProjectItem != null)
                {
                    _path = dataFileProjectItem.PhysicalPath;
                }
            }

/* VSWhidbey 271075, 257678
 *          // the following inspired by:
 *          // \VSDesigner\Designer\Microsoft\VisualStudio\Designer\Serialization\BaseDesignerLoader.cs
 *
 *          Type projectItemType = Type.GetType("EnvDTE.ProjectItem, " + AssemblyRef.EnvDTE);
 *          if (projectItemType != null)
 *          {
 *              Object currentProjItem = _site.GetService(projectItemType);
 *              PropertyInfo containingProjectProp = projectItemType.GetProperty("ContainingProject");
 *              Object dteProject = containingProjectProp.GetValue(currentProjItem, new Object[0]);
 *              Type projectType = Type.GetType("EnvDTE.Project, " + AssemblyRef.EnvDTE);
 *              PropertyInfo fullNameProperty = projectType.GetProperty("FullName");
 *              String projectPath = (String)fullNameProperty.GetValue(dteProject, new Object[0]);
 *
 *              _path = Path.GetDirectoryName(projectPath) + "\\web.config";
 *          }
 */
        }
示例#2
0
        public override DesignerDataSourceView GetView(string viewName)
        {
            if (!(viewName.Equals(ControllerDataSourceView.DefaultViewName)))
            {
                return(null);
            }
            IWebApplication webApp = ((IWebApplication)(this.Component.Site.GetService(typeof(IWebApplication))));

            if (webApp == null)
            {
                return(null);
            }
            IProjectItem item = webApp.GetProjectItemFromUrl("~/Controllers");

            if (_view == null)
            {
                _view = new ControllerDataSourceDesignView(this, ControllerDataSourceView.DefaultViewName);
            }
            _view.DataController = _control.DataController;
            _view.DataView       = _control.DataView;
            if (item != null)
            {
                _view.BasePath = item.PhysicalPath;
            }
            return(_view);
        }
        private void CreateImageHandler()
        {
            IWebApplication webApp = (IWebApplication)Component.Site.GetService(typeof(IWebApplication));

            GeneratedImage generatedImageControl = Component as GeneratedImage;

            if (generatedImageControl == null)
            {
                return;
            }

            try {
                var    rootFolder = (IFolderProjectItem)webApp.RootProjectItem;
                var    document   = webApp.GetProjectItemFromUrl(this.RootDesigner.DocumentUrl);
                string template   = GetHandlerTemplate(InferLanguage(document));

                var handlerDocument = rootFolder.AddDocument("ImageHandler1.ashx", ASCIIEncoding.Default.GetBytes(template));
                var handlerItem     = handlerDocument as IProjectItem;

                // REVIEW setting the property directly on the control instance does not seem to work
                //generatedImageControl.ImageHandlerUrl = handlerItem.AppRelativeUrl;
                PropertyDescriptor disc = TypeDescriptor.GetProperties(generatedImageControl)["ImageHandlerUrl"];
                if (disc != null)
                {
                    disc.SetValue(generatedImageControl, handlerItem.AppRelativeUrl);
                }

                handlerDocument.Open();
            }
            catch (Exception) {
                // don't do anything, happens if a file existed and user chose not to override
            }
        }
示例#4
0
 internal static string MapPath(IServiceProvider serviceProvider, string path)
 {
     if (path.Length != 0)
     {
         if (IsAbsolutePhysicalPath(path))
         {
             return(path);
         }
         WebFormsRootDesigner designer = null;
         if (serviceProvider != null)
         {
             IDesignerHost service = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost));
             if ((service != null) && (service.RootComponent != null))
             {
                 designer = service.GetDesigner(service.RootComponent) as WebFormsRootDesigner;
                 if (designer != null)
                 {
                     string          appRelativeUrl = designer.ResolveUrl(path);
                     IWebApplication application    = (IWebApplication)serviceProvider.GetService(typeof(IWebApplication));
                     if (application != null)
                     {
                         IProjectItem projectItemFromUrl = application.GetProjectItemFromUrl(appRelativeUrl);
                         if (projectItemFromUrl != null)
                         {
                             return(projectItemFromUrl.PhysicalPath);
                         }
                     }
                 }
             }
         }
     }
     return(null);
 }
        private string ReturnThumbnail(string imageUrl, Size size, int quality)
        {
            IWebApplication webApp = (IWebApplication)Component.Site.GetService(typeof(IWebApplication));
            IProjectItem    item   = webApp.GetProjectItemFromUrl(imageUrl);

            string basePath = item.PhysicalPath.Replace("\\", "-").Replace(":", "");
            string path     = Path.Combine(Path.GetTempPath(), string.Format("{0}-{1}{2}{3}.jpg", basePath, size.Height, size.Width, quality));

            return(File.Exists(path) ? string.Concat("<img src=\"", path, "\" />") : CreateNewThumbnail(item, size, path, quality));
        }
        /// <summary>
        ///     Retrieves the HTML markup that is used to represent the control at design time.
        /// </summary>
        /// <returns>
        ///     The HTML markup used to represent the control at design time.
        /// </returns>
        public override string GetDesignTimeHtml()
        {
            string imageUrl = GetPropertyValue <string>("ImageUrl");

            bool resize = GetPropertyValue <bool>("Resize");

            if (!resize)
            {
                IWebApplication webApp = (IWebApplication)Component.Site.GetService(typeof(IWebApplication));
                IProjectItem    item   = webApp.GetProjectItemFromUrl(imageUrl);
                return(string.Concat("<img src=\"", item.PhysicalPath, "\" />"));
            }

            Size maximumSize = GetPropertyValue <Size>("MaximumSize");
            int  quality     = GetPropertyValue <int>("Quality");

            return(Compare.IsNullOrEmpty(imageUrl) ? "<img src=\"\" />" : ReturnThumbnail(imageUrl, maximumSize, quality));
        }
示例#7
0
        /// <summary>
        ///     Retrieves the HTML markup that is used to represent the control at design time.
        /// </summary>
        /// <returns>
        ///     The HTML markup used to represent the control at design time.
        /// </returns>
        public override string GetDesignTimeHtml()
        {
            string imageUrl  = GetPropertyValue <string>("ImageUrl");
            string text      = GetPropertyValue <string>("Text");
            string color     = ColorTranslator.ToHtml(GetPropertyValue <Color>("ForeColor"));
            string fontNames = string.Join(",", GetPropertyValue <FontInfo>("Font").Names);

            IWebApplication webApp = (IWebApplication)Component.Site.GetService(typeof(IWebApplication));
            IProjectItem    item   = webApp.GetProjectItemFromUrl(imageUrl);

            return(string.Concat("<div style=\"color:", color, ";",
                                 "text-align:center;",
                                 "padding-top:30;",
                                 "font-family:", fontNames, ";",
                                 "font-size:12px;\">",
                                 text,
                                 "<br><br><img src=\"", item.PhysicalPath,
                                 "\" alt=\"busy\" /></div>"));
        }
 private Stream GetSiteMapFileStream(out string physicalPath)
 {
     physicalPath = string.Empty;
     if (base._host != null)
     {
         IWebApplication service = (IWebApplication)base._host.GetService(typeof(IWebApplication));
         if (service != null)
         {
             IProjectItem projectItemFromUrl = service.GetProjectItemFromUrl("~/web.sitemap");
             if (projectItemFromUrl != null)
             {
                 physicalPath = projectItemFromUrl.PhysicalPath;
                 IDocumentProjectItem item2 = projectItemFromUrl as IDocumentProjectItem;
                 if (item2 != null)
                 {
                     return(item2.GetContents());
                 }
             }
         }
     }
     return(null);
 }
示例#9
0
        private void OnOKButtonClick(object sender, EventArgs e)
        {
            System.Drawing.Image defaultPlusImage;
            string str = this._folderNameTextBox.Text.Trim();

            if (str.Length == 0)
            {
                UIServiceHelper.ShowError(base.ServiceProvider, System.Design.SR.GetString("TreeViewImageGenerator_MissingFolderName"));
                return;
            }
            if (str.IndexOfAny(Path.GetInvalidPathChars()) != -1)
            {
                UIServiceHelper.ShowError(base.ServiceProvider, System.Design.SR.GetString("TreeViewImageGenerator_InvalidFolderName", new object[] { str }));
                return;
            }
            IWebApplication service = (IWebApplication)this._treeView.Site.GetService(typeof(IWebApplication));

            if (service == null)
            {
                UIServiceHelper.ShowError(base.ServiceProvider, System.Design.SR.GetString("TreeViewImageGenerator_ErrorWriting"));
                return;
            }
            IFolderProjectItem rootProjectItem    = (IFolderProjectItem)service.RootProjectItem;
            IProjectItem       projectItemFromUrl = service.GetProjectItemFromUrl(Path.Combine("~/", str));

            if ((projectItemFromUrl != null) && !(projectItemFromUrl is IFolderProjectItem))
            {
                UIServiceHelper.ShowError(base.ServiceProvider, System.Design.SR.GetString("TreeViewImageGenerator_DocumentExists", new object[] { str }));
                return;
            }
            IFolderProjectItem folder = (IFolderProjectItem)projectItemFromUrl;

            if (folder == null)
            {
                if (UIServiceHelper.ShowMessage(base.ServiceProvider, System.Design.SR.GetString("TreeViewImageGenerator_NonExistentFolderName", new object[] { str }), System.Design.SR.GetString("TreeViewImageGenerator_Title"), MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    try
                    {
                        folder = rootProjectItem.AddFolder(str);
                        goto Label_015A;
                    }
                    catch
                    {
                        UIServiceHelper.ShowError(base.ServiceProvider, System.Design.SR.GetString("TreeViewImageGenerator_ErrorCreatingFolder", new object[] { str }));
                    }
                }
                return;
            }
Label_015A:
            defaultPlusImage = this._imageInfo.ExpandImage;
            if (defaultPlusImage == null)
            {
                defaultPlusImage = this.DefaultPlusImage;
            }
            System.Drawing.Image collapseImage = this._imageInfo.CollapseImage;
            if (collapseImage == null)
            {
                collapseImage = this.DefaultMinusImage;
            }
            System.Drawing.Image noExpandImage = this._imageInfo.NoExpandImage;
            int width = this._imageInfo.Width;

            if (width < 1)
            {
                UIServiceHelper.ShowError(base.ServiceProvider, System.Design.SR.GetString("TreeViewImageGenerator_InvalidValue", new object[] { "Width" }));
            }
            else
            {
                int height = this._imageInfo.Height;
                if (height < 1)
                {
                    UIServiceHelper.ShowError(base.ServiceProvider, System.Design.SR.GetString("TreeViewImageGenerator_InvalidValue", new object[] { "Height" }));
                }
                else
                {
                    int lineWidth = this._imageInfo.LineWidth;
                    if (lineWidth < 1)
                    {
                        UIServiceHelper.ShowError(base.ServiceProvider, System.Design.SR.GetString("TreeViewImageGenerator_InvalidValue", new object[] { "LineWidth" }));
                    }
                    else
                    {
                        int   lineStyle = (int)this._imageInfo.LineStyle;
                        Color lineColor = this._imageInfo.LineColor;
                        this._progressBar.Value        = 0;
                        this._progressBar.Visible      = true;
                        this._progressBarLabel.Visible = true;
                        try
                        {
                            bool     overwrite = false;
                            bool     flag2     = false;
                            Bitmap   image     = new Bitmap(width, height);
                            Graphics g         = Graphics.FromImage(image);
                            g.FillRectangle(new SolidBrush(this._imageInfo.TransparentColor), 0, 0, width, height);
                            this.RenderImage(g, 0, 0, width, height, 'i', lineStyle, lineWidth, lineColor, null);
                            string name = "i.gif";
                            flag2 |= this.SaveTransparentGif(image, folder, "i.gif", ref overwrite);
                            this._progressBar.Value++;
                            string str3 = "-rtl ";
                            for (int i = 0; i < str3.Length; i++)
                            {
                                image = new Bitmap(width, height);
                                g     = Graphics.FromImage(image);
                                g.FillRectangle(new SolidBrush(this._imageInfo.TransparentColor), 0, 0, width, height);
                                this.RenderImage(g, 0, 0, width, height, str3[i], lineStyle, lineWidth, lineColor, collapseImage);
                                g.Dispose();
                                name = "minus.gif";
                                if (str3[i] == '-')
                                {
                                    name = "dash" + name;
                                }
                                else if (str3[i] != ' ')
                                {
                                    name = str3[i] + name;
                                }
                                flag2 |= this.SaveTransparentGif(image, folder, name, ref overwrite);
                                this._progressBar.Value++;
                            }
                            for (int j = 0; j < str3.Length; j++)
                            {
                                image = new Bitmap(width, height);
                                g     = Graphics.FromImage(image);
                                g.FillRectangle(new SolidBrush(this._imageInfo.TransparentColor), 0, 0, width, height);
                                this.RenderImage(g, 0, 0, width, height, str3[j], lineStyle, lineWidth, lineColor, defaultPlusImage);
                                g.Dispose();
                                name = "plus.gif";
                                if (str3[j] == '-')
                                {
                                    name = "dash" + name;
                                }
                                else if (str3[j] != ' ')
                                {
                                    name = str3[j] + name;
                                }
                                flag2 |= this.SaveTransparentGif(image, folder, name, ref overwrite);
                                this._progressBar.Value++;
                            }
                            for (int k = 0; k < str3.Length; k++)
                            {
                                image = new Bitmap(width, height);
                                g     = Graphics.FromImage(image);
                                g.FillRectangle(new SolidBrush(this._imageInfo.TransparentColor), 0, 0, width, height);
                                this.RenderImage(g, 0, 0, width, height, str3[k], lineStyle, lineWidth, lineColor, noExpandImage);
                                g.Dispose();
                                name = ".gif";
                                if (str3[k] == '-')
                                {
                                    name = "dash" + name;
                                }
                                else if (str3[k] == ' ')
                                {
                                    name = "noexpand" + name;
                                }
                                else
                                {
                                    name = str3[k] + name;
                                }
                                flag2 |= this.SaveTransparentGif(image, folder, name, ref overwrite);
                                this._progressBar.Value++;
                            }
                            this._progressBar.Visible      = false;
                            this._progressBarLabel.Visible = false;
                            if (flag2)
                            {
                                UIServiceHelper.ShowMessage(base.ServiceProvider, System.Design.SR.GetString("TreeViewImageGenerator_LineImagesGenerated", new object[] { str }));
                            }
                        }
                        catch
                        {
                            this._progressBar.Visible      = false;
                            this._progressBarLabel.Visible = false;
                            UIServiceHelper.ShowError(base.ServiceProvider, System.Design.SR.GetString("TreeViewImageGenerator_ErrorWriting", new object[] { str }));
                            return;
                        }
                        this._treeView.LineImagesFolder = "~/" + str;
                        base.DialogResult = DialogResult.OK;
                        base.Close();
                    }
                }
            }
        }
示例#10
0
        /// <summary>
        /// Gets the config from file.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        private static string GetConfigFromFile(string key)
        {
            Grid grid = m_Site.Component as Grid;

            if (grid == null)
            {
                throw new GridException("Could not get Grid");
            }
            if (grid.WebConfigAppSettings != null)
            {
                if (grid.NextConfigCheck < System.DateTime.Now)
                {
                    return(GetConfigSetting(grid, key));
                }
                grid.NextConfigCheck = System.DateTime.Now.AddSeconds(5);
                return(GetConfigSetting(grid, grid.WebConfigFile, key));
            }
            DTE devenv = (DTE)m_Site.GetService(typeof(DTE));

            if (devenv == null)
            {
                MessageBox.Show("Error Message: No design time environment was detected.");
                return(null);
            }

            Array projects = (Array)devenv.ActiveSolutionProjects;

            if (projects.Length == 0)
            {
                MessageBox.Show("Error Message: No Projects found in your designer environment. (Your IDE contains 0 active projects)");
                return(null);
            }
            // go through the items of the project to find the configuration
            Project project = (Project)(projects.GetValue(0));

            foreach (ProjectItem item in project.ProjectItems)
            {
                // if it is the configuration, then open it up
                if (string.Compare(item.Name, "web.config", true) != 0)
                {
                    continue;
                }
                FileInfo info = new FileInfo("/");

                IWebApplication webApp = (IWebApplication)m_Site.GetService(typeof(IWebApplication));
                if (webApp != null)
                {
                    IProjectItem appitem = webApp.GetProjectItemFromUrl("~/web.config");
                    if (appitem.PhysicalPath == null)
                    {
                        MessageBox.Show(string.Format("Error Message: '{0}' has no physical path.", appitem.Name));
                        return(null);
                    }
                    info = new FileInfo(appitem.PhysicalPath);
                }
                else
                {
                    MessageBox.Show("Web Application Design Host is unavailable.");
                }
                if (info.Directory != null)
                {
                    if (System.IO.File.Exists(String.Format("{0}\\{1}", info.Directory.FullName, item.Name)) ==
                        false)
                    {
                        MessageBox.Show(
                            string.Format("Error Message: '{0}\\{1}' does not exists.", info.Directory.FullName,
                                          item.Name));
                        return(null);
                    }
                }

                if (info.Directory == null)
                {
                    continue;
                }
                string val = GetConfigSetting(grid, String.Format("{0}\\{1}", info.Directory.FullName, item.Name), key);
                if (val != null)
                {
                    return(val);
                }
            }

            return(null);
        }