Пример #1
0
 void writeConfigure(ContractManufacture cm, JUULProject p, DeviceStation ds, bool legacy, DateTime dt)
 {
     string[] content = new string[] {
         $"CM: {cm.ToString()}",
         $"project: {p.ToString()}",
         $"station: {ds.ToString()}",
         legacy?"legacy: 1":"legacy: 0",
         $"triggertime_auto: {triggertime_auto.Hour.ToString("D2")}-{triggertime_auto.Minute.ToString("D2")}-{triggertime_auto.Second.ToString("D2")}",
         $"history_backup_datetime: {dt.ToString("yyyy-MM-dd-HH-mm-ss")}"
     };
     File.WriteAllLines(sConfigureFilePath, content);
     Log($"Write the configure file, CM: {cm.ToString()}," +
         $" project: {p.ToString()}," +
         $" station: {ds.ToString()}," +
         $"legacy SW: {legacySW.ToString()}, " +
         $"trigger time: {triggertime_auto.ToString("HH-mm-ss")}" +
         $" history backup time: {dt.ToString("yyyy-MM-dd-HH-mm-ss")}.");
 }
        public Dictionary <string, List <string> > GetServerLogList(DeviceStation station)
        {
            Dictionary <string, List <string> > serverLogList = new Dictionary <string, List <string> >();
            string rootfolder = Path.Combine(sNetworkShareRootFolder, station.ToString(), Environment.MachineName);

            if (!Directory.Exists(rootfolder))
            {
                createDirectory(rootfolder);
            }
            string[] subfolderspath = Directory.GetDirectories(rootfolder, "*-*-*", SearchOption.TopDirectoryOnly);
            foreach (string subfolderfullpath in subfolderspath)
            {
                string        subfoldername = subfolderfullpath.Split('\\').Last();
                string[]      filespath     = Directory.GetFiles(subfolderfullpath, "*.txt", SearchOption.TopDirectoryOnly);
                List <string> files         = new List <string>();
                foreach (string onefilepath in filespath)
                {
                    string onefilename = onefilepath.Split('\\').Last();
                    files.Add(onefilename);
                }
                serverLogList.Add(subfoldername, files);
            }
            return(serverLogList);
        }
Пример #3
0
        public MainForm()
        {
            InitializeComponent();
            this.Text += " by Shawn Zhang @ JUUL Labs, version - " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            Show();

            createDirectory(@"D:\temp");
            createDirectory(sTempRootFolder);
            LogWriter = File.AppendText(Path.Combine(sTempRootFolder, "BackupLog.txt"));
            Log("Backup thread starts.");

            if (loadConfigure())
            {
                lCMName.Text      = CMName.ToString();
                lProjectName.Text = project.ToString();
                lStationName.Text = station.ToString();
            }
            else
            {
                CMName   = ContractManufacture.AFG;
                project  = JUULProject.Jagwar;
                station  = DeviceStation.FCT;
                legacySW = false;
                writeConfigure(CMName, project, station, legacySW, DateTime.Now.AddYears(-1));
                MessageBox.Show("The config.ini file is generated. Please correct the setting and restart the tool.");
                return;
            }
            switch (station)
            {
            case DeviceStation.ICP:
                sTestDataRootFolder = sICPDataRootFolder;
                break;

            case DeviceStation.FCT:
                sTestDataRootFolder = sFCTDataRootFolder;
                break;

            case DeviceStation.SFG:
                sTestDataRootFolder = sSFGDataRootFolder;
                break;

            case DeviceStation.FG00:
                sTestDataRootFolder = sFG00DataRootFolder;
                break;

            case DeviceStation.FG24:
                sTestDataRootFolder = sFG24DataRootFolder;
                break;

            case DeviceStation.Charger:
                sTestDataRootFolder = sChargerDataRootFolder;
                break;

            default:
                break;
            }

            sNetworkShareFolder_CM                                   = Path.Combine(sNetworkShareRootFolder, CMName.ToString());
            sNetworkShareFolder_CM_Project                           = Path.Combine(sNetworkShareFolder_CM, project.ToString());
            sNetworkShareFolder_CM_Project_Station                   = Path.Combine(sNetworkShareFolder_CM_Project, station.ToString());
            sNetworkShareFolder_CM_Project_Station_Automatic         = Path.Combine(sNetworkShareFolder_CM_Project_Station, BackupMode.Automatic.ToString());
            sNetworkShareFolder_CM_Project_Station_Automatic_Log     = Path.Combine(sNetworkShareFolder_CM_Project_Station_Automatic, "Log");
            sNetworkShareFolder_CM_Project_Station_Automatic_Summary = Path.Combine(sNetworkShareFolder_CM_Project_Station_Automatic, "Summary");
            sNetworkShareFolder_CM_Project_Station_Manual            = Path.Combine(sNetworkShareFolder_CM_Project_Station, BackupMode.Manual.ToString());
            sNetworkShareFolder_CM_Project_Station_Manual_Log        = Path.Combine(sNetworkShareFolder_CM_Project_Station_Manual, "Log");
            sNetworkShareFolder_CM_Project_Station_Manual_Summary    = Path.Combine(sNetworkShareFolder_CM_Project_Station_Manual, "Summary");

            try
            {
                InitializeFolders();

                //Set the mode as automatic mode by default.
                rbAuto.Checked      = true;
                dtpStartDate.Format = DateTimePickerFormat.Time;
                dtpStartDate.Value  = triggertime_auto;
                btStartBackup_Click(new object(), new EventArgs());
                this.WindowState = FormWindowState.Minimized;
                this.MainForm_Resize(new object(), new EventArgs());
            }
            catch (Exception ex)
            {
                UILog("Error: " + ex.Message);
                Log("Error: " + ex.Message);
            }
        }
        bool loadConfigure()
        {
            if (!File.Exists(sConfigureFilePath))
            {
                return(false);
            }
            string[] configFileLines = File.ReadAllLines(sConfigureFilePath);
            foreach (string oneline in configFileLines)
            {
                string[] s = oneline.Split(':');
                string   n = s[0].Trim();
                string   v = s[1].Trim();
                switch (n)
                {
                case "CM":
                    bool match = Enum.TryParse <ContractManufacture>(v, out CMName);
                    if (!match)
                    {
                        Log($"The contract manufacture name {v} is invalid. It should be AFG or Pegatron.");
                        return(false);
                    }
                    break;

                case "station":
                    match = Enum.TryParse <DeviceStation>(v, out station);
                    if (!match)
                    {
                        Log($"The station name {v} is invalid. It should be ICP, FCT, SFG, FG00, FG24 or Charger.");
                        return(false);
                    }
                    break;

                case "RootFolder":
                    if (v.ToUpper() == "ONLINE")
                    {
                        onlineMode    = true;
                        logRootFolder = @"D:\Online";
                    }
                    else
                    {
                        if (v.ToUpper() == "OFFLINE")
                        {
                            onlineMode    = false;
                            logRootFolder = @"D:\Offline";
                        }
                        else
                        {
                            Log($"The parameter {v} is invalid. It should be online or offline, case insensitive.");
                            return(false);
                        }
                    }

                    break;

                default:
                    break;
                }
            }
            try
            {
                Log($"Load configuration successfully, CM: {CMName.ToString()}," +
                    $"station: {station.ToString()}, " +
                    $"test log rootfolder is online: {onlineMode.ToString()}.");
            }
            catch
            {
                return(false);
            }
            return(true);
        }