Exemple #1
0
 public string Get([FromUri] int bits)
 {
     try {
         PassphraseController passphrasegen = new PassphraseController(AppDomain.CurrentDomain.BaseDirectory + "/dicts/" /*"c:/skola/8.semester/TP/Generator/Dictionaries/"*/);
         string[]             veta          = passphrasegen.generateSentenceFromEntrophy(bits);
         string celaveta = "";
         for (int i = 0; i < veta.Length; i++)
         {
             celaveta += veta[i] + " ";
         }
         return(celaveta);
     }catch (Exception e)
     {
         return(e.Message + " " + e.InnerException);
     }
 }
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            if (controller != null)
            {
                Intent i = new Intent();
                switch (item.ItemId)
                {
                case Resource.Id.generateFromEntropy:
                    SetContentView(Resource.Layout.GenerateEntropy);

                    executeButton = FindViewById <Button>(Resource.Id.generateEntropyButton);
                    textOut       = FindViewById <TextView>(Resource.Id.outputTextView);
                    textIn        = FindViewById <EditText>(Resource.Id.entropySizeTextField);

                    executeButton.Click += delegate
                    {
                        int entropy;
                        int.TryParse(textIn.Text, out entropy);

                        textOut.Text = entropy.ToString();
                        textOut.Text = string.Format(String.Join(" ", controller.generateSentenceFromEntrophy(entropy)));
                    };

                    return(true);

                case Resource.Id.translator:
                    SetContentView(Resource.Layout.PasswordTlanslator);

                    executeButton = FindViewById <Button>(Resource.Id.translateButton);
                    textOut       = FindViewById <TextView>(Resource.Id.translatedtextView);
                    textIn        = FindViewById <EditText>(Resource.Id.editTextIn);
                    spinner       = FindViewById <Spinner>(Resource.Id.translateSpinner);

                    spinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
                    var adapter = ArrayAdapter.CreateFromResource(
                        this, Resource.Array.passwordTranslateOptions, Android.Resource.Layout.SimpleSpinnerItem);
                    adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);

                    spinner.Adapter = adapter;

                    executeButton.Click += delegate
                    {
                        if (spinnerSelectedItemPosition == 0)
                        {
                            textOut.Text = "Z hesla";
                            textOut.Text = string.Format(String.Join(" ", controller.generateSentenceFromBinary(textIn.Text)));
                        }
                        else
                        {
                            textOut.Text = "Z vety";
                            textOut.Text = controller.generateBinaryFromSentence(textIn.Text);
                        }
                    };

                    return(true);

                case Resource.Id.closeApp:
                    Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
                    return(true);

                default:
                    return(false);
                }
            }

            return(false);
        }