예제 #1
0
        private void SetBatchNumber(bool regenerate)
        {
            Context        mContext = Application.Context;
            AppPreferences applicationPreferences = new AppPreferences(mContext);

            if (string.IsNullOrEmpty(applicationPreferences.GetAccessKey("batchnumber")) || regenerate)
            {
                batch = Guid.NewGuid();
                applicationPreferences.SaveAccessKey("batchnumber", batch.ToString());
            }

            batchnumber = applicationPreferences.GetAccessKey("batchnumber");
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            RequestedOrientation = ScreenOrientation.Portrait;
            Context        mContext = Application.Context;
            AppPreferences applicationPreferences = new AppPreferences(mContext);

            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_settings);
            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            // Load up any stored applicationPreferences
            TextView submitDataUrl = FindViewById <TextView>(Resource.Id.submit_data_url);

            submitDataUrl.Text = applicationPreferences.GetAccessKey("submitDataUrl");
            submitDataUrl.Text = submitDataUrl.Text.TrimEnd('\r', '\n');

            TextView loadConfigUrl = FindViewById <TextView>(Resource.Id.load_config_url);

            loadConfigUrl.Text = applicationPreferences.GetAccessKey("loadConfigUrl");
            loadConfigUrl.Text = loadConfigUrl.Text.TrimEnd('\r', '\n');

            TextView applicationKey = FindViewById <TextView>(Resource.Id.application_key);

            applicationKey.Text = applicationPreferences.GetAccessKey("applicationKey");
            applicationKey.Text = applicationKey.Text.TrimEnd('\r', '\n');

            TextView retentionPeriod = FindViewById <TextView>(Resource.Id.retention_period);

            retentionPeriod.Text = applicationPreferences.GetAccessKey("retentionPeriod");
            retentionPeriod.Text = retentionPeriod.Text.TrimEnd('\r', '\n');

            string databasePath = System.IO.Path.Combine(
                System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
                "localscandata.db3");
            SQLiteConnection databaseConnection = new SQLiteConnection(databasePath);

            databaseConnection.CreateTable <DespatchBayExpressDataBase.TrackingNumberPatterns>();

            PopulateRecycleView();
            TrackingScan = FindViewById <EditText>(Resource.Id.txtentry);

            TrackingScan.Text = "";
            TrackingScan.RequestFocus();

            TrackingScan.KeyPress += (object sender, View.KeyEventArgs e) =>
            {
                if ((e.Event.Action == KeyEventActions.Down) && (e.KeyCode == Keycode.Enter))
                {
                    if (e.Event.RepeatCount == 0)
                    {
                        string jsonstring = TrackingScan.Text;
                        //jsonstring = Regex.Replace(jsonstring, @"\s+", "");
                        Configuration configuration = new Configuration();
                        try
                        {
                            configuration = JsonConvert.DeserializeObject <Configuration>(jsonstring);
                            if (configuration.UpdateConfiguration.Count == 1)
                            {
                                foreach (UpdateConfiguration configItem in configuration.UpdateConfiguration)
                                {
                                    submitDataUrl.Text   = configItem.UploadEndPoint.ToString();
                                    loadConfigUrl.Text   = configItem.RegexEndPoint.ToString();
                                    applicationKey.Text  = configItem.ApplicationKey.ToString();
                                    retentionPeriod.Text = configItem.RetentionPeriod.ToString();
                                }
                                // Save some application preferences
                                applicationPreferences.SaveAccessKey("submitDataUrl", submitDataUrl.Text, true);
                                applicationPreferences.SaveAccessKey("loadConfigUrl", loadConfigUrl.Text, true);
                                applicationPreferences.SaveAccessKey("applicationKey", applicationKey.Text, true);
                                applicationPreferences.SaveAccessKey("retentionPeriod", retentionPeriod.Text, true);
                                try
                                {
                                    applicationPreferences.SaveAccessKey("serialNumber", Android.OS.Build.Serial.ToString(), true);
                                }
                                catch
                                {
                                    applicationPreferences.SaveAccessKey("serialNumber", "", true);
                                }
                                Log.Info("TAG-SETTINGS", "Settings - Call FetchTrackingRegExData");
                                System.Threading.Tasks.Task taskA = System.Threading.Tasks.Task.Factory.StartNew(() => FetchTrackingRegExData(loadConfigUrl.Text));
                                taskA.Wait();
                                Toast.MakeText(this, "Config QR code read successful", ToastLength.Long).Show();
                            }
                        }
                        catch (Exception ex)
                        {
                            // Any Error in the above block will cause this catch to fire - Even if the json keys don't exist
                            Toast.MakeText(this, "Config QR code not recognised", ToastLength.Long).Show();
                        }
                        PopulateRecycleView();
                        TrackingScan.Text = "";
                    }
                }
            };
        }