PersistenceMapperWEBAPIClient
No edit summary
No edit summary
Line 11: Line 11:
Another useful function is the "Closed for business" message. This is useful in environments that require some downtime in order for maintenance - like a new deploy.
Another useful function is the "Closed for business" message. This is useful in environments that require some downtime in order for maintenance - like a new deploy.


Checksum
==== Checksum ====
<html><pre>
<html><pre>
     public static void CheckIfOkToStartWithChecksum(PersistenceMapperWEBAPIClient pmapperWebClient, int checksumForThisES, IEcoTypeSystem typesystem, IAsyncSupportService asy)
     public static void CheckIfOkToStartWithChecksum(PersistenceMapperWEBAPIClient pmapperWebClient, int checksumForThisES, IEcoTypeSystem typesystem, IAsyncSupportService asy)

Revision as of 13:16, 14 December 2018

From before we have had the PersistenceMapperWCFClient that connects to a RemotePeristenceMapper (like the MDrivenServer is one example of).

We now also have the PersistenceMapperWEBAPIClient - it does the exact same thing but does not use WCF - instead it defaults to transport over https.

The main reason for this novelty is that Microsoft is moving away from WCF in .netStandard and ASP.Core.

As we introduced the PersistenceMapperWEBAPIClient we also added a few new functions that we have found useful:

The ability to compare checksum between client and server of the model content. This is important since a client that has the wrong model cannot be allowed to save objects to the server. Since we want to notify the user of this as soon as possible we need a way to find this fact out very early in the client-application -lifecycle.

Another useful function is the "Closed for business" message. This is useful in environments that require some downtime in order for maintenance - like a new deploy.

Checksum

    public static void CheckIfOkToStartWithChecksum(PersistenceMapperWEBAPIClient pmapperWebClient, int checksumForThisES, IEcoTypeSystem typesystem, IAsyncSupportService asy)
    {
      BackgroundWorker bw = new BackgroundWorker();
      bw.DoWork += (sender, e) => { CheckInBAckgroundThread(pmapperWebClient, checksumForThisES, typesystem, asy); };
      bw.RunWorkerAsync();

    }




    private static void CheckInBAckgroundThread(PersistenceMapperWEBAPIClient pmapperWebClient, int checksumForThisES, IEcoTypeSystem typesystem, IAsyncSupportService asy)
    {


      int tries = 0;
      DateTime time = DateTime.Now;
      bool ok = false;
      while (!ok && tries < 3 && (DateTime.Now - time) < TimeSpan.FromMinutes(1))
      {
        try
        {
          tries++;
          var res = pmapperWebClient.UsedHttpClient.GetStringAsync("CompareChecksumReturnDiffData?checksum=" + checksumForThisES.ToString()).Result;
          if (!string.IsNullOrEmpty(res.Replace('\"',' ').Trim()))
          {

            asy.DispatchTaskToMainThread(() => { HandleUserNotifications(res, typesystem); });
          }
          ok = true;
        }
        catch (Exception ex)
        {
          System.Threading.Thread.Sleep(200);
        }
      }

    }

    private static void HandleUserNotifications(string serverchecksumdata, IEcoTypeSystem typesystem)
    {

      var text = "WARNING - THE MDrivenServer SERVER HAS A DIFFERENT MODEL THAN YOU!!!\r\n" +
                      "\r\n" +
                      "The safe thing to do is to evolve the server...\r\n";



      string checksumdata = (typesystem as Eco.UmlRt.Impl.EcoTypeSystem).GetCheckSumData();

      if (serverchecksumdata != null && checksumdata != null)
      {
        int chunks = serverchecksumdata.Length / 200;

        int x = 0;
        string diffs = "";
        for (int i = 0; i < chunks; i++)
        {
          string s1 = serverchecksumdata.Substring(x * 200, 200);
          string s2 = checksumdata.Substring(x * 200, 200);
          if (s1 == s2)
          {

          }
          else
          {
            s1 = serverchecksumdata.Substring(Math.Max(0, (x * 200) - 50), 200 + 50 + 50); //Show a bit before and after the diff
            s2 = checksumdata.Substring(Math.Max(0, (x * 200) - 50), 200 + 50 + 50);
            diffs += x.ToString() + " SERVER:" + s1 + "\r\n";
            diffs += x.ToString() + " CLIENT:" + s2 + "\r\n";
            diffs += "\r\n";
            break;
          }
          x++;
        }

        MessageBox.Show(text + diffs);
        Application.Current.Shutdown();
      }
    }

This page was edited 96 days ago on 02/10/2024. What links here