Esempio n. 1
0
 internal void c_notify(m_notify notify)
 {
     if (notify.userid == all_command.address_updated)
     {
         reload_address();
     }
     else
     {
         a.api2.c_notify?.Invoke(notify);
     }
 }
Esempio n. 2
0
 internal void run(m_notify rsv)
 {
     if (a.api2.s_xid != null)
     {
         x_sync(rsv);
     }
     else
     {
         c_sync(rsv);
     }
 }
Esempio n. 3
0
        async void c_sync(m_notify rsv)
        {
            if (rsv.userid == all_command.reset_all_users)
            {
                return;
            }
            var type = list.FirstOrDefault(i => i.xid == rsv.xid);

            if (type == null)
            {
                return;
            }
            var    db   = a.c_db.general <m.c_history>();
            string id   = rsv.xid + "_" + rsv.userid;
            var    time = ((await db.get(id))?.time) ?? default;
            y_sync y    = new() { a_time = time, a_xid = rsv.xid };
            var    o    = await y.run(a.api3.c_run(rsv.userid));

            if (o.deleted != null && o.deleted.Length != 0)
            {
                await db.delete_many(i => o.deleted.Contains(i.id));

                await a.c_sync.delete(rsv.xid, rsv.userid, o.deleted);
            }
            if (o.updated != null && o.updated.Length != 0)
            {
                var items = o.updated.Select(i => JsonConvert.DeserializeObject(i, type.type) as m_sync).ToArray();
                var db2   = a.c_db.sync(rsv.xid, rsv.userid);
                foreach (var item in items)
                {
                    await db2.upsert(item);
                }
                await a.c_sync.upsert(rsv.xid, rsv.userid, items);
            }
            if (o.time != time)
            {
                await db.upsert(new m.c_history()
                {
                    id = id, time = o.time
                });
            }
        }

        async void x_sync(m_notify rsv)
        {
            if (a.api2.s_xid == all_command.x_center || a.api2.s_xid == null)
            {
            }

            var db          = a.s_db;
            var time_binary = (await db.general_x <m_string>().get("last_sync"))?.data;

            var time                       = time_binary == null ? default : DateTime.FromBinary(long.Parse(time_binary));
                                  y_sync y = new() { a_time = time, a_xid = all_command.x_center };
                                  var    o = await y.run(a.run_x);

                                  if (o.deleted != null && o.deleted.Length != 0)
                                  {
                                      await db.general_x <m_id>().delete_many(o.deleted);
                                  }

                                  if (o.updated != null && o.updated.Length != 0)
                                  {
                                      var items = o.updated.Select(i => JsonConvert.DeserializeObject <sync_center>(i)).ToArray();
                                      var db2   = db.general_x <sync_center>();
                                      foreach (var item in items)
                                      {
                                          await db2.upsert(item);
                                      }
                                  }
                                  if (o.time != time)
                                  {
                                      await db.general_x <m_string>().upsert(new m_string()
                {
                    id = "last_sync", data = o.time.ToBinary().ToString()
                });
                                  }
        }
    }
}