private static IProjectItem CreateItemForImage(SceneViewModel viewModel, DocumentReference localPath, PastePackage pastePackage) { try { IProject project = ResourceHelper.ProjectFromViewModel(viewModel); string directoryName = Path.GetDirectoryName(ResourceHelper.DocumentContextFromViewModel(viewModel).DocumentUrl.TrimEnd(Path.DirectorySeparatorChar)); string availableFilePath = ProjectPathHelper.GetAvailableFilePath(Path.GetFileName(localPath.Path), directoryName, project, true); using (Stream stream = pastePackage.ImageStreams[localPath.Path].GetStream()) { using (FileStream fileStream = File.Create(availableFilePath, (int)stream.Length, FileOptions.RandomAccess)) Microsoft.Expression.Framework.Clipboard.Container.CopyStream(stream, (Stream)fileStream); } IDocumentType documentType = project.GetDocumentType(localPath.Path); IProjectItem projectItem = project.AddItem(new DocumentCreationInfo() { DocumentType = documentType, TargetPath = availableFilePath, TargetFolder = directoryName }); if (projectItem != null) { viewModel.DesignerContext.ProjectManager.ItemSelectionSet.SetSelection((IDocumentItem)projectItem); } return(projectItem); } catch (Exception ex) { viewModel.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PasteElementsParseFailedDialogMessage, new object[1] { (object)ex.Message })); } return((IProjectItem)null); }
private string GetSupportingDirectory(string supportingFolderName, bool create) { string importDirectoryPath = this.ImportDirectoryPath; string path1 = Path.Combine(importDirectoryPath, supportingFolderName); IProject activeProject = this.importContext.ActiveProject; if (activeProject == null) { return((string)null); } if (this.supportingFolderName == null) { DocumentReference documentReference = DocumentReference.Create(path1); if (activeProject.FindItem(documentReference) != null) { string str1 = ProjectPathHelper.GetAvailableFilePath(supportingFolderName, importDirectoryPath, activeProject, true).Substring(importDirectoryPath.Length).Trim(Path.DirectorySeparatorChar); string str2 = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.ImportImageDirectoryOverwriteDialogMessage, new object[2] { (object)supportingFolderName, (object)str1 }); Dictionary <MessageChoice, string> dictionary = new Dictionary <MessageChoice, string>(); dictionary[MessageChoice.Yes] = StringTable.ImportImageDirectoryOverwriteDialogMessageYesButtonCaption; dictionary[MessageChoice.No] = StringTable.ImportImageDirectoryOverwriteDialogMessageNoButtonCaption; switch (this.messageDisplayService.ShowMessage(new MessageBoxArgs() { Message = str2, Button = MessageBoxButton.YesNoCancel, Image = MessageBoxImage.Exclamation, TextOverrides = (IDictionary <MessageChoice, string>)dictionary })) { case MessageBoxResult.Yes: supportingFolderName = str1; break; case MessageBoxResult.No: break; default: throw new OperationCanceledException(); } } this.supportingFolderName = supportingFolderName; } string path2 = Path.Combine(importDirectoryPath, this.supportingFolderName); if (!Microsoft.Expression.Framework.Documents.PathHelper.DirectoryExists(path2) && create) { Directory.CreateDirectory(path2); } this.supportingDirectoryPath = path2; return(this.supportingFolderName); }
internal MakeUserControlDialog(DesignerContext designerContext, string dialogTitle, TemplateItemHelper templateItemHelper, string recommendedName) { this.InitializeComponent(); this.userControlItem = templateItemHelper.FindTemplateItem("UserControl"); this.designerContext = designerContext; this.Title = dialogTitle; this.DataContext = (object)this; string str1 = designerContext.ProjectManager.TargetFolderForProject(designerContext.ActiveProject); if (!string.IsNullOrEmpty(recommendedName)) { string str2 = recommendedName + ".xaml"; DocumentReference documentReference = DocumentReference.Create(Path.Combine(str1, str2)); this.name = designerContext.ActiveProject.FindItem(documentReference) == null ? recommendedName : Path.GetFileNameWithoutExtension(ProjectPathHelper.GetAvailableFilePath(str2, str1, designerContext.ActiveProject)); } else if (this.userControlItem != null) { this.name = Path.GetFileNameWithoutExtension(ProjectPathHelper.GetAvailableFilePath(this.userControlItem.DefaultName, str1, designerContext.ActiveProject)); } this.controlNameMessageBubble = new MessageBubbleHelper((UIElement)this.Control_Name, (IMessageBubbleValidator) new ProjectItemNameValidator(designerContext.ActiveProject)); }
protected override bool CreateProjectItem() { IProjectItem projectItem; IProject project = this.SelectedProjectOrNull(); if (project == null) { return(false); } IDocumentType item = base.Services.DocumentTypes()[DocumentTypeNamesHelper.Folder]; string str = this.ProjectManager().TargetFolderForProject(project); string availableFilePath = ProjectPathHelper.GetAvailableFilePath(item.DefaultFileName, str, project); Directory.CreateDirectory(availableFilePath); try { List <DocumentCreationInfo> documentCreationInfos = new List <DocumentCreationInfo>(); DocumentCreationInfo documentCreationInfo = new DocumentCreationInfo() { DocumentType = item, TargetPath = availableFilePath }; documentCreationInfos.Add(documentCreationInfo); projectItem = project.AddItems(documentCreationInfos).FirstOrDefault <IProjectItem>(); } catch { Directory.Delete(availableFilePath); throw; } if (projectItem != null) { base.Services.SetSelection(projectItem); base.Services.CommandService().Execute("Project_RenameProjectItem", CommandInvocationSource.Internally); } return(projectItem != null); }
public bool TryCreateDesignTimeResourceReference() { bool?nullable = this.doNotAskAgain; if ((!nullable.GetValueOrDefault() ? 0 : (nullable.HasValue ? true : false)) != 0) { this.solutionSettingsManager.SetProjectProperty((INamedProject)this.rootProject, EditDesignTimeResourceModel.DoNotAskForDesignTimeResourcesAgain, (object)true); } else { this.solutionSettingsManager.ClearProjectProperty((INamedProject)this.rootProject, EditDesignTimeResourceModel.DoNotAskForDesignTimeResourcesAgain); } if (this.Selected != null) { try { List <IProjectItem> itemsToOpen = new List <IProjectItem>(); if (this.designTimeResources == null) { TemplateItemHelper templateItemHelper = new TemplateItemHelper(this.rootProject, (IList <string>)null, (IServiceProvider)this.context.Services); IProjectItemTemplate templateItem = templateItemHelper.FindTemplateItem("Resource Dictionary"); string availableFilePath = ProjectPathHelper.GetAvailableFilePath(EditDesignTimeResourceModel.TargetName, this.targetPath, this.rootProject, true); this.designTimeResources = Enumerable.SingleOrDefault <IProjectItem>(templateItemHelper.AddProjectItemsForTemplateItem(templateItem, Path.GetFileName(availableFilePath), this.targetPath, CreationOptions.DoNotSelectCreatedItems | CreationOptions.DesignTimeResource, out itemsToOpen)); } if (this.designTimeResources == null) { return(false); } DocumentResourceContainer resourceContainer = new DocumentResourceContainer(this.context.ResourceManager, this.designTimeResources); try { if (resourceContainer.ProjectItem.Document == null) { return(false); } IProject project = this.Selected.Container.ProjectItem.Project; if (project != this.rootProject && !Enumerable.Contains <IProject>(this.rootProject.ReferencedProjects, project)) { IProjectItem projectItem = this.rootProject.AddProjectReference(project); if (projectItem == null) { return(false); } projectItem.ContainsDesignTimeResources = true; } uint resourceChangeStamp = this.context.ResourceManager.ResourceChangeStamp; this.context.ResourceManager.LinkToResource((ResourceContainer)resourceContainer, this.Selected.Container.DocumentReference); this.context.ViewUpdateManager.RefreshViewUpdatesForDesignTimeResources(true); return(this.context.ResourceManager.ResourceChangeStamp > resourceChangeStamp); } finally { resourceContainer.Close(); } } catch (Exception ex) { if (ex is NotSupportedException || ErrorHandling.ShouldHandleExceptions(ex)) { this.context.Services.GetService <IMessageDisplayService>().ShowError(new ErrorArgs() { Exception = ex }); } else { throw; } } } return(false); }
public string AddSupportingFileToProject(string fileName, out string sourceReference, bool useExistingFile) { sourceReference = (string)null; IProject activeProject = this.importContext.ActiveProject; if (activeProject == null) { return((string)null); } this.GetSupportingFolderName(true); string path = Microsoft.Expression.Framework.Documents.PathHelper.BuildValidFileName(fileName); if (path != null) { ITypeResolver typeResolver = (ITypeResolver)(activeProject as IXamlProject).ProjectContext; if (typeResolver != null && !typeResolver.IsCapabilitySet(PlatformCapability.IsWpf)) { path = path.Replace("%", ""); } } string str1; if (string.IsNullOrEmpty(path)) { str1 = Microsoft.Expression.Framework.Documents.PathHelper.GetSafeExtension(fileName); fileName = StringTable.SupportingFilePlaceholder; if (str1 != null) { fileName += str1; } } else { fileName = path; str1 = Path.GetExtension(path); } string fullPath = (string)null; string str2 = (string)null; bool flag = false; string str3 = !useExistingFile ? this.temporaryFolderPlaceholder.Path : this.supportingDirectoryPath; while (true) { if (str2 != null) { goto label_20; } label_10: try { if (useExistingFile) { str2 = Path.Combine(str3, fileName); } else { str2 = ProjectPathHelper.GetAvailableFilePath(fileName, str3, (IProject)null, true); fileName = Path.GetFileName(str2); } fullPath = Path.Combine(this.supportingDirectoryPath, fileName); if (fullPath.Length > 256 || str2.Length > 256) { fullPath = (string)null; str2 = (string)null; throw new PathTooLongException(); } this.supportingFiles.Add(new KeyValuePair <string, string>(str2, fullPath)); continue; } catch (Exception ex) { if (flag) { fullPath = (string)null; str2 = (string)null; break; } fileName = string.IsNullOrEmpty(str1) ? StringTable.SupportingFilePlaceholder : StringTable.SupportingFilePlaceholder + str1; flag = true; continue; } label_20: if (fullPath == null) { goto label_10; } else { break; } } if (fullPath != null && str2 != null) { sourceReference = this.importContext.MakeSourceReference(fullPath); return(str2); } sourceReference = (string)null; return((string)null); }