Esempio n. 1
0
        private void toolBar_Click(Object obj, ToolStripItemClickedEventArgs args)
        {
            string imgKey = args.ClickedItem.ImageKey;

            if ("Zoom In".Equals(imgKey, StringComparison.CurrentCultureIgnoreCase))
            {
                ImageZoom(ZoomSize.ZoomIn);
            }
            else if ("Zoom Out".Equals(imgKey, StringComparison.CurrentCultureIgnoreCase))
            {
                ImageZoom(ZoomSize.ZoomOut);
            }
            else if ("Rotate Left".Equals(imgKey, StringComparison.CurrentCultureIgnoreCase))
            {
                ImageFlip(FlipDirection.Left);
            }
            else if ("Rotate Right".Equals(imgKey, StringComparison.CurrentCultureIgnoreCase))
            {
                ImageFlip(FlipDirection.Right);
            }
            else if ("Save".Equals(imgKey, StringComparison.CurrentCultureIgnoreCase))
            {
                SaveToFile();
            }
            else if ("Publish".Equals(imgKey, StringComparison.CurrentCultureIgnoreCase))
            {
                Publish();
            }
            else if ("Print".Equals(imgKey, StringComparison.CurrentCultureIgnoreCase))
            {
                PrintImage();
            }
            else if ("Cancel".Equals(imgKey, StringComparison.CurrentCultureIgnoreCase))
            {
                CancelOperation();
            }
            else if ("Exit".Equals(imgKey, StringComparison.CurrentCultureIgnoreCase))
            {
                if (exitDelegate != null)
                {
                    exitDelegate.Invoke();
                }
            }
            else if ("Transmit".Equals(imgKey, StringComparison.CurrentCultureIgnoreCase))
            {
                if (transDelegate != null)
                {
                    transDelegate.Invoke();
                }
            }
        }
Esempio n. 2
0
        private async Task SendMessageAsync(Func <Stream, Task> writer)
        {
            var transformIterator = ((IEnumerable <IMiddleware>)_middleware).Reverse().GetEnumerator();
            TransmitDelegate transformDelegator = null;

            transformDelegator = async transformedStream =>
            {
                if (transformIterator.MoveNext())
                {
                    using (_logger?.Tracer($"Middleware[{transformIterator.Current.GetType()}].SendAsync(...)"))
                    {
                        await transformIterator.Current.SendAsync(transformedStream, transformDelegator).ConfigureAwait(false);
                    }
                }
                else
                {
                    await writer(transformedStream).ConfigureAwait(false);
                }
            };

            await _writeLock.WaitAsync();

            try
            {
                using (var writeStream = _clientWebSocket.GetWriteStream())
                {
                    await transformDelegator
                    .Invoke(writeStream)
                    .ContinueWith(async task =>
                    {
                        // Dispose first before handling return state
                        transformIterator.Dispose();

                        // Unwrap and allow the outer exception handler to handle this case
                        task.WaitAndUnwrapException();
                    })
                    .ConfigureAwait(false);
                }
            }
            finally
            {
                _writeLock.Release();
            }
        }