Exemplo n.º 1
0
        internal ZmqContext(ContextProxy contextProxy)
        {
            if (contextProxy == null)
            {
                throw new ArgumentNullException("contextProxy");
            }

            _contextProxy = contextProxy;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a <see cref="ZmqContext"/> instance.
        /// </summary>
        /// <returns>A <see cref="ZmqContext"/> instance with the default thread pool size (1).</returns>
        public static ZmqContext Create()
        {
            var contextProxy = new ContextProxy();

            if (contextProxy.Initialize() == -1)
            {
                throw new ZmqException(ErrorProxy.GetLastError());
            }

            return(new ZmqContext(contextProxy));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a <see cref="ZmqContext"/> instance.
        /// </summary>
        /// <param name="threadPoolSize">Number of threads to use in the ZMQ thread pool.</param>
        /// <returns>A <see cref="ZmqContext"/> instance with the specified thread pool size.</returns>
        public static ZmqContext Create(int threadPoolSize)
        {
            if (threadPoolSize < 0)
            {
                throw new ArgumentOutOfRangeException("threadPoolSize", threadPoolSize, "Thread pool size must be non-negative.");
            }

            var contextProxy = new ContextProxy(threadPoolSize);

            if (contextProxy.Initialize() == -1)
            {
                throw new ZmqException(ErrorProxy.GetLastError());
            }

            return(new ZmqContext(contextProxy));
        }
Exemplo n.º 4
0
		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			// Use flyweight pattern to improve performance. It's guaranteed that no more than one instance of 
			// this editor can ever be used at the same time. (it's modal)
			DetermineFilterType(context);

			if (flyweight == null)
			{
				flyweight = new ContextProxy(context, filterType);
			}
			else
			{
				flyweight.SetContext(context);
			}

			value = editor.EditValue(flyweight, flyweight, value);
			return value;
		}
Exemplo n.º 5
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            // Use flyweight pattern to improve performance. It's guaranteed that no more than one instance of
            // this editor can ever be used at the same time. (it's modal)
            DetermineFilterType(context);

            if (flyweight == null)
            {
                flyweight = new ContextProxy(context, filterType);
            }
            else
            {
                flyweight.SetContext(context);
            }

            value = editor.EditValue(flyweight, flyweight, value);
            return(value);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Edits the specified object's value using the editor style indicated by the <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"></see> method.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that can be used to gain additional context information.</param>
        /// <param name="provider">An <see cref="T:System.IServiceProvider"></see> that this editor can use to obtain services.</param>
        /// <param name="value">The object to edit.</param>
        /// <returns>
        /// The new value of the object. If the value of the object has not changed, this should return the same object it was passed.
        /// </returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            // Use flyweight pattern to improve performance. It's guaranteed that no more than one instance of
            // this editor can ever be used at the same time. (it's modal)
            DetermineFilterType(context);


            List <Project> additionalProjects = GetAdditionalProjects(provider);

            if (flyweight == null)
            {
                bool useProjectItemWrapperValue = !string.IsNullOrEmpty(useProjectItemWrapper) ? bool.Parse(useProjectItemWrapper) : false;
                flyweight = new ContextProxy(context, filterType, additionalProjects, useProjectItemWrapperValue);
            }
            else
            {
                flyweight.SetContext(context);
            }
            value = editor.EditValue(flyweight, flyweight, value);
            return(value);
        }
Exemplo n.º 7
0
 static extern void CFMessagePortGetContext(/* CFMessagePortRef */ IntPtr ms, /* CFMessagePortContext* */ ref ContextProxy context);
Exemplo n.º 8
0
 static extern IntPtr CFMessagePortCreateLocal(/* CFAllocatorRef */ IntPtr allocator, /* CFStringRef */ IntPtr name, CFMessagePortCallBackProxy callout, /*  CFMessagePortContext */ ref ContextProxy context, [MarshalAs (UnmanagedType.I1)] ref bool shouldFreeInfo);
Exemplo n.º 9
0
        internal static CFMessagePort CreateLocalPort(CFAllocator allocator, string name, CFMessagePortCallBack callback, CFMessagePortContext context)
        {
            IntPtr a = allocator == null ? IntPtr.Zero : allocator.Handle;
            IntPtr n = NSString.CreateNative (name);
            bool shouldFreeInfo = false;
            var contextProxy = new ContextProxy ();

            // a GCHandle is needed because we do not have an handle before calling CFMessagePortCreateLocal
            // and that will call the RetainProxy. So using this (short-lived) GCHandle allow us to find back the
            // original context defined by developer
            var shortHandle = GCHandle.Alloc (contextProxy);

            if (context != null) {
                if (context.Retain != null)
                    contextProxy.retain = RetainProxy;
                if (context.Release != null)
                    contextProxy.release = ReleaseProxy;
                if (context.CopyDescription != null)
                    contextProxy.copyDescription = CopyDescriptionProxy;
                contextProxy.info = (IntPtr)shortHandle;
                lock (messagePortContexts)
                    messagePortContexts.Add (contextProxy.info, context);
            }

            try {
                var portHandle = CFMessagePortCreateLocal (a, n, messageOutputCallback, ref contextProxy, ref shouldFreeInfo);

                // we won't need short GCHandle after the Create call
                shortHandle.Free ();

                // TODO handle should free info
                if (portHandle == IntPtr.Zero)
                    return null;

                var result = new CFMessagePort (portHandle);

                lock (outputHandles)
                    outputHandles.Add (portHandle, callback);

                if (context != null) {
                    lock (messagePortContexts) {
                        messagePortContexts.Remove (contextProxy.info);
                        CFMessagePortGetContext (portHandle, ref contextProxy);
                        messagePortContexts.Add (contextProxy.info, context);
                    }

                    result.contextHandle = contextProxy.info;
                }

                return result;
            } finally {
                NSString.ReleaseNative (n);
            }
        }
Exemplo n.º 10
0
        internal static CFMessagePort CreateLocalPort(CFAllocator allocator, string name, CFMessagePortCallBack callback, CFMessagePortContext context)
        {
            IntPtr a = allocator == null ? IntPtr.Zero : allocator.Handle;
            IntPtr n = NSString.CreateNative(name);
            bool   shouldFreeInfo = false;
            var    contextProxy   = new ContextProxy();

            // a GCHandle is needed because we do not have an handle before calling CFMessagePortCreateLocal
            // and that will call the RetainProxy. So using this (short-lived) GCHandle allow us to find back the
            // original context defined by developer
            var shortHandle = GCHandle.Alloc(contextProxy);

            if (context != null)
            {
                if (context.Retain != null)
                {
                    contextProxy.retain = RetainProxy;
                }
                if (context.Release != null)
                {
                    contextProxy.release = ReleaseProxy;
                }
                if (context.CopyDescription != null)
                {
                    contextProxy.copyDescription = CopyDescriptionProxy;
                }
                contextProxy.info = (IntPtr)shortHandle;
                lock (messagePortContexts)
                    messagePortContexts.Add(contextProxy.info, context);
            }

            try {
                var portHandle = CFMessagePortCreateLocal(a, n, messageOutputCallback, ref contextProxy, ref shouldFreeInfo);

                // we won't need short GCHandle after the Create call
                shortHandle.Free();

                // TODO handle should free info
                if (portHandle == IntPtr.Zero)
                {
                    return(null);
                }

                var result = new CFMessagePort(portHandle);

                lock (outputHandles)
                    outputHandles.Add(portHandle, callback);

                if (context != null)
                {
                    lock (messagePortContexts) {
                        messagePortContexts.Remove(contextProxy.info);
                        CFMessagePortGetContext(portHandle, ref contextProxy);
                        messagePortContexts.Add(contextProxy.info, context);
                    }

                    result.contextHandle = contextProxy.info;
                }

                return(result);
            } finally {
                NSString.ReleaseNative(n);
            }
        }
Exemplo n.º 11
0
 static extern void CFMessagePortGetContext(/* CFMessagePortRef */ IntPtr ms, /* CFMessagePortContext* */ ref ContextProxy context);
Exemplo n.º 12
0
 static extern /* CFMessagePortRef */ IntPtr CFMessagePortCreateLocal(/* CFAllocatorRef */ IntPtr allocator, /* CFStringRef */ IntPtr name, CFMessagePortCallBackProxy callout, /*  CFMessagePortContext */ ref ContextProxy context, [MarshalAs(UnmanagedType.I1)] ref bool shouldFreeInfo);