ThrowOnFailure() private method

private ThrowOnFailure ( HResult hr ) : bool
hr HResult
return bool
Esempio n. 1
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);
            }
Esempio n. 2
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));
        }
Esempio n. 3
0
        public HResult Exec(Guid command, object argument, out object result)
        {
            result = null;

            try
            {
                CommandRegistration registration;

                if (_registrations.TryGetValue(command, out registration))
                {
                    var e = new NiExecEventArgs(argument);

                    registration.Exec(e);

                    result = e.Result;

                    return(HResult.OK);
                }

                foreach (var @delegate in Delegates)
                {
                    if (ErrorUtil.ThrowOnFailure(@delegate.Exec(command, argument, out result)))
                    {
                        return(HResult.OK);
                    }
                }

                return(HResult.False);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 4
0
        public static IEnumerable <T> GetEnumerable <T>(this INiIterator <T> self)
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }

            using (self)
            {
                while (true)
                {
                    bool available;
                    ErrorUtil.ThrowOnFailure(self.Next(out available));

                    if (!available)
                    {
                        break;
                    }

                    T current;
                    ErrorUtil.ThrowOnFailure(self.GetCurrent(out current));

                    yield return(current);
                }
            }
        }
Esempio n. 5
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;
                }
            }
        }
Esempio n. 6
0
 void listView_MouseUp(object sender, MouseEventArgs e)
 {
     if (_shell != null && (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right))
     {
         ErrorUtil.ThrowOnFailure(_shell.InvalidateRequerySuggested());
     }
 }
Esempio n. 7
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));
            }
Esempio n. 8
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));
        }
Esempio n. 9
0
        public static string GetString(this INiSettings self, string key)
        {
            string value;

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

            return(value);
        }
Esempio n. 10
0
        public override Size GetPreferredSize(Size proposedSize)
        {
            Size preferredSize;

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

            return(preferredSize);
        }
Esempio n. 11
0
        public static object GetPropertyEx(this INiWindowFrame self, int property)
        {
            object result;

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

            return(result);
        }
Esempio n. 12
0
        protected override bool ProcessDialogChar(char charCode)
        {
            if (base.ProcessDialogChar(charCode))
            {
                return(true);
            }

            return(ErrorUtil.ThrowOnFailure(_host.ProcessDialogChar(charCode)));
        }
Esempio n. 13
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));
        }
Esempio n. 14
0
        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (base.ProcessDialogKey(keyData))
            {
                return(true);
            }

            return(ErrorUtil.ThrowOnFailure(_host.ProcessDialogKey(keyData)));
        }
Esempio n. 15
0
        public NiEventSink(INiConnectionPoint connectionPoint)
        {
            if (connectionPoint == null)
            {
                throw new ArgumentNullException("connectionPoint");
            }

            _connectionPoint = connectionPoint;

            ErrorUtil.ThrowOnFailure(_connectionPoint.Advise(this, out _cookie));
        }
Esempio n. 16
0
            public override void Close()
            {
                // The base Dispose calls Close, so the != null check.

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

                base.Close();
            }
Esempio n. 17
0
        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
                                             ));
            }
        }
Esempio n. 18
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);
        }
Esempio n. 19
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);
        }
Esempio n. 20
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());
        }
Esempio n. 21
0
        protected override void OnClosed(EventArgs e)
        {
            var registerPriorityCommandTarget = (INiRegisterPriorityCommandTarget)GetService(typeof(INiRegisterPriorityCommandTarget));

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

            base.OnClosed(e);
        }
Esempio n. 22
0
 private void UpdateProgress()
 {
     if (_waitDialog != null)
     {
         ErrorUtil.ThrowOnFailure(_waitDialog.UpdateProgress(
                                      Message,
                                      ProgressText,
                                      StatusBarText,
                                      Progress,
                                      !CanCancel,
                                      out _hasCancelled
                                      ));
     }
 }
Esempio n. 23
0
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (base.ProcessCmdKey(ref msg, keyData))
            {
                return(true);
            }

            NiMessage message = msg;
            bool      result  = ErrorUtil.ThrowOnFailure(_host.ProcessCmdKey(ref message, keyData));

            msg = message;

            return(result);
        }
Esempio n. 24
0
        protected override void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (_connectionPoint != null)
                {
                    ErrorUtil.ThrowOnFailure(_connectionPoint.Unadvise(_cookie));
                    _connectionPoint = null;
                }

                _disposed = true;
            }

            base.Dispose(disposing);
        }
Esempio n. 25
0
        protected override void Select(bool directed, bool forward)
        {
            if (_select > 0)
            {
                return;
            }

            _select++;

            try
            {
                // We were the target of select next control. Forward the
                // call to the isolation client which does its search. If it
                // matches a control, we need to make ourselves active.

                if (ErrorUtil.ThrowOnFailure(_window.SelectNextControl(!directed || forward)))
                {
                    base.Select(directed, forward);
                    return;
                }

                // If the client wasn't able to select something, we continue the
                // search from here. One small detail is that SelectNextControl
                // does not match itself. When it would match an IsolationClient,
                // this would mean that the search does not go into the
                // IsolationHost. We specifically match this case by first doing
                // a non-wrapping search and matching the root for IsolationClient.
                // If that matches, we allow the IsolationClient to continue
                // the search upwards. Otherwise, we continue the search
                // from the root as usual.

                var root = ControlUtil.GetRoot(this);

                if (root.SelectNextControl(this, !directed || forward, true, true, !(root is NiIsolationClient)))
                {
                    return;
                }

                if (root is NiIsolationClient)
                {
                    ControlStubs.ControlSelect(root, directed, forward);
                }
            }
            finally
            {
                _select--;
            }
        }
Esempio n. 26
0
        public DialogResult Show(IWin32Window owner)
        {
            INiTaskDialog taskDialog;

            ErrorUtil.ThrowOnFailure(_shell.CreateTaskDialog(out taskDialog));

            if (_flags != 0)
            {
                ErrorUtil.ThrowOnFailure(taskDialog.SetFlags(_flags));
            }
            if (_mainInstruction != null)
            {
                ErrorUtil.ThrowOnFailure(taskDialog.SetMainInstruction(_mainInstruction));
            }
            if (_content != null)
            {
                ErrorUtil.ThrowOnFailure(taskDialog.SetContent(_content));
            }
            if (_expandedControlText != null)
            {
                ErrorUtil.ThrowOnFailure(taskDialog.SetExpandedControlText(_expandedControlText));
            }
            if (_expandedInformation != null)
            {
                ErrorUtil.ThrowOnFailure(taskDialog.SetExpandedInformation(_expandedInformation));
            }
            if (_mainIcon.HasValue)
            {
                ErrorUtil.ThrowOnFailure(taskDialog.SetMainIcon(_mainIcon.Value));
            }
            if (_commonButtons.HasValue)
            {
                ErrorUtil.ThrowOnFailure(taskDialog.SetCommonButtons(_commonButtons.Value));
            }

            bool verificationFlagChecked;
            int  radioButtonResult;
            int  result;

            ErrorUtil.ThrowOnFailure(taskDialog.Show(
                                         owner != null ? owner.Handle : IntPtr.Zero,
                                         out verificationFlagChecked,
                                         out radioButtonResult,
                                         out result
                                         ));

            return((DialogResult)result);
        }
Esempio n. 27
0
        private void RegisterEditorFactories()
        {
            var registry = (INiEditorFactoryRegistry)GetService(typeof(INiEditorFactoryRegistry));

            foreach (ProvideEditorFactoryAttribute attribute in GetType().GetCustomAttributes(typeof(ProvideEditorFactoryAttribute), true))
            {
                var editorFactory = (INiEditorFactory)Activator.CreateInstance(attribute.FactoryType);

                editorFactory.SetSite(this);

                ErrorUtil.ThrowOnFailure(registry.RegisterEditorFactory(
                                             attribute.FactoryType.GUID,
                                             editorFactory
                                             ));
            }
        }
Esempio n. 28
0
        public static string ResolveStringResource(this INiPackage self, string key)
        {
            if (String.IsNullOrEmpty(key))
            {
                return(key);
            }

            if (key.StartsWith("@"))
            {
                string value;
                ErrorUtil.ThrowOnFailure(self.GetStringResource(key.Substring(1), out value));
                return(value);
            }

            return(key);
        }
Esempio n. 29
0
        protected override void OnShown(EventArgs e)
        {
            var registerPriorityCommandTarget = (INiRegisterPriorityCommandTarget)GetService(typeof(INiRegisterPriorityCommandTarget));

            if (registerPriorityCommandTarget != null)
            {
                ErrorUtil.ThrowOnFailure(
                    registerPriorityCommandTarget.RegisterPriorityCommandTarget(
                        new CommandMapperWrapper(this),
                        out _cookie
                        )
                    );
            }

            base.OnShown(e);
        }
Esempio n. 30
0
        protected override void Select(bool directed, bool forward)
        {
            if (_select > 0)
            {
                return;
            }

            _select++;

            try
            {
                ErrorUtil.ThrowOnFailure(_host.SelectNextControl(!directed || forward));
            }
            finally
            {
                _select--;
            }
        }