public static void Doit(DSreplays Data, ScanStateChange stateChange, StartUp _startUp, int cores = 2) { source = new CancellationTokenSource(); token = source.Token; _empty = new ManualResetEvent(false); CORES = cores; Scan.Done = 0; Failed = new List <string>(); Console.WriteLine("Engine start."); s2dec.DEBUG = _startUp.Conf.Debug; s2dec.JsonFile = Program.myJson_file; s2dec.REPID = Data.ID; s2dec.ReplayFolder = Data.ReplayFolder; s2dec.LoadEngine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); //s2dec.LoadEngine(); s2dec.END = new DateTime(); s2dec.START = DateTime.UtcNow; stateChange.Update = !stateChange.Update; int total = 0; lock (Data.Todo) { _jobs_decode = new BlockingCollection <string>(); foreach (var ent in Data.Todo) { try { _jobs_decode.Add(ent); } catch (OperationCanceledException) { break; } total++; } } s2dec.TOTAL = total; Scan.Total = total; s2dec.TOTAL_DONE = 0; Scan.Info = s2dec.TOTAL_DONE + "/" + s2dec.TOTAL + " done. (0%)"; for (int i = 0; i < CORES; i++) { Thread thread = new Thread(OnHandlerStart) { IsBackground = true }; //Mark 'false' if you want to prevent program exit until jobs finish thread.Start(); } Task tsscan = Task.Factory.StartNew(() => { int i = 0; while (!_empty.WaitOne(1000)) { double twr = 0; if (s2dec.TOTAL > 0) { twr = (double)s2dec.TOTAL_DONE * 100 / (double)s2dec.TOTAL; } Scan.Done = Math.Round(twr, 2); string bab = s2dec.TOTAL_DONE + "/" + s2dec.TOTAL + " done. (" + Scan.Done.ToString() + "%)"; Scan.Info = bab; Console.Write("\r{0} ", bab); if (_jobs_decode.Count() == 0) { i++; if (!s2dec.END.Equals(DateTime.MinValue) || i > 20) { break; } } stateChange.Update = !stateChange.Update; } /* * Console.WriteLine("\r " + s2dec.TOTAL + "/" + s2dec.TOTAL + " done. (100%)"); * Console.WriteLine("Jobs done."); * Scan.Info = s2dec.TOTAL + "/" + s2dec.TOTAL + " done. (100%)"; * Scan.Done = 100; */ double wr = 0; if (s2dec.TOTAL > 0) { wr = (double)s2dec.TOTAL_DONE * 100 / (double)s2dec.TOTAL; } Scan.Done = Math.Round(wr, 2); string info = s2dec.TOTAL_DONE + "/" + s2dec.TOTAL + " done. (" + Scan.Done.ToString() + "%)"; Scan.Info = info; Scan.Running = false; Elapsed = s2dec.END - s2dec.START; if (s2dec.THREADS > 0) { int j = 0; while (s2dec.THREADS > 0 || j > 60) { Thread.Sleep(250); j++; } } Reload(Data); Failed = new List <string>(s2dec.REDO.Keys.ToList()); stateChange.Update = !stateChange.Update; }, TaskCreationOptions.AttachedToParent); }
public DSreplays(StartUp startUp, IDSdata_cache dsdata) { _startUp = startUp; _dsdata = dsdata; Init(); }
public static bool AutoUpload(StartUp startUp, DSreplays dsData) { string hash = "UndEsWarSommer"; string hash2 = "UndEsWarWinter"; using (SHA256 sha256Hash = SHA256.Create()) { string names = String.Join(";", startUp.Conf.Players); hash = GetHash(sha256Hash, names); hash2 = GetHash(sha256Hash, Program.myJson_file); } var client = new RestClient("https://www.pax77.org:9146"); //var client = new RestClient("https://192.168.178.28:9001"); //var client = new RestClient("http://192.168.178.28:9000"); //var client = new RestClient("http://localhost:5000"); //var client = new RestClient("https://localhost:44315"); List <dsreplay> temp = new List <dsreplay>(dsData.Replays); string lastrep = ""; if (temp.Count > 0) { lastrep = temp.OrderByDescending(o => o.GAMETIME).First().GAMETIME.ToString().Substring(0, 14); } DSinfo info = new DSinfo(); info.Name = hash; info.Json = hash2; info.LastRep = lastrep; info.LastUpload = startUp.Conf.LastUpload; info.Total = dsData.Replays.Count; info.Version = startUp.Conf.Version; var restRequest = new RestRequest("/secure/data/autoinfo", Method.POST); restRequest.RequestFormat = DataFormat.Json; restRequest.AddHeader("Authorization", "DSupload77"); restRequest.AddJsonBody(info); var response = client.Execute(restRequest); if (response != null && response.StatusCode == System.Net.HttpStatusCode.OK) { if (response.Content.Contains("UpToDate")) { return(true); } else { lastrep = response.Content; } } else { return(false); } lastrep = new String(lastrep.Where(Char.IsDigit).Take(14).ToArray()); double dlastrep = 0; try { dlastrep = Double.Parse(lastrep); } catch { return(false); } if (dlastrep == 0 || startUp.Conf.FullSend == true) { temp = new List <dsreplay>(dsData.Replays); } else { temp = new List <dsreplay>(dsData.Replays.Where(x => x.GAMETIME > dlastrep).ToList()); } List <string> anonymous = new List <string>(); foreach (dsreplay replay in temp) { Dictionary <string, string> plbackup = new Dictionary <string, string>(); foreach (dsplayer pl in replay.PLAYERS) { string plname = pl.NAME; if (startUp.Conf.Players.Contains(pl.NAME)) { pl.NAME = "player"; } else { pl.NAME = "player" + pl.REALPOS.ToString(); } plbackup[pl.NAME] = plname; } anonymous.Add(JsonConvert.SerializeObject(replay)); foreach (dsplayer pl in replay.PLAYERS) { if (plbackup.ContainsKey(pl.NAME)) { pl.NAME = plbackup[pl.NAME]; } } } string exp_csv = Program.workdir + "\\export.json"; if (!File.Exists(exp_csv)) { File.Delete(exp_csv); } File.WriteAllLines(exp_csv, anonymous); string exp_csv_gz = exp_csv + ".gz"; using (FileStream fileToBeZippedAsStream = new FileInfo(exp_csv).OpenRead()) { using (FileStream gzipTargetAsStream = new FileInfo(exp_csv_gz).Create()) { using (GZipStream gzipStream = new GZipStream(gzipTargetAsStream, CompressionMode.Compress)) { try { fileToBeZippedAsStream.CopyTo(gzipStream); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } } if (startUp.Conf.FullSend == true) { restRequest = new RestRequest("/secure/data/fullsend/" + hash); } else { restRequest = new RestRequest("/secure/data/autoupload/" + hash); } restRequest.RequestFormat = DataFormat.Json; restRequest.Method = Method.POST; restRequest.AddHeader("Authorization", "DSupload77"); restRequest.AddFile("content", exp_csv_gz); response = client.Execute(restRequest); if (response.StatusCode == System.Net.HttpStatusCode.OK) { if (startUp.Conf.FullSend == true) { startUp.Conf.FullSend = false; startUp.Save(); } return(true); } else { return(false); } }
public DSotf(StartUp startUp, DSreplays dsData, ScanStateChange scanState) { _startUp = startUp; _dsData = dsData; _scanState = scanState; }
public static bool Upload(StartUp startUp, DSreplays dsData) { return(AutoUpload(startUp, dsData)); }