Пример #1
0
        internal FiddlerAppContext(ILogger logger)
        {
            _logger = logger;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ApplicationExit += OnApplicationExit;

            FiddlerOptions.SetLogger(_logger);
            FiddlerOptions.Startup();

            _logger.Information("Starting loading profile form...");
            var profile = new LoadProfile {
                TopMost = true
            };
            var profileResult = profile.ShowDialog();

            if (profileResult == DialogResult.Cancel)
            {
                _logger.Information("No profile loaded... exiting.");
                return;
            }

            if (FiddlerOptions.UpdateCheckOnStart)
            {
                _logger.Information("Update check. Current version is {currentVersion}", FiddlerOptions.AppVersion);
                UpdateRunner.RunAsync(FiddlerOptions.RepositoryOwner, FiddlerOptions.RepositoryName, FiddlerOptions.AppVersion, false).GetAwaiter().GetResult();
            }

            _logger.Information("Starting main form...");
            MainForm = new MainForm();
            MainForm.Show();
        }
Пример #2
0
        private void OnDisconnected(object sender, EventArgs eventArgs)
        {
            UpdateRunner.RemoveUpdate(this);

            Status = ClientNetworkStatus.Disconnected;
            m_ClientSocket.OnConnect    -= OnConnected;
            m_ClientSocket.OnReceive    -= OnReceived;
            m_ClientSocket.OnDisconnect -= OnDisconnected;

            m_ClientSocket = null;
        }
Пример #3
0
        /// <summary>
        ///     Updates the database to the specified migration.
        /// </summary>
        /// <param name="targetMigration"> The Id of the migration to migrate to. If null is supplied, the database will be updated to the latest migration. </param>
        /// <param name="force"> Value indicating if data loss during automatic migration is acceptable. </param>
        public void Update(string targetMigration, bool force)
        {
            var runner = new UpdateRunner
            {
                TargetMigration = targetMigration,
                Force           = force
            };

            ConfigureRunner(runner);

            Run(runner);
        }
Пример #4
0
        public UpdatingContext(ILauncherSettings settings, IProgress <UpdateProgress> progress)
        {
            _isDirty          = false;
            _dirtyReasons     = new List <string>();
            _isRepairNeeded   = false;
            Settings          = settings;
            _progressReporter = progress;
            PatchesPath       = new List <PatchDefinition>();

            Runner     = new UpdateRunner();
            Downloader = new FileDownloader();
        }
Пример #5
0
        public bool Disconnect()
        {
            if (m_ClientSocket != null && (Status == ClientNetworkStatus.Connecting || Status == ClientNetworkStatus.Connected))
            {
                UpdateRunner.RemoveUpdate(this);

                Status = ClientNetworkStatus.Disconnecting;
                m_ClientSocket.Disconnect();
                return(true);
            }
            return(false);
        }
Пример #6
0
        public void Dispose()
        {
            eventHandlerDic.Clear();

            if (delayEvents.Count > 0)
            {
                UpdateRunner.RemoveUpdate(this);
            }
            for (int i = delayEvents.Count - 1; i >= 0; --i)
            {
                eventDataPool.Release(delayEvents[i]);
            }
            delayEvents.Clear();
        }
Пример #7
0
        public void Disconnect()
        {
            if (m_serverSocket != null)
            {
                UpdateRunner.RemoveUpdate(this);

                m_serverSocket.OnClientConnect    -= OnClientConnected;
                m_serverSocket.OnClientDisconnect -= OnClientDisconnected;

                m_serverSocket.OnReceive    -= OnReceived;
                m_serverSocket.OnDisconnect -= OnDisconnected;

                if (m_serverSocket.IsConnected)
                {
                    m_serverSocket.Disconnect();
                }

                m_serverSocket = null;
            }
        }
Пример #8
0
        public bool Connect(string ipString, int port)
        {
            if (m_ClientSocket != null)
            {
                return(false);
            }

            m_ClientSocket               = new TcpClientSocket();
            m_ClientSocket.OnConnect    += OnConnected;
            m_ClientSocket.OnReceive    += OnReceived;
            m_ClientSocket.OnDisconnect += OnDisconnected;

            Status = ClientNetworkStatus.Connecting;

            m_ClientSocket.Connect(IPAddress.Parse(ipString), port);

            UpdateRunner.AddUpdate(this);

            return(true);
        }
Пример #9
0
        public void DoUpdate(float deltaTime, float unscaleDeltaTime)
        {
            for (int i = delayEvents.Count - 1; i >= 0; --i)
            {
                EventData eventData = delayEvents[i];
                eventData.DelayTime -= unscaleDeltaTime;
                if (eventData.DelayTime <= 0)
                {
                    TriggerEvent(eventData.Sender, eventData.EventID, -1.0f, eventData.Values);
                    delayEvents.RemoveAt(i);

                    eventDataPool.Release(eventData);
                }
            }

            if (delayEvents.Count == 0)
            {
                UpdateRunner.RemoveUpdate(this);
            }
        }
Пример #10
0
        public void Listen(int port)
        {
            if (m_Port != port && m_serverSocket != null)
            {
                DebugLog.Warning("");
                Disconnect();
            }

            m_Port = port;

            m_serverSocket = new TcpServerSocket();

            m_serverSocket.OnClientConnect    += OnClientConnected;
            m_serverSocket.OnClientDisconnect += OnClientDisconnected;

            m_serverSocket.OnReceive    += OnReceived;
            m_serverSocket.OnDisconnect += OnDisconnected;

            m_serverSocket.Listen(m_Port);

            UpdateRunner.AddUpdate(this);
        }
Пример #11
0
        public void TriggerEvent(SystemObject sender, int eventID, float delayTime, params SystemObject[] values)
        {
            if (delayTime <= 0)
            {
                if (eventHandlerDic.TryGetValue(eventID, out List <EventHandler> handlerList))
                {
                    if (handlerList != null && handlerList.Count > 0)
                    {
                        for (var i = handlerList.Count - 1; i >= 0; --i)
                        {
                            if (handlerList[i] == null)
                            {
                                handlerList.RemoveAt(i);
                            }
                            else
                            {
                                handlerList[i](sender, eventID, values);
                            }
                        }
                    }
                }
            }
            else
            {
                EventData e = eventDataPool.Get();
                e.Sender    = sender;
                e.EventID   = eventID;
                e.DelayTime = delayTime;
                e.Values    = values;
                delayEvents.Add(e);

                if (delayEvents.Count == 1)
                {
                    UpdateRunner.AddUpdate(this);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Updates the database to the specified migration.
        /// </summary>
        /// <param name="targetMigration"> The Id of the migration to migrate to. If null is supplied, the database will be updated to the latest migration. </param>
        /// <param name="force"> Value indicating if data loss during automatic migration is acceptable. </param>
        public void Update(string targetMigration, bool force)
        {
            var runner = new UpdateRunner
                {
                    TargetMigration = targetMigration,
                    Force = force
                };
            ConfigureRunner(runner);

            Run(runner);
        }
Пример #13
0
 private async void OnClickUpdate(object sender, EventArgs e)
 {
     await UpdateRunner.RunAsync(FiddlerOptions.RepositoryOwner, FiddlerOptions.RepositoryName, FiddlerOptions.AppVersion).ConfigureAwait(false);
 }
Пример #14
0
        public ClientSocket(NetworkConfig networkConfig, UpdateRunner updateRunner)
        {
            if (networkConfig == null)
            {
                throw new ArgumentNullException(nameof(networkConfig));
            }

            if (updateRunner == null)
            {
                throw new ArgumentNullException(nameof(updateRunner));
            }

            updateRunner.Add(this);

            _socket = new UdpSocket(sizeof(ulong), networkConfig);
            _socket.HandleConnect += (socketService, rs) => {
                if (rs == null)
                {
                    Logger.Warn("连接失败!");
                    Enqueue(() => {
                        Connected?.Invoke(null, null);
                    });
                    return;
                }

                var length = rs.ShiftRight <ushort>();
                var data   = rs.ShiftRight(length);
                var bytes  = new byte[data.Count];
                Buffer.BlockCopy(data.Buffer, data.Offset, bytes, 0, bytes.Length);

                var buffer = Ssui.Security.DecryptAesKey(bytes, _keys);
                var aesKey = buffer.toString();
                Logger.Debug(aesKey);

                var peer = new Peer(_socket, aesKey);

                socketService.HandleDisconnect += () => {
                    Enqueue(() => {
                        Disconnected?.Invoke(peer);
                    });
                };

                socketService.HandleRead += (readStream) => {
                    // remote
                    var remoteMessageId = readStream.ShiftRight <ulong>();
                    var newReadStream   = readStream.Clone();
                    Ssui.Security.DecryptAES(newReadStream, aesKey);
                    Enqueue(() => {
                        RpcProxy.Invoke(remoteMessageId, newReadStream, peer);
                        newReadStream.Dispose();
                    });
                };

                socketService.HandleAcknowledge += (state, readStream) => {
                    var newReadStream = readStream.Clone();

                    var localMessageId = readStream.ShiftRight <ulong>();
                    Enqueue(() => {
                        peer.Acknowledge(state, localMessageId);
                        newReadStream.Dispose();
                    });
                };
                socketService.HandleError += error => Enqueue(() => Logger.Error(error));
                socketService.HandleWrite += (isSuccess) => {
                    Enqueue(() => {
                        if (!isSuccess)
                        {
                            Logger.Warn("发送失败!");
                        }
                    });
                };

                var newRs = rs.Clone();
                Enqueue(() => {
                    peer.SetStatus(ConnectionStatus.Connected, socketService);
                    Connected?.Invoke(peer, newRs);
                    newRs.Dispose();
                });
            };
        }