//Misc private void ShowBrowseFolderDialog() { System.Windows.Forms.FolderBrowserDialog dlgWRFolder = new System.Windows.Forms.FolderBrowserDialog() { Description = "Select the folder containing the potential Web Resource files", ShowNewFolderButton = false }; if (dlgWRFolder.ShowDialog() == System.Windows.Forms.DialogResult.OK) { IsActivePackageDirty = false; //Because Web Resources are relative to the root path, //all the current Web ResourceInfos should be cleared WebResourceInfos.Clear(); WebResourceInfosSelected.Clear(); //Change the rootpath and notify all bindings ActivePackage.Attribute("rootPath").Value = dlgWRFolder.SelectedPath; OnPropertyChanged("ActivePackage"); //Auto-save SavePackages(); //Display new files SearchAndPopulateFiles(); } }
private void SearchAndPopulateFiles() { if (ActivePackage == null) { return; } string searchText = FileSearchText; //Find all files string rootPath = ActivePackage.Attribute("rootPath").Value; DiscoverFiles(rootPath, searchText); }
private XElement ConvertFileInfoToWebResourceInfo(FileInfo fi) { var x = fi.Extension.Split('.'); string type = x[x.Length - 1].ToLower(); String name = fi.FullName.Replace(ActivePackage.Attribute("rootPath").Value.Replace("/", "\\"), String.Empty); XElement newWebResourceInfo = new XElement("WebResourceInfo", new XAttribute("name", name.Replace("\\", "/")), new XAttribute("filePath", name), new XAttribute("displayName", fi.Name), new XAttribute("type", type), new XAttribute("description", String.Empty)); return(newWebResourceInfo); }
private void CreateWebResource(XElement webResourceInfo) { try { //Create the Web Resource. WebResource wr = new WebResource() { Content = getEncodedFileContents(ActivePackage.Attribute("rootPath").Value + webResourceInfo.Attribute("filePath").Value), DisplayName = webResourceInfo.Attribute("displayName").Value, Description = webResourceInfo.Attribute("description").Value, LogicalName = WebResource.EntityLogicalName, Name = GetWebResourceFullNameIncludingPrefix(webResourceInfo) }; wr.WebResourceType = new OptionSetValue((int)ResourceExtensions.ConvertStringExtension(webResourceInfo.Attribute("type").Value)); //Special cases attributes for different web resource types. switch (wr.WebResourceType.Value) { case (int)ResourceExtensions.WebResourceType.Silverlight: wr.SilverlightVersion = "4.0"; break; } // ActivePublisher.CustomizationPrefix + "_/" + ActivePackage.Attribute("name").Value + webResourceInfo.Attribute("name").Value.Replace("\\", "/"), Guid theGuid = _serviceProxy.Create(wr); //If not the "Default Solution", create a SolutionComponent to assure it gets //associated with the ActiveSolution. Web Resources are automatically added //as SolutionComponents to the Default Solution. if (ActiveSolution.UniqueName != "Default") { AddSolutionComponentRequest scRequest = new AddSolutionComponentRequest(); scRequest.ComponentType = (int)componenttype.WebResource; scRequest.SolutionUniqueName = ActiveSolution.UniqueName; scRequest.ComponentId = theGuid; var response = (AddSolutionComponentResponse)_serviceProxy.Execute(scRequest); } } catch (Exception e) { AddMessage("Error: " + e.Message); return; } }
private string GetWebResourceFullNameIncludingPrefix(XElement webResourceInfo) { //The Web Resource name always starts with the Publisher's Prefix //i.e., "new_" string name = ActivePublisher.CustomizationPrefix + "_"; //Check to see if the user has chosen to add the Package Name as part of the //prefix. if (!String.IsNullOrWhiteSpace(ActivePackage.Attribute("isNamePrefix").Value) && Boolean.Parse(ActivePackage.Attribute("isNamePrefix").Value) == true) { name += "/" + ActivePackage.Attribute("name").Value; } //Finally add the name on to the prefix name += webResourceInfo.Attribute("name").Value; return(name); }
private void UpdateWebResource(XElement webResourceInfo, WebResource existingResource) { try { //These are the only 3 things that should (can) change. WebResource wr = new WebResource() { Content = getEncodedFileContents(ActivePackage.Attribute("rootPath").Value + webResourceInfo.Attribute("filePath").Value), DisplayName = webResourceInfo.Attribute("displayName").Value, Description = webResourceInfo.Attribute("description").Value }; wr.WebResourceId = existingResource.WebResourceId; _serviceProxy.Update(wr); } catch (Exception e) { AddMessage("Error: " + e.Message); return; } }