public static void launchScanner(bool showUI, string defaultTxt, int symbol, bool forceLandscape) { if (instance==null) { Debug.LogError("EasyCodeScanner - launchScanner error : scanner must be initialized before."); return; } #if UNITY_IPHONE //IPHONE - Display the UIViewController ConfigStruct conf = new ConfigStruct(); conf.showUI = showUI; conf.defaultText = defaultTxt; conf.symbols = symbol; conf.forceLandscape = forceLandscape; launchScannerImpl(ref conf); #endif #if UNITY_ANDROID //ANDROID - Launch the Activity with an Intent AndroidJavaClass ajc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject ajo = ajc.GetStatic<AndroidJavaObject>("currentActivity"); //In case RootActivity is the MAIN in the manifest //ajo.Call("launchScannerImpl", showUI, defaultTxt, symbol, forceLandscape); //In case RootActivity is not the MAIN activity in the manifest (multi-plugin) var jc = new AndroidJavaClass("com.c4mprod.ezcodescanner.RootActivity"); jc.CallStatic("launchScannerImpl", ajo, showUI, defaultTxt, symbol, forceLandscape); #endif }
public static void CallSocialShare(string title, string message) { ConfigStruct conf = new ConfigStruct(); conf.title = title; conf.message = message; showAlertMessage(ref conf); }
/// <summary> /// Configuration Assistant /// </summary> /// <returns>Service Status Code</returns> public ServiceStatus ConfigAssistant() { try { ConsoleWriteLine("\n --- LEARNWEB NOTIFIER CONFIGURATION ASSISTANT --- \n\n", ConsoleColor.Black, ConsoleColor.Green); Console.WriteLine("The service will create a configuration file which is necessary for the execution of the service. " + "Please enter all the data below and confirm each by pressing 'Enter'. Your password will be encrypted and only stored on your machine."); ConsoleWrite("\nLearnweb User (a_bcde01):", ConsoleColor.Black, ConsoleColor.Gray); Console.Write(" "); string inputLearnwebUser = Console.ReadLine(); ConsoleWrite("Learnweb Password:"******" "); string inputLearnwebPassword = ReadPassword(); Console.WriteLine("\n\n\nEnter the course IDs for the courses which should be monitored by the service. " + "You can add one or more courses. If you want to add more than one course, please separate the IDs with a comma, but without spaces (12345,67890).\n"); ConsoleWrite("Learnweb Course IDs:", ConsoleColor.Black, ConsoleColor.Gray); Console.Write(" "); List <string> inputCourses = Console.ReadLine().Split(',').ToList(); Console.WriteLine("\n\nEnter the data for the Pushover notification service. " + "You need an API token and a token for the receiver, which can be a single user or a usergroup.\n"); ConsoleWrite("Pushover API Token:", ConsoleColor.Black, ConsoleColor.Gray); Console.Write(" "); string inputPushoverToken = Console.ReadLine(); ConsoleWrite("Pushover Recipient Token:", ConsoleColor.Black, ConsoleColor.Gray); Console.Write(" "); string inputPushoverRecipient = Console.ReadLine(); Console.WriteLine(""); ConfigStruct newConfig = new ConfigStruct( new ConfigStruct.LearnwebConfig(inputLearnwebUser, inputLearnwebPassword, inputCourses), new ConfigStruct.PushoverConfig(inputPushoverToken, inputPushoverRecipient) ); if (GenerateConfig(newConfig) == ServiceStatus.OK) { ConsoleWriteLine("\nConfiguration file generated, please restart the service now!", ConsoleColor.Green); } else { ConsoleWriteLine("\nConfiguration file generation failed! Aborting...", ConsoleColor.Red); } Console.WriteLine("Press any key to quit...\n"); Console.ReadKey(true); Environment.Exit(0); return(ServiceStatus.OK); } catch (Exception ex) { logger.LogError(ex.Message); Environment.Exit(0); return(ServiceStatus.UnhandledException); } }
[DllImport("__Internal")] private static extern void showAlertMessage(ref ConfigStruct conf);
private static extern void showAlertMessage(ref ConfigStruct conf);
public static void SaveConfig(string path, ConfigStruct config) { var json = JsonConvert.SerializeObject(config, Formatting.Indented); File.WriteAllText(path, json); }
/// <summary> /// дXML�ĵ� /// </summary> /// <param name="name">���ݿ������������</param> /// <param name="con_str">���ݿ������Դ��Ϣ</param> public void writeXML(string name , ConfigStruct con_str) { try { //����һ��dataset System.Data.DataSet ds = new System.Data.DataSet("Autoconfig"); //�ж��Ƿ����config.xml�ļ�,������ڴӸ��ļ��ж�ȡ���ݵ�dataset if(System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\" +_FileName)) { ds.ReadXml(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\" +_FileName); } //�ж��Ƿ���ڸñ�,���������ɾ���ñ� if(ds.Tables.IndexOf(name.ToUpper()) != -1 ) { ds.Tables.Remove(name.ToUpper()); } //����һ��datatable System.Data.DataTable dt = new System.Data.DataTable(name.ToUpper()); //Ϊ�¶���ı������� dt.Columns.Add("key"); dt.Columns.Add("value"); SymmetricMethod sm = new SymmetricMethod(); //���Ӽ�¼���¶���ı��� dt.Rows.Add(new object[2]{ sm.Encrypto( str_HA ), sm.Encrypto( con_str.hostAddress)}); dt.Rows.Add(new object[2]{ sm.Encrypto( str_UN ), sm.Encrypto( con_str.userName)}); dt.Rows.Add(new object[2]{ sm.Encrypto( str_PWD ), sm.Encrypto( con_str.password)}); dt.Rows.Add(new object[2]{ sm.Encrypto( str_DBN ), sm.Encrypto( con_str.DBName)}); //�������ӵ�������µ�dataset�� ds.Tables.Add(dt); //д��xml�ĵ� ds.WriteXml(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\" +_FileName); //�ͷ�datatable �� dataset dt.Dispose(); ds.Dispose(); } catch(Exception exp) { //System.Windows.Forms.MessageBox.Show(exp.Message); throw exp; } }
/// <summary> /// ��XML�ĵ� /// </summary> /// <param name="name">Ҫȡ�������ļ��е�ָ������Դ������,��:��ϵͳ "oldsystem" </param> public ConfigStruct readXML(string name) { try { //�����µĽṹ���� ConfigStruct cfg = new ConfigStruct(); //����һ���µ�dataset System.Data.DataSet ds = new System.Data.DataSet(); //�ж��ļ��Ƿ����,��������ʾ������һ���յĽṹ���� if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\"+_FileName)) { //����������ȡconfig.xml�ļ������� ds.ReadXml(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\" +_FileName); } else { // System.Windows.Forms.MessageBox.Show("config.xml�ļ�������!" , "����", // System.Windows.Forms.MessageBoxButtons.OK , // System.Windows.Forms.MessageBoxIcon.Warning); return new ConfigStruct(); } //�жϱ��Ƿ����,��������ʾ������һ���յĽṹ���� if (ds.Tables.IndexOf(name.ToUpper())== -1 ) { // System.Windows.Forms.MessageBox.Show("��config.xml�в����ҵ���ص�����Դ��������Ϣ!" , "����", // System.Windows.Forms.MessageBoxButtons.OK , // System.Windows.Forms.MessageBoxIcon.Warning); return new ConfigStruct(); } SymmetricMethod sm = new SymmetricMethod(); // cfg.hostAddress = "CIT16-PC"; //cfg.userName ="******"; //cfg.password ="******"; //cfg.DBName = "AutoUpDateData"; //������ȡ��ֵ cfg.hostAddress = sm.Decrypto(ds.Tables[name.ToUpper()].Select("key='" + sm.Encrypto(str_HA) + "'")[0]["value"].ToString()); cfg.userName = sm.Decrypto(ds.Tables[name.ToUpper()].Select("key='" + sm.Encrypto(str_UN) + "'")[0]["value"].ToString()); cfg.password = sm.Decrypto(ds.Tables[name.ToUpper()].Select("key='" + sm.Encrypto(str_PWD) + "'")[0]["value"].ToString()); cfg.DBName = sm.Decrypto(ds.Tables[name.ToUpper()].Select("key='" + sm.Encrypto(str_DBN) + "'")[0]["value"].ToString()); ds.Dispose(); return cfg; } catch//(Exception exp) { //System.Windows.Forms.MessageBox.Show(exp.Message); return new ConfigStruct(); } }
/// <summary> /// ���������ַ���(����һ���ṹ����) /// </summary> /// <returns>String �����ַ���</returns> public string getConnectionString(ConfigStruct con_str) { try { return "Data Source="+con_str.hostAddress+";Initial Catalog="+con_str.DBName+ ";Persist Security Info=True;User ID="+con_str.userName+";Password="******";packet size=4096"; } catch//(Exception exp) { //System.Windows.Forms.MessageBox.Show(exp.Message); return null; } }
private static extern void launchScannerImpl(ref ConfigStruct conf);
public ConfigService(string path) { Config = JsonConvert.DeserializeObject <ConfigStruct>(File.ReadAllText(path)); }
[DllImport ("__Internal")] private static extern void launchScannerImpl(ref ConfigStruct conf);
[DllImport ("__Internal")] private static extern void showAlertMessage(ref ConfigStruct conf);
static void Main(string[] args) { //Config Parse WriteLine("===== Config Parse ====="); ConfigStruct config = new ConfigStruct(); string rString = ""; int numArgAccept = ConfigStruct.Parse(config, args, ref rString);; if (numArgAccept < 0) { ErrorWriteLine(rString); return; } WriteLine("Args Parsed Num:" + numArgAccept); ArgsShow(config); //Hex Load WriteLine("===== Hex Load ====="); AddressDataGroup <byte> dataGroup = new AddressDataGroup <byte>(); try { IntelHexLoader hexLoader = new IntelHexLoader(); IntelHexLoader.ResultEnum r = hexLoader.Load(config.HexFile, dataGroup); if (dataGroup.Groups.Count != 1) { ErrorWriteLine("Hex Not Have One Data Section."); return; } if (r != IntelHexLoader.ResultEnum.Success) { ErrorWriteLine(r.ToString()); return; } WriteLine("Hex Data Size:" + dataGroup.Groups[0].Datas.Count); } catch (Exception ee) { ErrorWriteLine(ee.Message); return; } //FlashSection Load JobMaker.FlashSectionStruct[] FlashSection = null; if (config.FlashSectionFile != "") { try { WriteLine("===== FlashSection Load ====="); FlashSection = (JobMaker.FlashSectionStruct[])SerializerHelper.Deserialize(config.FlashSectionFile, typeof(JobMaker.FlashSectionStruct[])); WriteLine("FlashSection Num:" + FlashSection.Length); } catch (Exception ee) { ErrorWriteLine(ee.Message); //return; } } //Job Make List <Job> jobs = new List <Job>(); try { WriteLine("===== Job Make ====="); JobMaker.EraseWrite(jobs, dataGroup, config.EraseOpt, FlashSection, true); if (config.JumpToFlash) { JobMaker.Go(jobs, dataGroup.Groups[0].Address); } WriteLine("Job Num:" + jobs.Count); } catch (Exception ee) { ErrorWriteLine(ee.Message); return; } //CAN Open ICAN CANDev = null; try { WriteLine("===== CAN Open ====="); string dllPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, config.CANDevFile); Assembly ass = Assembly.LoadFile(dllPath); Type tCAN = ass.GetType(config.CANDevClass); CANDev = (ICAN)Activator.CreateInstance(tCAN); bool rOpen = CANDev.Open(config.CANDeviceNo); if (!rOpen) { ErrorWriteLine("CAN Open Fail."); return; } bool rStart = CANDev.Start(config.CANPortNo, config.CANBPS, false, config.CANSendOnce, false); if (!rOpen) { ErrorWriteLine("CAN Start Fail."); return; } WriteLine("CAN Open Success"); } catch (Exception ee) { ErrorWriteLine(ee.Message); return; } //JobExecutor Init WriteLine("===== JobExecutor Init ====="); JobExecutor JE = new JobExecutor(CANDev, config.CANPortNo); JE.IsShowSendRecive = config.ShowReceiveSend; JE.TimeoutSpan = new TimeSpan(0, 0, config.Timeout); JE.TimeoutSpanErase = new TimeSpan(0, 0, config.TimeoutErase); JE.OnStateChange += JE_OnStateChange; JE.SetJob(jobs.ToArray()); //Run WriteLine("===== JobExecutor Running ====="); while (JE.IsRunning) { JE.BackgroundRun(false); Thread.Sleep(100); } WriteLine("End With:" + JE.JobsState); Console.ReadLine(); }
[DllImport("__Internal")] private static extern void launchScannerImpl(ref ConfigStruct conf);