Ejemplo n.º 1
0
        /// <summary>
        /// The proxy on reload requested.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="eventArgs">
        /// The event args.
        /// </param>
        private void ProxyOnReloadRequested(object sender, EventArgs eventArgs)
        {
            this.proxy.ReloadRequested -= this.ProxyOnReloadRequested;

            var newProxy = new IntellisenseProxy(this.projectUniqueName);

            newProxy.Initialized += this.ProxyOnInitialized;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IntellisenseSession"/> class.
        /// </summary>
        /// <param name="provider">
        /// The provider.
        /// </param>
        /// <param name="projectUniqueName">
        /// The project unique name.
        /// </param>
        /// <param name="projectHierarchyItem">
        /// The hierarchy item for the project for this intellisense session.
        /// </param>
        /// <param name="errorList">
        /// The error list to report errors to.
        /// </param>
        public IntellisenseSession(ConnectQlDocumentProvider provider, string projectUniqueName, IVsHierarchy projectHierarchyItem, UpdatedErrorListProvider errorList)
        {
            this.provider             = provider;
            this.projectUniqueName    = projectUniqueName;
            this.projectHierarchyItem = projectHierarchyItem;
            this.errorList            = errorList;

            var newProxy = new IntellisenseProxy(projectUniqueName);

            newProxy.Initialized += this.ProxyOnInitialized;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The proxy on initialized.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="eventArgs">
        /// The event args.
        /// </param>
        private void ProxyOnInitialized(object sender, EventArgs eventArgs)
        {
            ((IntellisenseProxy)sender).Initialized -= this.ProxyOnInitialized;

            var oldProxy = this.proxy;

            this.proxy = (IntellisenseProxy)sender;
            this.proxy.ReloadRequested += this.ProxyOnReloadRequested;
            this.proxy.DocumentUpdated += this.ProxyOnDocumentUpdated;

            if (oldProxy != null)
            {
                oldProxy.ReloadRequested -= this.ProxyOnReloadRequested;
                oldProxy.DocumentUpdated -= this.ProxyOnDocumentUpdated;
                oldProxy.Dispose();
            }

            foreach (var keyValuePair in this.documents)
            {
                this.proxy.UpdateDocument(keyValuePair.Key, keyValuePair.Value.Content, keyValuePair.Value.Version);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes the proxy.
        /// </summary>
        /// <param name="projectId">
        /// The project id.
        /// </param>
        private void Init(string projectId)
        {
            Task.Run(() =>
            {
                try
                {
                    var visualStudioProject = IntellisenseProxy.GetVisualStudioProjectByUniqueName(projectId);
                    var projectName         = "Unknown project";
                    var configFile          = (string)null;
                    var assemblies          = new string[0];

                    if (visualStudioProject != null)
                    {
                        projectName = visualStudioProject.Project.Name;

                        try
                        {
                            this.referencesEvents = visualStudioProject.Events.ReferencesEvents;

                            this.referencesEvents.ReferenceAdded   += this.ReferencesUpdated;
                            this.referencesEvents.ReferenceChanged += this.ReferencesUpdated;
                            this.referencesEvents.ReferenceRemoved += this.ReferencesUpdated;
                        }
                        catch (NotImplementedException)
                        {
                            //// CPS does not have reference events.
                        }

                        try
                        {
                            this.importsEvents                = visualStudioProject.Events.ImportsEvents;
                            this.importsEvents.ImportAdded   += this.ImportsUpdated;
                            this.importsEvents.ImportRemoved += this.ImportsUpdated;
                        }
                        catch (NotImplementedException)
                        {
                            //// CPS does not have import events.
                        }

                        configFile = visualStudioProject.Project.ProjectItems.OfType <ProjectItem>().FirstOrDefault(i => i.Name.EndsWith(".config", StringComparison.OrdinalIgnoreCase))?.FileNames[0];

                        assemblies = visualStudioProject.References.Cast <Reference>()
                                     .Where(r =>
                        {
                            try
                            {
                                return(!string.IsNullOrEmpty(r.Path));
                            }
                            catch
                            {
                                return(false);
                            }
                        })
                                     .Select(r => r.Path)
                                     .ToArray();
                    }

                    var setupInfomation = AppDomain.CurrentDomain.SetupInformation;

                    setupInfomation.ApplicationBase    = string.Empty;
                    setupInfomation.ConfigurationFile  = configFile;
                    setupInfomation.LoaderOptimization = LoaderOptimization.SingleDomain;

                    AppDomain.CurrentDomain.AssemblyResolve += IntellisenseProxy.AppDomainFix;

                    this.appDomain = AppDomain.CreateDomain($"Intellisense project {projectName} domain", null, setupInfomation);

                    object[] arguments =
                    {
                        assemblies,
                        typeof(ConnectQlContext).Assembly.Location
                    };

                    this.watchPaths = assemblies
                                      .Concat(new[]
                    {
                        configFile
                    }).ToArray();

                    this.WatchPaths(this.watchPaths);

                    this.handler = new RemoteEventHandler <byte[]>(this.IntellisenseSessionOnDocumentUpdated);

                    this.intellisenseSession = (AppDomainIntellisenseSession)this.appDomain.CreateInstanceFromAndUnwrap(
                        typeof(AppDomainIntellisenseSession).Assembly.Location,
                        typeof(AppDomainIntellisenseSession).FullName ?? string.Empty,
                        false,
                        BindingFlags.CreateInstance,
                        null,
                        arguments,
                        CultureInfo.CurrentCulture,
                        null);

                    this.intellisenseSession.DocumentUpdated += this.handler.Handler;

                    this.Initialized?.Invoke(this, EventArgs.Empty);
                }
                catch (Exception)
                {
                    this.Dispose();

                    Task.Run(async() =>
                    {
                        await Task.Delay(TimeSpan.FromSeconds(1));

                        this.Init(projectId);
                    });
                }
                finally
                {
                    AppDomain.CurrentDomain.AssemblyResolve -= IntellisenseProxy.AppDomainFix;
                }
            });
        }