Esempio n. 1
0
        bool login_task(string u, string p)
        {
            bool ret = false;

            try
            {
                string dir = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "hydra");
                System.IO.File.Delete(System.IO.Path.Combine(dir, "HydraLogin.xml"));
                string exe   = System.IO.Path.Combine(dir, "HydraLogin.exe");
                string param = $"-u={u} -p={p}";
                if (System.IO.File.Exists(exe))
                {
                    System.Collections.Specialized.StringDictionary envs = new System.Collections.Specialized.StringDictionary();
                    envs.Add("APSTHOME", System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA"));
                    //Tuple<int, string[]> res = Program.run_exe(@"c:\windows\system32\notepad.exe", param, envs);
                    Tuple <int, string[]> res = Program.run_exe(exe, param, envs);
                    if (res.Item1 == 0)
                    {
                        if (System.IO.File.Exists(System.IO.Path.Combine(dir, "HydraLogin.xml")))
                        {
                            utility.IniFile config = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "config.ini"));
                            // load xml
                            try
                            {
                                XmlDocument doc = new XmlDocument();
                                doc.Load(System.IO.Path.Combine(dir, "HydraLogin.xml"));
                                string uid = doc.DocumentElement?["id"]?.InnerText;
                                config.WriteValue("config", "uid", uid);
                                // clear ini device section
                                utility.IniFile ini = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "aviaDevice.ini"));
                                ini.DeleteSection("device");
                                // OE Control start
                                //OEControl.start();
                                ret = true;
                            }
                            catch (Exception) { }
                        }
                    }
                    else
                    {
                        this.Invoke(new Action(() =>
                        {
                            labelLoginStatus.Text    = $"Fail to login, error code: {res.Item1}";
                            labelLoginStatus.Visible = true;
                        }));
                    }
                }
            }
            catch (Exception)
            { }
            finally
            {
                this.Invoke(new Action(() =>
                {
                    this.UseWaitCursor = false;
                    this.Enabled       = true;
                }));
            }
            return(ret);
        }
Esempio n. 2
0
        private void MyApplicationContext_ThreadExit(object sender, EventArgs e)
        {
            Program.logIt("MyApplicationContext_ThreadExit: ++");
            //throw new NotImplementedException();
            // kill ui
            utility.IniFile config = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "config.ini"));
            string          s      = config.GetString("ui", "app", @"evaoi-3.1.0.3\evaoi-3.1.0.3.exe");

            s = System.IO.Path.GetFileNameWithoutExtension(s);
            Process[] p = Process.GetProcessesByName(s);
            if (p.Length > 0)
            {
                try
                {
                    p[0].Kill();
                }
                catch (Exception) { }
            }
            // kill server
            {
                s = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "avia", "FDPhoneRecognition.exe");
                Process ui = new Process();
                ui.StartInfo.FileName         = s;
                ui.StartInfo.Arguments        = "-kill-tcpserver";
                ui.StartInfo.UseShellExecute  = false;
                ui.StartInfo.CreateNoWindow   = true;
                ui.StartInfo.WindowStyle      = ProcessWindowStyle.Hidden;
                ui.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(s);
                ui.Start();
            }
            Program.logIt("MyApplicationContext_ThreadExit: --");
        }
Esempio n. 3
0
        static Process start_app()
        {
            Process p = null;

            try
            {
                utility.IniFile config = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "Avia", "config.ini"));
                string          app    = System.IO.Path.GetFullPath(config.GetString("ui", "app", ""));
                if (System.IO.File.Exists(app))
                {
                    // check if the app running.
                    var pp = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(app));
                    if (pp.Length == 0)
                    {
                        p = new Process();
                        p.StartInfo.FileName         = app;
                        p.StartInfo.Arguments        = "-ControlMode";
                        p.StartInfo.UseShellExecute  = true;
                        p.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(app);
                        p.Start();
                        p.WaitForInputIdle();
                    }
                    else
                    {
                        p = pp[0];
                        //SetForegroundWindow(p.MainWindowHandle);
                    }
                }
            }
            catch (Exception)
            {
            }
            return(p);
        }
Esempio n. 4
0
        private void WizardPagePlaceDevice_Commit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
        {
            bool skip = (bool)wizardPagePlaceDevice.Tag;

            if (skip)
            {
                this.UseWaitCursor = true;
                e.Cancel           = skip;
                Task.Run(() =>
                {
                    // check please device in avia
                    utility.IniFile avia_device = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "AviaDevice.ini"));
                    bool done = false;
                    while (!done)
                    {
                        string sid = avia_device.GetString("device", "sizeid", "");
                        if (!string.IsNullOrEmpty(sid))
                        {
                            done = true;
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(1000);
                        }
                    }
                    this.Invoke(new Action(() => {
                        wizardPagePlaceDevice.Tag = false;
                        wizardControl1.NextPage();
                    }));
                });
            }
            else
            {
            }
        }
Esempio n. 5
0
        static void prepare_label_xml(utility.IniFile config, Dictionary <string, object> data, string labelname = "label.xml")
        {
            string fn = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", labelname);

            try
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;
                using (XmlWriter xmlWriter = XmlWriter.Create(fn, settings))
                {
                    xmlWriter.WriteStartDocument();
                    xmlWriter.WriteStartElement("labelinfo");
                    xmlWriter.WriteStartElement("label");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("device");
                    xmlWriter.WriteElementString("meid_imei", data.ContainsKey("Index") ? data["Index"].ToString() : "1234567890");
                    xmlWriter.WriteElementString("modelnumber", data.ContainsKey("ModelName") ? data["ModelName"].ToString() : "");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("runtime");
                    xmlWriter.WriteElementString("iCloud", data.ContainsKey("Grade") ? data["Grade"].ToString() : "");
                    xmlWriter.WriteElementString("meid", data.ContainsKey("Index") ? data["Index"].ToString() : "1234567890");
                    xmlWriter.WriteElementString("modelnumber", data.ContainsKey("ModelName") ? data["ModelName"].ToString() : "");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndDocument();
                    xmlWriter.Flush();
                    xmlWriter.Close();
                }
            }
            catch (Exception) { }
        }
Esempio n. 6
0
        private void WizardPageResult_Commit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
        {
            utility.IniFile avia_device = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "AviaDevice.ini"));
            string          s           = avia_device.GetString("device", "device", "");

            if (string.Compare(s, "removed", true) != 0)
            {
                avia_device.WriteValue("device", "device", "removed");
                e.Cancel = true;
            }
        }
Esempio n. 7
0
 private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == '\r' || e.KeyChar == '\t')
     {
         //textBox1.Text = textBox1.Text.Trim();
         e.Handled = true;
         textBox1.SelectAll();
         utility.IniFile ini = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "aviaDevice.ini"));
         ini.WriteValue("device", "imei", textBox1.Text);
     }
 }
Esempio n. 8
0
        static Tuple <string, string> mappingModelByMaker(string maker, string model)
        {
            string ret1 = maker;
            string ret2 = model;
            string fn   = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName), "mappingModel.ini");

            if (System.IO.File.Exists(fn))
            {
                utility.IniFile ini = new utility.IniFile(fn);
                ret2 = ini.GetString(maker, model, model);
            }
            return(new Tuple <string, string>(ret1, ret2));
        }
Esempio n. 9
0
 private void WizardPageInProcess_Initialize(object sender, AeroWizard.WizardPageInitEventArgs e)
 {
     this.wizardPageInProcess.Controls.Add(this.imeiInput1);
     this.imeiInput1.Focus();
     labelStatus.Text = "Scan in progress";
     this.wizardPageInProcess.Text = labelStatus.Text;
     Task t = Task.Run(() =>
     {
         Task tt   = Task.Run(() => OEControl.scan());
         bool done = false;
         int step  = 0;
         utility.IniFile avia_device = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "AviaDevice.ini"));
         while (!done)
         {
             System.Threading.Thread.Sleep(300);
             wizardControl1.Invoke(new Action(() =>
             {
                 progressBar1.Value = Math.Min(step++, progressBar1.Maximum);
                 progressBar1.Update();
             }));
             // check the progress
             string cmd = avia_device.GetString("query", "command", "");
             if (string.Compare(cmd, "PMP", true) == 0)
             {
                 wizardControl1.Invoke(new Action(() =>
                 {
                     labelStatus.Text = "Inspection in progress";
                     this.wizardPageInProcess.Text = labelStatus.Text;
                 }));
             }
             // check result
             string grade = avia_device.GetString("device", "grade", "");
             if (!string.IsNullOrEmpty(grade))
             {
                 Program.logIt($"Result: {grade}");
                 done = true;
                 step = 100;
                 wizardControl1.Invoke(new Action(() =>
                 {
                     progressBar1.Value = progressBar1.Maximum;
                     progressBar1.Update();
                 }));
             }
         }
         wizardControl1.Invoke(new Action(() =>
         {
             wizardControl1.NextPage();
         }));
         tt.Wait();
     });
 }
Esempio n. 10
0
        public static int cmc_login(System.Collections.Specialized.StringDictionary args)
        {
            int ret = -1;

            Program.logIt("cmc_login: ++");
            string avia_dir = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA");
            string tool     = System.IO.Path.Combine(avia_dir, "hydra", "hydralogin.exe");
            string xml_file = System.IO.Path.Combine(avia_dir, "hydra", "hydralogin.xml");

            utility.IniFile config = new utility.IniFile(System.IO.Path.Combine(avia_dir, "config.ini"));
            if (System.IO.File.Exists(tool) && args.ContainsKey("u") && args.ContainsKey("p"))
            {
                try
                {
                    System.IO.File.Delete(xml_file);
                }
                catch (Exception) { }
                Process p = new Process();
                p.StartInfo.FileName        = tool;
                p.StartInfo.Arguments       = $"-u={args["u"]} -p={args["p"]}";
                p.StartInfo.CreateNoWindow  = true;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                p.StartInfo.EnvironmentVariables.Add("APSTHOME", avia_dir);
                p.Start();
                p.WaitForExit();
                //ret = p.ExitCode;
                if (p.ExitCode == 0 && System.IO.File.Exists(xml_file))
                {
                    // parse hydralogin xml
                    XmlDocument xml = new XmlDocument();
                    try
                    {
                        xml.Load(xml_file);
                        if (xml.DocumentElement != null)
                        {
                            if (xml.DocumentElement["id"] != null)
                            {
                                config.WriteValue("config", "userid", xml.DocumentElement["id"].InnerText);
                                ret = 0;
                            }
                        }
                    }
                    catch (Exception) { }
                }
            }
            Program.logIt($"cmc_login: -- ret={ret}");
            return(ret);
        }
Esempio n. 11
0
        private void WizardPageScanColor_Commit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
        {
            bool skip = (bool)wizardPageScanColor.Tag;

            if (skip)
            {
                this.UseWaitCursor = true;
                Task.Run(() =>
                {
                    // get color value.
                    DateTime _start = DateTime.Now;
                    bool done       = false;
                    while (!done && (DateTime.Now - _start).TotalMinutes < 1)
                    {
                        Tuple <bool, Color> res = util.read_color();
                        if (res.Item1)
                        {
                            done = true;
                            // write color rgb to ini
                            utility.IniFile avia_device = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "AviaDevice.ini"));
                            avia_device.WriteValue("device", "rgb", $"{res.Item2.R},{res.Item2.G},{res.Item2.B}");
                        }
                    }
                    if (!done)
                    {
                        //this.Invoke(new Action(() =>
                        //{
                        //    MessageBox.Show("Fail to get color, please try again.", "Error");
                        //}));
                        MessageBox.Show("Fail to get color, please try again.", "Error");
                        this.UseWaitCursor = false;
                    }
                    else
                    {
                        //System.Threading.Thread.Sleep(3000);
                        this.Invoke(new Action(() =>
                        {
                            wizardPageScanColor.Tag = false;
                            wizardControl1.NextPage();
                        }));
                    }
                });
                e.Cancel = true;
            }
            else
            {
            }
        }
Esempio n. 12
0
        static int handle_QueryPMP_Command(System.Collections.Specialized.StringDictionary args)
        {
            int ret = -1;

            utility.IniFile ini = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "AviaDevice.ini"));
            string          fn  = ini.GetString("query", "filename", "");
            string          fn1 = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", $"{fn}.bmp");

            if (!string.IsNullOrEmpty(fn) && save_image_file(fn, fn1))
            {
                // check model by images
                //Console.WriteLine("model=iphone8 plus red_M2_N");
                ret = AviaGetPhoneModel.start(fn1);
            }
            return(ret);
        }
Esempio n. 13
0
 private void WizardPageResult_Initialize(object sender, AeroWizard.WizardPageInitEventArgs e)
 {
     Program.logIt("WizardPageResult_Initialize: ");
     this.wizardPageResult.ShowNext = false;
     //this.wizardPageResult.Controls.Add(this.imeiInput1);
     // load grade
     {
         utility.IniFile avia_device = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "AviaDevice.ini"));
         string          grade       = avia_device.GetString("device", "grade", "D");
         labelGrade.Text = grade;
     }
     tokenSource = new CancellationTokenSource();
     // start task wait for device loaded
     Task t = Task.Factory.StartNew((o) =>
     {
         CancellationToken ct = (CancellationToken)o;
         // oe control
         Task tt = Task.Run(() => OEControl.unload());
         //OEControl.unload();
         utility.IniFile avia_device = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "AviaDevice.ini"));
         bool done = false;
         while (!done)
         {
             System.Threading.Thread.Sleep(1000);
             if (ct.IsCancellationRequested)
             {
                 // camcelled.
                 break;
             }
             else
             {
                 string s = avia_device.GetString("device", "device", "");
                 if (string.Compare(s, "removed", true) == 0)
                 {
                     done = true;
                 }
             }
         }
         tt.Wait();
         // device connect.
         if (done)
         {
             //this.Invoke(new Action(() => wizardControl1.NextPage()));
             this.Invoke(new Action(() => this.wizardPageResult.ShowNext = true));
         }
     }, tokenSource.Token);
 }
Esempio n. 14
0
 private void WizardPageSelect_Commit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
 {
     utility.IniFile ini = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "aviaDevice.ini"));
     if (!theRect.IsEmpty)
     {
         Point p  = System.Windows.Forms.Cursor.Position;
         Point p1 = this.PointToClient(p);
         Program.logIt($"position: {p1} on N {theRect.Contains(p1)}");
         if (theRect.Contains(p1))
         {
             ini.WriteValue("override", "grade", "D");
         }
     }
     //comboBoxModels.Tag = comboBoxModels.SelectedItem;
     ini.WriteValue("device", "select", comboBoxModels.SelectedItem.ToString());
     ini.WriteValue("query", "selected", comboBoxModels.SelectedItem.ToString());
 }
Esempio n. 15
0
        private void WizardPagePlaceDevice_Initialize(object sender, AeroWizard.WizardPageInitEventArgs e)
        {
            this.wizardPagePlaceDevice.Controls.Add(this.imeiInput1);
            this.imeiInput1.clear();
            this.imeiInput1.Focus();
            //pictureBox1.Image = Image.FromFile(@"C:\Tools\logs\Rotating_earth_(large).gif");
            Program.logIt("WizardPagePlaceDevice_Initialize: ++");
#if false
            tokenSource = new CancellationTokenSource();
            // start task wait for device loaded
            Task t = Task.Factory.StartNew((o) =>
            {
                // oe control
                Task tt = Task.Run(() => OEControl.load());
                CancellationToken ct        = (CancellationToken)o;
                utility.IniFile avia_device = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "AviaDevice.ini"));
                bool done = false;
                while (!done)
                {
                    System.Threading.Thread.Sleep(1000);
                    if (ct.IsCancellationRequested)
                    {
                        // camcelled.
                        break;
                    }
                    else
                    {
                        string s = avia_device.GetString("device", "device", "");
                        if (string.Compare(s, "ready", true) == 0)
                        {
                            done = true;
                        }
                    }
                }
                // device connect.
                if (done)
                {
                    this.Invoke(new Action(() => wizardControl1.NextPage()));
                }
                tt.Wait();
            }, tokenSource.Token);
#endif
            Program.logIt("WizardPagePlaceDevice_Initialize: --");
        }
Esempio n. 16
0
        private void WizardPagePlaceDevice_Commit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
        {
            this.UseWaitCursor = true;
            Task.Run(() =>
            {
                // wait for check device size
                utility.IniFile avia_device = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "AviaDevice.ini"));
                bool done = false;
                while (!done)
                {
                    System.Threading.Thread.Sleep(1000);
                    string s = avia_device.GetString("device", "device", "");
                    if (string.Compare(s, "ready", true) == 0)
                    {
                        done = true;
                    }
                }
                this.Invoke(new Action(() => wizardControl1.NextPage(this.wizardPageSelect, true)));
            });
            e.Cancel = true;

#if false
            if (!theRect.IsEmpty)
            {
                Point p  = System.Windows.Forms.Cursor.Position;
                Point p1 = this.PointToClient(p);
                Program.logIt($"position: {p1} on N {theRect.Contains(p1)}");
                if (theRect.Contains(p1))
                {
                    avia_device.WriteValue("override", "grade", "D");
                }
            }
            string s = avia_device.GetString("device", "device", "");
            if (string.Compare(s, "ready", true) != 0)
            {
                avia_device.WriteValue("device", "device", "ready");
                e.Cancel = true;
            }
#endif
        }
Esempio n. 17
0
        static void apple_tac_upload()
        {
            var jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            Dictionary <string, object>         data  = jss.Deserialize <Dictionary <string, object> >(System.IO.File.ReadAllText(@"data\iphone_tac.json"));
            List <Dictionary <string, object> > ready = new List <Dictionary <string, object> >();

            utility.IniFile ini = new utility.IniFile(@"data\iphone_model.ini");
            foreach (KeyValuePair <string, object> kvp in data)
            {
                Dictionary <string, object> d  = (Dictionary <string, object>)kvp.Value;
                Dictionary <string, object> db = new Dictionary <string, object>();
                db.Add("uuid", kvp.Key);
                db.Add("cmc_maker", "Apple");
                db.Add("cmc_model", d["model"]);
                db.Add("maker", "Apple");
                db.Add("model", ini.GetString("Apple", d["model"].ToString(), d["model"].ToString()));
                ready.Add(db);
            }
            string s = jss.Serialize(ready.ToArray());

            System.IO.File.WriteAllText("test.json", s);

            foreach (Dictionary <string, object> d in ready)
            {
                s = jss.Serialize(d);
                try
                {
                    WebClient wc = new WebClient();
                    wc.Credentials = new NetworkCredential("cmc", "cmc1234!");
                    wc.Headers.Add("Content-Type", "application/json");
                    s = wc.UploadString("http://dc.futuredial.com/cmc/CCTest", s);
                }
                catch (Exception ex)
                {
                    logIt(ex.Message);
                }
                //break;
            }
        }
Esempio n. 18
0
 private void WizardPagePlaceDevice_Enter(object sender, EventArgs e)
 {
     Program.logIt("WizardPagePlaceDevice_Enter: ++");
     Task.Run(() => OEControl.load());
     //this.imeiInput1.clear();
     // this.imeiInput1.Focus();
     labelReady.Visible             = false;
     wizardPagePlaceDevice.ShowNext = false;
     utility.IniFile ini = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "aviaDevice.ini"));
     //ini.WriteValue("device", "select", comboBoxModels.SelectedItem.ToString());
     ini.DeleteSection("device");
     //this.wizardPagePlaceDevice.Commit += new System.EventHandler<AeroWizard.WizardPageConfirmEventArgs>(this.WizardPagePlaceDevice_Commit);
     //this.wizardPagePlaceDevice.Commit += WizardPagePlaceDevice_Commit;
     Task.Run(() =>
     {
         utility.IniFile avia_device = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "AviaDevice.ini"));
         bool done = false;
         while (!done)
         {
             System.Threading.Thread.Sleep(1000);
             {
                 string s = avia_device.GetString("device", "device", "");
                 if (string.Compare(s, "ready", true) == 0)
                 {
                     done = true;
                 }
             }
         }
         if (done)
         {
             this.Invoke(new Action(() =>
             {
                 labelReady.Visible             = true;
                 wizardPagePlaceDevice.ShowNext = true;
             }));
         }
     });
     Program.logIt("WizardPagePlaceDevice_Enter: --");
 }
Esempio n. 19
0
        public static Tuple <bool, SizeF> get_current_device_size()
        {
            bool  ret = false;
            SizeF sz  = SizeF.Empty;

            utility.IniFile ini = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "aviaDevice.ini"));
            string          s   = ini.GetString("device", "size", "");

            if (!string.IsNullOrEmpty(s))
            {
                string[] xy = s.Split(',');
                if (xy.Length > 1)
                {
                    float x;
                    float y;
                    if (float.TryParse(xy[0], out x) && float.TryParse(xy[1], out y))
                    {
                        ret = true;
                        sz  = new SizeF(x, y);
                    }
                }
            }
            return(new Tuple <bool, SizeF>(ret, sz));
        }
Esempio n. 20
0
        public static Tuple <bool, Dictionary <string, SizeF> > get_all_device_size()
        {
            bool ret = false;
            Dictionary <string, SizeF> data = new Dictionary <string, SizeF>();

            utility.IniFile             ini    = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "aviaDevice.ini"));
            Dictionary <string, string> models = ini.GetSectionValues("models");

            foreach (KeyValuePair <string, string> kvp in models)
            {
                ret = true;
                string[] xy = kvp.Value.Split(',');
                if (xy.Length > 1)
                {
                    float x;
                    float y;
                    if (float.TryParse(xy[0], out x) && float.TryParse(xy[1], out y))
                    {
                        data.Add(kvp.Key, new SizeF(x, y));
                    }
                }
            }
            return(new Tuple <bool, Dictionary <string, SizeF> >(ret, data));
        }
Esempio n. 21
0
        int install(Dictionary <string, object> args)
        {
            int ret = 1;
            //for(int i = 0; i < 10; i++)
            //{
            //    update_status($"step: {i + 1}");
            //    System.Threading.Thread.Sleep(1000);
            //}
            // start install.
            String root = @"D:\BZVisualInspect";

            System.IO.Directory.CreateDirectory(root);
            // download
            update_status($"Download CMC from server.");
            string cmc_zip = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "cmc.zip");

            try
            {
                System.IO.File.Delete(cmc_zip);
                WebClient wc = new WebClient();
                wc.Credentials = new NetworkCredential("fd_clean", "fd_clean340!");
                wc.DownloadFile("ftp://ftp8.futuredial.com/SmartGrading/cmc.zip", cmc_zip);
            }
            catch (Exception) { }
            if (System.IO.File.Exists(cmc_zip))
            {
                update_status($"unzip to {root}.");
                ZipFile.ExtractToDirectory(cmc_zip, root);
                // save config.ini
                update_status($"Generate config.ini");
                utility.IniFile config = new utility.IniFile(System.IO.Path.Combine(root, "config.ini"));
                foreach (KeyValuePair <string, object> kvp in args)
                {
                    config.WriteValue("config", kvp.Key, kvp.Value.ToString());
                }
                // create shortcuts:
                update_status($"Create shortcut");
                {
                    System.IO.Directory.CreateDirectory(System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "FutureDial"));
                    WshShell     shell    = new WshShell();
                    string       fn       = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup), "SMARTGradeDownlaoder.lnk");
                    IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(fn);
                    shortcut.Description      = "SMART Grade Downloader";
                    shortcut.IconLocation     = System.IO.Path.Combine(root, "icon1.ico");
                    shortcut.TargetPath       = System.IO.Path.Combine(root, "FDAcorn.exe");
                    shortcut.Arguments        = "-StartDownLoad";
                    shortcut.WorkingDirectory = root;
                    shortcut.Save();
                    //
                    fn                        = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory), "SMARTGrade.lnk");
                    shortcut                  = (IWshShortcut)shell.CreateShortcut(fn);
                    shortcut.Description      = "SMART Grade";
                    shortcut.IconLocation     = System.IO.Path.Combine(root, "icon1.ico");
                    shortcut.TargetPath       = System.IO.Path.Combine(root, "AviaUI.exe");
                    shortcut.Arguments        = "";
                    shortcut.WorkingDirectory = root;
                    shortcut.Save();
                }
                //
                {
                    string fn = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "FutureDial");
                    System.IO.Directory.CreateDirectory(fn);
                }
                //
                {
                    System.Environment.SetEnvironmentVariable("APSTHOME", root);
                    System.Environment.SetEnvironmentVariable("APSTHOME", root, EnvironmentVariableTarget.Machine);
                }
                // disable UAC
                {
                    RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", true);
                    if (rk != null)
                    {
                        rk.SetValue("EnableLUA", 0);
                        rk.Close();
                    }
                }
                ret = 0;
            }
            else
            {
                ret = 4;
            }

            return(ret);
        }
Esempio n. 22
0
        public static int sendTransactionToVerizon(System.Collections.Specialized.StringDictionary args)
        {
            int ret = -1;

            Program.logIt("sendTransactionToVerizon: ++");
            string avia_dir = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA");
            string tool     = System.IO.Path.Combine(avia_dir, "hydra", "hydraTransaction.exe");
            Dictionary <string, object> data = null;
            string url = args.ContainsKey("verizonurl") ? args["verizonurl"] : "";

            if (args.ContainsKey("json") && System.IO.File.Exists(args["json"]))
            {
                try
                {
                    var jss = new System.Web.Script.Serialization.JavaScriptSerializer();
                    data = jss.Deserialize <Dictionary <string, object> >(System.IO.File.ReadAllText(args["json"]));
                }
                catch (Exception ex)
                {
                    Program.logIt($"sendTransaction: {ex.Message}");
                    ret = 1;
                }
            }
            if (!string.IsNullOrEmpty(url) && data != null && System.IO.File.Exists(tool) && System.IO.File.Exists(System.IO.Path.Combine(avia_dir, "config.ini")))
            {
                utility.IniFile config = new utility.IniFile(System.IO.Path.Combine(avia_dir, "config.ini"));
                if (System.IO.File.Exists(tool))
                {
                    var ms = new MemoryStream();
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    using (XmlWriter xmlWriter = XmlWriter.Create(ms, settings))
                    {
                        xmlWriter.WriteStartDocument();
                        xmlWriter.WriteStartElement("root");
                        xmlWriter.WriteElementString("ESN", data.ContainsKey("Index") ? data["Index"].ToString() : "1234567890");
                        xmlWriter.WriteElementString("ProcessingStation", System.Environment.MachineName);
                        xmlWriter.WriteStartElement("AutomationResult");
                        xmlWriter.WriteStartElement("TRANDATA");
                        xmlWriter.WriteElementString("HEXESN", data.ContainsKey("Index") ? data["Index"].ToString() : "1234567890");
                        int error_code = 1;
                        if (data.ContainsKey("Grade"))
                        {
                            error_code = 1;
                            xmlWriter.WriteElementString("GRADE", data.ContainsKey("Grade").ToString());
                        }
                        else
                        {
                            xmlWriter.WriteElementString("GRADE", "Fail");
                            error_code = 0;
                        }
                        xmlWriter.WriteElementString("CRACK", "");
                        xmlWriter.WriteElementString("POWER", "TRUE");
                        xmlWriter.WriteElementString("RESULT", error_code == 1? "PASS": "******");
                        xmlWriter.WriteElementString("TIMESTAMP", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"));
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();
                        xmlWriter.Close();
                    }
                    try
                    {
                        Program.logIt($"try to send transaction to url: {url}");
                        WebClient wc  = new WebClient();
                        byte[]    res = wc.UploadData(url, ms.ToArray());
                        string    s   = System.Text.Encoding.UTF8.GetString(res);
                        Program.logIt($" to send transaction to url: {url}");
                    }
                    catch (Exception ex)
                    {
                        Program.logIt(ex.Message);
                        Program.logIt(ex.StackTrace);
                    }

                    ret = 0;
                }
            }
            Program.logIt($"sendTransactionToVerizon: -- ret={ret}");
            return(ret);
        }
Esempio n. 23
0
        static void test()
        {
            logIt($"cwd: {System.Environment.CurrentDirectory}");
            utility.IniFile ini  = new utility.IniFile("data\\iPhone_Model.ini");
            string[]        keys = ini.GetKeyNames("Apple");
            //apple_tac_upload();
            //dump_collection("CCTest");
            //upload_data();
            //util.check_imei("490154203237518");
            //try
            //{
            //    string str = System.IO.File.ReadAllText("ready.json");
            //    var jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            //    Dictionary<string, object>[] records = jss.Deserialize<Dictionary<string, object>[]>(str);
            //    upload_data(records);
            //}
            //catch (Exception)
            //{

            //}
#if false
            // download imei2model db
            Tuple <bool, Dictionary <string, object>[], DateTime> res = getAllCollectDocuments("imei2model");
            if (res.Item1)
            {
                Dictionary <string, object> d = new Dictionary <string, object>();
                var jss = new System.Web.Script.Serialization.JavaScriptSerializer();
                d.Add("lastmodified", res.Item3.ToString("s"));
                d.Add("doc", res.Item2);
                System.IO.File.WriteAllText("imei2model.json", jss.Serialize(d));
            }
#endif
#if false
            var jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            jss.MaxJsonLength = 20971520;
            Dictionary <string, object> db     = jss.Deserialize <Dictionary <string, object> >(System.IO.File.ReadAllText("imei2model.json"));
            Dictionary <string, int>    counts = new Dictionary <string, int>();
            if (db.ContainsKey("doc"))
            {
                ArrayList al = (ArrayList)db["doc"];
                foreach (Dictionary <string, object> r in al)
                {
                    if (r.ContainsKey("model") && r.ContainsKey("maker"))
                    {
                        string k = $"{r["maker"]}-{r["model"]}";
                        if (counts.ContainsKey(k))
                        {
                            int i = counts[k];
                            counts[k] = i + 1;
                        }
                        else
                        {
                            counts.Add(k, 1);
                        }
                    }
                }
            }
            foreach (KeyValuePair <string, int> kvp in counts)
            {
                logIt($"{kvp.Key}: {kvp.Value}");
            }
#endif
        }
Esempio n. 24
0
        /// <summary>
        /// prepare env for AVIA product
        ///
        /// save flag in avia.ini,
        ///
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static int startup(System.Collections.Specialized.StringDictionary args)
        {
            int    ret = -1;
            string dir = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("fdhome"), "avia");

            System.Environment.CurrentDirectory = dir;
            // 1. start FDPhoneRecognition.exe -start-tcpserver
            string tool = System.IO.Path.Combine(dir, "FDPhoneRecognition.exe");

            if (System.IO.File.Exists(tool))
            {
                Process p = new Process();
                p.StartInfo.FileName       = tool;
                p.StartInfo.Arguments      = $"-start-tcpserver";
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
                p.Start();
            }
            // 2. start AviaToolset.exe -OEControl
            utility.IniFile config = new utility.IniFile(System.IO.Path.Combine(dir, "config.ini"));
            tool = config.GetString("ui", "app", @"evaoi-3.1.0.3\evaoi-3.1.0.3.exe");
            tool = System.IO.Path.GetFullPath(tool);
            if (System.IO.File.Exists(tool))
            {
                Process p = new Process();
                p.StartInfo.FileName         = tool;
                p.StartInfo.Arguments        = $"-ControlMode";
                p.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(tool);
                p.StartInfo.CreateNoWindow   = true;
                p.StartInfo.WindowStyle      = ProcessWindowStyle.Hidden;
                p.Start();
                p.WaitForInputIdle();
            }
            // 3. prepare models and save into aviadevice.ini
            try
            {
                tool = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(tool), "evaoi.xml");
                if (System.IO.File.Exists(tool))
                {
                    Tuple <bool, string, SizeF> res = get_modeldir_and_ratio(tool);
                    if (res.Item1)
                    {
                        utility.IniFile ad = new utility.IniFile(System.IO.Path.Combine(dir, "aviadevice.ini"));
                        foreach (string model in System.IO.Directory.GetDirectories(res.Item2))
                        {
                            //Program.logIt($"model: {System.IO.Path.GetFileName(model)}");
                            tool = System.IO.Path.Combine(model, "work_station_1", "layout.xml");
                            Tuple <Rectangle, bool, string>[] areas = retrieve_area_by_filename(tool);
                            SizeF sz = SizeF.Empty;
                            foreach (Tuple <Rectangle, bool, string> i in areas)
                            {
                                SizeF s = new SizeF(res.Item3.Width * i.Item1.Width, res.Item3.Height * i.Item1.Height);
                                //Program.logIt($"size={sz}, {i.Item1}");
                                if (s.Width > sz.Width && s.Height > sz.Height)
                                {
                                    sz = s;
                                }
                            }
                            Program.logIt($"model: {System.IO.Path.GetFileName(model)}, size={sz}");
                            ad.WriteValue("models", System.IO.Path.GetFileName(model), $"{sz.Width},{sz.Height}");
                        }
                    }
                }
            }
            catch (Exception) { }
            return(ret);
        }
Esempio n. 25
0
 void get_colorid_from_rgb()
 {
     utility.IniFile avia_device = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "AviaDevice.ini"));
     string          ts          = avia_device.GetString("device", "rgb", "");
 }
Esempio n. 26
0
        private void Form1_Load(object sender, EventArgs e)
        {
            this.UseWaitCursor = false;
            //Bitmap b = new Bitmap(AviaFlowControl.Properties.Resources.AVIA_RGB_web);
            //pictureBox3.Paint += PictureBox3_Paint;
            //wizardControl1.Paint += WizardControl1_Paint;
            //Task.Run(() =>
            //{
            //    while (true)
            //    {
            //        System.Threading.Thread.Sleep(1000);
            //        this.Invoke(new Action(() => { this.Invalidate(); }));
            //    }
            //});
#if false
            Task.Run(() =>
            {
                // start oe app
                utility.IniFile config = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "config.ini"));
                string s = config.GetString("ui", "rect", "");
                if (string.IsNullOrEmpty(s))
                {
                    try
                    {
                        string[] ss       = s.Split(',');
                        int x             = Int32.Parse(ss[0]);
                        int y             = Int32.Parse(ss[1]);
                        int w             = Int32.Parse(ss[2]);
                        int h             = Int32.Parse(ss[3]);
                        Rectangle theRect = new Rectangle(x, y, w, h);
                    }
                    catch (Exception) { }
                }
                s             = config.GetString("ui", "app", @"evaoi-3.1.0.3\evaoi-3.1.0.3.exe");
                string ui_exe = System.IO.Path.GetFullPath(s);
                s             = System.IO.Path.GetFileNameWithoutExtension(ui_exe);
                Process[] p   = Process.GetProcessesByName(s);
                if (p.Length > 0)
                {
                    ShowWindow(p[0].MainWindowHandle, 2);
                    theApp = p[0];
                }
                else
                {
                    if (System.IO.File.Exists(ui_exe))
                    {
                        try
                        {
                            Process ui                    = new Process();
                            ui.StartInfo.FileName         = ui_exe;
                            ui.StartInfo.Arguments        = "-ControlMode";
                            ui.StartInfo.UseShellExecute  = true;
                            ui.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(ui_exe);
                            theApp = ui;
                            ui.Start();
                            ui.WaitForInputIdle();
                        }
                        catch (Exception) { }
                    }
                }

                // connect to OE server
                if (!OEControl.connect())
                {
                    // fail to connect the OE server
                    this.Invoke(new Action(() =>
                    {
                        MessageBox.Show("Fail to connect UI", "Error");
                    }));
                }
                else
                {
                    // connected
                    // load models
                    s = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(ui_exe), "evaoi.xml");
                    if (System.IO.File.Exists(s))
                    {
                        XmlDocument doc = new XmlDocument();
                        try
                        {
                            doc.Load(s);
                            if (doc.DocumentElement != null)
                            {
                                s = doc.DocumentElement["system"]?["ModelDir"]?.InnerText;
                                if (System.IO.Directory.Exists(s))
                                {
                                    foreach (string m in System.IO.Directory.GetDirectories(s))
                                    {
                                        models.Add(System.IO.Path.GetFileName(m));
                                    }
                                }
                            }
                        }
                        catch (Exception) { }
                    }
                }
            });
#endif
            // connect to OE server
            if (!OEControl.connect())
            {
                // fail to connect the OE server
                this.Invoke(new Action(() =>
                {
                    MessageBox.Show("Fail to connect UI", "Error");
                    this.Close();
                }));
            }
        }
Esempio n. 27
0
        private void WizardPageLogin_Commit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
        {
            //Point p = System.Windows.Forms.Cursor.Position;
            //Point p1 = new Point();
            //p1.X = p.X - this.DesktopLocation.X ;
            //p1.Y = p.Y - this.DesktopLocation.Y ;
            //Program.logIt($"position: {p1} on N {theRect}: {theRect.Contains(p1)}");

            if (wizardPageLogin.Tag == null)
            {
                this.Enabled   = false;
                Cursor.Current = Cursors.WaitCursor;
                e.Cancel       = true;
                // start log in process
                Task t = Task.Run(() =>
                {
                    try
                    {
                        // log in
                        string dir = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "hydra");
                        System.IO.File.Delete(System.IO.Path.Combine(dir, "HydraLogin.xml"));
                        string exe   = System.IO.Path.Combine(dir, "HydraLogin.exe");
                        string param = $"-u={textBoxUsername.Text} -p={textBoxPassword.Text}";
                        if (System.IO.File.Exists(exe))
                        {
                            System.Collections.Specialized.StringDictionary envs = new System.Collections.Specialized.StringDictionary();
                            envs.Add("APSTHOME", System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA"));
                            //Tuple<int, string[]> res = Program.run_exe(@"c:\windows\system32\notepad.exe", param, envs);
                            Tuple <int, string[]> res = Program.run_exe(exe, param, envs);
                            if (res.Item1 == 0)
                            {
                                // login success, run OE
                                //Task tt = Task.Run(() =>
                                //{
                                //    string exe1 = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "iLauncher.exe");
                                //    string param1 = $"-desktop=test -exe=\"{System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "AviaToolset.exe")}\" -args=\"-oecontrol -start\"";
                                //    Process p = new Process();
                                //    p.StartInfo.FileName = exe1;
                                //    p.StartInfo.Arguments = param1;
                                //    p.StartInfo.UseShellExecute = false;
                                //    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                                //    p.StartInfo.CreateNoWindow = true;
                                //    p.Start();
                                //});
                                if (System.IO.File.Exists(System.IO.Path.Combine(dir, "HydraLogin.xml")))
                                {
                                    utility.IniFile config = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "config.ini"));
                                    // load xml
                                    try
                                    {
                                        XmlDocument doc = new XmlDocument();
                                        doc.Load(System.IO.Path.Combine(dir, "HydraLogin.xml"));
                                        string uid = doc.DocumentElement?["id"]?.InnerText;
                                        config.WriteValue("config", "uid", uid);
                                        //tt.Wait();
                                        wizardControl1.Invoke(new Action(() =>
                                        {
                                            wizardControl1.NextPage();
                                        }));
                                        // clear ini device section
                                        utility.IniFile ini = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "aviaDevice.ini"));
                                        ini.DeleteSection("device");
                                        // OE Control start
                                        OEControl.start();
                                    }
                                    catch (Exception) { }
                                }
                            }
                            else
                            {
                                wizardControl1.Invoke(new Action(() =>
                                {
                                    labelLoginStatus.Text    = $"Fail to login, error code: {res.Item1}";
                                    labelLoginStatus.Visible = true;
                                }));
                            }
                        }
                    }
                    catch (Exception) { }
                    finally
                    {
                        this.Invoke(new Action(() =>
                        {
                            this.Enabled        = true;
                            wizardPageLogin.Tag = null;
                        }));
                        //wizardPageLogin.Tag = null;
                    }
                });
                wizardPageLogin.Tag = t;
            }
            else
            {
                wizardPageLogin.Tag = null;
            }
        }
Esempio n. 28
0
 void WizardPageSelect_PrepareModels()
 {
     if (checkBox1.Checked)
     {
         utility.IniFile             ini    = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "aviaDevice.ini"));
         Dictionary <string, string> models = ini.GetSectionValues("models");
         comboBoxModels.DataSource = models.Keys.ToArray();
     }
     else
     {
         Tuple <bool, SizeF> current_device = util.get_current_device_size();
         Tuple <bool, Dictionary <string, SizeF> > models = util.get_all_device_size();
         if (current_device.Item1 && models.Item1)
         {
             List <string> ms = new List <string>();
             foreach (KeyValuePair <string, SizeF> kvp in models.Item2)
             {
                 SizeF diff = current_device.Item2 - kvp.Value;
                 if (Math.Abs(diff.Height) < 2 && Math.Abs(diff.Width) < 2)
                 {
                     ms.Add(kvp.Key);
                 }
             }
             comboBoxModels.DataSource = ms.ToArray();
         }
     }
     // set last selected device as default
     {
         utility.IniFile ini = new utility.IniFile(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA", "aviaDevice.ini"));
         string          s   = ini.GetString("query", "selected", "");
         if (!string.IsNullOrEmpty(s))
         {
             if (comboBoxModels.Items.Count == 0)
             {
                 comboBoxModels.DataSource = new string[] { s };
             }
             else
             {
                 if (!comboBoxModels.Items.Contains(s))
                 {
                     List <string> src = new List <string>((string[])comboBoxModels.DataSource);
                     src.Add(s);
                     comboBoxModels.DataSource = src.ToArray();
                     //comboBoxModels.Items.Add(s);
                 }
             }
             if (comboBoxModels.Items.Contains(s))
             {
                 comboBoxModels.SelectedItem = s;
             }
         }
     }
     if (comboBoxModels.Items.Count > 0)
     {
         label4.Visible = false;
     }
     else
     {
         label4.Visible = true;
     }
 }
Esempio n. 29
0
        public static int sendTransaction(System.Collections.Specialized.StringDictionary args)
        {
            int ret = -1;

            Program.logIt($"sendTransaction: ++ {args["json"]}");
            string avia_dir = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("FDHOME"), "AVIA");
            string tool     = System.IO.Path.Combine(avia_dir, "hydra", "hydraTransaction.exe");

            utility.IniFile             ini  = new utility.IniFile(System.IO.Path.Combine(avia_dir, "AviaDevice.ini"));
            Dictionary <string, object> data = null;

            if (args.ContainsKey("json") && System.IO.File.Exists(args["json"]))
            {
                try
                {
                    var jss = new System.Web.Script.Serialization.JavaScriptSerializer();
                    data = jss.Deserialize <Dictionary <string, object> >(System.IO.File.ReadAllText(args["json"]));
                    string imei = ini.GetString("device", "imei", "");
                    if (!string.IsNullOrEmpty(imei))
                    {
                        data["Index"] = imei;
                    }
                }
                catch (Exception ex)
                {
                    Program.logIt($"sendTransaction: {ex.Message}");
                    ret = 1;
                }
            }
            if (data != null && System.IO.File.Exists(tool) && System.IO.File.Exists(System.IO.Path.Combine(avia_dir, "config.ini")))
            {
                utility.IniFile config = new utility.IniFile(System.IO.Path.Combine(avia_dir, "config.ini"));

                // save label.xml
                prepare_label_xml(config, data);

                string vzw_url = config.GetString("avia", "verizonurl", "");
                if (!string.IsNullOrEmpty(vzw_url))
                {
                    // send transaction to verizon interface.
                    if (!args.ContainsKey("verizonurl"))
                    {
                        args.Add("verizonurl", vzw_url);
                    }
                    sendTransactionToVerizon(args);
                }

                if (System.IO.File.Exists(tool))
                {
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    using (XmlWriter xmlWriter = XmlWriter.Create("test.xml", settings))
                    {
                        xmlWriter.WriteStartDocument();
                        xmlWriter.WriteStartElement("TransLog");
                        xmlWriter.WriteStartElement("FDEMT_TransactionRecord");
                        xmlWriter.WriteElementString("company", config.GetString("config", "companyid", "9"));
                        xmlWriter.WriteElementString("site", config.GetString("config", "siteid", "1"));
                        xmlWriter.WriteElementString("operator", config.GetString("config", "userid", "144"));
                        xmlWriter.WriteElementString("productid", config.GetString("config", "productid", "41"));
                        xmlWriter.WriteElementString("solutionid", config.GetString("config", "solutionid", "34"));
                        xmlWriter.WriteElementString("workstationName", System.Environment.MachineName);
                        xmlWriter.WriteElementString("sourcePhoneID", "PST_APE_UNIVERSAL_USB_FD");
                        xmlWriter.WriteElementString("sourceMake", "Apple");
                        xmlWriter.WriteElementString("sourceModel", data.ContainsKey("ModelName") ? data["ModelName"].ToString() : "");
                        xmlWriter.WriteElementString("esnNumber", data.ContainsKey("Index") ? data["Index"].ToString() : "1234567890");
                        xmlWriter.WriteElementString("StartTime", data.ContainsKey("InspectionTime") ? data["InspectionTime"].ToString() : DateTime.Now.ToString("G"));
                        xmlWriter.WriteElementString("CriteriaFileName", data.ContainsKey("CriteriaFileName") ? System.IO.Path.GetFileName(data["CriteriaFileName"].ToString()) : "");
                        int error_code = 1;
                        if (data.ContainsKey("Grade"))
                        {
                            error_code = 1;
                            string s  = data["Grade"].ToString();
                            string s1 = ini.GetString("override", "grade", s);
                            xmlWriter.WriteElementString("grade", s1);
                            if (string.IsNullOrEmpty(s1))
                            {
                                s1 = "D";
                            }
                            ini.WriteValue("device", "grade", s1);
                        }
                        else
                        {
                            error_code = 0;
                            ini.WriteValue("device", "grade", "D");
                        }
                        xmlWriter.WriteElementString("errorCode", error_code.ToString());
                        xmlWriter.WriteElementString("timeCreated", DateTime.Now.ToString("G"));
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();
                        xmlWriter.Close();
                    }

                    Process p = new Process();
                    p.StartInfo.FileName       = tool;
                    p.StartInfo.Arguments      = $"-add -config={config.Path} -xml=test.xml";
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
                    p.Start();
                    p.WaitForExit();
                    ret = 0;
                }
            }
            if (args.ContainsKey("json"))
            {
                try
                {
                    System.IO.File.Delete(args["json"]);
                }
                catch (Exception) { }
            }
            Program.logIt($"sendTransaction: -- ret={ret}");
            return(ret);
        }
Esempio n. 30
0
        public static int sendTransaction_BZ(System.Collections.Specialized.StringDictionary args)
        {
            int ret = -1;

            Program.logIt($"sendTransaction_BZ: ++ {args?["json"]}");
            if (args.ContainsKey("json") && System.IO.File.Exists(args["json"]))
            {
                Dictionary <string, object> data = null;
                try
                {
                    var jss = new System.Web.Script.Serialization.JavaScriptSerializer();
                    data = jss.Deserialize <Dictionary <string, object> >(System.IO.File.ReadAllText(args["json"]));
                }
                catch (Exception ex)
                {
                    Program.logIt($"sendTransaction: {ex.Message}");
                    ret = 1;
                }
                // get data
                string          dir    = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
                string          tool   = System.IO.Path.Combine(dir, "hydra", "hydraTransaction.exe");
                utility.IniFile config = new utility.IniFile(System.IO.Path.Combine(dir, "config.ini"));
                // generate xml
                {
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    using (XmlWriter xmlWriter = XmlWriter.Create(System.IO.Path.Combine(dir, "test.xml"), settings))
                    {
                        xmlWriter.WriteStartDocument();
                        xmlWriter.WriteStartElement("TransLog");
                        xmlWriter.WriteStartElement("FDEMT_TransactionRecord");
                        xmlWriter.WriteElementString("company", config.GetString("config", "companyid", "9"));
                        xmlWriter.WriteElementString("site", config.GetString("config", "siteid", "1"));
                        xmlWriter.WriteElementString("operator", config.GetString("config", "userid", "144"));
                        xmlWriter.WriteElementString("productid", config.GetString("config", "productid", "41"));
                        xmlWriter.WriteElementString("solutionid", config.GetString("config", "solutionid", "34"));
                        xmlWriter.WriteElementString("workstationName", System.Environment.MachineName);
                        xmlWriter.WriteElementString("sourcePhoneID", "PST_APE_UNIVERSAL_USB_FD");
                        xmlWriter.WriteElementString("sourceMake", "Apple");
                        xmlWriter.WriteElementString("sourceModel", data.ContainsKey("ModelName") ? data["ModelName"].ToString() : "");
                        xmlWriter.WriteElementString("esnNumber", data.ContainsKey("Index") ? data["Index"].ToString() : "1234567890");
                        xmlWriter.WriteElementString("StartTime", data.ContainsKey("InspectionTime") ? data["InspectionTime"].ToString() : DateTime.Now.ToString("G"));
                        xmlWriter.WriteElementString("CriteriaFileName", data.ContainsKey("CriteriaFileName") ? System.IO.Path.GetFileName(data["CriteriaFileName"].ToString()) : "");
                        int error_code = 1;
                        if (data.ContainsKey("Grade"))
                        {
                            error_code = 1;
                            string s = data["Grade"].ToString();
                            xmlWriter.WriteElementString("grade", s);
                        }
                        else
                        {
                            error_code = 0;
                        }
                        xmlWriter.WriteElementString("errorCode", error_code.ToString());
                        xmlWriter.WriteElementString("timeCreated", DateTime.Now.ToString("G"));
                        // prepare -Grade=Standard/FD Rule Base/FD AI/Final Grade
                        if (args.ContainsKey("grade") && !string.IsNullOrEmpty(args["grade"]))
                        {
                            Regex r = new Regex(@"^(.*)\/(.*)\/(.*)\/(.*)$");
                            Match m = r.Match(args["grade"]);
                            if (m.Success && m.Groups.Count == 5)
                            {
                                if (!string.IsNullOrEmpty(m.Groups[1].Value))
                                {
                                    xmlWriter.WriteElementString("verizon", m.Groups[1].Value);
                                }
                                if (!string.IsNullOrEmpty(m.Groups[2].Value))
                                {
                                    xmlWriter.WriteElementString("FDRulebase", m.Groups[2].Value);
                                }
                                if (!string.IsNullOrEmpty(m.Groups[3].Value))
                                {
                                    xmlWriter.WriteElementString("FDAI", m.Groups[3].Value);
                                }
                                if (!string.IsNullOrEmpty(m.Groups[4].Value))
                                {
                                    xmlWriter.WriteElementString("Final", m.Groups[4].Value);
                                }
                            }
                        }
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();
                        xmlWriter.Close();
                    }
                }
                try
                {
                    Process p = new Process();
                    p.StartInfo.FileName         = tool;
                    p.StartInfo.Arguments        = $"-add -config={config.Path} -xml=test.xml";
                    p.StartInfo.WorkingDirectory = dir;
                    p.StartInfo.CreateNoWindow   = true;
                    p.StartInfo.WindowStyle      = ProcessWindowStyle.Hidden;
                    p.Start();
                    p.WaitForExit();
                    ret = 0;
                }
                catch (Exception)
                {
                }
            }
            else
            {
                Program.logIt("ERROR: Missing json file.");
            }
            Program.logIt($"sendTransaction_BZ: -- ret={ret}");
            return(ret);
        }