Exemplo n.º 1
0
        internal void ReadSolution(ProgressMonitor monitor)
        {
            var sln = new SlnFile();

            sln.Read(this.FileName);

            using (currentLoadContext = new SolutionLoadContext(this))
                SolutionExtension.OnReadSolution(monitor, sln);
            currentLoadContext = null;
        }
Exemplo n.º 2
0
        public async Task <SolutionItem> AddItem(ProgressMonitor monitor, string filename, bool createSolutionConfigurations)
        {
            if (monitor == null)
            {
                monitor = new ProgressMonitor();
            }
            using (var ctx = new SolutionLoadContext(ParentSolution)) {
                var entry = await Services.ProjectService.ReadSolutionItem(monitor, filename, null, ctx : ctx);

                AddItem(entry, createSolutionConfigurations);
                return(entry);
            }
        }
Exemplo n.º 3
0
        public async Task <SolutionFolderItem> ReloadItem(ProgressMonitor monitor, SolutionFolderItem sitem)
        {
            if (Items.IndexOf(sitem) == -1)
            {
                throw new InvalidOperationException("Solution item '" + sitem.Name + "' does not belong to folder '" + Name + "'");
            }

            SolutionItem item = sitem as SolutionItem;

            if (item != null)
            {
                // Load the new item

                SolutionItem newItem;
                try {
                    if (ParentSolution.IsSolutionItemEnabled(item.FileName))
                    {
                        using (var ctx = new SolutionLoadContext(ParentSolution))
                            newItem = await Services.ProjectService.ReadSolutionItem(monitor, item.FileName, null, ctx : ctx, itemGuid : item.ItemId);
                    }
                    else
                    {
                        UnknownSolutionItem e = new UnloadedSolutionItem()
                        {
                            FileName = item.FileName
                        };
                        e.ItemId   = item.ItemId;
                        e.TypeGuid = item.TypeGuid;
                        newItem    = e;
                    }
                } catch (Exception ex) {
                    UnknownSolutionItem e = new UnknownSolutionItem();
                    e.LoadError = ex.Message;
                    e.FileName  = item.FileName;
                    newItem     = e;
                }

                if (!Items.Contains(item))
                {
                    // The old item is gone, which probably means it has already been reloaded (BXC20615), or maybe removed.
                    // In this case, there isn't anything else we can do
                    newItem.Dispose();

                    // Find the replacement if it exists
                    return(Items.OfType <SolutionItem> ().FirstOrDefault(it => it.FileName == item.FileName));
                }

                // Replace in the file list
                Items.Replace(item, newItem);

                item.ParentFolder = null;
                DisconnectChildEntryEvents(item);
                ConnectChildEntryEvents(newItem);

                NotifyModified("Items");
                OnItemRemoved(new SolutionItemChangeEventArgs(item, ParentSolution, true)
                {
                    ReplacedItem = item
                }, true);
                OnItemAdded(new SolutionItemChangeEventArgs(newItem, ParentSolution, true)
                {
                    ReplacedItem = item
                }, true);

                item.Dispose();
                return(newItem);
            }
            else
            {
                return(sitem);
            }
        }
Exemplo n.º 4
0
 public virtual Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
 {
     throw new NotSupportedException();
 }
Exemplo n.º 5
0
 public Task <SolutionItem> ReadSolutionItem(ProgressMonitor monitor, string file, MSBuildFileFormat format, string typeGuid = null, string itemGuid = null, SolutionLoadContext ctx = null)
 {
     return(Runtime.RunInMainThread(async delegate {
         if (!File.Exists(file))
         {
             throw new IOException(GettextCatalog.GetString("File not found: {0}", file));
         }
         file = Path.GetFullPath(file);
         var metadata = GetReadSolutionItemMetadata(file, typeGuid, itemGuid);
         using (Counters.ReadSolutionItem.BeginTiming("Read project " + file, metadata)) {
             file = GetTargetFile(file);
             var r = GetObjectReaderForFile(file, typeof(SolutionItem));
             if (r == null)
             {
                 throw new UnknownSolutionItemTypeException();
             }
             SolutionItem loadedItem = await r.LoadSolutionItem(monitor, ctx, file, format, typeGuid, itemGuid);
             if (loadedItem != null)
             {
                 loadedItem.NeedsReload = false;
                 UpdateReadSolutionItemMetadata(metadata, loadedItem);
             }
             return loadedItem;
         }
     }));
 }
Exemplo n.º 6
0
 public async Task <SolutionItem> ReadSolutionItem(ProgressMonitor monitor, string file)
 {
     using (var ctx = new SolutionLoadContext(null))
         return(await ReadSolutionItem(monitor, file, null, null, null, ctx));
 }
Exemplo n.º 7
0
        public async Task <SolutionFolderItem> ReloadItem(ProgressMonitor monitor, SolutionFolderItem sitem)
        {
            if (Items.IndexOf(sitem) == -1)
            {
                throw new InvalidOperationException("Solution item '" + sitem.Name + "' does not belong to folder '" + Name + "'");
            }

            if (sitem is SolutionItem item)
            {
                // Load the new item

                SolutionItem newItem;
                try {
                    if (ParentSolution.IsSolutionItemEnabled(item.FileName))
                    {
                        using (var ctx = new SolutionLoadContext(ParentSolution))
                            newItem = await Services.ProjectService.ReadSolutionItem(monitor, item.FileName, null, ctx : ctx, itemGuid : item.ItemId);
                    }
                    else
                    {
                        UnknownSolutionItem e = new UnloadedSolutionItem()
                        {
                            FileName = item.FileName
                        };
                        e.ItemId   = item.ItemId;
                        e.TypeGuid = item.TypeGuid;
                        newItem    = e;
                    }
                } catch (Exception ex) {
                    newItem = new UnknownSolutionItem {
                        LoadError = ex.Message,
                        FileName  = item.FileName
                    };
                }

                if (!Items.Contains(item))
                {
                    // The old item is gone, which probably means it has already been reloaded (BXC20615), or maybe removed.
                    // In this case, there isn't anything else we can do
                    newItem.Dispose();

                    // Find the replacement if it exists
                    return(Items.OfType <SolutionItem> ().FirstOrDefault(it => it.FileName == item.FileName));
                }

                // Replace in the file list
                Items.Replace(item, newItem);

                item.ParentFolder = null;
                DisconnectChildEntryEvents(item);
                ConnectChildEntryEvents(newItem);

                // Shutdown project builder before the ItemAdded event is fired. This should prevent the old out of
                // date project builder being used by the TypeSystemService when getting reference information. The
                // TypeSystemService loads the project when the ItemAdded event is fired before the item is disposed.
                // Disposing the project will also shutdown the project builder but this happens too late and can
                // result in the old project builder being used which does not have the latest project xml.
                if (item is Project)
                {
                    await RemoteBuildEngineManager.UnloadProject(item.FileName);
                }

                NotifyModified("Items");
                OnItemRemoved(new SolutionItemChangeEventArgs(item, ParentSolution, true)
                {
                    ReplacedItem = item
                }, true);
                OnItemAdded(new SolutionItemChangeEventArgs(newItem, ParentSolution, true)
                {
                    ReplacedItem = item
                }, true);

                item.Dispose();
                return(newItem);
            }

            return(sitem);
        }
Exemplo n.º 8
0
 public override Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
 {
     return(Task <SolutionItem> .Factory.StartNew(delegate {
         CompiledAssemblyProject p = new CompiledAssemblyProject();
         p.LoadFrom(fileName);
         return p;
     }));
 }
        public override Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
        {
            CompiledAssemblyProject p = new CompiledAssemblyProject();

            p.LoadFrom(fileName);
            return(Task.FromResult <SolutionItem> (p));
        }
Exemplo n.º 10
0
 public override Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
 {
     return(Task.Run(() => {
         foreach (var f in MSBuildFileFormat.GetSupportedFormats())
         {
             if (f.CanReadFile(fileName, typeof(SolutionItem)))
             {
                 return MSBuildProjectService.LoadItem(monitor, fileName, f, typeGuid, itemGuid, ctx);
             }
         }
         throw new NotSupportedException();
     }));
 }
Exemplo n.º 11
0
        public override async Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
        {
            if (CanRead(fileName, typeof(SolutionItem)))
            {
                return(await MSBuildProjectService.LoadItem(monitor, fileName, MSBuildFileFormat.VS2012, typeGuid, itemGuid, ctx));
            }

            throw new NotSupportedException();
        }