How I can refresh ParseUser.CurrentUser in Xamarin for iOS ?
There is no any method like refresh().
From the Parse forums:
ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.fetchInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
ParseUser currUser = (ParseUser) object;
// Do Stuff with currUSer
} else {
// Failure!
}
}
});
Related
I am trying to handle protocol activation and as per docs I should handle all of that within OnLaunched method so that is what I am trying to do here, but Microsoft.Windows.AppLifecycle.ProtocolActivatedEventArgs doesnt exist.
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
var activatedArgs = AppInstance.GetCurrent().GetActivatedEventArgs();
var e = args.UWPLaunchActivatedEventArgs;
InitializeRootFrame(e);
if (activatedArgs.Kind is ExtendedActivationKind.Launch)
{
if (!e.PrelaunchActivated)
{
if (RootFrame.Content == null)
{
RootFrame.Navigate(typeof(LoginPage), e.Arguments);
}
Window.Current.Activate();
}
}
else //Launched by some other means other than normal launching
{
try
{
if (activatedArgs.Kind is ExtendedActivationKind.Protocol && activatedArgs is Microsoft.Windows.AppLifecycle.ProtocolActivatedEventArgs eventArgs)
{
//var a = activatedArgs.Data as ProtocolActivatedEventArgs;
var queryParameters = HttpUtility.ParseQueryString(activatedArgs.Data.Uri.Query);
PocessQueryForToken(queryParameters);
}
}
catch (Exception)
{
}
finally
{
RootFrame.Navigate(typeof(LoginPage));
Window.Current.Activate();
HasLaunched = true;
}
}
HasLaunched = true;
}
There is only a AppActivationArguments Class in the Microsoft.Windows.AppLifecycle NameSpace. So the behavior you got is expected because you are looking for a class that doesn't even exist.
Based on the document for AppActivationArguments, we could know that the activatedArgs we got contains a data object which has one of the following data types, depending on the activation type specified by the Kind property.
File ->IFileActivatedEventArgs
Protocol ->IProtocolActivatedEventArgs
StartupTask ->IStartupTaskActivatedEventArgs
The IProtocolActivatedEventArgs should be the thing that we are looking for. The document here-ProtocolActivatedEventArgs Class shows that this Class comes from the Windows.ApplicationModel.Activation Namespace.
So the code should looks like this:
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
var eventargs = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs();
if (eventargs.Kind is ExtendedActivationKind.Protocol && eventargs.Data is Windows.ApplicationModel.Activation.ProtocolActivatedEventArgs)
{
ProtocolActivatedEventArgs ProtocolArgs = eventargs.Data as ProtocolActivatedEventArgs;
var uri = ProtocolArgs.Uri;
}
}
This is my code in my registration form:
public override void Guardar()
{
if (ValidarCampos() == true)
{
try
{
if (MessageBox.Show("Desea guardar este registro?", "Mensaje", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
using (DBEntities db = new DBEntities())
{
bool contactExists = db.cliente.Any(o => o.nombre_cliente.Equals(txtRegCliente.Text));
if (contactExists)
{
MessageBox.Show("El cliente ingresado ya existe");
txtRegCliente.Clear();
return;
}
else
{
if (cliente_id == null)
oCliente = new cliente();
oCliente.nombre_cliente = txtRegCliente.Text;
oCliente.vendedor_id = Convert.ToInt32(cbRegVendedor.SelectedValue);
oCliente.tipo_cliente_id = Convert.ToInt32(cbRegTipoCliente.SelectedValue);
if (cliente_id == null)
{
db.cliente.Add(oCliente);
}
else
{
db.Entry(oCliente).State = EntityState.Modified;
}
db.SaveChanges();
MessageBox.Show("Se ha guardado correctamente");
this.Close();
}
}
}
}
catch (Exception error)
{
MessageBox.Show("Ha ocurrido un error: " + error.Message);
}
}
}
I have 2 buttons, New and Edit, both open the same windows form. If I click "New" the textbox and combobox are clean and if it's "Edit" the form will be open with the values from database. It works fine when it's "New" but when it's "Edit" and I want to modify another textbox that is not "nombre_cliente" I get a message: "The customer already exist". I just want to return to the form if the especific textbox "nombre_cliente" is already in the database in both cases "New" and "Edit" I am using windows form, EF Database, C#
EDIT:
This is my first form:
And it's code(the important part for my problem) :
private int? GetId()
{
try
{
return int.Parse(dgvTablas.Rows[dgvTablas.CurrentRow.Index].Cells[0].Value.ToString());
}
catch
{
return null;
}
}
#endregion
public override void Nuevo()
{
Presentation.FrmRegCliente oCliente = new Presentation.FrmRegCliente();
oCliente.ShowDialog();
Refrescar();
}
public override void Editar()
{
int? cliente_id = GetId();
if (cliente_id != null)
{
Presentation.FrmRegCliente oCliente = new Presentation.FrmRegCliente(cliente_id);
oCliente.ShowDialog();
Refrescar();
}
}
And my second form for add or edit a record:
And the part of code that I skipped at the beginning:
public partial class FrmRegCliente : FrmBaseGuardar
{
public int? cliente_id;
cliente oCliente = null;
public FrmRegCliente(int? cliente_id = null)
{
InitializeComponent();
this.cliente_id = cliente_id;
if (cliente_id != null)
CargaDatos();
else
{
CargarVendedor();
CargarTipoCliente();
}
}
private void CargaDatos()
{
CargarVendedor();
CargarTipoCliente();
using (DBEntities db = new DBEntities())
{
oCliente = db.cliente.Find(cliente_id);
cliente_id = oCliente.cliente_id;
txtRegCliente.Text = oCliente.nombre_cliente;
cbRegVendedor.SelectedValue = Convert.ToInt32(oCliente.vendedor_id);
cbRegTipoCliente.SelectedValue = Convert.ToInt32(oCliente.tipo_cliente_id);
}
}
//button "Guardar" code
PD: Sorry if my grammar is incorrect, english is not my first language
In Xamarin forms, I tried to make a login form using MVVM. When I write the code there is no error but it does not give the desired output.
public Command Login
{
get
{
return new Command(() =>
{
var d = database.loggin(Usernamelogin, Passwordlogin);
if (d != null)
{
if (d.UserName == Usernamelogin && d.Password == Passwordlogin)
{
App.Current.MainPage.DisplayAlert("Notification", "Successfully Login", "Okay");
}
else
{
App.Current.MainPage.DisplayAlert("Notification", "Error Login", "Okay");
}
}
else
{
App.Current.MainPage.DisplayAlert("Notification", "No data", "Okay");
}
});
}
}
this is login command
public Register_person loggin(string mail,string pass )
{
return Conn.Table<Register_person>().FirstOrDefault(t => (t.Email == mail && t.Password == pass));
}
I only get the display message when the database is null statement. I cannot find why.
public ICommand Login { get; set; }
then add a constructor
public LoginViewModel()
{
Login = new Command(Login_Clicked);
}
then create a method Login_Clicked
private void Login_Clicked()
{
database = new Database();
var Logindata = database.GetUsername(_usernamelogin);
if (string.IsNullOrWhiteSpace(_usernamelogin) || string.IsNullOrWhiteSpace(_passwordlogin))
{
// your code
}
else
{
if (Logindata != null)
{
if (Logindata.UserName == _usernamelogin && Logindata.Password == _passwordlogin)
{
// your code
}
else
{
// your code
}
}
else
{
// your code
}
}
}
linc query
return Conn.Table<your Table name>().FirstOrDefault(t => t.Email == mail);
I extract email in the table
I have created a Singelton
static readonly License_plateRequests _instance = new License_plateRequests();
private License_plateRequests()
{
}
public static License_plateRequests instance
{
get { return _instance; }
}
public License_plate license_plateFirst { get; set; }
I run a clickevent in a page, to run some code where i set the singelton value. Its my first application in WPF so, i dont know if the patteren is right.
private async void enterButton_Click(object sender, RoutedEventArgs e)
{
if (ImageStatus.Source.ToString() == "pack://application:,,,/ParkeringsApp;component/Countries/Denmark-icon.png")
{
nationality = "DK";
}
if (ImageStatus.Source.ToString() == "pack://application:,,,/ParkeringsApp;component/Countries/Germany-icon.png")
{
nationality = "GER";
}
if (ImageStatus.Source.ToString() == "pack://application:,,,/ParkeringsApp;component/Countries/Norway-icon.png")
{
nationality = "NOR";
}
if (ImageStatus.Source.ToString() == "pack://application:,,,/ParkeringsApp;component/Countries/Sweden-icon.png")
{
nationality = "SWE";
}
if (ImageStatus.Source.ToString() == "pack://application:,,,/ParkeringsApp;component/Countries/United-Kingdom-flat-icon.png")
{
nationality = "GB";
}
var data = await loginRequest.LoginAsync();
var token = await loginRequest.ParkingToken(data.jwt);
var licenseplate = await licensePlate.LicensePlate(token, nationality, numberplateInput.Content.ToString());
var parkings = await licensePlate.getParkingById(token, licenseplate.id);
try
{
foreach (var parking in parkings)
{
if (parking == null)
{
parkingRequests.ParkCar(token, "aca0cd99-e392-4069-847f-8953ca86d7e6", licenseplate.id);
NavigationService.Navigate(new RegistredPage());
}
else if (parking.time_end == 0)
{
NavigationService.Navigate(paymentPage, licenseplate);
licensePlate.license_plateFirst.country.alpha2 = nationality;
}
else
{
parkingRequests.ParkCar(token, "aca0cd99-e392-4069-847f-8953ca86d7e6", licenseplate.id);
NavigationService.Navigate(new RegistredPage());
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
}
Then i navigate by NavigationService to the next page PaymentPage.
I get a nullpointer Exception in PaymentPage.
public partial class PaymentPage : Page
{
License_plateRequests licensePlate = License_plateRequests.instance;
public PaymentPage()
{
InitializeComponent();
System.Diagnostics.Debug.WriteLine(licensePlate.license_plateFirst.country.alpha2);
}
}
I get the null pointer when i try to run the application. I havent set the value yet, so offcourse
licensePlate.license_plateFirst.country.alpha2
gives me null. But i havent loaded that page yet, and i havent set the value.
How can i handle this, so i can get the value when the page is first loaded?
We want to upload the media to Amazon S3 via Sitecore & save the path of the uploaded media to the custom field.
So we created a custom field,which has a menu button to upload the media.
Here's my custom field class:
public class ExternalImage : Edit
{
public ExternalImage()
{
this.Class = "scContentControl";
}
public override void HandleMessage(Message message)
{
Assert.ArgumentNotNull(message, "message");
base.HandleMessage(message);
string name;
if (message["id"] == this.ID && (name = message.Name) != null)
{
if (name == "externalimage:open")
{
// Need help to open media upload popup here
}
}
}
}
UPDATE
After some research I came to know that I need to call/invoke the media:upload command within the code,so here is what I did(without any success ):
if (name == "externalimage:open")
{
string text = "media:upload(load=1,tofolder=1,id={3D6658D8-A0BF-4E75-B3E2-D050FABCF4E1})";
var item2 = Client.ContentDatabase.GetItem("{3D6658D8-A0BF-4E75-B3E2-D050FABCF4E1}");
Command command = CommandManager.GetCommand(text);
if (command == null)
{
SheerResponse.Alert(Translate.Text("Edit command not found."), new string[0]);
return;
}
CommandState commandState = CommandManager.QueryState(text, item2);
command.Execute(new CommandContext(item2));
return;
}