Пример #1
0
        private async Task <IEnumerable <ResourceEntity>?> GetSelectedResourceEntitiesAsync()
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync();

            var monitorSelection = GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;

            var selection = monitorSelection?.GetSelectedProjectItems();

            if (selection == null)
            {
                return(null);
            }

            var files = selection
                        .Select(item => item.GetMkDocument())
                        .ExceptNullItems()
                        .Where(file => ProjectFileExtensions.IsResourceFile(file))
                        .ToArray();

            if (!files.Any())
            {
                return(null);
            }

            var groups = await Task.WhenAll(files.Select(GetSelectedResourceEntitiesAsync)).ConfigureAwait(true);

            var entities = groups
                           .SelectMany(items => items)
                           .ToArray();

            return((entities.Length > 0) && (entities.Length == selection.Count) ? entities : null);
        }
Пример #2
0
        public void GetInfoPListNode()
        {
            // Exact Include
            Assert.IsNotNull(ProjectFileExtensions.GetInfoPListNode(GetMSBuildProject("<ItemGroup><None Include=\"Info.plist\" /></ItemGroup>")), "None");
            Assert.IsNotNull(ProjectFileExtensions.GetInfoPListNode(GetMSBuildProject("<ItemGroup><BundleResource Include=\"Info.plist\" /></ItemGroup>")), "BundleResource");
            Assert.IsNotNull(ProjectFileExtensions.GetInfoPListNode(GetMSBuildProject("<ItemGroup><Content Include=\"Info.plist\" /></ItemGroup>")), "Content");
            Assert.IsNull(ProjectFileExtensions.GetInfoPListNode(GetMSBuildProject("<ItemGroup><Whatever Include=\"Info.plist\" /></ItemGroup>")), "Whatever");

            // With LogicalName
            Assert.IsNotNull(ProjectFileExtensions.GetInfoPListNode(GetMSBuildProject("<ItemGroup><None Include=\"doc\"><LogicalName>Info.plist</LogicalName></None></ItemGroup>")), "None 2");
            Assert.IsNotNull(ProjectFileExtensions.GetInfoPListNode(GetMSBuildProject("<ItemGroup><BundleResource Include=\"doc\"><LogicalName>Info.plist</LogicalName></BundleResource></ItemGroup>")), "BundleResource 2");
            Assert.IsNotNull(ProjectFileExtensions.GetInfoPListNode(GetMSBuildProject("<ItemGroup><Content Include=\"doc\"><LogicalName>Info.plist</LogicalName></Content></ItemGroup>")), "Content 2");
            Assert.IsNull(ProjectFileExtensions.GetInfoPListNode(GetMSBuildProject("<ItemGroup><Whatever Include=\"Info.plist\"><LogicalName>Info.plist</LogicalName></Whatever></ItemGroup>")), "Whatever 2");

            // With Link
            Assert.IsNull(ProjectFileExtensions.GetInfoPListNode(GetMSBuildProject("<ItemGroup><None Include=\"doc\"><Link>Info.plist</Link></None></ItemGroup>")), "None 3");
            Assert.IsNull(ProjectFileExtensions.GetInfoPListNode(GetMSBuildProject("<ItemGroup><BundleResource Include=\"doc\"><Link>Info.plist</Link></BundleResource></ItemGroup>")), "BundleResource 3");
            Assert.IsNull(ProjectFileExtensions.GetInfoPListNode(GetMSBuildProject("<ItemGroup><Content Include=\"doc\"><Link>Info.plist</Link></Content></ItemGroup>")), "Content 3");
            Assert.IsNull(ProjectFileExtensions.GetInfoPListNode(GetMSBuildProject("<ItemGroup><Whatever Include=\"Info.plist\"><Link>Info.plist</Link></Whatever></ItemGroup>")), "Whatever 3");
        }
Пример #3
0
        private async Task <IEnumerable <ResourceEntity>?> GetSelectedResourceEntitiesAsync()
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync();

            var vsixCompatibility = ExportProvider.GetExportedValue <IVsixCompatibility>();

            var selectedFiles = await vsixCompatibility.GetSelectedFilesAsync().ConfigureAwait(false);

            if (!selectedFiles.Any())
            {
                return(null);
            }

            var resourceFiles = selectedFiles.Where(file => ProjectFileExtensions.IsResourceFile(file));

            var groups = await Task.WhenAll(resourceFiles.Select(GetSelectedResourceEntitiesAsync)).ConfigureAwait(true);

            var entities = groups
                           .SelectMany(items => items)
                           .ToArray();

            return((entities.Length > 0) && (entities.Length == selectedFiles.Count) ? entities : null);
        }
Пример #4
0
        public DialogResult SaveProject(ProjectForm projectForm, bool newLocation)
        {
            DialogResult result;

            if (projectForm.project.Path == null || newLocation)
            {
                removeProjectFromRecoveryFile(projectForm.project.ProjectFile);
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Title            = "Type name of folder new project will be saved to";
                saveFileDialog.InitialDirectory = ProjectsPath;
                saveFileDialog.Filter           = "Plain LT10 Project (*.ltp)|*.ltp|Plain LT10 Project (compr) (*.ltpi)|*.ltpi|Referenced LT10 Project (*.ltpe)|*.ltpe|Packed LT10 Project (*.ltpp)|*.ltpp";
                saveFileDialog.FilterIndex      = 4;
                saveFileDialog.FileName         = Path.GetFileNameWithoutExtension(projectForm.project.Caption);
                saveFileDialog.AddExtension     = false;
                string          projectFile;
                ProjectFileType pft;
                if ((result = saveFileDialog.ShowDialog(this)) == DialogResult.OK)
                {
                    pft         = (ProjectFileType)saveFileDialog.FilterIndex;
                    projectFile = saveFileDialog.FileName;
                    if (pft == ProjectFileType.Normal || pft == ProjectFileType.CompressedIS)
                    {
                        projectFile = Path.Combine(projectFile, Path.GetFileName(projectFile));
                    }
                    projectFile = Path.ChangeExtension(projectFile, ProjectFileExtensions.GetExtension(pft));
                    SaveProject(projectForm, projectFile, pft);
                }
                saveFileDialog.Dispose();
            }
            else
            {
                SaveProject(projectForm, projectForm.project.ProjectFile, projectForm.project.FileType);
                result = DialogResult.OK;
            }
            return(result);
        }
Пример #5
0
 protected override bool IncludeFile(string fileName)
 {
     return(ProjectFileExtensions.IsResourceFile(fileName));
 }
Пример #6
0
 public static XmlReader getXmlReader(string filePath, out Stream stream)
 {
     return(getXmlReader(filePath, ProjectFileExtensions.GetProjectFileType(System.IO.Path.GetExtension(filePath)), out stream));
 }
Пример #7
0
        public ProjectBase(string fileName)
            : this()
        {
            SpectraContainerBase container;

            object[] args = new object[3];
            args[0] = this;
            Stream stream;

            //jesli rozszerzeniu pliku projektu to evpc projekt zostal zapisany w plikach skompresowanych i
            //taki rodzaj strumienia musi byc wykorzystany
            //if (this._compressed = System.IO.Path.GetExtension(fileName) == ".evpc")
            this._fileType = ProjectFileExtensions.GetProjectFileType(System.IO.Path.GetExtension(fileName));
            if (this._fileType == ProjectFileType.Normal)
            {
                stream = new FileStream(fileName, FileMode.Open);
            }
            else
            {
                stream = new GZipStream(new FileStream(fileName, FileMode.Open), CompressionMode.Decompress);
            }

            try {
                int spectraCount = -1;
                //this._path = System.IO.Path.GetDirectoryName(fileName);
                this._projectFile = fileName;
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreWhitespace = true;
                using (XmlReader reader = XmlReader.Create(stream, settings)) {
                    reader.Read(); //declaration
                    reader.Read(); //project
                    if (reader.HasAttributes)
                    {
                        while (reader.MoveToNextAttribute())
                        {
                            switch (reader.Name)
                            {
                            case "caption": this._caption = reader.Value; break;

                            case "calculatedValues": this._calculatedValues = Boolean.Parse(reader.Value); break;

                            case "spectraCount": spectraCount = int.Parse(reader.Value); break;
                            }
                        }
                        reader.MoveToElement();
                    }
                    //List<IParameter> bindingParameters = new List<IParameter>();
                    //reader.ReadStartElement("project");
                    while (reader.Read())
                    {
                        switch (reader.Name)
                        {
                        case "models":
                            bool includedModelsData = reader.GetAttribute("defs") == "included";
                            while (reader.Read())
                            {
                                if (reader.Name == "model")
                                {
                                    BindingFlags bindingFlags = BindingFlags.CreateInstance;
                                    Assembly     ass          = Assembly.GetAssembly(this.GetSpectraContainerType());
                                    string       typeName     = this.GetSpectraContainerType().ToString();

                                    XmlReader containerReader;

                                    if (includedModelsData)
                                    {
                                        containerReader = reader.ReadSubtree();
                                        args[1]         = containerReader;
                                        args[2]         = null;
                                        try {
                                            container = (SpectraContainerBase)ass.CreateInstance(typeName, true, bindingFlags, null, args, null, null);
                                            if (container != null)
                                            {
                                                AddSpectraContainer(container);
                                            }
                                        } finally {
                                            containerReader.Close();
                                        }
                                    }
                                    else
                                    {
                                        Stream conStream;
                                        reader.MoveToFirstAttribute();
                                        string containerFileName = reader.Value;     // containerElement.Attributes["file"].Value;
                                        containerFileName = System.IO.Path.Combine(this.Path, containerFileName);
                                        containerReader   = getXmlReader(containerFileName, this._fileType, out conStream);
                                        try {
                                            //args = new object[] { this, containerReader, System.IO.Path.GetDirectoryName(containerFileName) };
                                            args[1]   = containerReader;
                                            args[2]   = System.IO.Path.GetDirectoryName(containerFileName);
                                            container = (SpectraContainerBase)ass.CreateInstance(typeName, true, bindingFlags, null, args, null, null);
                                            if (container != null)
                                            {
                                                AddSpectraContainer(container);
                                            }
                                        } finally {
                                            containerReader.Close();
                                            conStream.Close();
                                        }
                                        reader.MoveToElement();
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                            break;

                        case "bindings":
                            //if (reader.ReadToFollowing("bindings")) {
                            while (reader.Read())
                            {
                                if (reader.Name == "binding")
                                {
                                    string name = reader.GetAttribute("name");
                                    switch (reader.GetAttribute("type"))
                                    {
                                    case "parameter":
                                        _bindingsManager.Add(new ParameterBinding(reader, this, name));
                                        break;

                                    case "group":
                                        _bindingsManager.Add(new GroupBinding(reader, this, name));
                                        break;
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
            } finally {
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }