Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Using Zumero Sync to sync a SQLite database - Getting error during sync.

$
0
0

I am using Zumero Sync to sync a SQLite DB in my Forms application, I am getting an error during sync.
I am using VS Pro 2015
When it its the sync function I get a pop up "An unhandled exception occured" in VS

Here is my code
SQLite_Android.CS
[assembly: Dependency(typeof(SQLite_Android))]

namespace HDW_Market.Droid
{

public class SQLite_Android : ISQLite
{
    private string fullPath;
    public SQLite_Android()
    {
    }

    #region ISQLite implementation
    public SQLite.SQLiteConnection GetConnection()
    {


        var sqliteFilename = "marketvendors.db3";
        string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); // Documents folder
        var path = Path.Combine(documentsPath, sqliteFilename);



        var conn = new SQLite.SQLiteConnection(path);

        // Return the database connection 
        return conn;
    }
    #endregion

    void ReadWriteStream(Stream readStream, Stream writeStream)
    {
        int Length = 256;
        Byte[] buffer = new Byte[Length];
        int bytesRead = readStream.Read(buffer, 0, Length);
        // write the required bytes
        while (bytesRead > 0)
        {
            writeStream.Write(buffer, 0, bytesRead);
            bytesRead = readStream.Read(buffer, 0, Length);
        }
        readStream.Close();
        writeStream.Close();
    }

}

}

DataLayer.CS

namespace HDW_Market
{
public class DataLayer
{
public DataLayer()
{
}

    public static void Sync(string filename, string cipherkey, string server_url, string dbfile, string auth_scheme, string user, string password)

    {

        //todo Fails at sync
        try
        {
            ZumeroClient.Sync(filename, cipherkey, server_url, dbfile, auth_scheme, user, password);
        }
        catch (ZumeroException e)
        {
            //Converting this to a base exception so that the upper layers don't have to depend 
            //on the Zumero library.
            throw new Exception("Zumero exception " + e.ErrorCode + ": " + e.ErrorString + " == " + e.ErrorDetails);
        }
    }


}

}

Under Android project
MainActivity

namespace HDW_Market.Droid
{
[Activity(Label = "HDW_Market", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{

    private string fullPath;
    string sqliteFilename;
    string path;        
    string urlText = "****";        
    string sDbfile = "****";
    string sAuthScheme = "{\"scheme_type\":\"table\",\"table\":\"users\"}";
    string sUsername = "****";
    string sPassword = "****";        
    string sCipherKey = "";

    protected override async void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);



        sqliteFilename = "marketvendors.db3";
        fullPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); // Documents folder
        path = Path.Combine(fullPath, sqliteFilename);

        await Sync();


        global::Xamarin.Forms.Forms.Init(this, bundle);
        Zumero.DataGridComponent.Init();
        LoadApplication(new App());
    }

    private async Task Sync()
    {


        try
        {
            await Task.Run(() => {
               DataLayer.Sync(path, sCipherKey, urlText, sDbfile, sAuthScheme, sUsername, sPassword);

            });
        }
        catch (Exception e)
        {

            return;
        }



    }



}

}


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>