How can access to the Location Service API be disabled?
I did receive a letter from the Microsoft Development Center which contains this tip:
Your app must provide in-app settings that allow the user to enable
and disable your app's access to and use of location from the Location
Service API.
Can anyone provide further assistance on how I go about doing this?
Paste this code right after InitializeComponent(); in MainPage.xaml. You will have to add reference to IsolatedStorage by this line using System.IO.IsolatedStorage;.
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
return;
}
else
{
MessageBoxResult result = MessageBox.Show("Allow this app to access your location?", "Location", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
}
else
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
}
IsolatedStorageSettings.ApplicationSettings.Save();
}
Also create a Settings.xaml page with a ToggleSwitch which has the following code:
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] == true)
{
locationSwitch.IsChecked = true;
}
else
{
locationSwitch.IsChecked = false;
}
}
else
{
MessageBoxResult result = MessageBox.Show("Allow this app to access your location?", "Location", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
}
else
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
}
IsolatedStorageSettings.ApplicationSettings.Save();
}
private void locationSwitch_Checked(object sender, RoutedEventArgs e)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
private void locationSwitch_Unchecked(object sender, RoutedEventArgs e)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
And on the page that you use Location / GPS data include the following code:
if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] == true)
{
//Do Something
}
else
{
MessageBox.Show("Please enable location services to use this feature. You can turn it on from Settings.");
}
This will surely help. I use the same. Do upvote and mark as answer if this helps you too :)
Does your app use location services and you need to have the ability to disable it OR are you asking in general?
If it's the first then just stop collecting data and disable it in your app. If it's the second then go into the WPmanifest and uncheck it
Related
i have 4 errors and im working on my save button if i could get these fixed it will only save the selected items that the user wants
THIS IS NOT all the code just the code that im having problems with. this program is for and icecream application with 2 combo boxes and 3 check boxes
I PUTT COMMENT LINES WHERE I HAVE THE ERRORS ARE AT
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(
new FileStream(sfd.FileName,
FileMode.Create,
FileAccess.Write)
);
if(flavorBox) // i have an error right here (Cannot implicitly convert type 'System.Windows.Forms.ComboBox' to 'boolean)
{
sw.WriteLine(flavorBox.SelectedItem);
}
else(syrupBox) //syays i need semecolons right here for some reason
{
sw.WriteLine(syrupBox.SelectedItem);
}
if (Nuts.Checked)
{
this.Tag = "checked";
sw.WriteLine(Nuts);
}
else(Cherries.Checked) //says i need semicolons here to i dont know why
{
this.Tag = "checked";
sw.WriteLine(Cherries);
}
if(Sprinkles.Checked)
{
this.Tag = "checked";
sw.WriteLine(Sprinkles);
}
sw.Close();
}
}
THIS IS MY 4TH ERROR
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Are you sure you want to send the data back?",
"Data Sender",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning);
if (result == DialogResult.No)
{
e.Cancel() = true; //ITS ASKED ME AM I MISSING A DIRECTIVE OR ASSEMBLY REFRENCE (FOR CANCEL)
}
In an if-else only the if should have a condition, and the else should not. Use an else if statement to explicitly define a condition.
if (Nuts.Checked)
{
this.Tag = "checked";
sw.WriteLine(Nuts);
}
else if(Cherries.Checked)
{
this.Tag = "checked";
sw.WriteLine(Cherries);
}
else if(Sprinkles.Checked)
{
this.Tag = "checked";
sw.WriteLine(Sprinkles);
}
Flavorbox is a textbox, so by doing if(flavorbox) you are checking if flavorbox is equal to true or false. It's a textbox so this isn't possible. You'll probably have to just change the flavorbox. Try the following:
if(!String.IsNullOrEmpty(flavorbox.Text)) {
sw.WriteLine(flavorBox.SelectedItem);
}
1. about
if(flavorBox)
what are you checking?
about the:
else(syrupBox) and else(Cherries.Checked)
you cannot do else(something).
you can do else if(something)
because else is all the rest of the options.
so change them to:
else if(syrupBox) and else if(Cherries.Checked)
2. about the cancel:
what are you trying to do?
when you click no in the dialog, what are you trying to accomplish with the e.cancel?
For the fourth error, note that EventArgs.Cancel is a property, not a method. Remove the brackets:
e.Cancel = true;
I have two forms i.e., frmLogin and frmDash. I have username and password saved in credentials.txt file. My default run form is frmLogin. Now my problem is, when application starts it checks username and password from credentials.txtand directly shows frmDash. Its working, but problem is, with frmDash , frmLogin is also opening at back. How to solve this?
I have tried this(Form1 is frmLogin):
private void Form1_Load(object sender, EventArgs e)
{
try
{
var credentialLines = File.ReadAllLines(Environment.CurrentDirectory + "\\credentials\\credentials.txt");
if (credentialLines.Any())
{
UserName_reLogin = credentialLines[0];
Password_reLogin = credentialLines[1];
if (LoginUser(Log_API, UserName_reLogin, Password_reLogin))
{
logIn_Status = "true";
GlolbalUtil.LogIn_Status = logIn_Status;
//this.Hide();
frmDash frmDash = new frmDash();
frmDash.Owner = this;
frmDash.Show();
txtUsername.Text = "";
txtPassword.Text = "";
//GlolbalUtil.accept_status = "1";
this.Enabled = false;
}
else
{
MessageBox.Show("Please Check Username and password");
}
}
else
{
this.Enabled = true;
}
}
catch
{
}
}
Move to your login logic to Program.cs in the Main function for something like this
var credentialLines = File.ReadAllLines(Environment.CurrentDirectory + "\\credentials\\credentials.txt");
if (credentialLines.Any()){
UserName_reLogin = credentialLines[0];
Password_reLogin = credentialLines[1];
if (LoginUser(Log_API, UserName_reLogin, Password_reLogin)){
Application.Run(new frmDash ());
}else{
Application.Run(new frmlogin());
}
}else
{
Application.Run(new frmlogin());
}
First of all, you should check if the credential exists before opening the login Form.
but anyway to hide forms use this.Hide(); to hide forms
private void FrmLogin_Shown(object sender, EventArgs e)
{
if (GlolbalUtil.authenticate == "true")
{
this.Hide();
}
else if(GlolbalUtil.authenticate == "false")
{
this.Show();
}
}
GlobalUtil.authenticate is global variable to check if user is logged in or not. if user is logged in that means GlobalUtil.authenticate=="true", then only frmLogin will hide otherwise show. worked perfectly.
Im creating a skype tool and it is goin great but my skype resolver key http://resolveme.org/api.php?key=51e77c68b11df&skypePseudo= expired. Is there any way i can make one with C# and put it in the program in replace of the code below?! Thanks (:
private void metroButton27_Click_2(object sender, EventArgs e)
{
WebRequest.Create("http://resolveme.org/api.php?key=51e77c68b11df&skypePseudo=" + this.metroTextBox15.Text);
this.metroTextBox16.Enabled = true;
if (string.IsNullOrEmpty(this.metroTextBox15.Text))
{
MessageBox.Show("Enter A Skype Username", "Box Not Filled In");
this.metroTextBox16.Enabled = false;
}
else
{
this.metroTextBox16.Text = new WebClient().DownloadString("http://resolveme.org/api.php?key=51e77c68b11df&skypePseudo=" + this.metroTextBox15.Text);
}
}
I made a skype resolver in Java, and i'm recording it with a better GUI in C#.
Try this API: http://data-stresstest.nl/boot/api.php?skype=(skypename here)
Don't really know what you are asking for.
Try this??
private void metroButton27_Click_2(object sender, EventArgs e)
{
if (metroTextBox16.Text == "") //Checks if Textbox = Blank.
{
MessageBox.Show("Enter a username.", "ERROR"); //Shows a message box.
}
else
{
this.metroTextBox16.Text = new WebClient().DownloadString("http://resolveme.org/api.php?key=51e77c68b11df&skypePseudo=" + this.metroTextBox15.Text);
}
}
currently my window is like this with the edit and delete button disabled. In order to enable the buttons, user have to login with the administrator type. Right now, I already login with the administrator type from the member type. The disabled buttons supposed to be enabled after I logged in with the administrator type, but it is not.
Is there any way to enable the button, after the form opened with the buttons disabled?
Here is the images:
As you can see on the below image, there is a admin login button with edit and delete buttons disabled. (Main System Form):
Administrator Login (Privelege Form)
Here is the code that I am using:
public class SystemManager
{
public static void AdminLogin(string _value1, string _value2, Form _windowsForm, TextBox _windowsTextBox)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
string query = "SELECT * FROM [Member] WHERE [Username] = #Username";
connection.Open();
using (OleDbCommand command = new OleDbCommand(query, connection))
{
command.Parameters.Add("#Username", OleDbType.VarChar);
command.Parameters["#Username"].Value = _value1;
using (OleDbDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
string password = (string)reader["Password"];
string userType = (string)reader["UserType"];
_isValidPassword = BCrypt.ValidateHash(_value2, password);
if (userType == "Administrator")
{
_isAdministrator = true;
}
else if (userType != "Administrator")
{
_isAdministrator = false;
}
if (_isValidPassword && _isAdministrator)
{
Authenticate _authenticate = new Authenticate();
_authenticate.ShowDialog();
ShowMessageBox("Authenticated.", "Success", 2);
UserInformation.isAdministrator = true;
_windowsForm.Hide();
_windowsForm.Close();
}
}
if (!_isValidPassword || !_isAdministrator)
{
Authenticate _authenticate = new Authenticate();
_authenticate.ShowDialog();
ShowMessageBox("Either username or password incorrect or you are not administrator. Please try again.", "Error", 1);
ClearTextBoxes(_windowsForm.Controls);
_windowsTextBox.Focus();
}
reader.Close();
}
}
connection.Close();
}
}
}
public partial class MainSystem: Form
{
void MainSystem_Load(object sender, EventArgs e)
{
UserPrivelege();
}
void UserPrivelege()
{
if (UserInformation.CurrentLoggedInUserType == "Member")
{
this.button3.Enabled = false; // Edit Button
this.button4.Enabled = false; // Delete Button
this.button7.Enabled = false;
this.button9.Enabled = true; // Admin Login Button
}
else if (UserInformation.CurrentLoggedInUserType == "Administrator" || UserInformation.isAdministrator)
{
this.button3.Enabled = true; // Edit Button
this.button4.Enabled = true; // Delete Button
this.button7.Enabled = true;
this.button9.Enabled = false; // Admin Login Button
}
}
}
public partial class Privelege : Form
{
void button1_Click(object sender, EventArgs e) // OK Button
{
Check();
}
void Check()
{
if (this.textBox1.Text == string.Empty || string.IsNullOrWhiteSpace(this.textBox1.Text))
{
SystemManager.ShowMessageBox("Username field required.", "Information", 2);
}
else if (this.textBox2.Text == string.Empty || string.IsNullOrWhiteSpace(this.textBox2.Text))
{
SystemManager.ShowMessageBox("Password field required.", "Information", 2);
}
else
{
SystemManager.AdminLogin(this.textBox1.Text, this.textBox2.Text, this, this.textBox1);
}
}
Thank you.
I really appreciate your answer.
There are several architectural issues here which when resolved will also make this function the way you want. First of all it is not ideal to call a function from a form which will act upon that form. It is a much better practice to return what is needed from that function and have the code to digest that result in the form which it affects. Let's try a simple example of what the login button could do:
private void btnLogin_Click(object sender, EventArgs e)
{
var login = new LoginForm();
login.ShowDialog();
var result = login.DialogResult == System.Windows.Forms.DialogResult.Yes;
if (result)
{
button2.Enabled = true;
button3.Enabled = true;
}
}
Obviously the only way this would work is if your login for was setting its DialogResult property, which is a simple way to pass a result from a modal dialog. We still have the issue of converting a login result to that value. This can be addressed in the login button of the dialog, and the login method it calls.
private void btnDialogLogin_Click(object sender, EventArgs e)
{
// Form validation here...
var result = SystemManager.AdminLogin(NameButton.Text, PassButton.Text);
DialogResult = DialogResult.No;
if (result)
{
DialogResult = DialogResult.Yes;
}
this.Close();
}
Now we have to change the AdminLogin method to a boolean:
public class SystemManager
{
public static bool AdminLogin(string _value1, string _value2)
{
// Database and evluation...
if(isAdmin)
{
return true;
}
return false;
}
}
This will make it easy to pass values as they are needed, without each object knowing more details about the other than is necessary. If the admin login needs to pass more information than just if the user is an admin, than create a class which contains all the different things one might want to know about the user's login and pass that as a return instead.
what you can do here is, once the user clicks login on your first form, you can send a boolean value to the constructor of your second form, say true for admin and false for others and depending on this value you can enable or disable your button.
The form load event, MainSystem_Load(), is only fired once (at first initialization). The UserPrivelege() function isn't called after the admin login. You will need to invoke that functionality after the admin logs in.
assign value to UserInformation.CurrentLoggedInUserType and on click of Admin login button open your login form as dialog and after close of this form call UserPrivelege(); fuction
Admin login onclick :-
PrivelegeForm frm= new LoginForm();
DialogResult result= frm.ShowDialog();
if (result==DialogResult.Ok)
{
UserPrivelege();
}
don't forget to assign your static variable UserInformation.CurrentLoggedInUserType
I am working on a program to manage a minecraft server with a local UI as well as a remote interface. I have a button on a ribbon bar that will enable or disable the remote interface and a textbox for inputting the port. Currently, I disable the textbox when the networking is enabled, but, disabling does not re-enable the textbox after I set it to true again (and setting a breakpoint reveals it to still be false).
private void NetToggleChecked(object sender, RoutedEventArgs e) {
portTextBox.IsEnabled = false;
if (ButtonPressedByUser) {
var result = MessageBox.Show("Are you sure you want to enable networking with the current settings?" +
" If not properly configured, it may be possible for an attacker to enter your server.",
"Simple Bukkit Wrapper", MessageBoxButton.YesNo, MessageBoxImage.Warning,
MessageBoxResult.No);
if (result == MessageBoxResult.No) {
ButtonPressedByUser = false;
NetworkToggle.IsChecked = false;
ButtonPressedByUser = true;
return;
}
}
Config.NetConf["enabled"] = "true";
int port;
if (!int.TryParse(Config.NetConf["port"], out port)) {
MessageBox.Show("Port could not be parsed (is it a number?)");
ButtonPressedByUser = false;
NetworkToggle.IsChecked = false;
ButtonPressedByUser = true;
return;
}
Net.Listener.StartListening(port);
}
private void NetworkToggleUnchecked(object sender, RoutedEventArgs e) {
portTextBox.IsEnabled = true;
if (ButtonPressedByUser) {
var result =
MessageBox.Show("Are you sure you wish to disable all networking to your server? It will " +
"be impossible to connect to it remotely and any existing connections will be closed.",
"", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
if (result == MessageBoxResult.No) {
ButtonPressedByUser = false;
NetworkToggle.IsChecked = true;
ButtonPressedByUser = true;
return;
}
}
Config.NetConf["enabled"] = "false";
Net.Listener.StopListening();
}
Thank you for any help resolving why the textbox will not enable again.
Old Question but i kept coming across it while searching for an answer so figured i'd post an answer anyways. There is a bug in the ribbonTextbox control that results in isenabled always being false if there is no command associated. There are 2 ways round this from what i have found:
1: Create a new control based on the ribbontextbox and override the isenabledcore property to always return true. As shown here Cannot set RibbonTextBox isEnable to False
2: Create a dummy command and associate it with the control
public static readonly ICommand DummyCommand = new RoutedCommand("Dummy", typeof(Control));
public static void Dummy(Object sender, ExecutedRoutedEventArgs e)
{
// Do nothing its a dummy command
}
public static void CanDummy(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
as described in a comment in this link http://blogs.msdn.com/b/wpf/archive/2010/10/21/wpf-ribbon-october-2010-update-details.aspx .
AS i said probably no help to the original poster but i kept coming across it while looking for an answer so it may save someone else a few minutes of googling time.