protected override void OnError(ErrorEventArgs e)
            {
                _serverSocket.OnUpdate -= Update;

                _serverSocket.ExecuteOnUpdate(() =>
                {
                    if (OnErrorEvent != null)
                        OnErrorEvent.Invoke(e.Message);
                });
            }
Пример #2
0
        partial void ProcessEachCommandError(CommandError error)
        {
            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);
            }
        }
 protected void RaiseOnError(OnErrorEventArgs args)
 {
     OnErrorEvent?.Invoke(this, args);
 }
Пример #4
0
        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);
        }
Пример #5
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;
                    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);
            }
        }
Пример #6
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);
            }
        }
Пример #7
0
        protected override Task OnError(Exception exception, ConsumeResult <string, string> result)
        {
            OnErrorEvent.Invoke(exception, result);

            return(Task.CompletedTask);
        }
Пример #8
0
 protected void RaiseOnError(OnErrorExportSharedBufferEventArgs args)
 {
     OnErrorEvent?.Invoke(args);
 }
Пример #9
0
 /// <summary>
 /// 引发<see cref="OnErrorEvent"/>事件
 /// </summary>
 /// <param name="args"></param>
 public void OnError(OnErrorEventArgs args)
 {
     OnErrorEvent?.Invoke(this, args);
 }
Пример #10
0
 private void OnError(int errorId, CommandDto command, string errorMsg)
 {
     OnErrorEvent?.Invoke(errorId, command, errorMsg);
 }
Пример #11
0
 private void RaiseOnError(OnErrorEventArgs args)
 {
     OnErrorEvent?.Invoke(this, args);
 }
Пример #12
0
 public void OnError(Exception error)
 {
     OnErrorEvent?.Invoke(error);
 }