Example #1
0
        public static void SendLogsToServer()
        {
            // check for logs that didnt make it (either new or failed last time)
            string logPath = Path.Combine(GetAppFolder(), LogFolder);

            // should do them in the right order
            var logs = Directory.EnumerateFiles(logPath);

            List <string> failures = new List <string>();

            FuHttp h = new FuHttp();

            if (!h.Login(Cfg.getEncrypted("HttpUsername"), Cfg.getEncrypted("HttpPassword")))
            {
                //MessageBox.Show("There was a problem with your Fu Website credentials");
                return;
            }

            foreach (string log in logs)
            {
                string fname   = log;
                string logFile = Path.GetFileName(log);
                if (logFile.StartsWith("COMPLETE_") || logFile.StartsWith("INCOMPLETE_"))
                {
                    // already finished, skip
                }
                else
                {
                    try
                    {
                        string response = h.UploadLog(fname);
                        if (response.ToLower() == "success")
                        {
                            string newFilePath = Path.Combine(Path.GetDirectoryName(fname), String.Format("COMPLETE_{0}", Path.GetFileName(fname)));
                            System.IO.File.Move(fname, newFilePath);
                        }
                        else
                        {
                            string newFilePath = Path.Combine(Path.GetDirectoryName(fname), String.Format("INCOMPLETE_{0}", Path.GetFileName(fname)));
                            System.IO.File.Move(fname, newFilePath);
                            failures.Add(response);
                        }
                    } catch (Exception e) {
                        string newFilePath = Path.Combine(Path.GetDirectoryName(fname), String.Format("INCOMPLETE_{0}", Path.GetFileName(fname)));
                        System.IO.File.Move(fname, newFilePath);
                        failures.Add(e.Message);
                    }
                }
            }

            if (failures.Count > 0)
            {
                MessageBox.Show("Transmission error(s)!" + Environment.NewLine + String.Join(Environment.NewLine, failures.ToArray()));
            }
        }