예제 #1
0
        public void Wait(WaitHandle[] waitHandles)
        {
            if (waitHandles == null)
            {
                throw new ArgumentNullException("waitHandles");
            }
            if (waitHandles.Length == 0 || waitHandles.Any(p => p == null))
            {
                throw new ArgumentException("Wait handles cannot be of zero length and cannot contain null entries");
            }

            var waitHandlePointers = waitHandles.Select(p => p.SafeWaitHandle.DangerousGetHandle()).ToArray();

            if (_waitDialog == null)
            {
                var factory = (INiWaitDialogFactory)_serviceProvider.GetService(typeof(INiWaitDialogFactory));
                ErrorUtil.ThrowOnFailure(factory.CreateInstance(out _waitDialog));
            }

            ErrorUtil.ThrowOnFailure(_waitDialog.ShowWaitDialog(
                                         Caption,
                                         Message,
                                         ProgressText,
                                         StatusBarText,
                                         ShowDelay,
                                         CanCancel,
                                         ShowRealProgress,
                                         Progress,
                                         waitHandlePointers
                                         ));

            ErrorUtil.ThrowOnFailure(_waitDialog.HasCanceled(out _hasCancelled));
        }
예제 #2
0
        public static Stream ToStream(IResource resource)
        {
            if (resource == null)
            {
                throw new ArgumentNullException("resource");
            }

            // This is a hack for performance reasons. When the resource
            // represents a file, there really is no reason why we can't just
            // go to disk ourselves instead of going over AppDomain boundaries.

            string fileName = resource.FileName;

            if (fileName != null && File.Exists(fileName))
            {
                return(File.OpenRead(fileName));
            }

            IStream stream;

            ErrorUtil.ThrowOnFailure(resource.Open(out stream));

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

            return(ToStream(stream));
        }
예제 #3
0
            public override int Read(byte[] buffer, int offset, int count)
            {
                if (buffer == null)
                {
                    throw new ArgumentNullException("buffer");
                }
                if (offset < 0)
                {
                    throw new ArgumentOutOfRangeException("offset");
                }
                if (count <= 0 || buffer.Length < offset + count)
                {
                    throw new ArgumentOutOfRangeException("count");
                }

                byte[] marshalBuffer;
                ErrorUtil.ThrowOnFailure(_stream.Read(count, out marshalBuffer));

                if (marshalBuffer == null)
                {
                    return(0);
                }

                Array.Copy(marshalBuffer, 0, buffer, offset, Math.Min(marshalBuffer.Length, count));

                return(marshalBuffer.Length);
            }
예제 #4
0
        public void Wait(Action <NiWaitDialog> callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            using (var @event = new ManualResetEvent(false))
            {
                Exception exception = null;

                ThreadPool.QueueUserWorkItem(p => exception = DoCallback(callback, @event));

                Wait(new WaitHandle[] { @event });

                // A pending requery may have already been processed because we've
                // had to process events. Invalidate requery to ensure we're in
                // a valid state.

                ErrorUtil.ThrowOnFailure(((INiShell)_serviceProvider.GetService(typeof(INiShell))).InvalidateRequerySuggested());

                if (exception != null)
                {
                    throw exception;
                }
            }
        }
예제 #5
0
 void listView_MouseUp(object sender, MouseEventArgs e)
 {
     if (_shell != null && (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right))
     {
         ErrorUtil.ThrowOnFailure(_shell.InvalidateRequerySuggested());
     }
 }
예제 #6
0
        public HResult GetNiResources(out IResource value)
        {
            value = null;

            try
            {
                var attribute = GetType().GetCustomAttributes(typeof(NiResourcesAttribute), false);

                if (attribute.Length == 0)
                {
                    throw new InvalidOperationException(NeutralResources.CouldNotFindResourcesAttribute);
                }

                string resourceName = GetType().Namespace + "." + ((NiResourcesAttribute)attribute[0]).ResourceName + ".resources";

                if (!GetType().Assembly.GetManifestResourceNames().Contains(resourceName))
                {
                    return(HResult.False);
                }

                value = ResourceUtil.FromManifestResourceStream(
                    GetType().Assembly,
                    resourceName
                    );

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
예제 #7
0
        public HResult PreFilterMessage(ref NiMessage message)
        {
            try
            {
                if (_preMessageFilterRecursion > 0)
                {
                    return(HResult.False);
                }

                _preMessageFilterRecursion++;

                try
                {
                    return(MessageFilterUtil.InvokeMessageFilter(ref message)
                        ? HResult.OK
                        : HResult.False);
                }
                finally
                {
                    _preMessageFilterRecursion--;
                }
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
예제 #8
0
        public HResult GetStringResource(string key, out string value)
        {
            value = null;

            try
            {
                if (key == null)
                {
                    throw new ArgumentNullException("key");
                }

                EnsureStringResources();

                value = _stringResourceManager.GetString(key);

                if (String.IsNullOrEmpty(value))
                {
                    throw new ArgumentException(String.Format(NeutralResources.InvalidResource, key));
                }

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
예제 #9
0
        public virtual HResult Initialize()
        {
            try
            {
                var commandTarget = this as INiCommandTarget;

                if (commandTarget != null)
                {
                    ((INiCommandManager)GetService(typeof(INiCommandManager))).RegisterCommandTarget(commandTarget, out _commandTargetCookie);
                }

                RegisterEditorFactories();

                ToolStripManager.Renderer = new VS2012ToolStripRenderer();

                Application.AddMessageFilter(new MessageFilter(this));

                MouseWheelMessageFilter.Install();

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
예제 #10
0
            public override void Write(byte[] buffer, int offset, int count)
            {
                if (buffer == null)
                {
                    throw new ArgumentNullException("buffer");
                }
                if (offset < 0)
                {
                    throw new ArgumentOutOfRangeException("offset");
                }
                if (count <= 0 || buffer.Length < offset + count)
                {
                    throw new ArgumentOutOfRangeException("count");
                }

                var marshalBuffer = buffer;

                if (offset != 0 || buffer.Length != count)
                {
                    marshalBuffer = new byte[count];

                    Array.Copy(buffer, offset, marshalBuffer, 0, count);
                }

                ErrorUtil.ThrowOnFailure(_stream.Write(marshalBuffer));
            }
예제 #11
0
        public static HResult CreateInstance(this INiLocalRegistry self, Guid guid, IServiceProvider serviceProvider, out object instance)
        {
            instance = null;

            try
            {
                var hr = self.CreateInstance(guid, out instance);
                if (ErrorUtil.Failure(hr))
                {
                    return(hr);
                }

                if (serviceProvider != null)
                {
                    var objectWithSite = instance as INiObjectWithSite;
                    if (objectWithSite != null)
                    {
                        hr = objectWithSite.SetSite(serviceProvider);
                        if (ErrorUtil.Failure(hr))
                        {
                            return(hr);
                        }
                    }
                }

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
예제 #12
0
        public override Size GetPreferredSize(Size proposedSize)
        {
            Size preferredSize;

            ErrorUtil.ThrowOnFailure(_window.GetPreferredSize(proposedSize, out preferredSize));

            return(preferredSize);
        }
예제 #13
0
        public static object GetPropertyEx(this INiWindowFrame self, int property)
        {
            object result;

            ErrorUtil.ThrowOnFailure(self.GetProperty(property, out result));

            return(result);
        }
예제 #14
0
        public static string GetString(this INiSettings self, string key)
        {
            string value;

            ErrorUtil.ThrowOnFailure(self.GetSetting(key, out value));

            return(value);
        }
예제 #15
0
        private void SetText(string value)
        {
            int line;
            int index;

            ErrorUtil.ThrowOnFailure(TextBuffer.GetLastLineIndex(out line, out index));

            ErrorUtil.ThrowOnFailure(TextBuffer.ReplaceLines(0, 0, line, index, value ?? String.Empty));
        }
예제 #16
0
        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (base.ProcessDialogKey(keyData))
            {
                return(true);
            }

            return(ErrorUtil.ThrowOnFailure(_host.ProcessDialogKey(keyData)));
        }
예제 #17
0
        protected override bool ProcessDialogChar(char charCode)
        {
            if (base.ProcessDialogChar(charCode))
            {
                return(true);
            }

            return(ErrorUtil.ThrowOnFailure(_host.ProcessDialogChar(charCode)));
        }
예제 #18
0
 public HResult Unadvise(int cookie)
 {
     try
     {
         return(_listeners.Remove(cookie) ? HResult.OK : HResult.False);
     }
     catch (Exception ex)
     {
         return(ErrorUtil.GetHResult(ex));
     }
 }
예제 #19
0
            public override void Close()
            {
                // The base Dispose calls Close, so the != null check.

                if (_stream != null && _closeBaseStream)
                {
                    ErrorUtil.ThrowOnFailure(_stream.Close());
                }

                base.Close();
            }
예제 #20
0
 HResult INiIsolationClient.ProcessMnemonic(char charCode)
 {
     try
     {
         return(ProcessMnemonic(charCode) ? HResult.OK : HResult.False);
     }
     catch (Exception ex)
     {
         return(ErrorUtil.GetHResult(ex));
     }
 }
예제 #21
0
        public NiEventSink(INiConnectionPoint connectionPoint)
        {
            if (connectionPoint == null)
            {
                throw new ArgumentNullException("connectionPoint");
            }

            _connectionPoint = connectionPoint;

            ErrorUtil.ThrowOnFailure(_connectionPoint.Advise(this, out _cookie));
        }
예제 #22
0
 HResult INiIsolationHost.ProcessDialogChar(char charData)
 {
     try
     {
         return(ProcessDialogChar(charData) ? HResult.OK : HResult.False);
     }
     catch (Exception ex)
     {
         return(ErrorUtil.GetHResult(ex));
     }
 }
예제 #23
0
        protected override INiIsolationClient CreateWindow()
        {
            var commandManager = (INiCommandManager)GetService(typeof(INiCommandManager));

            ErrorUtil.ThrowOnFailure(commandManager.CreateCommandBarWindow(CommandBarId, out _window));

            ErrorUtil.ThrowOnFailure(_window.Initialize());

            SetBoundsCore(0, 0, Width, Height, BoundsSpecified.Size);

            return(_window);
        }
예제 #24
0
파일: NiForm.cs 프로젝트: vector-man/netide
        private void ShowHelp()
        {
            if (_helpTopic.Length > 0)
            {
                var match = HelpTopicRe.Match(_helpTopic);

                ErrorUtil.ThrowOnFailure(((INiHelp)GetService(typeof(INiHelp))).Navigate(
                                             match.Groups[1].Value,
                                             match.Groups[2].Value
                                             ));
            }
        }
예제 #25
0
            public HResult Write(byte[] buffer)
            {
                try
                {
                    _stream.Write(buffer, 0, buffer.Length);

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
예제 #26
0
        HResult INiOptionPage.Apply()
        {
            try
            {
                OnApply(EventArgs.Empty);

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
예제 #27
0
        private string GetText()
        {
            int line;
            int index;

            ErrorUtil.ThrowOnFailure(TextBuffer.GetLastLineIndex(out line, out index));

            string result;

            ErrorUtil.ThrowOnFailure(TextBuffer.GetLineText(0, 0, line, index, out result));

            return(result);
        }
예제 #28
0
파일: NiForm.cs 프로젝트: vector-man/netide
        protected override void OnClosed(EventArgs e)
        {
            var registerPriorityCommandTarget = (INiRegisterPriorityCommandTarget)GetService(typeof(INiRegisterPriorityCommandTarget));

            if (registerPriorityCommandTarget != null)
            {
                ErrorUtil.ThrowOnFailure(
                    registerPriorityCommandTarget.UnregisterPriorityCommandTarget(_cookie)
                    );
            }

            base.OnClosed(e);
        }
예제 #29
0
        public static IEnumerable <INiWindowFrame> GetDocumentWindows(this INiShell self)
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }

            INiIterator <INiWindowFrame> iterator;

            ErrorUtil.ThrowOnFailure(self.GetDocumentWindowIterator(out iterator));

            return(iterator.GetEnumerable());
        }
예제 #30
0
            public HResult Close()
            {
                try
                {
                    _stream.Close();

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }