Пример #1
0
        public void Update(INiNotificationItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            string subject;

            ErrorUtil.ThrowOnFailure(item.GetSubject(out subject));
            Subject = subject;

            string message;

            ErrorUtil.ThrowOnFailure(item.GetMessage(out message));
            Message = message;

            NiNotificationItemPriority priority;

            ErrorUtil.ThrowOnFailure(item.GetPriority(out priority));
            Priority = priority;

            DateTime?created;

            ErrorUtil.ThrowOnFailure(item.GetCreated(out created));
            Created = created;
        }
Пример #2
0
            public HResult UpdateButton(int cookie, INiTitleBarButton button)
            {
                try
                {
                    if (button == null)
                    {
                        throw new ArgumentNullException("button");
                    }

                    TitleBarButton wrapper;
                    if (!_buttonMap.TryGetValue(cookie, out wrapper))
                    {
                        return(HResult.False);
                    }

                    wrapper.Update(button);

                    var formChrome = _mainWindowChrome.FormChrome;
                    if (formChrome != null)
                    {
                        formChrome.PaintNonClientArea();
                    }

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
            public HResult SetEnabled(bool enabled)
            {
                try
                {
                    if (enabled != _enabled)
                    {
                        _enabled = enabled;

                        if (_enabled)
                        {
                            FormChrome                  = new VisualStudioFormChrome();
                            FormChrome.BorderColor      = _color;
                            FormChrome.PrimaryColor     = _color;
                            FormChrome.ContainerControl = _mainForm;

                            // Buttons may have been added before the chrome was
                            // available. Trigger the title bar button manager
                            // to actually create the buttons.

                            ((NiTitleBarButtonManager)GetService(typeof(INiTitleBarButtonManager))).RebuildButtons();
                        }
                        else
                        {
                            FormChrome.Dispose();
                            FormChrome = null;
                        }
                    }

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Пример #4
0
        protected override void SendCallback(IAsyncResult ar)
        {
            try
            {
                // Retrieve the socket from the state object.

                // Complete sending the data to the remote device.
                if (ar.AsyncState is Socket client)
                {
                    //Receive(client);

                    client.EndSend(ar);
                    //.WriteLine("Sent {0} bytes to server.", bytesSent);
                }
                else
                {
                    throw new ArgumentException(nameof(ar));
                }
                // Signal that all bytes have been sent.
                _sendDone.Set();
            }
            catch (Exception e)
            {
                ErrorUtil.WriteError(e).GetAwaiter().GetResult();
            }
        }
Пример #5
0
        protected override void ConnectCallback(IAsyncResult ar)
        {
            try
            {
                // Retrieve the socket from the state object.

                // Complete the connection.
                if (ar.AsyncState is Socket client)
                {
                    client.EndConnect(ar);
                }
                else
                {
                    throw new ArgumentException(nameof(ar));
                }
                //Console.WriteLine("Socket connected to {0}", client.RemoteEndPoint.ToString());

                // Signal that the connection has been made.
                _connectDone.Set();
            }
            catch (Exception e)
            {
                ErrorUtil.WriteError(e).GetAwaiter().GetResult();
            }
        }
Пример #6
0
            public HResult Show()
            {
                try
                {
                    VerifyNotDisposed();

                    if (_shown)
                    {
                        _owner.IsHidden = false;
                        _owner.Show();
                    }
                    else
                    {
                        _shown = true;

                        ((NiEnv)_owner.GetService(typeof(INiEnv))).MainForm.ShowContent(_owner);
                    }

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Пример #7
0
            public HResult Show(IntPtr owner, out bool verificationFlagChecked, out int radioButtonResult, out int result)
            {
                verificationFlagChecked = false;
                radioButtonResult       = 0;
                result = 0;

                try
                {
                    if (owner == IntPtr.Zero)
                    {
                        var ownerWindow = NetIde.Util.Forms.Form.FindDefaultOwnerWindow(_serviceProvider);
                        if (ownerWindow != null)
                        {
                            owner = ownerWindow.Handle;
                        }
                    }

                    if (String.IsNullOrEmpty(_taskDialog.WindowTitle))
                    {
                        _taskDialog.WindowTitle = ((INiEnv)_serviceProvider.GetService(typeof(INiEnv))).ContextName;
                    }

                    result = _taskDialog.Show(owner, out verificationFlagChecked, out radioButtonResult);

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Пример #8
0
        public HResult UpdateItem(int cookie, INiNotificationItem item)
        {
            try
            {
                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                NotificationItem wrapper;
                if (!_itemMap.TryGetValue(cookie, out wrapper))
                {
                    return(HResult.False);
                }

                wrapper.Update(item);

                UpdateButton();

                if (_window != null)
                {
                    _window.RedrawItems(_items);
                }

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Пример #9
0
        public HResult RemoveItem(int cookie)
        {
            try
            {
                NotificationItem wrapper;
                if (!_itemMap.TryGetValue(cookie, out wrapper))
                {
                    return(HResult.False);
                }

                _itemMap.Remove(cookie);
                _items.Remove(wrapper);

                UpdateButton();

                if (_window != null)
                {
                    _window.RedrawItems(_items);
                }

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Пример #10
0
        public HResult IsDocumentOpen(string document, out INiHierarchy hier, out INiWindowFrame windowFrame)
        {
            hier        = null;
            windowFrame = null;

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

                OpenDocument openDocument;
                if (_openDocuments.TryGetValue(document, out openDocument))
                {
                    hier        = openDocument.Item;
                    windowFrame = openDocument.WindowFrame;

                    return(HResult.OK);
                }

                return(HResult.False);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Пример #11
0
        public HResult AddItem(INiNotificationItem item, out int cookie)
        {
            cookie = 0;

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

                cookie = _nextCookie++;

                var wrapper = new NotificationItem(cookie);
                wrapper.Update(item);

                _itemMap.Add(cookie, wrapper);
                _items.Add(wrapper);

                UpdateButton();

                if (_window != null)
                {
                    _window.RedrawItems(_items);
                }

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Пример #12
0
                public void OnClose(NiFrameCloseMode closeMode, ref bool cancel)
                {
                    try
                    {
                        if (_owner._docData == null)
                        {
                            return;
                        }

                        NiSaveMode saveMode;

                        switch (closeMode)
                        {
                        case NiFrameCloseMode.PromptSave: saveMode = NiSaveMode.Save; break;

                        case NiFrameCloseMode.SaveIfDirty: saveMode = NiSaveMode.SilentSave; break;

                        default: return;
                        }

                        string document;
                        bool   saved;
                        ErrorUtil.ThrowOnFailure(_owner._docData.SaveDocData(saveMode, out document, out saved));

                        cancel = !saved;
                    }
                    catch (Exception ex)
                    {
                        Log.Warn("Failed to save document", ex);
                    }
                }
Пример #13
0
        public override HResult Initialize()
        {
            try
            {
                var hr = base.Initialize();

                if (ErrorUtil.Failure(hr))
                {
                    return(hr);
                }

                ErrorUtil.ThrowOnFailure(Frame.SetIcon(Resources.Folders));
                ErrorUtil.ThrowOnFailure(Frame.SetCaption(Labels.ProjectExplorer));

                _control = new ProjectExplorerControl
                {
                    Site = new SiteProxy(this),
                    Dock = DockStyle.Fill
                };

                Controls.Add(_control);

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Пример #14
0
        public void RaisePerform()
        {
            Running = true;

            try
            {
                ErrorUtil.ThrowOnFailure(Handler.Perform(this));

                Success = true;
            }
            catch (Exception ex)
            {
                _syncContext.Send(
                    p => _jobManager.CreateTaskDialog()
                    .FromException(ex)
                    .Show(),
                    null
                    );

                Exception = ex;
            }
            finally
            {
                Running   = false;
                Completed = true;
            }
        }
Пример #15
0
        public HResult Register(string document, INiHierarchy hier, INiPersistDocData docData, out int cookie)
        {
            cookie = -1;

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

                cookie = Interlocked.Increment(ref _lastCookie);

                _registrations.Add(cookie, new Registration(document, hier, docData));

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Пример #16
0
        public void SelectDetails(IStream stream, FileType fileType)
        {
            LastWriteTime = stream == null ? null : stream.LastWriteTime;

            if (stream == null)
            {
                FileSize = null;
            }
            else
            {
                long length;
                ErrorUtil.ThrowOnFailure(stream.GetLength(out length));

                FileSize = length;
            }

            var textFileType = fileType as TextFileType;

            HaveBom         = textFileType != null && textFileType.Encoding.GetPreamble().Length > 0;
            LineTermination = textFileType == null ? (LineTermination?)null : textFileType.LineTermination;
            Encoding        = textFileType == null ? null : textFileType.Encoding;

            if (textFileType == null)
            {
                ContentType = null;
            }
            else
            {
                var highlighter = HighlightingManager.Manager.FindHighlighterForFile(stream.Name);

                ContentType = highlighter == null ? null : highlighter.Name;
            }
        }
Пример #17
0
        public HResult GetDocumentInfo(int cookie, out string document, out INiHierarchy hier, out INiPersistDocData docData)
        {
            document = null;
            hier     = null;
            docData  = null;

            try
            {
                Registration registration;
                if (!_registrations.TryGetValue(cookie, out registration))
                {
                    throw new ArgumentOutOfRangeException("cookie", NeutralResources.DocumentNotRegistered);
                }

                document = registration.Document;
                hier     = registration.Item;
                docData  = registration.DocData;

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Пример #18
0
        public static INiHierarchy FindByDocument(this INiHierarchy self, string document)
        {
            var projectItem = self as INiProjectItem;

            if (projectItem != null)
            {
                string fileName;
                ErrorUtil.ThrowOnFailure(projectItem.GetFileName(out fileName));

                if (fileName != null && String.Equals(document, fileName, StringComparison.OrdinalIgnoreCase))
                {
                    return(self);
                }
            }

            foreach (var child in self.GetChildren())
            {
                var result = FindByDocument(child, document);

                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
Пример #19
0
            public HResult Close(NiFrameCloseMode closeMode)
            {
                try
                {
                    VerifyNotDisposed();

                    _owner._suppressClosing = true;

                    try
                    {
                        bool cancel = false;
                        _owner.RaiseClose(closeMode, ref cancel);

                        if (cancel)
                        {
                            return(HResult.False);
                        }

                        _owner.Close();
                    }
                    finally
                    {
                        _owner._suppressClosing = false;
                    }

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Пример #20
0
        public HResult RegisterPriorityCommandTarget(INiCommandTarget commandTarget, out int cookie)
        {
            cookie = 0;

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

                cookie = _nextPriorityCommandTargetCookie++;
                _priorityCommandTargets.Add(cookie, commandTarget);
                _priorityCommandTargetsOrdered.Add(commandTarget);

                // The available command targets have changed; force a requery.

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

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Пример #21
0
            public HResult SetFlags(NiTaskDialogFlags flags)
            {
                try
                {
                    _taskDialog.EnableHyperlinks         = flags.HasFlag(NiTaskDialogFlags.EnableHyperlinks);
                    _taskDialog.AllowDialogCancellation  = flags.HasFlag(NiTaskDialogFlags.AllowDialogCancellation);
                    _taskDialog.UseCommandLinks          = flags.HasFlag(NiTaskDialogFlags.UseCommandLinks);
                    _taskDialog.UseCommandLinksNoIcon    = flags.HasFlag(NiTaskDialogFlags.UseCommandLinksNoIcon);
                    _taskDialog.ExpandFooterArea         = flags.HasFlag(NiTaskDialogFlags.ExpandFooterArea);
                    _taskDialog.ExpandedByDefault        = flags.HasFlag(NiTaskDialogFlags.ExpandedByDefault);
                    _taskDialog.VerificationFlagChecked  = flags.HasFlag(NiTaskDialogFlags.VerificationFlagChecked);
                    _taskDialog.ShowProgressBar          = flags.HasFlag(NiTaskDialogFlags.ShowProgressBar);
                    _taskDialog.ShowMarqueeProgressBar   = flags.HasFlag(NiTaskDialogFlags.ShowMarqueeProgressBar);
                    _taskDialog.CallbackTimer            = flags.HasFlag(NiTaskDialogFlags.CallbackTimer);
                    _taskDialog.PositionRelativeToWindow = flags.HasFlag(NiTaskDialogFlags.PositionRelativeToWindow);
                    _taskDialog.RightToLeftLayout        = flags.HasFlag(NiTaskDialogFlags.RightToLeftLayout);
                    _taskDialog.NoDefaultRadioButton     = flags.HasFlag(NiTaskDialogFlags.NoDefaultRadioButton);
                    _taskDialog.CanBeMinimized           = flags.HasFlag(NiTaskDialogFlags.CanBeMinimized);

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Пример #22
0
        public override void Operation()
        {
            while (true)
            {
                try
                {
                    while (true)
                    {
                        _allDone.Reset();

                        // Start an asynchronous socket to listen for connections.
                        Socketv4.BeginAccept(
                            AcceptCallback,
                            Socketv4);

                        // Wait until a connection is made before continuing.
                        _allDone.WaitOne();
                    }
                }
                catch (Exception e)
                {
                    Message.Body = e;
                    ErrorUtil.WriteError(e).GetAwaiter().GetResult();
                }
                Socketv4.Close();
            }
            // ReSharper disable once FunctionNeverReturns
        }
Пример #23
0
        public override void Operation()
        {
            try
            {
                // Connect to the remote endpoint.
                Socketv4.BeginConnect(new IPEndPoint(IPAddress.Loopback, Config.Port),
                                      ConnectCallback, Socketv4);
                _connectDone.WaitOne();

                // Send test data to the remote device.
                Send(Socketv4, Message);
                _sendDone.WaitOne();

                // Receive the response from the remote device.
                Receive(Socketv4);
                _receiveDone.WaitOne();

                // Write the response to the console.
                //Console.WriteLine("Response received : {0}", response);

                // Release the socket.
                Socketv4.Shutdown(SocketShutdown.Both);
                Socketv4.Close();
            }
            catch (Exception e)
            {
                ErrorUtil.WriteError(e).GetAwaiter().GetResult();
            }
        }
Пример #24
0
        public HResult SetBuffer(INiTextLines textBuffer)
        {
            try
            {
                if (textBuffer == null)
                {
                    throw new ArgumentNullException("textBuffer");
                }

                if (_textLines != null)
                {
                    _textLines.BeginUpdate -= _textLines_BeginUpdate;
                    _textLines.EndUpdate   -= _textLines_EndUpdate;
                }

                _textLines = (NiTextLines)textBuffer;

                if (_textLines != null)
                {
                    Control.Document = _textLines.Document;

                    _textLines.BeginUpdate += _textLines_BeginUpdate;
                    _textLines.EndUpdate   += _textLines_EndUpdate;
                }

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Пример #25
0
            public HResult AddButton(INiTitleBarButton button, out int cookie)
            {
                cookie = 0;

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

                    cookie = _nextCookie++;

                    var wrapper = new TitleBarButton(this, cookie);
                    wrapper.Update(button);

                    _buttonMap.Add(cookie, wrapper);
                    _buttons.Add(wrapper);

                    RebuildButtons();

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Пример #26
0
        public HResult GetSelection(int index, out int startLine, out int startIndex, out int endLine, out int endIndex)
        {
            startLine  = -1;
            startIndex = -1;
            endLine    = -1;
            endIndex   = -1;

            try
            {
                var selection = SelectionManager.SelectionCollection;

                if (index < 0 || index >= selection.Count)
                {
                    throw new ArgumentOutOfRangeException("index");
                }

                var selectionItem = selection[index];

                startLine  = selectionItem.StartPosition.Line;
                startIndex = selectionItem.StartPosition.Column;
                endLine    = selectionItem.EndPosition.Line;
                endIndex   = selectionItem.EndPosition.Column;

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Пример #27
0
        protected override ClassificationNode DoSetItem()
        {
            var nodeToSet      = GetItem <ClassificationNode>();
            var startDate      = GetParameter <DateTime?>(nameof(SetIteration.StartDate));
            var finishDate     = GetParameter <DateTime?>(nameof(SetIteration.FinishDate));
            var structureGroup = GetParameter <TreeStructureGroup>("StructureGroup");

            ErrorUtil.ThrowIfNotFound(nodeToSet, nameof(SetIteration.Node), GetParameter <string>(nameof(SetIteration.Node)));

            var(_, tp) = GetCollectionAndProject();

            var client = GetClient <WorkItemTrackingHttpClient>();

            if (!ShouldProcess(tp, $"Set dates on iteration '{nodeToSet.RelativePath}'"))
            {
                return(null);
            }

            var patch = new WorkItemClassificationNode()
            {
                Attributes = new Dictionary <string, object>()
                {
                    ["startDate"]  = startDate,
                    ["finishDate"] = finishDate
                }
            };

            var result = client.UpdateClassificationNodeAsync(patch, tp.Name, structureGroup, nodeToSet.RelativePath.Substring(1))
                         .GetResult($"Error setting dates on iteration '{nodeToSet.FullPath}'");

            return(new ClassificationNode(result, tp.Name, client));
        }
Пример #28
0
        public override HResult Initialize()
        {
            try
            {
                var hr = base.Initialize();

                if (ErrorUtil.Failure(hr))
                {
                    return(hr);
                }

                // If we were provided an INiTextLines, perform its initialization
                // now. We clear the field to force correct initialization.

                if (_textLines != null)
                {
                    var textLines = _textLines;
                    _textLines = null;
                    return(SetBuffer(textLines));
                }

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Пример #29
0
        private void Publish()
        {
            if (_suppressPublish)
            {
                return;
            }

            _suppressPublish = true;

            try
            {
                NiCommand.Value = Item.Text;

                if (NiCommand.Value != _lastPublished)
                {
                    _lastPublished = NiCommand.Value;

                    var commandManager = (INiCommandManager)_serviceProvider.GetService(typeof(INiCommandManager));

                    object unused;
                    ErrorUtil.ThrowOnFailure(commandManager.Exec(NiCommand.Id, Item.Text, out unused));
                }
            }
            finally
            {
                _suppressPublish = false;
            }
        }
Пример #30
0
        protected override INiIsolationClient CreateWindow()
        {
            var window = new Proxy(this);

            ErrorUtil.ThrowOnFailure(window.Initialize());

            return(window);
        }