Save Position on the cloud or locally
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I have a tracking software. At first I just send the position to the web Service
[Table("Positions")]
public class SalesmanPosition
[PrimaryKey, AutoIncrement]
public int PositionId get; set;
public int SalesmanId get; set;
public double X_long get; set;
public double Y_lat get; set;
public DateTime Event_time get; set;
private void PositionSaveWeb(SalesmanPosition sp)
SecurityProtocolType.Tls;
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
string json = JsonConvert.SerializeObject(sp);
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
string result = TryWebRequest(httpWebRequest);
But then realize sometimes internet connection isn't available so I decide store the position on a sqlite db until the connection is available again. So I create another class to handle the db.
public static class OrmExample
private static string dbPath = "/storage/emulated/0/DCIM/myDatabase.db3";
public static void StartDatabase()
SQLiteConnection db = new SQLiteConnection( dbPath, false);
db.CreateTable<SalesmanPosition>();
public static List<SalesmanPosition> GetPendingPositions()
List<SalesmanPosition> query;
using (SQLiteConnection db = new SQLiteConnection(dbPath, false))
query = db.Query<SalesmanPosition>("SELECT * FROM [Positions]");
return query;
public static void PositionDelete((SalesmanPosition sp))
using (SQLiteConnection db = new SQLiteConnection(dbPath, false))
db.Delete(sp);
public static void PositionInsert(SalesmanPosition sp)
using (SQLiteConnection db = new SQLiteConnection(dbPath, false))
db.Insert(sp);
Right now In my main code I have
private void SavePosition ( SalesmanPosition newPosition )
GetConnectionStatus();
if (isOnline)
PositionSaveWeb(newPosition);
foreach( SalesmanPosition sp in OrmExample.GetPendingPositions()
PositionSaveWeb(sp);
PositionDelete(sp);
else
OrmExample.PositionInsert(newPosition);
But not sure I should add all those function as method for the class SalesmanPosition
- SavePosition
- PositionInsert
- PositionDelete
And on the Orm only the StartDatabase
and GetPendingPositions()
So should be resume to
newPosition.Save(); // include connection check and decide if send web or save locally.
if (isOnline)
foreach( SalesmanPosition sp in OrmExample.GetPendingPositions()
sp.Save();
sp.Delete();
c# sqlite xamarin
add a comment |Â
up vote
1
down vote
favorite
I have a tracking software. At first I just send the position to the web Service
[Table("Positions")]
public class SalesmanPosition
[PrimaryKey, AutoIncrement]
public int PositionId get; set;
public int SalesmanId get; set;
public double X_long get; set;
public double Y_lat get; set;
public DateTime Event_time get; set;
private void PositionSaveWeb(SalesmanPosition sp)
SecurityProtocolType.Tls;
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
string json = JsonConvert.SerializeObject(sp);
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
string result = TryWebRequest(httpWebRequest);
But then realize sometimes internet connection isn't available so I decide store the position on a sqlite db until the connection is available again. So I create another class to handle the db.
public static class OrmExample
private static string dbPath = "/storage/emulated/0/DCIM/myDatabase.db3";
public static void StartDatabase()
SQLiteConnection db = new SQLiteConnection( dbPath, false);
db.CreateTable<SalesmanPosition>();
public static List<SalesmanPosition> GetPendingPositions()
List<SalesmanPosition> query;
using (SQLiteConnection db = new SQLiteConnection(dbPath, false))
query = db.Query<SalesmanPosition>("SELECT * FROM [Positions]");
return query;
public static void PositionDelete((SalesmanPosition sp))
using (SQLiteConnection db = new SQLiteConnection(dbPath, false))
db.Delete(sp);
public static void PositionInsert(SalesmanPosition sp)
using (SQLiteConnection db = new SQLiteConnection(dbPath, false))
db.Insert(sp);
Right now In my main code I have
private void SavePosition ( SalesmanPosition newPosition )
GetConnectionStatus();
if (isOnline)
PositionSaveWeb(newPosition);
foreach( SalesmanPosition sp in OrmExample.GetPendingPositions()
PositionSaveWeb(sp);
PositionDelete(sp);
else
OrmExample.PositionInsert(newPosition);
But not sure I should add all those function as method for the class SalesmanPosition
- SavePosition
- PositionInsert
- PositionDelete
And on the Orm only the StartDatabase
and GetPendingPositions()
So should be resume to
newPosition.Save(); // include connection check and decide if send web or save locally.
if (isOnline)
foreach( SalesmanPosition sp in OrmExample.GetPendingPositions()
sp.Save();
sp.Delete();
c# sqlite xamarin
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a tracking software. At first I just send the position to the web Service
[Table("Positions")]
public class SalesmanPosition
[PrimaryKey, AutoIncrement]
public int PositionId get; set;
public int SalesmanId get; set;
public double X_long get; set;
public double Y_lat get; set;
public DateTime Event_time get; set;
private void PositionSaveWeb(SalesmanPosition sp)
SecurityProtocolType.Tls;
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
string json = JsonConvert.SerializeObject(sp);
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
string result = TryWebRequest(httpWebRequest);
But then realize sometimes internet connection isn't available so I decide store the position on a sqlite db until the connection is available again. So I create another class to handle the db.
public static class OrmExample
private static string dbPath = "/storage/emulated/0/DCIM/myDatabase.db3";
public static void StartDatabase()
SQLiteConnection db = new SQLiteConnection( dbPath, false);
db.CreateTable<SalesmanPosition>();
public static List<SalesmanPosition> GetPendingPositions()
List<SalesmanPosition> query;
using (SQLiteConnection db = new SQLiteConnection(dbPath, false))
query = db.Query<SalesmanPosition>("SELECT * FROM [Positions]");
return query;
public static void PositionDelete((SalesmanPosition sp))
using (SQLiteConnection db = new SQLiteConnection(dbPath, false))
db.Delete(sp);
public static void PositionInsert(SalesmanPosition sp)
using (SQLiteConnection db = new SQLiteConnection(dbPath, false))
db.Insert(sp);
Right now In my main code I have
private void SavePosition ( SalesmanPosition newPosition )
GetConnectionStatus();
if (isOnline)
PositionSaveWeb(newPosition);
foreach( SalesmanPosition sp in OrmExample.GetPendingPositions()
PositionSaveWeb(sp);
PositionDelete(sp);
else
OrmExample.PositionInsert(newPosition);
But not sure I should add all those function as method for the class SalesmanPosition
- SavePosition
- PositionInsert
- PositionDelete
And on the Orm only the StartDatabase
and GetPendingPositions()
So should be resume to
newPosition.Save(); // include connection check and decide if send web or save locally.
if (isOnline)
foreach( SalesmanPosition sp in OrmExample.GetPendingPositions()
sp.Save();
sp.Delete();
c# sqlite xamarin
I have a tracking software. At first I just send the position to the web Service
[Table("Positions")]
public class SalesmanPosition
[PrimaryKey, AutoIncrement]
public int PositionId get; set;
public int SalesmanId get; set;
public double X_long get; set;
public double Y_lat get; set;
public DateTime Event_time get; set;
private void PositionSaveWeb(SalesmanPosition sp)
SecurityProtocolType.Tls;
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
string json = JsonConvert.SerializeObject(sp);
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
string result = TryWebRequest(httpWebRequest);
But then realize sometimes internet connection isn't available so I decide store the position on a sqlite db until the connection is available again. So I create another class to handle the db.
public static class OrmExample
private static string dbPath = "/storage/emulated/0/DCIM/myDatabase.db3";
public static void StartDatabase()
SQLiteConnection db = new SQLiteConnection( dbPath, false);
db.CreateTable<SalesmanPosition>();
public static List<SalesmanPosition> GetPendingPositions()
List<SalesmanPosition> query;
using (SQLiteConnection db = new SQLiteConnection(dbPath, false))
query = db.Query<SalesmanPosition>("SELECT * FROM [Positions]");
return query;
public static void PositionDelete((SalesmanPosition sp))
using (SQLiteConnection db = new SQLiteConnection(dbPath, false))
db.Delete(sp);
public static void PositionInsert(SalesmanPosition sp)
using (SQLiteConnection db = new SQLiteConnection(dbPath, false))
db.Insert(sp);
Right now In my main code I have
private void SavePosition ( SalesmanPosition newPosition )
GetConnectionStatus();
if (isOnline)
PositionSaveWeb(newPosition);
foreach( SalesmanPosition sp in OrmExample.GetPendingPositions()
PositionSaveWeb(sp);
PositionDelete(sp);
else
OrmExample.PositionInsert(newPosition);
But not sure I should add all those function as method for the class SalesmanPosition
- SavePosition
- PositionInsert
- PositionDelete
And on the Orm only the StartDatabase
and GetPendingPositions()
So should be resume to
newPosition.Save(); // include connection check and decide if send web or save locally.
if (isOnline)
foreach( SalesmanPosition sp in OrmExample.GetPendingPositions()
sp.Save();
sp.Delete();
c# sqlite xamarin
asked Jan 12 at 20:42
Juan Carlos Oropeza
14618
14618
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f184988%2fsave-position-on-the-cloud-or-locally%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password