I have a piece of code that saves my ussers in my database like so:
public void createAccount()
{
FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://xxx-xxx.firebaseio.com/");
FirebaseApp.DefaultInstance.SetEditorP12FileName("xxx xxx-dd21907c659a.p12");
FirebaseApp.DefaultInstance.SetEditorServiceAccountEmail("xxx#xxx-xxx.iam.gserviceaccount.com");
FirebaseApp.DefaultInstance.SetEditorP12Password("notasecret");
DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;
FirebaseDatabase.DefaultInstance.GetReference("users").Child(username.GetComponent<InputField>().text).Child("likes").GetValueAsync().ContinueWith(task =>
{
if (task.IsFaulted)
{
email.GetComponent<InputField>().textComponent.color = Color.red;
}
else if (task.IsCompleted)
{
DataSnapshot snapshot = task.Result;
if (snapshot.Value == null)
{
DataBase.userID = username.GetComponent<InputField>().text;
DataBase.email = email.GetComponent<InputField>().text;
DataBase.password = password.GetComponent<InputField>().text;
DataBase.signedIn = true;
reference.Child("users").Child(DataBase.userID).Child("likes").SetValueAsync(DataBase.followers);
reference.Child("users").Child(DataBase.userID).Child("email").SetValueAsync(DataBase.email);
reference.Child("users").Child(DataBase.userID).Child("password").SetValueAsync(DataBase.password);
SceneManager.LoadScene("game");
}
else
{
username.GetComponent<InputField>().textComponent.color = Color.red;
}
}
});
}
It works just fine when I use it on unity but when I compile it and run it on my android device it doesn't send any information to the database. It does not even turn the text color to red which would indicate that the task is faulted.... Hope you can help me figure it out.
remove spaces from the project direction, including the name itself.
try to make the names of all the directories in the project space-free.
Related
I'am in the process of migrating my game to the new UnityAds 4.3.0.
I am unable to comprehend how to migrate to the new unity listeners and how to use the old code.
I have added the listners
public class UnityAdsManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
My old code
button_video.GetComponent<Button>().onClick.AddListener(delegate
{
playSound(buttonSound);
//RewarderAd
if (Advertisement.IsReady("rewardedVideo"))
{
UnityEngine.Debug.Log("Advertisement.IsReady2");
ShowOptions showOptions = new ShowOptions
{
resultCallback = delegate(ShowResult result)
{
if (result == ShowResult.Finished && isVideo)
{
SecurityPlayerPrefs.SetInt("Credit", credit);
}
}
};
Advertisement.Show(_adUnitId, this);
}
Advertisement.Show(_adUnitId, this);
Debug.Log("Ad Showing: " + _adUnitId);
});
isFreeView = true;
}
I understand that the oncompletion code will get the rewards done.
// Implement the Show Listener's OnUnityAdsShowComplete callback method to determine if the user gets a reward:
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
{
if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
{
Debug.Log("Unity Ads Rewarded Ad Completed");
// Grant a reward.
// Load another ad:
Advertisement.Load(_adUnitId, this);
}
}
is there a possibility to use the old code "ShowOption" and reward the user.
Or am I going about this the wrong way?
I am facing an stranger issue when I try to debug one of my api via Swagger. If I remove the debugger points, the swagger automatically closes without showing the output. However, if I add debugger points, the debugger stops working and a pop-up is displayed showing the message the target process exited with code 1073741819 while evaluating a function.
Here is the pop-up that I have mentioned:
Here is the api that I am getting this issue on:
[HttpGet("feerate")]
public async Task<ActionResult<ResponseVM>> GetFeeRate(FeeName feeName, FeeSchedule feeSchedule, FeeUnit feeUnit, int vcu)
{
try
{
var rv = await service.GetFeeRate(feeName, feeSchedule, feeUnit, vcu);
return Ok(new ResponseVM
{
success = true,
data = rv,
message = "Fee rate fetched successfully"
});
}
catch (Exception ex)
{
return Ok(new ResponseVM
{
success = false,
message = ex.Message
});
}
}
Here is the service function:
public async Task<PaginatedResponseVM<FeeScheduleDto>> GetFeeRate(FeeName feeName, FeeSchedule feeSchedule, FeeUnit feeUnit, int vcu)
{
var accQueryList = _dbContext.FeeSchedule.Where(x => x.FeeSchedule == feeSchedule);
accQueryList = accQueryList.Where(x => x.FeeName == feeName);
accQueryList = accQueryList.Where(x => x.FeeUnit == feeUnit);
accQueryList = accQueryList.Where(x => x.TierStart <= vcu);
accQueryList = accQueryList.Where(x => x.TierEnd > vcu);
var count = await accQueryList.CountAsync();
var items = _mapper.Map<List<FeeScheduleDto>>(await accQueryList.ToListAsync());
var returnView = new PaginatedResponseVM<FeeScheduleDto>(count, items);
return returnView;
}
Here is what I tried to resolve it:
Restarted my PC
Upgraded Visual Studio version
Repaired the Visual Studio via Control Panel
Cleaned the solution and Rebuild it
But the issue persists, so is there anyone who faced a similar issue and how it was resolved?
Any help would be appreciated.
Everyone thank you for all your replies and insights. However, the problem was with my Enum that I had used in the Dto file in the wrong manner. As the pop-up error says, I had to check again and again and at last correct my silly mistake.
So, while the enum is converted to string, the enum variable should be converted to string rather than the returning string variable itself.
Here is the correct way:
public FeeScheduleEnum FeeSchedule { get; set; }
public string FeeScheduleName { get { return FeeSchedule.ToString(); } }
So, this is where I had done that silly mistake:
public FeeScheduleEnum FeeSchedule { get; set; }
public string FeeScheduleName { get { return FeeScheduleName.ToString(); } }
Posting my answer here for anyone else doing that same mistake as I did.
I have an issue with signing in anonymously into my Firebase database for my Unity game. I have a method for signing anonymously into the database and another one that reads the database and prints a json string.
public IEnumerator anonymousSignIn()
{
var register = auth.SignInAnonymouslyAsync();
yield return new WaitUntil(predicate: ()=> register.IsCompleted);
}
public IEnumerator readDatabase()
{
var DBTask = DBreference.Child("users").GetValueAsync();
yield return new WaitUntil(predicate: () => DBTask.IsCompleted);
if (DBTask.Exception != null)
{
Debug.LogWarning(message: $"Failed to register task with {DBTask.Exception}");
}
else if (DBTask.Result.Value == null)
{
Debug.LogWarning("No data found in the database");
}
else
{
DataSnapshot snapshot = DBTask.Result;
string json = snapshot.GetRawJsonValue();
Debug.Log(json);
}
}
I then call these functions via a button in my Unity games using the method:
public void readButton()
{
StartCoroutine(anonymousSign());
StartCoroutine(readDatabase());
}
However, this sometimes works and other times It says permission denied and I don't understand why.
My database rules for reading are: ".read": "auth != null",
I got the same error.
After that, I changed the code
From:
Auth.SignInAnonymouslyAsync().ContinueWith(task => { SignInAnonymously(task, "Guest"); });
To:
Auth.SignInAnonymouslyAsync().ContinueWithOnMainThread(task => { SignInAnonymously(task, "Guest"); });
Don't use Async for Anonymous Sign In, but run on Main Thread.
It worked for me!
I want to pull and run an Image with Docker.DotNet and I am desperated, I have no Idea how to do this with this library.
Can anyone help me?
I looked at the tutorial on the https://github.com/microsoft/Docker.DotNet but that is not helpful.
public class DockerService
{
private readonly DockerClient DockerClient;
public DockerService()
{
if (OperatingSystem.IsWindows())
{
DockerClient = new DockerClientConfiguration(new Uri("npipe://./pipe/docker_engine")).CreateClient();
}
else if (OperatingSystem.IsLinux())
{
DockerClient = new DockerClientConfiguration(new Uri("unix:///var/run/docker.sock")).CreateClient();
}
else
{
throw new Exception("unknown operation system");
}
}
public void StartCompose()
{
var progress = new Progress<JSONMessage>();
var task = PullImage(
new ImagesCreateParameters()
{
FromImage = "mcr.microsoft.com/dotnet/core/sdk",
Tag = "latest"
},null,
progress);
task.Wait();
}
private Task PullImage(ImagesCreateParameters imagesCreateParameters, AuthConfig authConfig,
Progress<JSONMessage> progress)
{
return DockerClient.Images.CreateImageAsync(imagesCreateParameters, authConfig, progress);
}
}
I expect something to happen when I start task.wait()? But the it runs for several minutes and nothing happens.
Your code downloads the image and adds it to your local Docker registry. Run the command docker images from the command line and you should see that the image is there now.
Your image name looks wrong. You have the repository, but not the tag.
Looking at: https://hub.docker.com/_/microsoft-dotnet-core-sdk/
suggests you need: mcr.microsoft.com/dotnet/core/sdk:2.2
This is what I have so far which calls a GetCoordinates method and navigates to the map on a button click. I'm wondering though how I would pass over the coordinate data.
Does anyone know how I could pass the MyGeoPosition variable of type GeoPosition to the OnNavigatedTo method of my map class? I know how to call a method from another class but not how to pass data such as a variable.
private async Task GetCoordinates(string name = "My Car")
{
await Task.Run(async () =>
{
// Get the phone's current location.
Geolocator MyGeolocator = new Geolocator();
//need to pass the below variable containing coordinate data..
MyGeolocator.DesiredAccuracyInMeters = 5;
Geoposition MyGeoPosition = null;
try
{
MyGeoPosition = await MyGeolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Location is disabled in phone settings or capabilities are not checked.");
}
catch (Exception ex)
{
// Something else happened while acquiring the location.
MessageBox.Show(ex.Message);
}
});
}
//sets location of parking space using the GetCoordinates method
//opens map
private async void setLocationBtn_Click(object sender, RoutedEventArgs e)
{
await this.GetCoordinates();
NavigationService.Navigate(new Uri("/Maps.xaml", UriKind.Relative));
}
Try something like this
FirstPage
this.NavigationService.Navigate(new Uri(string.Format("LocationView.xaml?GeoX={0}&GeoY={1}", GeoX, GeoY), UriKind.Relative));
secondPage
if (NavigationContext.QueryString.ContainsKey("GeoX") && NavigationContext.QueryString.ContainsKey("GeoY"))
{
double GeoX =Convert.ToDouble(NavigationContext.QueryString["GeoX"].ToString());
double GeoY = Convert.ToDouble(NavigationContext.QueryString["GeoY"].ToString());
....
}
You could use PhoneApplicationservice to pass data between pages in windows phone application.
Here is good example about PhoneApplicationservice. Here is a short example how PhoneApplicationService works, may this will help you.
private async void setLocationBtn_Click(object sender, RoutedEventArgs e)
{
await this.GetCoordinates();
PhoneApplicationService.Current.State["Data"] = your data;
NavigationService.Navigate(new Uri("/Maps.xaml", UriKind.Relative));
}
//On Second page
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var data =PhoneApplicationService.Current.State["Data"] as Cast your type
PhoneApplicationService.Current.State.Remove("Data");
}
You can pass data by four ways which is clearly explained in following post
http://nishantcop.blogspot.in/2011/08/passing-data-between-pages-in-windows.html
Found another way in my searching for another issue:
http://msdn.microsoft.com/en-us/library/windows/apps/hh771188.aspx
Scroll down to: Passing information between pages
Its a lot simpler than my solution above, but my solution has other requirements hence why I chose that one, but for your needs, this is a better way.
I had a similar issue where I was passing user credentials between classes and I decided to use IsolatedStorageSettings class. But I have read that Windows will be depreciating this class in the future as it moves to merge Windows and Windows Phone code.
SO, this is the class I believe Microsoft want you to use so that you dont get stuck with a depreciated class in the future, and its called Windows.storage.
Hope this helps.
My case as said if for passing username and password along with if the user was a premium user and if when the app starts if they are already logged on. It would then re-log the user on automatically.
Here I create the storage in MainPage class
IsolatedStorageSettings myUserSettings = IsolatedStorageSettings.ApplicationSettings;
Here is the MainPage class method:
private void GetUserData()
{
// System.Diagnostics.Debug.WriteLine("Grabbing Data");
if (IsolatedStorageSettings.ApplicationSettings.Contains("userLoggedIn"))
{
string isLoggedIn = IsolatedStorageSettings.ApplicationSettings["userLoggedIn"] as string;
if (isLoggedIn.EndsWith("rue"))
isLoggedOn = true;
else
isLoggedOn = false;
// System.Diagnostics.Debug.WriteLine("log in data " + isLoggedIn + " " + isLoggedOn);
}
else
{
myUserSettings.Add("userLoggedIn", "false");
isLoggedOn = false;
}
if (IsolatedStorageSettings.ApplicationSettings.Contains("fullAccess"))
{
string hasFullAccess = IsolatedStorageSettings.ApplicationSettings["fullAccess"] as string;
if (hasFullAccess.EndsWith("rue"))
fullAccess = true;
else
fullAccess = false;
}
else
{
myUserSettings.Add("fullAccess", "false");
fullAccess = false;
}
if (IsolatedStorageSettings.ApplicationSettings.Contains("username"))
{
username = IsolatedStorageSettings.ApplicationSettings["username"] as string;
}
else
{
myUserSettings.Add("username", "");
username = "me";
}
if (IsolatedStorageSettings.ApplicationSettings.Contains("password"))
{
password = IsolatedStorageSettings.ApplicationSettings["password"] as string;
}
else
{
myUserSettings.Add("password", "");
password = "v";
}
myUserSettings.Save();
}
Now in my Login Class I have to create the storage variable again
IsolatedStorageSettings myUserSettings = IsolatedStorageSettings.ApplicationSettings;
And now once I verfied the user I write the relevant information to the storage file: (parts of method missing as irrelevant)
// Here I have just finished using JSON to extra info from a JSON response
if (success.EndsWith("rue"))
{
if (!myUserSettings.Contains("userLoggedIn"))
{
myUserSettings.Add("userLoggedIn", success);
}
else
{
myUserSettings["userLoggedIn"] = success;
}
if (!myUserSettings.Contains("username"))
{
myUserSettings.Add("username", username);
}
else
{
myUserSettings["username"] = username;
}
if (!myUserSettings.Contains("password"))
{
myUserSettings.Add("password", password);
}
else
{
myUserSettings["password"] = password;
}
if (!myUserSettings.Contains("fullAccess"))
{
myUserSettings.Add("fullAccess", fullAccess);
}
else
{
myUserSettings["fullAccess"] = fullAccess;
}
myUserSettings.Save();
and if something does not work, check that you did save the file as follows:
myUserSettings.Save();
Hope you can make sense of my example but please refer to the doco from Microsoft. This link shows a simple example I used to solve my requirements.