コード例 #1
0
        protected override void OnError(ErrorEventArgs e)
        {
            _serverSocket.OnUpdateEvent -= Update;

            _serverSocket.ExecuteOnUpdate(() =>
            {
                OnErrorEvent?.Invoke(e.Message);
            });
        }
コード例 #2
0
            protected override void OnError(ErrorEventArgs e)
            {
                _serverSocket.OnUpdate -= Update;

                _serverSocket.ExecuteOnUpdate(() =>
                {
                    if (OnErrorEvent != null)
                        OnErrorEvent.Invoke(e.Message);
                });
            }
コード例 #3
0
 /// <inheritdoc />
 protected override void OnError(SocketError error)
 {
     try
     {
         OnErrorEvent?.Invoke(error);
     }
     catch (Exception ex)
     {
         Debug.LogException(ex);
     }
 }
コード例 #4
0
ファイル: WonderCard.cs プロジェクト: LucasMbele/7-wonders
 public override void UseRequest()
 {
     if (Data.CanBuildCurrentStep(LocalPlayer))
     {
         var action = new WonderCardBuildAction(this);
         GameManager.Instance.PlayerActionRequest(action);
     }
     else
     {
         OnErrorEvent.TriggerEvents("Not enough money"); // TODO
     }
 }
コード例 #5
0
        partial void ProcessEachCommandError(CommandError error)
        {
            var ctx = context;

            if (ctx is null)
            {
                throw new InvalidOperationException("context should be set");
            }

            if (status == TsClientStatus.Connecting)
            {
                ChangeState(ctx, TsClientStatus.Disconnected, error);
            }
            else
            {
                OnErrorEvent?.Invoke(this, error);
            }
        }
コード例 #6
0
ファイル: BaseCrawler.cs プロジェクト: adysoft/quasar
        public List <Screenshot> SyncScreenshots()
        {
            List <Screenshot> synced = new List <Screenshot>();

            try
            {
                int pageCount        = GetNumberOfPagesOnline();
                int startPage        = Math.Max(GetNumberOfPagesOffline(), 1);
                int pagesToProcessed = pageCount - startPage + 1;
                int processedPage    = 0;
                for (int i = Math.Max(startPage, 1); i <= pageCount; i++)
                {
                    try
                    {
                        string page = GetPageUrlAtIndex(i);
                        if (ThreadDownloadProgressEvent != null)
                        {
                            double progress = (processedPage++) / (double)pagesToProcessed;
                            ThreadDownloadProgressEvent(page, progress * 100);
                        }

                        var pageDirectory  = Path.Combine(Settings.RootDirectory, $"page-{i}");
                        var screenshotUrls = GetScreenshotUrls(page);
                        synced = DownloadScreenshots(screenshotUrls.Item2, pageDirectory, page, screenshotUrls.Item1, Settings.TempRootDirectory);
                    }
                    catch (Exception e)
                    {
                        OnErrorEvent?.Invoke(new Exception($"Error when processing page ${i}", e));
                        break;
                    }
                    finally
                    {
                        ThreadSyncedEvent?.Invoke(Settings.Name);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                ThreadSyncedEvent?.Invoke(Settings.Name);
            }

            return(synced);
        }
コード例 #7
0
ファイル: Client.cs プロジェクト: esmelov/SimpleTCPChat
 private void _async_recieve_data()
 {
     try
     {
         while (IsRunning)
         {
             string[] recieveMessages = ReceiveData();
             if (recieveMessages.Length > 0)
             {
                 IncomingMessageEvent?.Invoke(this, recieveMessages);
             }
             Thread.Sleep(10);
         }
     }
     catch (Exception ex)
     {
         OnErrorEvent?.Invoke(this, ex);
     }
 }
コード例 #8
0
        partial void ProcessEachCommandError(CommandError error)
        {
            bool skipError  = false;
            bool disconnect = false;

            lock (statusLock)
            {
                if (status == TsClientStatus.Connecting)
                {
                    disconnect = true;
                    skipError  = true;
                }
            }

            if (disconnect)
            {
                DisconnectInternal(context, error, TsClientStatus.Disconnected);
            }
            if (!skipError)
            {
                OnErrorEvent?.Invoke(this, error);
            }
        }
コード例 #9
0
ファイル: BaseCrawler.cs プロジェクト: adysoft/quasar
        protected List <Screenshot> DownloadScreenshots(ReadOnlyCollection <string> screenshotUrls, string targetDirectory, string page, string pageSource, string tempDirectory)
        {
            var screenshots = new List <Screenshot>();

            if (!Directory.Exists(targetDirectory))
            {
                Directory.CreateDirectory(targetDirectory);
            }

            var cached = new HashSet <string>(Directory.GetFiles(Settings.RootDirectory, "*.*", SearchOption.AllDirectories).Select(Path.GetFileNameWithoutExtension));

            foreach (string screenshotUrl in screenshotUrls)
            {
                try
                {
                    string hashCode   = $"{screenshotUrl.GetHashCode():X}";
                    string ext        = Path.GetExtension(screenshotUrl);
                    string fileName   = hashCode + ext;
                    string cachedFile = Path.Combine(Settings.CacheDirectory, fileName);
                    if (!cached.Contains(hashCode))
                    {
                        DownloadingScreenshotEvent?.Invoke(screenshotUrl);
                        WebClient webClient = new WebClient();
                        webClient.Headers.Add("user-agent", "Quasar");
                        var data = webClient.DownloadData(screenshotUrl);
                        if (String.IsNullOrEmpty(ext) || ext.Length > 4)
                        {
                            if (IsJpeg(data))
                            {
                                ext        = ".jpg";
                                fileName   = hashCode + ext;
                                cachedFile = Path.Combine(Settings.CacheDirectory, fileName);
                            }
                            else if (IsPng(data))
                            {
                                ext        = ".png";
                                fileName   = hashCode + ext;
                                cachedFile = Path.Combine(Settings.CacheDirectory, fileName);
                            }
                            else
                            {
                                OnErrorEvent?.Invoke(new Exception($"Unknown file format: {screenshotUrl}"));
                            }
                        }

                        File.WriteAllBytes(cachedFile, data);
                        GetImageSize(cachedFile, out var width, out var height);
                        if (height * width > 1027 * 768)
                        {
                            string targetFile = Path.Combine(targetDirectory, fileName);
                            string tempFile   = Path.Combine(tempDirectory, fileName);
                            if (!File.Exists(targetFile))
                            {
                                File.Copy(cachedFile, targetFile);
                                if (!File.Exists(tempFile))
                                {
                                    File.Copy(targetFile, tempFile);
                                }

                                string thumbnailsDirectory = Path.Combine(tempDirectory, "thumbnails");
                                if (!Directory.Exists(thumbnailsDirectory))
                                {
                                    Directory.CreateDirectory(thumbnailsDirectory);
                                }

                                string thumbnailPath = Path.Combine(thumbnailsDirectory, fileName);
                                ImageProcessing.MakeThumbnail(targetFile, thumbnailPath);
                                File.Delete(cachedFile);
                                var screenshot = new Screenshot {
                                    LocalPath = targetFile, TempPath = tempFile, ThumbnailPath = thumbnailPath, Url = screenshotUrl, ThreadPost = GetScreenshotAnchorUrl(page, pageSource, screenshotUrl)
                                };
                                screenshots.Add(screenshot);
                                ScreenshotDownloaded?.Invoke(screenshot);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    OnErrorEvent?.Invoke(new Exception($"Failed to download {screenshotUrl}", e));
                }
            }

            return(screenshots);
        }
コード例 #10
0
ファイル: Ts3FullClient.cs プロジェクト: sertsch1/TS3AudioBot
        private void InvokeEvent(LazyNotification lazyNotification)
        {
            var notification = lazyNotification.Notifications;

            switch (lazyNotification.NotifyType)
            {
            case NotificationType.ChannelCreated: break;

            case NotificationType.ChannelDeleted: break;

            case NotificationType.ChannelChanged: break;

            case NotificationType.ChannelEdited: break;

            case NotificationType.ChannelMoved: break;

            case NotificationType.ChannelPasswordChanged: break;

            case NotificationType.ClientEnterView: OnClientEnterView?.Invoke(this, notification.Cast <ClientEnterView>()); break;

            case NotificationType.ClientLeftView:
                var clientLeftArr = notification.Cast <ClientLeftView>().ToArray();
                var leftViewEvent = clientLeftArr.FirstOrDefault(clv => clv.ClientId == packetHandler.ClientId);
                if (leftViewEvent != null)
                {
                    packetHandler.ExitReason = leftViewEvent.Reason;
                    DisconnectInternal(context, setStatus: Ts3ClientStatus.Disconnected);
                    break;
                }
                OnClientLeftView?.Invoke(this, clientLeftArr);
                break;

            case NotificationType.ClientMoved: OnClientMoved?.Invoke(this, notification.Cast <ClientMoved>()); break;

            case NotificationType.ServerEdited: break;

            case NotificationType.TextMessage: OnTextMessageReceived?.Invoke(this, notification.Cast <TextMessage>()); break;

            case NotificationType.TokenUsed: break;

            // full client events
            case NotificationType.InitIvExpand: { var result = lazyNotification.WrapSingle <InitIvExpand>(); if (result.Ok)
                                                  {
                                                      ProcessInitIvExpand(result.Value);
                                                  }
            } break;

            case NotificationType.InitIvExpand2: { var result = lazyNotification.WrapSingle <InitIvExpand2>(); if (result.Ok)
                                                   {
                                                       ProcessInitIvExpand2(result.Value);
                                                   }
            } break;

            case NotificationType.InitServer: { var result = lazyNotification.WrapSingle <InitServer>(); if (result.Ok)
                                                {
                                                    ProcessInitServer(result.Value);
                                                }
            } break;

            case NotificationType.ChannelList: break;

            case NotificationType.ChannelListFinished: ChannelSubscribeAll(); break;

            case NotificationType.ClientNeededPermissions: break;

            case NotificationType.ClientChannelGroupChanged: break;

            case NotificationType.ClientServerGroupAdded: break;

            case NotificationType.ConnectionInfo: break;

            case NotificationType.ConnectionInfoRequest: ProcessConnectionInfoRequest(); break;

            case NotificationType.ChannelSubscribed: break;

            case NotificationType.ChannelUnsubscribed: break;

            case NotificationType.ClientChatComposing: break;

            case NotificationType.ServerGroupList: break;

            case NotificationType.ClientServerGroup: break;

            case NotificationType.FileUpload: break;

            case NotificationType.FileDownload: break;

            case NotificationType.FileTransfer: break;

            case NotificationType.FileTransferStatus: break;

            case NotificationType.FileList: break;

            case NotificationType.FileListFinished: break;

            case NotificationType.FileInfoTs: break;

            case NotificationType.ChannelGroupList: break;

            case NotificationType.PluginCommand: { var result = lazyNotification.WrapSingle <PluginCommand>(); if (result.Ok)
                                                   {
                                                       ProcessPluginRequest(result.Value);
                                                   }
            } break;

            // special
            case NotificationType.CommandError:
            {
                var result = lazyNotification.WrapSingle <CommandError>();
                var error  = result.Ok ? result.Value : Util.CustomError("Got empty error while connecting.");

                bool skipError  = false;
                bool disconnect = false;
                lock (statusLock)
                {
                    if (status == Ts3ClientStatus.Connecting)
                    {
                        disconnect = true;
                        skipError  = true;
                    }
                }

                if (disconnect)
                {
                    DisconnectInternal(context, error, Ts3ClientStatus.Disconnected);
                }
                if (!skipError)
                {
                    OnErrorEvent?.Invoke(this, error);
                }
            }
            break;

            case NotificationType.Unknown:
            default: throw Util.UnhandledDefault(lazyNotification.NotifyType);
            }
        }
コード例 #11
0
        private void InvokeEvent(LazyNotification lazyNotification)
        {
            var notification = lazyNotification.Notifications;

            switch (lazyNotification.NotifyType)
            {
            case NotificationType.ChannelCreated: break;

            case NotificationType.ChannelDeleted: break;

            case NotificationType.ChannelChanged: break;

            case NotificationType.ChannelEdited: break;

            case NotificationType.ChannelMoved: break;

            case NotificationType.ChannelPasswordChanged: break;

            case NotificationType.ClientEnterView: OnClientEnterView?.Invoke(this, notification.Cast <ClientEnterView>()); break;

            case NotificationType.ClientLeftView:
                var clientLeftArr = notification.Cast <ClientLeftView>().ToArray();
                var leftViewEvent = clientLeftArr.FirstOrDefault(clv => clv.ClientId == packetHandler.ClientId);
                if (leftViewEvent != null)
                {
                    packetHandler.ExitReason = leftViewEvent.Reason;
                    lock (statusLock)
                    {
                        status = Ts3ClientStatus.Disconnected;
                        DisconnectInternal(context);
                    }
                    break;
                }
                OnClientLeftView?.Invoke(this, clientLeftArr);
                break;

            case NotificationType.ClientMoved: OnClientMoved?.Invoke(this, notification.Cast <ClientMoved>()); break;

            case NotificationType.ServerEdited: break;

            case NotificationType.TextMessage: OnTextMessageReceived?.Invoke(this, notification.Cast <TextMessage>()); break;

            case NotificationType.TokenUsed: break;

            // full client events
            case NotificationType.InitIvExpand: ProcessInitIvExpand((InitIvExpand)notification.FirstOrDefault()); break;

            case NotificationType.InitServer: ProcessInitServer((InitServer)notification.FirstOrDefault()); break;

            case NotificationType.ChannelList: break;

            case NotificationType.ChannelListFinished: try { ChannelSubscribeAll(); } catch (Ts3CommandException) { } break;

            case NotificationType.ClientNeededPermissions: break;

            case NotificationType.ClientChannelGroupChanged: break;

            case NotificationType.ClientServerGroupAdded: break;

            case NotificationType.ConnectionInfo: break;

            case NotificationType.ConnectionInfoRequest: ProcessConnectionInfoRequest(); break;

            case NotificationType.ChannelSubscribed: break;

            case NotificationType.ChannelUnsubscribed: break;

            case NotificationType.ClientChatComposing: break;

            case NotificationType.ServerGroupList: break;

            case NotificationType.ServerGroupsByClientId: break;

            case NotificationType.StartUpload: break;

            case NotificationType.StartDownload: break;

            case NotificationType.FileTransfer: break;

            case NotificationType.FileTransferStatus: break;

            case NotificationType.FileList: break;

            case NotificationType.FileListFinished: break;

            case NotificationType.FileInfo: break;

            // special
            case NotificationType.Error:
                lock (statusLock)
                {
                    if (status == Ts3ClientStatus.Connecting)
                    {
                        status = Ts3ClientStatus.Disconnected;
                        DisconnectInternal(context, false);
                    }
                }

                OnErrorEvent?.Invoke(this, (CommandError)notification.First());
                break;

            case NotificationType.Unknown:
            default: throw Util.UnhandledDefault(lazyNotification.NotifyType);
            }
        }
コード例 #12
0
        protected override Task OnError(Exception exception, ConsumeResult <string, string> result)
        {
            OnErrorEvent.Invoke(exception, result);

            return(Task.CompletedTask);
        }
コード例 #13
0
 private void RaiseOnError(OnErrorEventArgs args)
 {
     OnErrorEvent?.Invoke(this, args);
 }
コード例 #14
0
 protected void RaiseOnError(OnErrorExportSharedBufferEventArgs args)
 {
     OnErrorEvent?.Invoke(args);
 }
コード例 #15
0
 /// <summary>
 /// 引发<see cref="OnErrorEvent"/>事件
 /// </summary>
 /// <param name="args"></param>
 public void OnError(OnErrorEventArgs args)
 {
     OnErrorEvent?.Invoke(this, args);
 }
コード例 #16
0
 private void OnError(int errorId, CommandDto command, string errorMsg)
 {
     OnErrorEvent?.Invoke(errorId, command, errorMsg);
 }
コード例 #17
0
 protected void RaiseOnError(OnErrorEventArgs args)
 {
     OnErrorEvent?.Invoke(this, args);
 }
コード例 #18
0
 public void OnError(Exception error)
 {
     OnErrorEvent?.Invoke(error);
 }