示例#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);
 }
示例#2
0
 public void Modify(IProject project, IReadOnlyList <IProject> priorProjects, string solutionPath)
 {
     project.AddItem(
         new XElement(
             "PackageReference",
             new XAttribute("Include", _id),
             new XAttribute("Version", _version)));
 }
示例#3
0
 public void Modify(IProject project, IReadOnlyList <IProject> priorProjects, string solutionPath)
 {
     foreach (var priorProject in priorProjects)
     {
         project.AddItem(new XElement("ProjectReference",
                                      new XAttribute("Include",
                                                     $"..\\{priorProject.RelativeProjectFilePath}")));
     }
 }
示例#4
0
        public void AddLicensedItem(string projectPath, string typeName, string assemblyName)
        {
            IProject      matchByUrl = DocumentItemExtensions.FindMatchByUrl <IProject>(this.context.ProjectManager.CurrentSolution.Projects, projectPath);
            List <string> list       = new List <string>();
            string        path       = Path.Combine(matchByUrl.ProjectRoot.Path, "Properties\\Licenses.licx");

            if (matchByUrl.FindItem(DocumentReference.Create(path)) == null)
            {
                IDocumentType documentType = this.context.DocumentTypeManager.DocumentTypes[DocumentTypeNamesHelper.Licx];
                matchByUrl.AddItem(new DocumentCreationInfo()
                {
                    DocumentType = documentType,
                    TargetPath   = path
                });
            }
            else if (Microsoft.Expression.Framework.Documents.PathHelper.FileExists(path))
            {
                using (StreamReader streamReader = File.OpenText(path))
                {
                    while (!streamReader.EndOfStream)
                    {
                        list.Add(streamReader.ReadLine());
                    }
                }
            }
            string str1 = typeName + ", " + assemblyName;

            if (list.Contains(str1))
            {
                return;
            }
            list.Add(str1);
            string directoryName = Path.GetDirectoryName(path);

            if (!Microsoft.Expression.Framework.Documents.PathHelper.DirectoryExists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }
            using (StreamWriter text = File.CreateText(path))
            {
                foreach (string str2 in list)
                {
                    text.WriteLine(str2);
                }
            }
        }
示例#5
0
        public static IProjectItem AddImageDataFromClipboard(IProjectManager projectManager, IProject project)
        {
            InteropBitmap data;
            IProjectItem  projectItem;

            try
            {
                data = (InteropBitmap)Clipboard.GetData(DataFormats.Bitmap);
                goto Label0;
            }
            catch (OutOfMemoryException outOfMemoryException)
            {
                LowMemoryMessage.Show();
                projectItem = null;
            }
            return(projectItem);

Label0:
            if (data == null)
            {
                return(null);
            }
            FormatConvertedBitmap formatConvertedBitmap = new FormatConvertedBitmap(data, PixelFormats.Bgr32, null, 0);
            string str = projectManager.TargetFolderForProject(project);
            string availableFilePath = ProjectPathHelper.GetAvailableFilePath("Image.png", str, null);

            using (FileStream fileStream = new FileStream(availableFilePath, FileMode.Create, FileAccess.Write))
            {
                PngBitmapEncoder pngBitmapEncoder = new PngBitmapEncoder();
                pngBitmapEncoder.Frames.Add(BitmapFrame.Create(formatConvertedBitmap));
                pngBitmapEncoder.Save(fileStream);
                fileStream.Close();
            }
            DocumentCreationInfo documentCreationInfo = new DocumentCreationInfo()
            {
                SourcePath = availableFilePath,
                TargetPath = availableFilePath
            };

            return(project.AddItem(documentCreationInfo));
        }
        private bool CopyLocal()
        {
            bool     flag          = false;
            IProject activeProject = this.DesignerContext.ActiveProject;

            if (this.CanCopyLocal)
            {
                DocumentReference projectRoot = activeProject.ProjectRoot;
                Path.Combine(projectRoot.Path, Path.GetFileName(this.documentReference.Path));
                try
                {
                    IProjectItem projectItem = activeProject.AddItem(new DocumentCreationInfo()
                    {
                        TargetFolder = projectRoot.Path,
                        SourcePath   = this.documentReference.Path
                    });
                    if (projectItem != null)
                    {
                        this.ContentProvider = this.designerContext.ResourceManager.GetContentProviderForResourceDictionary(projectItem);
                        flag = true;
                    }
                    else
                    {
                        flag = false;
                    }
                }
                catch (Exception ex)
                {
                    this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.FileOpenFailedDialogMessage, new object[2]
                    {
                        (object)this.documentReference.Path,
                        (object)ex.Message
                    }));
                }
            }
            return(flag);
        }