Exemple #1
0
 public static void PutNow(SerialCCS serial, bool forceReplace)
 {
     if (OnPutCCS != null)
     {
         OnPutCCS(serial);
     }
     Try(() =>
     {
         PutAsync(CCSStore, serial, forceReplace, null).Wait();
         return(true);
     }, 3);
 }
Exemple #2
0
 public bool Equals(SerialCCS cCS)
 {
     return(cCS != null &&
            EqualityComparer <int[]> .Default.Equals(NumericID, cCS.NumericID) &&
            EqualityComparer <byte[]> .Default.Equals(Data, cCS.Data));
 }
Exemple #3
0
        public static Tuple <SerialSDS, SerialCCS> Begin(Int3 myID, Action <SerialSDS> fetchSDS, Action <SerialCCS> fetchCCS)
        {
            sdsPoller = new DBType.ContinuousPoller <SerialSDS>(null, (collection) =>
            {
                SerialSDS latest = null;
                foreach (var candidate in collection)
                {
                    if (latest == null || latest.Generation < candidate.Generation)
                    {
                        latest = candidate;
                    }
                    else if (latest.Generation == candidate.Generation)
                    {
                        //weird, but let's check
                        if (!candidate.IC.IsEmpty)
                        {
                            throw new IntegrityViolation("SDS candidate at g=" + candidate.Generation + " is not consistent");
                        }
                        if (candidate.Generation != latest.Generation)
                        {
                            throw new IntegrityViolation("SDS candidate at g=" + candidate.Generation + " mismatch with favorite at g=" + latest.Generation);
                        }
                        var comp = new Helper.Comparator()
                                   .Append(candidate.SerialEntities, latest.SerialEntities)
                                   .Finish();
                        if (comp != 0)
                        {
                            Log.Error("Persistent SDS data mismatch at g=" + candidate.Generation);
                            if (comp < 0)
                            {
                                latest = candidate;
                            }
                        }
                    }
                }
                if (!latest.IC.IsEmpty)
                {
                    throw new IntegrityViolation("Chosen persistent SDS candidate at g=" + latest.Generation + " is not consistent");
                }
                return(latest);
            });
            sdsPoller.Start(SDSStore, myID.Encoded);
            sdsPoller.OnChange = serial => fetchSDS(serial);


            ccsPoller = new DBType.ContinuousPoller <SerialCCS>(null, (collection) =>
            {
                SerialCCS latest = null;
                foreach (var candidate in collection)
                {
                    if (latest == null || latest.Generation < candidate.Generation)
                    {
                        latest = candidate;
                    }
                    else if (latest.Generation == candidate.Generation)
                    {
                        //weird, but let's check
                        if (candidate.Generation != latest.Generation)
                        {
                            throw new IntegrityViolation("CCS candidate at g=" + candidate.Generation + " mismatch with favorite at g=" + latest.Generation);
                        }
                        var comp = new Helper.Comparator()
                                   .Append(candidate.Data, latest.Data)
                                   .Finish();
                        if (comp != 0)
                        {
                            Log.Error("Persistent CCS data mismatch at g=" + candidate.Generation);
                            if (comp < 0)
                            {
                                latest = candidate;
                            }
                        }
                    }
                }
                return(latest);
            });
            ccsPoller.Start(CCSStore, myID.Encoded);
            ccsPoller.OnChange = serial => fetchCCS(serial);

            return(new Tuple <SerialSDS, SerialCCS>(sdsPoller.Latest, ccsPoller.Latest));
        }