In my Xamarin iOS PCL app I'm trying to insert a record into my local Sqlite table, have it synced via Azure Mobile Services, and then read it back.
Here is the code:
private IMobileServiceSyncTable<Job> jobTable;
public async Task InitializeAsync()
{
var store = new MobileServiceSQLiteStore("localdata.db");
store.DefineTable<Job> ();
await this.MobileService.SyncContext.InitializeAsync(store);
jobTable = this.MobileService.GetSyncTable<Job>();
jobTable = this.MobileService.GetSyncTable<Job>();
JObject newJob = new JObject ();
newJob.Add ("Id","job_123");
jobTable.InsertAsync (newJob);
this.MobileService.SyncContext.PushAsync();
var readResult = jobTable.ReadAsync ().Result.AsQueryable();
var resultList = from data in readResult
select data;
var resultCount = resultList.Count ();
}
So far - nothing gets synced up with my Sql Server db (which is on the recieving end of the Mobile Services), and the resultCount remain at 0
I'm sure I do something wrong here, just can't seem to nail what exactly.
-Eugene
You should use PullAsync instead of ReadAsync. Also, you need to await the call to all of your async method calls, such as InsertAsync, PushAsync, and PullAsync.
See this tutorial for a detailed example: http://azure.microsoft.com/en-us/documentation/articles/mobile-services-xamarin-ios-get-started-offline-data/
Related
I am trying to use ListTablesSegmentedAsync and it doesn't seem to be using the continuable token. I am using Microsoft.Azure.Cosmos.Table v1.0.8 and trying to list tables on the storage emulator. Here's my simplified test code:
public async Task ListTablesTest(
CloudTableClient client)
{
TableContinuationToken continuationToken = null;
TableResultSegment ret;
ret = await client.ListTablesSegmentedAsync(
string.Empty,
5,
continuationToken,
CancellationToken.None);
continuationToken = ret.ContinuationToken;
ret = await client.ListTablesSegmentedAsync(
string.Empty,
5,
continuationToken,
CancellationToken.None);
}
Both calls to ListTablesSegmentedAsync return the first 5 tables (alphabetically). The token returned from the first call looks correct, as far as I can tell. Am I missing something? Maybe this doesn't work in the emulator?
Please make sure you're using the latest version of azure storage explorer 1.16.0 and azure storage emulator 5.10.
In my test, I'm also using Microsoft.Azure.Cosmos.Table v1.0.8, it can list next 5 tables by using ContinuationToken:
I have many problems to read data from a simple Firebase DB and to store it.
It's the first time that I use it so any help will be appreciated.
The solution is Xamarin.Forms and this is the Android part, my main problem.
This is my DB Structure:
I need to read and write the "number" value stored.
I add all Firebase package like Firebase.Database and Firebase.Connection
In my Android Prj I have a class with these:
MainActivity.cs
private void InitFirebaseAuth()
{
var options = new FirebaseOptions.Builder()
.SetApplicationId("******")
.SetApiKey("*******")
.SetDatabaseUrl("******")
.Build();
if (app == null)
app = FirebaseApp.InitializeApp(this, options, "SaloneB");
}
FirebaseHelper.cs
DatabaseReference databaseReference;
FirebaseDatabase database
public void Connect()
{
database = FirebaseDatabase.GetInstance(MainActivity.app);
}
First I call Connect then I try something like this without result:
FirebaseClient firebase = new FirebaseClient("*****");
//This to retrieve value
var items = await firebase
.Child("number_of_user") //name of the table
.OnceAsync(); //retrieve the value
Items result is 0 elements
Thanks for help
I need to search files by file name and content. Current implementation used Ole DB connection to windows search. But as I understand, Ole db wouldn't be implemented in .net core. I guess that I should use solution like Lucene .So I need advice, how to access windows search from .net-core at least or any ideas how to make that in cross-platform manner without windows search.
You basically have a couple of options. You can get hold of the FTQuery Tool (FTQuery.exe) in Windows 7 SDK and use Process Class in System.Diagnostics to get results by parsing standard output.
Alternatively you can create a separate ASP.NET Web API 2 project to act as a bridge between Windows Search and .NET Core using the following code as an action in your controller.
public async Task<IHttpActionResult> Post()
{
var data = new ArrayList();
var conn = new OleDbConnection("Provider=Search.CollatorDSO;Extended Properties='Application=Windows'");
await conn.OpenAsync();
string sql = await Request.Content.ReadAsStringAsync();
var cmd = new OleDbCommand(sql, conn);
using (var rdr = await cmd.ExecuteReaderAsync(CommandBehavior.CloseConnection))
{
while (await rdr.ReadAsync())
{
var row = new Dictionary<string, object>();
for (int i = 0; i < rdr.FieldCount; i++)
{
if (!rdr.IsDBNull(i))
row.Add(rdr.GetName(i), rdr.GetValue(i));
}
data.Add(row);
}
}
return Json(data);
}
I have the following code which I use frequently with Android and iOS when creating apps. Simply, it creates a lock when inserting, creating or updating a table.
public class SQL
{
readonly object dbLock = new object();
const string DBClauseSyncOff = "PRAGMA SYNCHRONOUS=OFF;";
const string DBClauseVacuum = "VACUUM;";
#region Setup
public bool SetupDB()
{
lock (dbLock)
As soon as the WinPhone 8.1 app hits this lock line, an exception is thrown. As this is part of a Xam.Forms application, I call this into existence using the following
public App()
{
App.Self = this;
var netLanguage = DependencyService.Get<ILocalise>().GetCurrent();
LangResources.Culture = new CultureInfo(netLanguage);
ConnectionString = DependencyService.Get<ISQLite>().GetConnectionString();
App.Self.SQLitePlatform = DependencyService.Get<ISQLite>().GetPlatform();
DBManager = new SQL();
DBManager.SetupDB();
Nothing is being called asynchronously with the two dependency services returning as their names suggest the connection and platform in use.
The calls look like this
public string GetConnectionString()
{
var documents = ApplicationData.Current.LocalFolder.Path;
var pConnectionString = System.IO.Path.Combine(documents, "preferences.db");
var connectionString = string.Format("{0}; New=true; Version=3;PRAGMA locking_mode=NORMAL; PRAGMA journal_mode=WAL; PRAGMA cache_size=20000; PRAGMA page_size=32768; PRAGMA synchronous=off", pConnectionString);
return connectionString;
}
public ISQLitePlatform GetPlatform()
{
return new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT();
}
If I comment out the SetupDB line, the app runs as I would expect. If it is left in, the app crashes with the error that it cannot create the initial display.
Is there something I need to be doing (or not doing) in order for the DB code to work on all platforms and not just Android and iOS?
I want to develop a Dragon Timer Windows Store App for GuildWars 2.
Whatever, I save a timestamp in a sql database. To get this timestamp in the app, I made a php script that writes the content of the database to a page. Now I'm trying to receive that string via the HttpClient.GetStringAsync() Method. Here's the code snipped:
async Task<Dictionary<String, DateTime>> GetKillTimes()
{
Dictionary<String, DateTime> killTimes = new Dictionary<String,DateTime>();
HttpClient httpClient = new HttpClient();
Task<string> getStringTask = httpClient.GetStringAsync("http://www.wp10454523.server-he.de/truhentimer/getTimes.php");
String rawKillTimes = await getStringTask;
//Parse to Dictionary...
return killTimes;
}
I tried some different Methods I got from google (WebRequest ...), but every one got stuck at the Get-Part. Am I maybe misinterpreting the function? Shouldn't I get the content of the page, which is a simple String?
You have to use await keyword as web request & response in WinRT are asynchronous so you have to use await keyword. await before httpClient.GetStringAsync(...)
Task<string> getStringTask = await httpClient.GetStringAsync("http://www.wp10454523.server-he.de/truhentimer/getTimes.php");