Firebase in Unity - Disable persistence - c#

I'm making a mobile game for Android using Firebase. This game has a system that allows the player to play offline and update/retrieve data from the database depending on the saved date-time.
This date-time (written in a local file) should be the same as the one saved in the database, and to do so I wrote this:
reference.Child("users/"+this.id+"/updateDate").SetValueAsync(updateDate).ContinueWith(task =>
{
if (task.IsCompleted) {
Debug.Log("Setting new update date into file: "+updateDate);
this.lastUpdateDate = updateDate;
WriteFile();
}
});
The problem is that, even if there is no internet connection, the value gets modified but the condition below is never satisfied so what happens is this:
If you read the value, even without internet connection, you read the "new" date-time, while the file still contains the "old" one (the one actually in the database).
I know the best solution is to delete everything and let offline persistence do its work, but I did a couple tests and it doesn't even work on Android's build. So my question is the following:
Is there a way to disable offline persistence in Unity?
Because I've tried "FirebaseDatabase.DefaultInstance.setPersistenceEnabled(false)" but it seems like that function is not even present in the Unity's API (it gives me compile errors).
Thank you for your assistance!

To disable persistence, do:
Firebase.FirebaseDatabase.DefaultInstance.SetPersistenceEnabled(false);
If you're coming from Google with the "Failed to initialize persistence storage" crash when testing Unity with 2 editors, do
#if UNITY_EDITOR
Firebase.FirebaseDatabase.DefaultInstance.SetPersistenceEnabled(false);
#endif

Related

Xamarin.Forms Android app SQLite data disappears

I am writing a Xamarin.Forms app for Android using C#. I setup the Sqlite dB at: System.Environment.SpecialFolder.Personal
When the app is deployed on device I can add data and then retrieve it.
However, when I check the app next day(offline, without debugging from pc) all the dB data is gone.
Does it mean that the dB file is gone after some time?
Data from DB should not gone.
Are your sure that your DB initialization code is ok? Maybe every time you started the app, tha data is restoring to some start state?
The mysterious dissappearance of data in a sqlite db can have multiple causes.
Make sure that your db file exists, maybe you can implement a small debug button somwhere which will throw an alert which tells you if the file exists.
However using System.Environment.SpecialFolder.Personal shouldn't be the cause, I use that folder for my apps as well.
Second, do you actively commit your transactions? Especially when your app gets backgrounded, i would recommend calling Commit() in order to make sure that every pending transaction gets written into database, since you never know when the garbage collector comes around while your app is backgrounded.
If you are working with multiple threads, make sure that you are opening your database in a mode supporting a multithreaded environment.
If you open your sqlite db with a simple
SQLiteConnection conn = new SQLite.SQLiteConnection(path);
the database will open single-threaded.
Try this instead:
SQLiteConnection conn = new SQLite.SQLiteConnection(path, SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.NoMutex);
If that doesn't help, please give a bit more insight into your code (how do you open the db, how do you insert/update data, etc...)

Importing work items into TFS from another system

TL;DR: How can I createTFS work items as a specific state?
I am trying to import our work items from our old system (Rational Team Concert). There aren't any suitable automagic tools, so I'm doing it manually. I exported everything I need into a neutral format and plan on importing them with a simple-ish C# program (Json data that has all the attributes from RTC). I've already decided how to map the info from RTC to TFS.
My problem is, how can I import TFS work items as a specific state? There is only one valid initial state. I'm not above programatically moving the state through the workflow, but that seems a bit crazy.
Thanks. I'm hoping I've missed something.
The TFS Integration Platform (which I don't recommend using) has an option called EnableBypassRuleDataSubmission (see here for more info: http://blogs.msdn.com/b/willy-peter_schaub/archive/2009/11/10/tfs-integration-platform-what-is-the-enablebypassruledatasubmission-in-the-configuration-file-question-answer-7.aspx)
This is what allows it to create WI's directly into the desired state. You should be able to use the same API's to do the same thing yourself. Note: TFS Integration Platform is Open Source I believe, so you can track down it's source and see exactly how it accomplishes it.

How to make a "Settings" file

I'm working on a C# WinForms app and I would like to know how can I make a "save state" button. I've heard about serialization, but I want the form to be restarted every run, but allow the user to reload the saved state.
For example, in games you can save your progress and then when you run the game you can either start a new game, or load the save (in either way, when you run the game you always get to the main menu, whether you want to start a new game or load the saved game), that's what I'm looking for.
I hope I've made myself clear.
you have to use the Isolated Storage in .NET to store application data clickhere
Many ways to do it however depending on the size and security specification of the information which needs to be loaded you could take different approaches.
One approach is surly what Dhaval Patel mentioned earlier [Isolated Storage in .NET]. If this information of yours is part of a wizard or something similar I would personally store them in a database table. This way your data will be quite accessible[Query-able] and you could enforce your security constraint much easier and you will have lots of room for maneuver in terms of future improvements.
Another advice[Only my personal opinion] : Don't pollute your config file with those settings in case you had that in your mind.

Python, Web app won't save to file. Server Side

If you want a quick version scroll down to the "Edit|1|" part.
I HAVE done a bit of searching on this and can't seem to figure it out. I have a Webserver and a Minecraft server on the same machine (it never takes large loads so its ok) and I need the user to be able to put some input (in an html form), have that input saved in a file on the server, handled by a middleman app (which I've already got done and is in c#) and the middleman app interacts with the minecraft server.
Now everything I either have done before or know how to do. The only problem is saving the content of the form into a temporary text file so that the middleman app can do its magic. I thought about using SQL (since its on the server cause minecraft uses it for stats) but in my opinion its a bit overkill for something that will only be there for a few seconds. (not to mention then ill have to add SQL into the middleman app).
I don't really care where on the server the file ends up since I'll likely hard code the location into the middleman app and it will be deleted after the middleman app reads it. I can get saving to work in IDLE but not in this app on the server.
(I know this code won't take in anything from a form, this was just written as a test to save files)
import os
name = "none";
def editFile():
workfile = open("edit.x",'w')
workfile.write(name)
workfile.close()
def application(environ, start_response):
status = "200 OK"
output = "Testificate (Feature will be up shortly)"
response_headers = [('Content-type', 'text/plain'),('Content-Length',str(len(output)))]
start_response(status, response_headers)
return [output]
Extra Server info...
Hardware: Sufficiently powerful
WebServer: Wamp w/ Python Module installed on Apache
Also here is a link to what runs with that code Click HERE.
Edit|1|: I guess I didn't get much into the problem (It was late lastnight when I wrote this). Basically Any type of file will do. I want Ideally the simplest to implement. The above code has no result On the server. It never creates the file nor can it read from the file (if I create it manually). I've been working at it for about a day and a half now. I'm really just hoping Its a mistake on my part. Could the server config in wamp dis-allow the creation of files via Python?
Check out the tempfile module, for example, tempfile.mkstemp() with a known directory. Have your "middleman app" poll (or perhaps using inotify) the directory for new files, process the file, and then delete it when done.
So I realized what I did while at lunch today. (facepalming myself in the process). The reason it wasn't working was the fact that I used backslashes, not forward slashes. So here is the working version of the above (I used triple quotes just to be sure). I also changed it to be absolute path.
def editFile():
workfile = open("""C:/wamp/www/test/edit.txt""",'w')
workfile.write(name)
workfile.close()
After that it worked flawlessly. So if anyone else makes that small mistake here is a reminder. lol Thanks to "mhawke" for the reply on tempfiles Its good info to have in either case.

Updating a desktop application without touching the attached .mdf

Just a quick question:
I'm in the finalizing state of my current C# project, and I'd like to send a version out to people that has 90% of the features initially requested, but it'll be a version of the software that will do all they need - they need the software as soon as possible, basically.
Therefore I'm going to be using the online install option in VS2008 that will use updating to add the final few features, as well as additional things, later. What I'm wondering is the following:
The program will come packaged with a .mdf file. When I create a new version of the program however, I don't want to change all of the data that has been added to the database already. My question is how do I go about doing this?
Thanks!
How are you planning to distribute the update? An installer will have flags indicating when a file should be replaced. (Date, version etc)
One-Click installation has the ability to check for changes on program startup.

Categories

Resources