Example #1
0
 public static void RemoveService <T>(IPropertyOwner propertyOwner) where T : class
 {
     if (propertyOwner != null)
     {
         var sm = TryGetOrCreate(propertyOwner, null);
         sm?.RemoveService <T>();
     }
 }
Example #2
0
        /// <summary>
        /// Add service to a service manager associated with a particular Property owner
        /// </summary>
        /// <typeparam name="T">Service type</typeparam>
        /// <param name="serviceInstance">Service instance</param>
        /// <param name="propertyOwner">Property owner</param>
        /// <param name="shell"></param>
        public static void AddService <T>(T serviceInstance, IPropertyOwner propertyOwner, ICoreShell shell) where T : class
        {
            var sm = FromPropertyOwner(propertyOwner, shell);

            Debug.Assert(sm != null);

            sm.AddService(serviceInstance);
        }
Example #3
0
        public static void RemoveService <T>(IPropertyOwner propertyOwner, IContentType contentType) where T : class
        {
            var sm = ServiceManager.FromPropertyOwner(propertyOwner);

            Debug.Assert(sm != null);

            sm.RemoveService <T>(contentType);
        }
Example #4
0
        /// <summary>
        /// Add service to a service manager associated with a particular property owner.
        /// Typically used to store services implemented in native code and identified by
        /// the interface GUID.
        /// </summary>
        /// <typeparam name="serviceGuid">Service GUID</typeparam>
        /// <param name="serviceInstance">Service instance</param>
        /// <param name="propertyOwner">Property owner</param>
        public static void AddService(ref Guid serviceGuid, object serviceInstance, IPropertyOwner propertyOwner)
        {
            var sm = ServiceManager.FromPropertyOwner(propertyOwner);

            Debug.Assert(sm != null);

            sm.AddService(ref serviceGuid, serviceInstance);
        }
Example #5
0
        public static void RemoveService(IPropertyOwner propertyOwner, ref Guid guidService)
        {
            var sm = ServiceManager.FromPropertyOwner(propertyOwner);

            Debug.Assert(sm != null);

            sm.RemoveService(ref guidService);
        }
Example #6
0
        /// <summary>
        /// Add content type specific service to a service manager associated with a particular Property owner
        /// </summary>
        /// <typeparam name="T">Service type</typeparam>
        /// <param name="serviceInstance">Service instance</param>
        /// <param name="propertyOwner">Property owner</param>
        /// <param name="contentType">Content type of the service</param>
        public static void AddService <T>(T serviceInstance, IPropertyOwner propertyOwner, IContentType contentType) where T : class
        {
            var sm = ServiceManager.FromPropertyOwner(propertyOwner);

            Debug.Assert(sm != null);

            sm.AddService <T>(serviceInstance, contentType);
        }
 public PropertyChangeNotifier(IPropertyOwner owner)
 {
     if (activeNotifiers.ContainsKey(owner))
     {
         throw new InvalidOperationException($"Cannot nest delayed notification for {owner}.");
     }
     activeNotifiers.Add(this.owner = owner, this);
 }
 public IEditorOptions GetOptions(IPropertyOwner scope)
 {
     if (scope == null)
     {
         throw new ArgumentNullException(nameof(scope));
     }
     return(scope.Properties.GetOrCreateSingletonProperty(typeof(IEditorOptions), () => new EditorOptions(this, GlobalOptions, scope)));
 }
Example #9
0
        private static void DisposeServiceManagerOnIdle(IPropertyOwner propertyOwner, ICoreShell shell)
        {
            var sm = FromPropertyOwner(propertyOwner, null);

            if (sm != null)
            {
                IdleTimeAction.Create(() => sm.Dispose(), 150, new object(), shell);
            }
        }
Example #10
0
 public EditorOptions(EditorOptionsFactoryService service, EditorOptions parent, IPropertyOwner scope)
 {
     this.service = service;
     this.parent  = parent;
     dict         = new Dictionary <string, object>(StringComparer.Ordinal);
     weakChildren = new List <WeakReference>();
     this.scope   = scope;
     UpdateOptions(null);
 }
Example #11
0
 public static T GetService <T>(IPropertyOwner propertyOwner) where T : class
 {
     try {
         var sm = TryGetOrCreate(propertyOwner, null);
         return(sm?.GetService <T>());
     } catch (Exception) {
         return(null);
     }
 }
        public IEditorOptions GetOptions(IPropertyOwner scope)
        {
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }

            return(scope.Properties.GetOrCreateSingletonProperty <IEditorOptions>(() => new EditorOptions(this.GlobalOptions as EditorOptions, scope, this)));
        }
Example #13
0
        public static void RemoveService <T>(IPropertyOwner propertyOwner) where T : class
        {
            if (propertyOwner != null)
            {
                var sm = FromPropertyOwner(propertyOwner);
                Debug.Assert(sm != null);

                sm.RemoveService <T>();
            }
        }
        /// <inheritdoc />
        public IFeatureService GetOrCreate(IPropertyOwner scope)
        {
            if (scope == null)
            {
                throw new ArgumentNullException(nameof(scope));
            }

            return(scope.Properties.GetOrCreateSingletonProperty(
                       () => new FeatureService(GlobalFeatureService, this)));
        }
Example #15
0
        public static T Get <T>(this IPropertyOwner owner) where T : class
        {
            T t;

            if (owner.Properties.TryGetProperty(typeof(T), out t))
            {
                return(t);
            }
            return(null);
        }
Example #16
0
 public TextUndoHistory(IPropertyOwner propertyOwner)
 {
     State            = TextUndoHistoryState.Idle;
     PropertyOwner    = propertyOwner ?? throw new ArgumentNullException(nameof(propertyOwner));
     Properties       = new PropertyCollection();
     redoList         = new List <TextUndoTransaction>();
     undoList         = new List <TextUndoTransaction>();
     readOnlyRedoList = new ReadOnlyCollection <TextUndoTransaction>(redoList);
     readOnlyUndoList = new ReadOnlyCollection <TextUndoTransaction>(undoList);
 }
        static List <string> CreateItemPropertyNotificationLog(IPropertyOwner i)
        {
            List <string> log = new List <string>();

            i.PropertyChanging += (s, e) =>
                                  log.Add($"-{e.PropertyName}: {((IPropertyOwner)s)[e.PropertyName]}");
            i.PropertyChanged += (s, e) =>
                                 log.Add($"+{e.PropertyName}: {((IPropertyOwner)s)[e.PropertyName]}");
            return(log);
        }
Example #18
0
        /// <summary>
        ///  Retrieves service from a service manager for this Property owner given service type and content type
        /// </summary>
        /// <typeparam name="T">Service type</typeparam>
        /// <param name="propertyOwner">Property owner</param>
        /// <param name="contentType">Content type</param>
        /// <returns>Service instance</returns>
        public static T GetService <T>(IPropertyOwner propertyOwner, IContentType contentType) where T : class
        {
            var sm = ServiceManager.FromPropertyOwner(propertyOwner);

            if (sm != null)
            {
                return(sm.GetService <T>(contentType));
            }

            return(null);
        }
Example #19
0
        public static ICollection <T> GetAllServices <T>(IPropertyOwner propertyOwner) where T : class
        {
            var sm = ServiceManager.FromPropertyOwner(propertyOwner);

            if (sm != null)
            {
                return(sm.GetAllServices <T>());
            }

            return(new List <T>());
        }
Example #20
0
		public TextUndoHistory(IPropertyOwner propertyOwner) {
			if (propertyOwner == null)
				throw new ArgumentNullException(nameof(propertyOwner));
			State = TextUndoHistoryState.Idle;
			PropertyOwner = propertyOwner;
			Properties = new PropertyCollection();
			redoList = new List<TextUndoTransaction>();
			undoList = new List<TextUndoTransaction>();
			readOnlyRedoList = new ReadOnlyCollection<TextUndoTransaction>(redoList);
			readOnlyUndoList = new ReadOnlyCollection<TextUndoTransaction>(undoList);
		}
Example #21
0
        public static T GetService <T>(IPropertyOwner propertyOwner) where T : class
        {
            try {
                var sm = ServiceManager.FromPropertyOwner(propertyOwner);
                Debug.Assert(sm != null);

                return(sm.GetService <T>());
            } catch (Exception) {
                return(null);
            }
        }
Example #22
0
        public static object GetService(IPropertyOwner propertyOwner, ref Guid serviceGuid)
        {
            try {
                var sm = ServiceManager.FromPropertyOwner(propertyOwner);
                Debug.Assert(sm != null);

                return(sm.GetService(ref serviceGuid));
            } catch (Exception) {
                return(null);
            }
        }
        protected virtual void OnCacheContainerClosing(IPropertyOwner cacheContainer)
        {
            TPresenter presenter;

            if (cacheContainer.Properties.TryGetProperty <TPresenter>(typeof(TPresenter), out presenter))
            {
                presenter.Dispose();

                cacheContainer.Properties.RemoveProperty(typeof(TPresenter));
            }
        }
Example #24
0
        public FakeEditorOptions(ExportProvider exportProvider, IPropertyOwner scope)
        {
            foreach (var optionDefinition in exportProvider.GetExportedValues <EditorOptionDefinition>())
            {
                if (!optionDefinition.IsApplicableToScope(scope))
                {
                    continue;
                }

                _supportedOptions[optionDefinition.Name] = optionDefinition;
            }
        }
Example #25
0
        /// <summary>
        /// Returns service manager attached to a given Property owner
        /// </summary>
        /// <param name="propertyOwner">Property owner</param>
        /// <returns>Service manager instance</returns>
        public static ServiceManager FromPropertyOwner(IPropertyOwner propertyOwner)
        {
            ServiceManager sm = null;

            if (propertyOwner.Properties.ContainsProperty(ServiceManagerId))
            {
                sm = propertyOwner.Properties.GetProperty(ServiceManagerId) as ServiceManager;
                return(sm);
            }

            return(new ServiceManager(propertyOwner));
        }
Example #26
0
 public ThemeProperty(
     IPropertyOwner owner, int index, long offset, TMT propertyId, TMT primitiveType,
     PropertyOrigin origin, object value)
 {
     Owner         = owner;
     Index         = index;
     Offset        = offset;
     PropertyId    = propertyId;
     PrimitiveType = primitiveType;
     Origin        = origin;
     Value         = value;
 }
Example #27
0
        public void Dispose()
        {
            if (this._propertyOwner != null)
            {
                this._propertyOwner.Properties.RemoveProperty(ServiceManagerId);

                this._servicesByGuid.Clear();
                this._servicesByType.Clear();
                this._servicesByContentType.Clear();

                this._propertyOwner = null;
            }
        }
Example #28
0
        /// <summary>Alias to <c>owner.Properties.GetOrCreateSingletonProperty&lt;T&gt;(creator)</c>.</summary>
        /// <remarks>Do not use it in a cycle due to performance issue.</remarks>
        public static T ObtainOrAttachProperty <T>(this IPropertyOwner owner, Func <T> creator) where T : class
        {
            if (owner is null)
            {
                throw new ArgumentNullException(nameof(owner));
            }
            if (creator is null)
            {
                throw new ArgumentNullException(nameof(creator));
            }

            return(owner.Properties.GetOrCreateSingletonProperty(creator));
        }
Example #29
0
        /// <summary>Alias to <c>(T)owner.Properties.GetProperty(typeof(T))</c>.</summary>
        /// <remarks>Do not use it in a cycle due to performance issue.</remarks>
        public static T ObtainProperty <T>(this IPropertyOwner owner)
        {
            if (owner is null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            if (owner.Properties.TryGetProperty <T>(typeof(T), out var result))
            {
                return(result);
            }

            throw new InvalidOperationException("The specified type could not be found inside the property bag");
        }
Example #30
0
        public int ContinueFromSynchronousEvent(IDebugEvent2 pEvent)
        {
            if (pEvent == null)
            {
                throw new ArgumentNullException("pEvent");
            }
            if (!(pEvent is DebugEvent))
            {
                return(VSConstants.E_INVALIDARG);
            }

            if (pEvent is IDebugEngineCreateEvent2)
            {
                return(VSConstants.S_OK);
            }

            IPropertyOwner propertyOwner = pEvent as IPropertyOwner;

            if (propertyOwner != null)
            {
                bool manualResume;
                propertyOwner.Properties.TryGetProperty("ManualResume", out manualResume);

                SuspendPolicy suspendPolicy;
                if (!manualResume && propertyOwner.Properties.TryGetProperty(typeof(SuspendPolicy), out suspendPolicy))
                {
                    IThreadReference thread = propertyOwner.Properties.GetProperty <IThreadReference>(typeof(IThreadReference));

                    switch (suspendPolicy)
                    {
                    case SuspendPolicy.All:
                        JavaDebugProgram program = propertyOwner.Properties.GetProperty <JavaDebugProgram>(typeof(JavaDebugProgram));
                        JavaDebugThread  debugThread;
                        program.Threads.TryGetValue(thread.GetUniqueId(), out debugThread);
                        program.Continue(debugThread);
                        break;

                    case SuspendPolicy.EventThread:
                        Task.Factory.StartNew(thread.Resume).HandleNonCriticalExceptions();
                        break;

                    case SuspendPolicy.None:
                        break;
                    }
                }
            }

            return(VSConstants.S_OK);
        }
Example #31
0
        public static ServiceManagerBase TryGetOrCreate(IPropertyOwner propertyOwner, Func <IPropertyOwner, ServiceManagerBase> factory)
        {
            ServiceManagerBase sm = null;

            if (propertyOwner.Properties.ContainsProperty(typeof(ServiceManagerBase)))
            {
                sm = propertyOwner.Properties.GetProperty(typeof(ServiceManagerBase)) as ServiceManagerBase;
            }
            else if (factory != null)
            {
                sm = factory(propertyOwner);
            }

            return(sm);
        }
Example #32
0
 private bool NotReadyRockAndRoll(IPropertyOwner view)
 {
     return view == null ||
            Dte.ActiveDocument == null;
 }
		public IEditorOptions GetOptions(IPropertyOwner scope) {
			if (scope == null)
				throw new ArgumentNullException(nameof(scope));
			return scope.Properties.GetOrCreateSingletonProperty(typeof(IEditorOptions), () => new EditorOptions(this, GlobalOptions, scope));
		}