Пример #1
0
        private void ProcessDossierFile()
        {
            System.Diagnostics.Stopwatch digSW = new Stopwatch();
            digSW.Start();
            GC.Collect();
            try
            {
                _messages.Add("Info : Refreshing Dossier File (" + GetPlayerName + ")");

                string     tempFile   = Guid.NewGuid().ToString();
                FTPDetails ftpDetails = new FTPDetails();
                if (ftpDetails.AllowFTP && _fetchFromFTP == false)
                {
                    try //we only attempting to upload if it fails bad luc k
                    {
                        Task.Factory.StartNew(() => new FTPTools().Upload(ftpDetails.Host, _dossierFilePath, ftpDetails.UserID, ftpDetails.UserPWD, _messages, GetPlayerName));
                    }
                    catch { _messages.Add(String.Format("Error : File failed submitting to FTP site. [{0}]", GetPlayerName)); }
                }

                //if (UserSettings.AllowVBAddictUpload && _fetchFromFTP == false)
                //{
                //    try
                //    {
                //        //disable until we can resolve issue with upload
                //       //Task.Factory.StartNew(() => new VBAddictUpload().UploadToVBAddict(_dossierFilePath, GetPlayerName, _messages));
                //    }
                //    catch {}
                //}

                if (UserSettings.Cloud_Allow)
                {
                    string cloudPath = UserSettings.Cloud_Path;
                    if (Directory.Exists(cloudPath))
                    {
                        FileInfo fi = new FileInfo(_dossierFilePath);
                        if (string.Compare(Path.Combine(cloudPath, fi.Name), _dossierFilePath, true) != 0)
                        {
                            try
                            {
                                File.Copy(_dossierFilePath, Path.Combine(cloudPath, fi.Name), true);
                            }
                            catch (Exception ex)
                            {
                                _messages.Add(String.Format("Error : File failed to copy to sharing folder. [{0}] - {1}", GetPlayerName, ex.Message));
                            }
                        }
                        fi = null;
                    }
                }

                string dossierFilePath = "";
                bool   markDSForDelete = false;
                if (ftpDetails.AllowFTP && _fetchFromFTP)
                {
                    try
                    {
                        dossierFilePath = new FTPTools().Download(ftpDetails.Host, _dossierFilePath, ftpDetails.UserID, ftpDetails.UserPWD, _messages, GetPlayerName);
                        markDSForDelete = true;
                    }
                    catch
                    {
                        dossierFilePath = _dossierFilePath;
                        _messages.Add(String.Format("Error : Failed Retrieving file from FTP. Default back to local cache file [{0}]", GetPlayerName));
                    }
                }
                else
                {
                    dossierFilePath = _dossierFilePath;
                }

                //start dosier decrypt
                Process process = new Process();

//#if DEBUG
//                process.StartInfo.CreateNoWindow = false;
//                process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
//#else
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
//#endif

                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardOutput = true;

                process.StartInfo.WorkingDirectory = WOTHelper.GetPythonDirectory();
                process.StartInfo.FileName         = WOTHelper.GetPythonDirectory() + "\\" + WOTHelper.GetPythonFile();
                process.StartInfo.Arguments        = String.Format(@"""{0}"" -s -t", dossierFilePath.Replace(@"\", @"\\"));
                //WOTHelper.AddToLog(process.StartInfo.WorkingDirectory);
                //WOTHelper.AddToLog(process.StartInfo.FileName);
                //WOTHelper.AddToLog(process.StartInfo.Arguments);

                try
                {
                    process.Start();
                }
                catch
                {
                    _messages.Add("Error starting WOTDC2J.");
                }


                string file = process.StandardOutput.ReadToEnd();

                //WOTHelper.AddToLog("OUT: " + file);

                process.WaitForExit();
                process.Dispose();


                //string file = File.ReadAllText(String.Format("{0}\\{1}", WOTHelper.GetTempFolder(), tempFile));
                //File.Delete(String.Format("{0}\\{1}", WOTHelper.GetTempFolder(), tempFile));


                if (markDSForDelete)
                {
                    File.Delete(dossierFilePath);
                }

                try
                {
                    string       fileName     = DateTime.Now.AddHours(UserSettings.TimeAdjustment).ToString("yyyyMMdd");
                    dynamic      obj_testfile = Newtonsoft.Json.JsonConvert.DeserializeObject(file);
                    MemoryTables mt           = new MemoryTables(WOTHelper.GetDBPath(_playerName));
                    mt.Fill(obj_testfile, int.Parse(fileName));

                    if (IsNewestFile(fileName, mt))
                    {
                        //string fileName = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(unixTimeStamp).AddHours(TimeZoneInfo.Local.BaseUtcOffset.Hours).AddHours(AppSettings.TimeAdjustment).ToString("yyyyMMdd");
                        CreateRecentBattle(mt);
                        SaveFile(fileName, mt);

                        file = null;
                        //lastPlayed.Clear();
                        LoadDossierFiles();
                        OnCurrentFileChange(EventArgs.Empty);
                    }
                    //((IDisposable)obj).Dispose();
                }
                catch (Exception ex)
                {
                    _messages.Add("Error : Unable to parse json (" + GetPlayerName + ") - " + ex.Message);
                }
            }
            catch (Exception ex)
            {
                _messages.Add("Error : Refreshing Dossier File (" + GetPlayerName + ") - " + ex.Message);
                try
                {
                    LoadDossierFiles();
                    OnCurrentFileChange(EventArgs.Empty);
                }
                catch (Exception ex1)
                {
                    _messages.Add("Error : Refreshing Dossier File (" + GetPlayerName + ") - " + ex1.Message);
                }
            }
            _messages.Add("Info : Dossier file refreshed successfully. (" + GetPlayerName + ")");
            digSW.Stop();
            _messages.Add("Diagnostics : Dossier Processing Finished in " + digSW.ElapsedMilliseconds + " miliseconds");
        }