Save Position on the cloud or locally

The name of the pictureThe name of the pictureThe name of the pictureClash 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();








share|improve this question

























    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();








    share|improve this question





















      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();








      share|improve this question











      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();










      share|improve this question










      share|improve this question




      share|improve this question









      asked Jan 12 at 20:42









      Juan Carlos Oropeza

      14618




      14618

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          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



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          Chat program with C++ and SFML

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          Will my employers contract hold up in court?