Ejemplo n.º 1
0
        /// <summary>
        /// Start a task.
        /// </summary>
        public void Start()
        {
            if (IsRunning || IsFinished)
            {
                return;
            }
            IsRunning = true;

            CurrentSegment = -1;
            if (startThread != null)
            {
                startThread.Abort();
            }
            startThread = new Thread(delegate()
            {
                while (!Analysis())
                {
                    for (int i = 5; i > 0; i--)
                    {
                        StatusUpdate?.Invoke(this, 0, i, Status.AnalysisFailed);
                        Thread.Sleep(1000);
                    }
                }
                CurrentSegment = 0;
                Segments[CurrentSegment].Start();
                StartProgressMonitor();
                startThread = null;
            });
            startThread.Start();
        }
Ejemplo n.º 2
0
        private async Task RunStatusMonitorAsync(CancellationToken token)
        {
            try
            {
                while (!token.IsCancellationRequested)
                {
                    string eth0, wlan0, hostName;
                    GetNetworkProperties(out eth0, out wlan0, out hostName);

                    BrainHatServerStatus status = new BrainHatServerStatus()
                    {
                        HostName     = hostName,
                        Eth0Address  = eth0,
                        Wlan0Address = wlan0,
                        TimeStamp    = DateTimeOffset.UtcNow,
                    };

                    StatusUpdate?.Invoke(this, new BrainHatStatusEventArgs(status));

                    await Task.Delay(2000);
                }
            }
            catch (OperationCanceledException)
            { }
            catch (Exception e)
            {
                Log?.Invoke(this, new LogEventArgs(this, "RunStatusMonitorAsync", e, LogLevel.ERROR));
            }
        }
Ejemplo n.º 3
0
        private void ContentFilesDownloadFinished(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                var message = Localization.GetText("GameUpdater.Message.CannotReadContentFile");

#pragma warning disable CS0162
                if (LauncherSetup.IS_CHANGELOG_HTML)
                {
                    //only wrap in HTML if we already expect an HTML document
                    message = message.WrapAsHTML();
                }
#pragma warning restore CS0162

                ChangelogLoaded?.Invoke(message);
                UpdateFailed?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                if (File.Exists("content.changes"))
                {
                    ChangelogLoaded?.Invoke(File.ReadAllText("content.changes"));
                }
                StatusUpdate?.Invoke(Localization.GetText("GameUpdater.Status.CheckingLocalFiles"));
                GameVersionDetected?.Invoke(contentFile.GameVersion);

                fileCheckWorker                     = new BackgroundWorker();
                fileCheckWorker.DoWork             += CheckFiles;
                fileCheckWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.CheckFilesFinished);
                fileCheckWorker.RunWorkerAsync();
            }
        }
Ejemplo n.º 4
0
        private void Segment_Finished()
        {
            if (CurrentSegment < Segments.Count - 1)
            {
                CurrentSegment++;
                Segments[CurrentSegment].Start();
            }
            else
            {
                AbortProgressMonitor();
                ProgressPercentage = 100;
                StatusUpdate?.Invoke(this, ProgressPercentage, 0, Status.Merging);
                string directory = Path.Combine(ConfigManager.GetSettings().DownloadPath, FilenameValidation(string.Format("[{0}]{1}", Description, Title)));
                Directory.CreateDirectory(directory);
                string filename = FilenameValidation($"{Index}-{Part}");
                string filepath = Path.Combine(directory, $"{filename}.{Segments[0].Extention}");

                // valid path length
                if (filepath.Length > MAX_PATH - 1)     // Reserve 1 char for <NULL>
                {
                    int truncateCount = filepath.Length - (MAX_PATH - 1);
                    if (truncateCount > filename.Length - 1)     // Least 1 char for filename
                    {
                        // Should never occur
                        throw new Exception($"无法创建合法文件名,截断失败: {filename} (截断计数: {truncateCount})");
                    }
                    filename = filename.Substring(0, filename.Length - truncateCount);
                    filepath = directory + $"{filename}.{Segments[0].Extention}";
                }

                int      count = Segments.Count;
                string[] paths = new string[count];
                for (int i = 0; i < count; i++)
                {
                    paths[i] = Segments[i].Filepath;
                }

                if (MergeRequired)
                {
                    FlvUtil.FlvMerge(paths, filepath);
                }
                else
                {
                    File.Copy(Segments[0].Filepath, filepath, true);
                }


                foreach (string path in paths)
                {
                    File.Delete(path);
                }
                IsFinished = true;
                IsRunning  = false;
                StatusUpdate?.Invoke(this, 100, 0, Status.Finished);

                DownloadFinishedNotification.SendNotification(this, filepath);

                Finished?.Invoke(this, filepath);
            }
        }
Ejemplo n.º 5
0
        private static void DevicePoll_Received(List <C4UFX.CANMessage> responses)
        {
            StatusUpdate?.Invoke("Querying names (1/3)...");


            foreach (C4UFX.CANMessage response in responses)
            {
                FndTnd address = CANInterface.IdToFndTnd(response.ID);
                if (address.FromDevice > 0)
                {
                    Node   currentNode = allResponses.First(x => x.NodeId == address.FromNode);
                    byte   fromNode    = CANInterface.IdToFndTnd(response.ID).FromNode;
                    byte   fromDevice  = CANInterface.IdToFndTnd(response.ID).FromDevice;
                    Device newDevice;
                    switch ((Signatures)response.Data[2])
                    {
                    case Signatures.MechanicalSwitch: newDevice = new MechanicalSwitch(fromNode, fromDevice); break;

                    case Signatures.StatusLED: newDevice = new StatusLED(fromNode, fromDevice); break;

                    case Signatures.InfraredInput: newDevice = new InfraredInput(fromNode, fromDevice); break;

                    case Signatures.DimmerOut: newDevice = new DimmerOut(fromNode, fromDevice); break;

                    case Signatures.LatLong: newDevice = new LatLong(fromNode, fromDevice); break;

                    case Signatures.TimerEvent: newDevice = new TimerEvent(fromNode, fromDevice); break;

                    case Signatures.Scene: newDevice = new Scene(fromNode, fromDevice); break;

                    case Signatures.RealTimeClock: newDevice = new RealTimeClock(fromNode, fromDevice); break;

                    default: newDevice = new UnknownDevice(fromNode, fromDevice); break;
                    }

                    currentNode.Devices.Add(newDevice);
                }
            }

            Dictionary <byte, List <byte> > sendList = new Dictionary <byte, List <byte> >();

            foreach (Node node in allResponses)
            {
                if (sendList.Keys.Contains(node.NodeId))
                {
                    break;
                }
                sendList.Add(node.NodeId, new List <byte>());
                for (byte i = 1; i < 127; i++)
                {
                    sendList[node.NodeId].Add(i);
                }
            }

            CANPing poll = new CANPing(Commands.CmdSysEName1, sendList);

            poll.ResponseReceived += Name1Poll_Received;
            PongsReceived?.Invoke(allResponses, false);
        }
Ejemplo n.º 6
0
        private bool Analysis()
        {
            StatusUpdate?.Invoke(ProgressPercentage, 0, Status.Analyzing);
            Segments = new List <Segment>();
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("avid", Aid.ToString());
            dic.Add("cid", Cid.ToString());
            dic.Add("qn", Qn.ToString());
            try
            {
                IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/x/player/playurl", dic, false);
                if (json.GetValue("code").ToLong() == 0)
                {
                    if (json.GetValue("data").GetValue("quality").ToLong() == Qn)
                    {
                        foreach (IJson v in json.GetValue("data").GetValue("durl"))
                        {
                            Segment segment = new Segment(Aid, Regex.Unescape(v.GetValue("url").ToString()), SegmentType.Mixed, v.GetValue("size").ToLong(), Threads);
                            segment.Finished += Segment_Finished;
                            Segments.Add(segment);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    json = BiliApi.GetJsonResult("http://api.bilibili.com/pgc/player/web/playurl", dic, false);
                    if (json.GetValue("code").ToLong() == 0)
                    {
                        if (json.GetValue("result").GetValue("quality").ToLong() == Qn)
                        {
                            foreach (IJson v in json.GetValue("result").GetValue("durl"))
                            {
                                Segment segment = new Segment(Aid, Regex.Unescape(v.GetValue("url").ToString()), SegmentType.Mixed, v.GetValue("size").ToLong(), Threads);
                                segment.Finished += Segment_Finished;
                                Segments.Add(segment);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (WebException)
            {
                return(false);
            }
        }
Ejemplo n.º 7
0
        private void ContentFilesDownload(object sender, DoWorkEventArgs e)
        {
            StatusUpdate?.Invoke(Localization.GetText("GameUpdater.Status.DownloadingIndexFiles"));
            WebClient webClient = Helpers.BuildWebClient();

            if (File.Exists("content.xml"))
            {
                File.Delete("content.xml");
            }
            if (File.Exists("content.version"))
            {
                File.Delete("content.version");
            }
            if (File.Exists("content.changes"))
            {
                File.Delete("content.changes");
            }

            try
            {
                webClient.DownloadFile(LauncherSetup.FTP_GAME_CONTENT_FILE, "content.xml");
            }
            catch
            {
                Logger.Log($"{Localization.GetText("GameUpdater.Log.FailedToDownload")} \"content.xml\"");
            }

            try
            {
                webClient.DownloadFile(LauncherSetup.FTP_GAME_VERSION_FILE, "content.version");
            }
            catch
            {
                Logger.Log($"{Localization.GetText("GameUpdater.Log.FailedToDownload")} \"content.version\"");
            }

            try
            {
                webClient.DownloadFile(LauncherSetup.FTP_GAME_CHANGES_FILE, "content.changes");
            }
            catch
            {
                Logger.Log($"{Localization.GetText("GameUpdater.Log.FailedToDownload")} \"content.changes\"");
            }

            contentFile = HashGenerator.ContentFile.FromFile(HashGenerator.RootDirectory.CombinePath("content.xml"));
            if (contentFile != null)
            {
                return;
            }

            MessageBox.Show(Localization.GetText("GameUpdater.Error.CannotReadContentFile"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            e.Cancel = true;
        }
 private void UpdateStatus(string message, bool logDebug = false)
 {
     if (logDebug)
     {
         LogDebug(message);
     }
     else
     {
         LogTrace(message);
     }
     StatusUpdate?.Invoke(this, new StatusChangedEventArgs(message));
 }
Ejemplo n.º 9
0
 public void Hit(int strength, Character attacker)
 {
     Health -= strength;
     if (Health <= 0)
     {
         StatusUpdate?.Invoke($"Was that really necessary?", Color.Red);
         Objects.Remove(this);
         new Poof(GridX, GridY);
         Game.GameStep -= Game_GameStep;
         StatusUpdate  -= Game.UpdateStatus;
     }
 }
        protected virtual void OnStatusUpdate(UninstallHandlerUpdateArgs e)
        {
            // Filter out repeated updates
            if (Equals(_previousArgs, e))
            {
                return;
            }
            _previousArgs = e;

            StatusUpdate?.Invoke(this, e);
            Console.WriteLine(e.Message);
        }
Ejemplo n.º 11
0
 public Dorf(int gridX, int gridY, Egg egg) : base(gridX, gridY)
 {
     speed        = egg.Speed;
     isMale       = Game.R.Next(2) == 0;
     generation   = egg.Generation;
     health       = stamina = 100;
     hunger       = egg.Hunger;
     strength     = egg.Strength;
     intelligence = egg.Intelligence;
     radiation    = egg.Radiation;
     StatusUpdate?.Invoke($"{name} was born!", Color.Navy);
     BasicInitialization();
 }
Ejemplo n.º 12
0
        private static void NodePoll_PollReceived(List <C4UFX.CANMessage> responses)
        {
            if (responses.Count == 0)
            {
                StatusUpdate?.Invoke("No Nodes found - Check your connection.");
                return;
            }

            StatusUpdate?.Invoke("Pinging devices...");

            foreach (C4UFX.CANMessage response in responses)
            {
                byte fromNode = CANInterface.IdToFndTnd(response.ID).FromNode;
                Node newNode;
                switch ((Signatures)response.Data[2])
                {
                case Signatures.SmartSwitch: newNode = new SmartSwitch(fromNode); break;

                case Signatures.ACDimmer: newNode = new ACDimmer(fromNode); break;

                case Signatures.TimerRTC: newNode = new TimerRTC(fromNode); break;

                case Signatures.SceneController: newNode = new SceneController(fromNode); break;

                default: newNode = new UnknownNode(fromNode); break;
                }

                allResponses.Add(newNode);
            }

            Dictionary <byte, List <byte> > sendList = new Dictionary <byte, List <byte> >();

            foreach (Node node in allResponses)
            {
                if (sendList.Keys.Contains(node.NodeId))
                {
                    break;
                }
                sendList.Add(node.NodeId, new List <byte>());
                for (byte i = 1; i < 127; i++)
                {
                    sendList[node.NodeId].Add(i);
                }
            }

            CANPing poll = new CANPing(Commands.CmdSysPing, sendList);

            poll.ResponseReceived += DevicePoll_Received;
            PongsReceived?.Invoke(allResponses, false);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Reduces health by the specified damage, and checks for death.
 /// </summary>
 /// <param name="damage">The damage.</param>
 /// <param name="reason">The reason (phrased as "(name) has died from (reason)...").</param>
 /// <returns>Whether the predator has died from the damage.</returns>
 private bool Hurt(double damage)
 {
     Health -= damage;
     if (Health <= 0)
     {
         StatusUpdate?.Invoke($"You have neutralized a predator.", Color.DarkGreen);
         Characters.Remove(this);
         new Poof(GridX, GridY); //Yeah, sure
         Game.GameStep -= Step;
         StatusUpdate  -= Game.UpdateStatus;
         return(true);
     }
     return(false);
 }
Ejemplo n.º 14
0
 public void SendUpdate(PipelineStatus status)
 {
     if (_completedTasks == 0)
     {
         StatusUpdate?.Invoke(
             new PipelineUpdate(status, 0.0));
     }
     else
     {
         var progress = _completedTasks / _numberOfTasks * 100;
         StatusUpdate?.Invoke(
             new PipelineUpdate(status, progress));
     }
 }
Ejemplo n.º 15
0
 public void Execute()
 {
     Status = "Executing";
     StatusUpdate?.Invoke(this, new EventArgs());
     if (_task())
     {
         Status = "Success";
         StatusUpdate?.Invoke(this, new EventArgs());
     }
     else
     {
         Status = "Failed";
         StatusUpdate?.Invoke(this, new EventArgs());
     }
 }
Ejemplo n.º 16
0
        private async void Current_StateChangedAndroid(object sender, MediaManager.Playback.StateChangedEventArgs e)
        {
            if (_playerInfo != null)
            {
                if (_seekToCurrentTC && e.State == MediaPlayerState.Playing)
                {
                    await CrossMediaManager.Current.SeekTo(TimeSpan.FromSeconds(_playerInfo.Position.CurrentTC));

                    _seekToCurrentTC = false;
                }

                _playerInfo.Status = e.State;
                StatusUpdate?.Invoke(_playerInfo);
            }
        }
Ejemplo n.º 17
0
        private static void Name1Poll_Received(List <C4UFX.CANMessage> responses)
        {
            StatusUpdate?.Invoke("Querying names (2/3)...");

            foreach (C4UFX.CANMessage response in responses)
            {
                FndTnd address  = CANInterface.IdToFndTnd(response.ID);
                string namePart = string.Empty;
                for (int i = 1; i < response.Data.Length; i++)
                {
                    namePart += (char)response.Data[i];
                }

                Node thisNode = allResponses.Find(x => x.NodeId == address.FromNode);
                //if (thisNode == null)
                //    allResponses.Add(new UnknownNode(address.FromNode));

                if (address.FromDevice == 0)
                {
                    allResponses.Find(x => x.NodeId == address.FromNode).SetNamePart(namePart, 1);
                }
                else
                {
                    allResponses.Find(x => x.NodeId == address.FromNode).Devices.Find(x => x.DeviceId == address.FromDevice).SetNamePart(namePart, 1);
                }
                //If the node/device isn't found, add it to the list
            }

            Dictionary <byte, List <byte> > sendList = new Dictionary <byte, List <byte> >();

            foreach (Node node in allResponses)
            {
                if (sendList.Keys.Contains(node.NodeId))
                {
                    break;
                }
                sendList.Add(node.NodeId, new List <byte>());
                foreach (Device device in node.Devices)
                {
                    sendList[node.NodeId].Add(device.DeviceId);
                }
            }

            CANPing poll = new CANPing(Commands.CmdSysEName2, sendList);

            poll.ResponseReceived += Name2Poll_Received;
            PongsReceived?.Invoke(allResponses, false);
        }
Ejemplo n.º 18
0
        public static void PollNetwork()
        {
            StatusUpdate?.Invoke("Pinging nodes...");

            Dictionary <byte, List <byte> > sendList = new Dictionary <byte, List <byte> >();

            for (byte i = 1; i < 127; i++)
            {
                sendList.Add(i, new List <byte>());
            }

            CANPing nodePoll = new CANPing(Commands.CmdSysPing, sendList);

            nodePoll.ResponseReceived += NodePoll_PollReceived;
            PongsReceived?.Invoke(allResponses, false);
        }
Ejemplo n.º 19
0
        private void CheckFilesFinished(object sender, RunWorkerCompletedEventArgs e)
        {
            if (corruptFiles.Count > 0)
            {
                ReportDownloadStatus();

                fileUpdateWorker                     = new BackgroundWorker();
                fileUpdateWorker.DoWork             += UpdateFiles;
                fileUpdateWorker.RunWorkerCompleted += UpdateFilesFinished;
                fileUpdateWorker.RunWorkerAsync();
            }
            else
            {
                StatusUpdate?.Invoke(Localization.GetText("GameUpdater.Status.Finished"));
                UpdateFinished?.Invoke(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 20
0
        private void Segment_Finished()
        {
            if (CurrentSegment < Segments.Count - 1)
            {
                CurrentSegment++;
                Segments[CurrentSegment].Start();
            }
            else
            {
                AbortProgressMonitor();
                ProgressPercentage = 100;
                StatusUpdate?.Invoke(this, ProgressPercentage, 0, Status.Merging);
                string directory = ConfigManager.GetSettings().DownloadPath + "\\" + string.Format("[{0}]{1}", Description, Title) + "\\";
                Directory.CreateDirectory(directory);
                string filepath = directory + FilenameValidation(string.Format("[{0}]{1}_{2}-{3}.{4}", Description, Title, Index, Part, Segments[0].Extention));

                int      count = Segments.Count;
                string[] paths = new string[count];
                for (int i = 0; i < count; i++)
                {
                    paths[i] = Segments[i].Filepath;
                }

                if (MergeRequired)
                {
                    FlvUtil.FlvMerge(paths, filepath);
                }
                else
                {
                    File.Copy(Segments[0].Filepath, filepath, true);
                }


                foreach (string path in paths)
                {
                    File.Delete(path);
                }
                IsFinished = true;
                IsRunning  = false;
                StatusUpdate?.Invoke(this, 100, 0, Status.Finished);

                DownloadFinishedNotification.SendNotification(this, filepath);

                Finished?.Invoke(this, filepath);
            }
        }
Ejemplo n.º 21
0
        private void UpdateFilesFinished(object sender, RunWorkerCompletedEventArgs e)
        {
            if (File.Exists("content.xml"))
            {
                File.Delete("content.xml");
            }
            if (File.Exists("content.version"))
            {
                File.Delete("content.version");
            }
            if (File.Exists("content.changes"))
            {
                File.Delete("content.changes");
            }

            StatusUpdate?.Invoke(Localization.GetText("GameUpdater.Status.Finished"));
            UpdateFinished?.Invoke(this, EventArgs.Empty);
        }
Ejemplo n.º 22
0
        private static void Name3Poll_Received(List <C4UFX.CANMessage> responses)
        {
            StatusUpdate?.Invoke("Querying parameters (1/2)...");

            foreach (C4UFX.CANMessage response in responses)
            {
                FndTnd address  = CANInterface.IdToFndTnd(response.ID);
                string namePart = string.Empty;
                for (int i = 1; i < response.Data.Length; i++)
                {
                    namePart += (char)response.Data[i];
                }

                if (address.FromDevice == 0)
                {
                    allResponses.First(x => x.NodeId == address.FromNode).SetNamePart(namePart, 3);
                }
                else
                {
                    allResponses.First(x => x.NodeId == address.FromNode).Devices.First(x => x.DeviceId == address.FromDevice).SetNamePart(namePart, 3);
                }
            }

            Dictionary <byte, List <byte> > sendList = new Dictionary <byte, List <byte> >();

            foreach (Node node in allResponses)
            {
                if (sendList.Keys.Contains(node.NodeId))
                {
                    break;
                }
                sendList.Add(node.NodeId, new List <byte>());
                foreach (Device device in node.Devices)
                {
                    sendList[node.NodeId].Add(device.DeviceId);
                }
            }

            CANPing poll = new CANPing(Commands.CmdSysEPar, sendList);

            poll.ResponseReceived += Parameters1_Received;
            PongsReceived?.Invoke(allResponses, false);
        }
Ejemplo n.º 23
0
 private void Segment_Finished()
 {
     if (CurrentSegment < Segments.Count - 1)
     {
         CurrentSegment++;
         Segments[CurrentSegment].Download();
     }
     else
     {
         AbortProgressMonitor();
         ProgressPercentage = 100;
         StatusUpdate?.Invoke(ProgressPercentage, 0, Status.Merging);
         string directory = Bili_dl.SettingPanel.settings.DownloadPath + "\\";
         Directory.CreateDirectory(directory);
         if (Segments.Count > 1)
         {
             List <string> paths = new List <string>();
             foreach (Segment segment in Segments)
             {
                 paths.Add(segment.Filepath);
             }
             Flv.Merge(paths, directory + FilenameValidation(string.Format("[{0}]{1}_{2}-{3}.flv", Description, Title, Index, Part)));
             foreach (string path in paths)
             {
                 File.Delete(path);
             }
         }
         else
         {
             FileStream fileStreamInput  = new FileStream(Segments[0].Filepath, FileMode.Open);
             FileStream fileStreamOutput = new FileStream(directory + FilenameValidation(string.Format("[{0}]{1}_{2}-{3}.flv", Description, Title, Index, Part)), FileMode.Create);
             fileStreamInput.CopyTo(fileStreamOutput);
             fileStreamInput.Close();
             fileStreamOutput.Close();
             File.Delete(Segments[0].Filepath);
         }
         IsFinished = true;
         IsRunning  = false;
         StatusUpdate?.Invoke(100, 0, Status.Finished);
         Finished?.Invoke(this);
     }
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Reduces health by the specified damage, and checks for death.
 /// </summary>
 /// <param name="damage">The damage.</param>
 /// <param name="reason">The reason (phrased as "[name] has died from [reason]...").</param>
 /// <returns>Whether the dorf has died from the damage.</returns>
 private bool Hurt(double damage, string reason)
 {
     Health -= damage;
     if (Health <= 0)
     {
         Amount--;
         Characters.Remove(this);
         StatusUpdate?.Invoke($"{name} has died from {reason}...", Color.Red);
         if (Amount == 0)
         {
             StatusUpdate?.Invoke($"GENOCIDE: There are no Dorfs left!", Color.DarkRed);
         }
         new Poof(GridX, GridY);
         new SoundPlayer(Properties.Resources.death).Play();
         Game.GameStep -= Step;
         StatusUpdate  -= Game.UpdateStatus;
         return(true);
     }
     return(false);
 }
Ejemplo n.º 25
0
        protected async Task <string> PerformDownloadAsync(string proposedDownloadFilePath, Func <Progress <DownloadProgress>, Task <string> > func)
        {
            var progress = new Progress <DownloadProgress>();

            progress.ProgressChanged += (_, e) => DownloadProgressChanged?.Invoke(this, e);

            DownloadBegin?.Invoke(this, proposedDownloadFilePath);

            try
            {
                var result = await func(progress);

                StatusUpdate?.Invoke(this, result);

                return(result);
            }
            finally
            {
                DownloadCompleted?.Invoke(this, proposedDownloadFilePath);
            }
        }
Ejemplo n.º 26
0
        private static void Parameters1_Received(List <C4UFX.CANMessage> responses)
        {
            StatusUpdate?.Invoke("Querying parameters (2/2)...");

            foreach (C4UFX.CANMessage response in responses)
            {
                FndTnd address = CANInterface.IdToFndTnd(response.ID);
                for (int i = 0; i < response.DLC - 1; i++)
                {
                    if (address.FromDevice == 0)
                    {
                        allResponses.First(x => x.NodeId == address.FromNode).Parameters1[i] = response.Data[i + 1];
                    }
                    else
                    {
                        allResponses.First(x => x.NodeId == address.FromNode).Devices.First(x => x.DeviceId == address.FromDevice).Parameters1[i] = response.Data[i + 1];
                    }
                }
            }

            Dictionary <byte, List <byte> > sendList = new Dictionary <byte, List <byte> >();

            foreach (Node node in allResponses)
            {
                if (sendList.Keys.Contains(node.NodeId))
                {
                    break;
                }
                sendList.Add(node.NodeId, new List <byte>());
                foreach (Device device in node.Devices)
                {
                    sendList[node.NodeId].Add(device.DeviceId);
                }
            }

            CANPing poll = new CANPing(Commands.CmdSysEPar2, sendList);

            poll.ResponseReceived += Parameters2_Received;
            PongsReceived?.Invoke(allResponses, false);
        }
Ejemplo n.º 27
0
        private void ProgressMonitor()
        {
            long total = 0;

            foreach (Segment segment in Segments)
            {
                total += segment.Length;
            }
            long downloadedLast = 0;

            foreach (Segment segment in Segments)
            {
                foreach (Segment.DownloadThread thread in segment.DownloadThreads)
                {
                    downloadedLast += thread.Position;
                }
            }
            while (true)
            {
                long downloaded = 0;
                foreach (Segment segment in Segments)
                {
                    if (segment.IsFinished)
                    {
                        downloaded += segment.Length;
                    }
                    else
                    {
                        foreach (Segment.DownloadThread thread in segment.DownloadThreads)
                        {
                            downloaded += thread.Position;
                        }
                    }
                }
                StatusUpdate?.Invoke((double)downloaded / total * 100, downloaded - downloadedLast, Status.Downloading);
                downloadedLast = downloaded;
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 28
0
        private static void Parameters2_Received(List <C4UFX.CANMessage> responses)
        {
            StatusUpdate?.Invoke("Poll Complete!");

            foreach (C4UFX.CANMessage response in responses)
            {
                FndTnd address = CANInterface.IdToFndTnd(response.ID);
                for (int i = 0; i < response.DLC - 1; i++)
                {
                    if (address.FromDevice == 0)
                    {
                        allResponses.First(x => x.NodeId == address.FromNode).Parameters2[i] = response.Data[i + 1];
                    }
                    else
                    {
                        allResponses.First(x => x.NodeId == address.FromNode).Devices.First(x => x.DeviceId == address.FromDevice).Parameters2[i] = response.Data[i + 1];
                    }
                }
            }

            Dictionary <byte, List <byte> > sendList = new Dictionary <byte, List <byte> >();

            foreach (Node node in allResponses)
            {
                if (sendList.Keys.Contains(node.NodeId))
                {
                    break;
                }
                sendList.Add(node.NodeId, new List <byte>());
                foreach (Device device in node.Devices)
                {
                    sendList[node.NodeId].Add(device.DeviceId);
                }
            }

            PongsReceived?.Invoke(allResponses, true);
        }
Ejemplo n.º 29
0
 private void ReportDownloadStatus()
 {
     StatusUpdate?.Invoke($"{Localization.GetText("GameUpdater.Status.DownloadingNeededFiles")} ({filesUpdated}/{corruptFiles.Count})");
     ProgressUpdate?.Invoke(filesUpdated, corruptFiles.Count);
 }
Ejemplo n.º 30
0
 public static void UpdateStatus(string status, System.Drawing.Color color)
 {
     StatusUpdate?.Invoke(status, color);
 }