GetHResult() private method

private GetHResult ( Exception exception ) : HResult
exception System.Exception
return HResult
Esempio n. 1
0
            public HResult Open(out IStream stream)
            {
                stream = null;

                try
                {
                    stream = StreamUtil.FromFile(FileName, FileMode.Open);

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Esempio n. 2
0
        HResult INiIsolationClient.GetPreferredSize(Size proposedSize, out Size preferredSize)
        {
            preferredSize = new Size();

            try
            {
                preferredSize = GetPreferredSize(proposedSize);

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 3
0
            public HResult Open(out IStream stream)
            {
                stream = null;

                try
                {
                    stream = StreamUtil.FromManifestResourceStream(_assembly, _resourceName);

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Esempio n. 4
0
            public HResult Open(out IStream stream)
            {
                stream = null;

                try
                {
                    stream = StreamUtil.FromByteArray(_byteArray);

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Esempio n. 5
0
        HResult INiIsolationHost.ProcessCmdKey(ref NiMessage message, Keys keyData)
        {
            try
            {
                Message msg    = message;
                bool    result = ProcessCmdKey(ref msg, keyData);
                message = msg;

                return(result ? HResult.OK : HResult.False);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 6
0
        public HResult GetCurrent(out TOut current)
        {
            current = default(TOut);

            try
            {
                current = GetCurrentFromInput(_enumerator.Current);

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 7
0
        public HResult Next(out bool available)
        {
            available = false;

            try
            {
                available = _enumerator.MoveNext();

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 8
0
            public HResult GetPosition(out long position)
            {
                position = 0;

                try
                {
                    position = _stream.Position;

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Esempio n. 9
0
            public HResult GetLength(out long length)
            {
                length = 0;

                try
                {
                    length = _stream.Length;

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Esempio n. 10
0
        public virtual HResult Initialize()
        {
            try
            {
                // Frame holds on to a reference to the listener, so we don't have to.

                if (Frame != null)
                {
                    new Listener(this);
                }

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 11
0
        public HResult SetHost(INiIsolationHost host)
        {
            try
            {
                if (host == null)
                {
                    throw new ArgumentNullException("host");
                }

                _host = host;

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 12
0
        public HResult Remove(T item)
        {
            try
            {
                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                bool removed = _inner.Remove(item);

                return(removed ? HResult.OK : HResult.False);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 13
0
        public HResult Insert(int index, T item)
        {
            try
            {
                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                _inner.Insert(index, item);

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 14
0
        public HResult GetSetting(string key, out string value)
        {
            value = null;

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

                using (var registryKey = OpenRegistryKey(false))
                {
                    if (registryKey != null)
                    {
                        object rawValue = registryKey.GetValue(key);

                        if (rawValue is string)
                        {
                            value = (string)rawValue;
                        }
                        else if (rawValue is int)
                        {
                            value = ((int)rawValue).ToString(CultureInfo.InvariantCulture);
                        }
                        else if (rawValue is string[])
                        {
                            value = String.Join(Environment.NewLine, (string[])rawValue);
                        }

                        if (value != null)
                        {
                            return(HResult.OK);
                        }
                    }

                    return(HResult.False);
                }
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 15
0
        HResult INiOptionPage.Deactivate(out bool canDeactivate)
        {
            canDeactivate = false;

            try
            {
                var e = new CancelEventArgs();

                OnDeactivate(e);

                canDeactivate = !e.Cancel;

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 16
0
        public HResult SetSetting(string key, string value)
        {
            try
            {
                if (key == null)
                {
                    throw new ArgumentNullException("key");
                }

                using (var registryKey = OpenRegistryKey(true))
                {
                    if (value == null)
                    {
                        registryKey.DeleteValue(key, false);
                    }
                    else
                    {
                        int intValue;

                        if (int.TryParse(value, NumberStyles.None, CultureInfo.InvariantCulture, out intValue))
                        {
                            registryKey.SetValue(key, intValue);
                        }
                        else if (value.Contains('\n'))
                        {
                            registryKey.SetValue(key, MultiStringRe.Split(value), RegistryValueKind.MultiString);
                        }
                        else
                        {
                            registryKey.SetValue(key, value);
                        }
                    }

                    _connectionPoint.ForAll(p => p.OnSettingChanged(key, value));

                    return(HResult.OK);
                }
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 17
0
        public HResult Register(INiRegistrationContext registrationContext)
        {
            try
            {
                if (registrationContext == null)
                {
                    throw new ArgumentNullException("registrationContext");
                }

                var packageGuid = GetType().GUID.ToString("B").ToUpperInvariant();

                var    descriptionAttribute = GetType().GetCustomAttributes(typeof(DescriptionAttribute), true).Cast <DescriptionAttribute>().SingleOrDefault();
                string description          = descriptionAttribute != null ? descriptionAttribute.Description : registrationContext.PackageId;

                using (var key = registrationContext.CreateKey("Packages\\" + packageGuid))
                {
                    key.SetValue(null, this.ResolveStringResource(description));

                    foreach (var type in GetType().Assembly.GetTypes())
                    {
                        foreach (RegistrationAttribute attribute in type.GetCustomAttributes(typeof(RegistrationAttribute), true))
                        {
                            attribute.Register(this, registrationContext, key);
                        }
                    }
                }

                using (var key = registrationContext.CreateKey("InstalledProducts\\" + registrationContext.PackageId))
                {
                    key.SetValue(null, description);
                    key.SetValue("Package", packageGuid);
                    key.SetValue("Version", GetType().Assembly.GetName().Version.ToString());
                }

                // Add the installed products key.

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 18
0
        public HResult QueryClose(out bool canClose)
        {
            canClose = false;

            try
            {
                var ev = new CancelEventArgs();

                OnPackageClosing(ev);

                canClose = !ev.Cancel;

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 19
0
        public HResult QueryStatus(Guid command, out NiCommandStatus status)
        {
            status = 0;

            try
            {
                CommandRegistration registration;

                if (_registrations.TryGetValue(command, out registration))
                {
                    status = NiCommandStatus.Supported;

                    if (registration.QueryStatus != null)
                    {
                        var e = new NiQueryEventArgs();

                        registration.QueryStatus(e);

                        status |= e.Status;
                    }
                    else
                    {
                        status |= NiCommandStatus.Enabled;
                    }

                    return(HResult.OK);
                }

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

                return(HResult.False);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 20
0
        public HResult Advise(object sink, out int cookie)
        {
            cookie = 0;

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

                cookie = ++_nextCookie;

                _listeners.Add(cookie, sink);

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 21
0
            public HResult Exec(Guid command, object argument, out object result)
            {
                result = null;

                try
                {
                    var hr = _commandMapper.Exec(command, argument, out result);

                    // If we're a modal dialog, we want to prevent other command
                    // handlers from seeing any commands.

                    if (hr == HResult.False && _form.Modal)
                    {
                        return(HResult.OK);
                    }

                    return(hr);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Esempio n. 22
0
            public HResult QueryStatus(Guid command, out NiCommandStatus status)
            {
                status = 0;

                try
                {
                    var hr = _commandMapper.QueryStatus(command, out status);

                    // If we're a modal dialog, we want to prevent other command
                    // handlers from seeing any commands.

                    if (hr == HResult.False && _form.Modal)
                    {
                        return(HResult.OK);
                    }

                    return(hr);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Esempio n. 23
0
        HResult INiIsolationClient.PreviewKeyDown(Keys keyData)
        {
            try
            {
                var result = HResult.False;

                var target = FindTarget(NativeMethods.GetFocus());
                if (target != null)
                {
                    var e = new PreviewKeyDownEventArgs(keyData);

                    ControlStubs.ControlOnPreviewKeyDown(target, e);

                    result = e.IsInputKey ? HResult.OK : HResult.False;
                }

                return(result);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 24
0
        public HResult Unregister(INiRegistrationContext registrationContext)
        {
            try
            {
                if (registrationContext == null)
                {
                    throw new ArgumentNullException("registrationContext");
                }

                var packageGuid = GetType().GUID.ToString("B").ToUpperInvariant();

                using (var key = registrationContext.CreateKey("Packages\\" + packageGuid))
                {
                    foreach (var type in GetType().Assembly.GetTypes())
                    {
                        foreach (RegistrationAttribute attribute in type.GetCustomAttributes(typeof(RegistrationAttribute), true))
                        {
                            attribute.Unregister(this, registrationContext, key);
                        }
                    }
                }

                // Un-registration allows attributes to perform cleanup other
                // than from inside the package namespace. The package namespace
                // itself is unconditionally deleted anyway, so the attributes
                // don't have to clean up that.

                registrationContext.RemoveKey("Packages\\" + packageGuid);
                registrationContext.RemoveKey("InstalledProducts\\" + registrationContext.PackageId);

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 25
0
            public HResult Read(int length, out byte[] buffer)
            {
                buffer = null;

                try
                {
                    buffer = new byte[length];

                    if (length == 0)
                    {
                        return(HResult.OK);
                    }

                    int read = _stream.Read(buffer, 0, length);

                    if (read == 0)
                    {
                        buffer = null;

                        return(HResult.False);
                    }

                    if (read != length)
                    {
                        Debug.Assert(read < length);

                        Array.Resize(ref buffer, read);
                    }

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Esempio n. 26
0
        public HResult SetSite(IServiceProvider serviceProvider)
        {
            try
            {
                if (serviceProvider == null)
                {
                    throw new ArgumentNullException("serviceProvider");
                }

                // This is the first time we get access to an IServiceProvider
                // from a new AppDomain. Install logging redirection now.

                LoggingRedirection.Install(serviceProvider);

                _serviceProvider  = serviceProvider;
                _serviceContainer = new NiServiceContainer(serviceProvider);

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Esempio n. 27
0
        public HResult CreateToolWindow(Guid guid, out INiWindowPane toolWindow)
        {
            toolWindow = null;

            try
            {
                var registration = GetType()
                                   .GetCustomAttributes(typeof(ProvideToolWindowAttribute), true)
                                   .Cast <ProvideToolWindowAttribute>()
                                   .SingleOrDefault(p => p.ToolType.GUID == guid);

                if (registration != null)
                {
                    toolWindow = CreateToolWindow(registration.ToolType);
                    return(HResult.OK);
                }

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