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)); }
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)); }
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); }
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; } } }
void listView_MouseUp(object sender, MouseEventArgs e) { if (_shell != null && (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)) { ErrorUtil.ThrowOnFailure(_shell.InvalidateRequerySuggested()); } }
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)); } }
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)); } }
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)); } }
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)); } }
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)); }
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)); } }
public override Size GetPreferredSize(Size proposedSize) { Size preferredSize; ErrorUtil.ThrowOnFailure(_window.GetPreferredSize(proposedSize, out preferredSize)); return(preferredSize); }
public static object GetPropertyEx(this INiWindowFrame self, int property) { object result; ErrorUtil.ThrowOnFailure(self.GetProperty(property, out result)); return(result); }
public static string GetString(this INiSettings self, string key) { string value; ErrorUtil.ThrowOnFailure(self.GetSetting(key, out value)); return(value); }
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)); }
protected override bool ProcessDialogKey(Keys keyData) { if (base.ProcessDialogKey(keyData)) { return(true); } return(ErrorUtil.ThrowOnFailure(_host.ProcessDialogKey(keyData))); }
protected override bool ProcessDialogChar(char charCode) { if (base.ProcessDialogChar(charCode)) { return(true); } return(ErrorUtil.ThrowOnFailure(_host.ProcessDialogChar(charCode))); }
public HResult Unadvise(int cookie) { try { return(_listeners.Remove(cookie) ? HResult.OK : HResult.False); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public override void Close() { // The base Dispose calls Close, so the != null check. if (_stream != null && _closeBaseStream) { ErrorUtil.ThrowOnFailure(_stream.Close()); } base.Close(); }
HResult INiIsolationClient.ProcessMnemonic(char charCode) { try { return(ProcessMnemonic(charCode) ? HResult.OK : HResult.False); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public NiEventSink(INiConnectionPoint connectionPoint) { if (connectionPoint == null) { throw new ArgumentNullException("connectionPoint"); } _connectionPoint = connectionPoint; ErrorUtil.ThrowOnFailure(_connectionPoint.Advise(this, out _cookie)); }
HResult INiIsolationHost.ProcessDialogChar(char charData) { try { return(ProcessDialogChar(charData) ? HResult.OK : HResult.False); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
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); }
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 )); } }
public HResult Write(byte[] buffer) { try { _stream.Write(buffer, 0, buffer.Length); return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
HResult INiOptionPage.Apply() { try { OnApply(EventArgs.Empty); return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
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); }
protected override void OnClosed(EventArgs e) { var registerPriorityCommandTarget = (INiRegisterPriorityCommandTarget)GetService(typeof(INiRegisterPriorityCommandTarget)); if (registerPriorityCommandTarget != null) { ErrorUtil.ThrowOnFailure( registerPriorityCommandTarget.UnregisterPriorityCommandTarget(_cookie) ); } base.OnClosed(e); }
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()); }
public HResult Close() { try { _stream.Close(); return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }