Example #1
0
 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);
 }
Example #2
0
        internal void BrowseButton_Click(object sender, RoutedEventArgs args)
        {
            string folderPath = ProjectPathHelper.GetFolderPath(this.browseDialogTitle, this.browseDialogTitleVista, this.NewPath);

            if (!string.IsNullOrEmpty(folderPath))
            {
                this.NewPath = folderPath;
            }
        }
Example #3
0
        public void AddProject(string path)
        {
            var projectPath = ProjectPathHelper.NormalizeProjectDirectoryPath(path);

            if (projectPath != null)
            {
                _needRefresh = _projects.Add(path);
            }
        }
Example #4
0
        private void BrowseButton_Click(object sender, RoutedEventArgs args)
        {
            string folderPath = ProjectPathHelper.GetFolderPath(StringTable.SelectProjectFolderDialogDescription, StringTable.SelectProjectFolderDialogDescriptionVista, this.ProjectPath);

            if (!string.IsNullOrEmpty(folderPath))
            {
                this.ProjectPath = folderPath;
            }
        }
Example #5
0
        private void BrowseButton_Click(object sender, RoutedEventArgs args)
        {
            string folderPath = ProjectPathHelper.GetFolderPath("Select the location for your new project folder.", "Browse For Folder", this.ProjectPath);

            if (!string.IsNullOrEmpty(folderPath))
            {
                this.ProjectPath = folderPath;
            }
        }
Example #6
0
        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);
        }
Example #7
0
        private string GetProjectJsonPath(string projectJson)
        {
            projectJson = ProjectPathHelper.NormalizeProjectFilePath(projectJson);

            if (File.Exists(projectJson))
            {
                return(projectJson);
            }

            throw new GracefulException(string.Format(LocalizableStrings.MigratonUnableToFindProjectJson, projectJson));
        }
Example #8
0
        private string GetProjectJsonPath(string projectJson)
        {
            projectJson = ProjectPathHelper.NormalizeProjectFilePath(projectJson);

            if (File.Exists(projectJson))
            {
                return(projectJson);
            }

            throw new Exception($"Unable to find project file at {projectJson}");
        }
Example #9
0
        public static int Compare(string first, string second, CultureInfo cultureInfo)
        {
            AlphabeticThenNumericComparer.SeparatedString separatedString  = AlphabeticThenNumericComparer.TrimDigits(first, cultureInfo);
            AlphabeticThenNumericComparer.SeparatedString separatedString1 = AlphabeticThenNumericComparer.TrimDigits(second, cultureInfo);
            int num = ProjectPathHelper.CompareForDisplay(separatedString.BaseString, separatedString1.BaseString, cultureInfo);

            if (num == 0)
            {
                num = (separatedString.BaseString == first || separatedString1.BaseString == second ? first.CompareTo(second) : separatedString.Number - separatedString1.Number);
            }
            return(num);
        }
Example #10
0
 public static object CleanPartialCompileDirectory()
 {
     try
     {
         string str = Microsoft.Expression.Framework.Documents.PathHelper.ResolveCombinedPath(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), PartialXamlBuilder.DefaultXamlCopyDirectory);
         ProjectPathHelper.CleanDirectory(str, true);
     }
     catch (IOException oException)
     {
     }
     return(null);
 }
Example #11
0
 public static void CleanFontCache()
 {
     if (FontResolver.createdAnyFontResolvers)
     {
         return;
     }
     try
     {
         ProjectPathHelper.CleanDirectory(FontResolver.fontCacheLocation, true);
     }
     catch
     {
     }
 }
Example #12
0
 private void PathTextBox_LostFocus(object sender, RoutedEventArgs e)
 {
     if (PathHelper.IsValidPath(this.projectPath))
     {
         if (PathHelper.IsPathRelative(this.projectPath))
         {
             this.ProjectPath = PathHelper.ResolveRelativePath(this.defaultProjectPath, this.projectPath);
         }
         if (ProjectPathHelper.IsValidProjectFileName(this.ProjectName))
         {
             string projectName = this.ProjectName;
             string str         = null;
             string projectPath = this.ProjectPath;
             this.ProjectName = PathHelper.GetAvailableFileOrDirectoryName(projectName, str, projectPath, false);
         }
     }
 }
Example #13
0
 protected sealed override bool InternalConvert(ConversionTarget file, ConversionType initialState, ConversionType targetState)
 {
     if (this.GetVersion(file) == targetState)
     {
         return(true);
     }
     if (!ProjectPathHelper.AttemptToMakeWritable(file.ProjectStore.DocumentReference, base.Context))
     {
         return(false);
     }
     if (!this.UpgradeProject(file.ProjectStore, initialState, targetState))
     {
         return(false);
     }
     file.ProjectStore.Save();
     return(true);
 }
Example #14
0
        public override int CompareTo(HierarchicalNode treeItem)
        {
            ProjectItemNode projectItemNode = treeItem as ProjectItemNode;

            if (projectItemNode == null)
            {
                return(-1);
            }
            if (this.ProjectItem is FolderStandIn)
            {
                return(-1);
            }
            if (projectItemNode.ProjectItem is FolderStandIn)
            {
                return(1);
            }
            IDocumentType item = base.Services.DocumentTypeManager().DocumentTypes[DocumentTypeNamesHelper.Folder];

            if (this.ProjectItem.DocumentType == item)
            {
                if (projectItemNode.ProjectItem.DocumentType != item)
                {
                    return(-1);
                }
                return(AlphabeticThenNumericComparer.Compare(this.DisplayName, projectItemNode.DisplayName, CultureInfo.CurrentCulture));
            }
            if (projectItemNode.ProjectItem.DocumentType == item)
            {
                return(1);
            }
            try
            {
                if (Microsoft.Expression.Framework.Documents.PathHelper.GetSafeExtension(this.FullPath) == Microsoft.Expression.Framework.Documents.PathHelper.GetSafeExtension(projectItemNode.FullPath))
                {
                    int num = AlphabeticThenNumericComparer.Compare(Path.GetFileNameWithoutExtension(this.FullPath), Path.GetFileNameWithoutExtension(projectItemNode.FullPath), CultureInfo.CurrentCulture);
                    return(num);
                }
            }
            catch (ArgumentException argumentException)
            {
            }
            return(ProjectPathHelper.CompareForDisplay(this.DisplayName, projectItemNode.DisplayName, CultureInfo.CurrentCulture));
        }
        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));
        }
        private bool AttemptToCopyToOutOfBrowserPrivateLocation(DocumentReference xapLocation, DocumentReference privateDeploymentDirectory)
        {
            if (!PathHelper.FileOrDirectoryExists(xapLocation.Path))
            {
                return(false);
            }
            string str = PathHelper.ResolveCombinedPath(privateDeploymentDirectory.Path, OutOfBrowserDeploymentService.PrivateXapName);
            IEnumerable <MoveResult> source = (IEnumerable <MoveResult>)ProjectPathHelper.CopySafe((IEnumerable <MoveInfo>) new List <MoveInfo>()
            {
                new MoveInfo()
                {
                    Source      = xapLocation.Path,
                    Destination = str
                }
            }, MoveOptions.OverwriteDestination, false);

            if (source != null)
            {
                return(EnumerableExtensions.CountIs <MoveResult>(source, 1));
            }
            return(false);
        }
Example #17
0
        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 static ProjectContextCollection EnsureValid(this ProjectContextCollection contextCollection, string projectFilePath)
        {
            IEnumerable <DiagnosticMessage> errors;

            if (contextCollection == null)
            {
                errors = new[]
                {
                    new DiagnosticMessage(
                        ErrorCodes.DOTNET1017,
                        $"Project file does not exist '{ProjectPathHelper.NormalizeProjectFilePath(projectFilePath)}'.",
                        projectFilePath,
                        DiagnosticMessageSeverity.Error)
                };
            }
            else
            {
                errors = contextCollection
                         .ProjectDiagnostics
                         .Where(d => d.Severity == DiagnosticMessageSeverity.Error);
            }

            if (errors.Any())
            {
                StringBuilder errorMessage = new StringBuilder($"The current project is not valid because of the following errors:{Environment.NewLine}");

                foreach (DiagnosticMessage message in errors)
                {
                    errorMessage.AppendLine(message.FormattedMessage);
                }

                throw new GracefulException(errorMessage.ToString());
            }

            return(contextCollection);
        }
Example #19
0
        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);
        }
        private void TryDeleteFile(string fileName, string projectPath)
        {
            string str = Microsoft.Expression.Framework.Documents.PathHelper.ResolveRelativePath(Path.GetDirectoryName(projectPath), fileName);

            if (Microsoft.Expression.Framework.Documents.PathHelper.FileExists(str) && ProjectPathHelper.AttemptToMakeWritable(DocumentReference.Create(str), base.Context))
            {
                Microsoft.Expression.Framework.Documents.PathHelper.ClearFileOrDirectoryReadOnlyAttribute(str);
                File.Delete(str);
            }
        }
        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);
        }
Example #22
0
 protected bool AttemptToMakeWriteable(DocumentReference documentReference)
 {
     return(ProjectPathHelper.AttemptToMakeWritable(documentReference, this.Context));
 }