コード例 #1
0
        private static Dictionary <FactID, FactID> ForEachFact(FactTreeMemento tree, Func <FactMemento, FactID?> processFact)
        {
            Dictionary <FactID, FactID> localIdByRemoteId = new Dictionary <FactID, FactID>();

            foreach (IdentifiedFactBase identifiedFact in tree.Facts)
            {
                if (identifiedFact is IdentifiedFactMemento)
                {
                    FactMemento translatedMemento = TranslateMemento(localIdByRemoteId, (IdentifiedFactMemento)identifiedFact);
                    if (translatedMemento != null)
                    {
                        FactID?localId = processFact(translatedMemento);
                        if (localId != null)
                        {
                            localIdByRemoteId.Add(identifiedFact.Id, localId.Value);
                        }
                    }
                }
                else if (identifiedFact is IdentifiedFactRemote)
                {
                    localIdByRemoteId.Add(identifiedFact.Id,
                                          ((IdentifiedFactRemote)identifiedFact).RemoteId);
                }
            }
            return(localIdByRemoteId);
        }
コード例 #2
0
 protected static FactMemento CreateRoom(long domainId)
 {
     FactMemento room = new FactMemento(TypeRoom);
     room.Data = new byte[] { 1, 2, 3, 4 };
     room.AddPredecessor(RoleRoomDomain, new FactID { key = domainId }, true);
     return room;
 }
コード例 #3
0
            public CorrespondenceFact CreateFact(FactMemento memento)
            {
                Like newFact = new Like(memento);


                return(newFact);
            }
コード例 #4
0
        private static FactMemento NewGame(Guid gameGuid)
        {
            FactMemento saveGame = new FactMemento(GameType);

            saveGame.Data = gameGuid.ToByteArray();
            return(saveGame);
        }
コード例 #5
0
        private List <IdentifiedFactMemento> FindExistingFacts(FactMemento memento, Procedures procedures, bool readCommitted)
        {
            int typeId = SaveType(procedures, memento.FactType);

            // Load all candidates that have the same hash code.
            return(procedures.GetEqualFactsByHashCode(memento, readCommitted, typeId));
        }
コード例 #6
0
            public CorrespondenceFact CreateFact(FactMemento memento)
            {
                Domain newFact = new Domain(memento);


                return(newFact);
            }
コード例 #7
0
 // Hydration constructor
 private CloudCentralThought(FactMemento memento)
 {
     InitializeResults();
     _cloud = new PredecessorObj <Cloud>(this, RoleCloud, memento);
     _prior = new PredecessorList <CloudCentralThought>(this, RolePrior, memento);
     _value = new PredecessorObj <Thought>(this, RoleValue, memento);
 }
コード例 #8
0
            public CorrespondenceFact CreateFact(FactMemento memento)
            {
                ShareDelete newFact = new ShareDelete(memento);


                return(newFact);
            }
コード例 #9
0
            public CorrespondenceFact CreateFact(FactMemento memento)
            {
                DisableToastNotification newFact = new DisableToastNotification(memento);


                return(newFact);
            }
コード例 #10
0
        private static void ReadBinary(IDataReader reader, FactMemento memento, int columnIndex)
        {
            byte[] buffer = new byte[1024];
            int    length = (int)reader.GetBytes(columnIndex, 0, buffer, 0, buffer.Length);

            memento.Data = new byte[length];
            Array.Copy(buffer, memento.Data, length);
        }
コード例 #11
0
        private static FactMemento NewMove(FactID gameId, byte moveIndex)
        {
            var move = new FactMemento(MoveType);

            move.Data = new byte[] { moveIndex };
            move.AddPredecessor(MoveGame, gameId, true);
            return(move);
        }
コード例 #12
0
        protected static FactMemento CreateRoom(long domainId)
        {
            FactMemento room = new FactMemento(TypeRoom);

            room.Data = new byte[] { 1, 2, 3, 4 };
            room.AddPredecessor(RoleRoomDomain, new FactID {
                key = domainId
            }, true);
            return(room);
        }
コード例 #13
0
 public FactID? FindExistingFact(string domain, FactMemento fact)
 {
     using (var procedures = new Procedures(new Session(_connectionString)))
     {
         FactID id;
         if (FindExistingFact(fact, out id, procedures, readCommitted: true))
             return id;
         return null;
     }
 }
コード例 #14
0
 private void AddToFactTree(string domain, FactTreeMemento messageBody, FactID factId, Dictionary <FactID, FactID> localIdByRemoteId)
 {
     if (!messageBody.Contains(factId))
     {
         FactMemento fact = _repository.Load(domain, factId);
         foreach (PredecessorMemento predecessor in fact.Predecessors)
         {
             AddToFactTree(domain, messageBody, predecessor.ID, localIdByRemoteId);
         }
         messageBody.Add(new IdentifiedFactMemento(factId, fact));
     }
 }
コード例 #15
0
 public FactID?FindExistingFact(string domain, FactMemento fact)
 {
     using (var session = new Session(_connectionString))
     {
         FactID id;
         if (FindExistingFact(fact, out id, session, readCommitted: true))
         {
             return(id);
         }
         return(null);
     }
 }
コード例 #16
0
 public FactID? FindExistingFact(string domain, FactMemento memento)
 {
     lock (this)
     {
         // See if the fact already exists.
         FactRecord fact = _factTable.FirstOrDefault(o =>
             o.IdentifiedFactMemento.Memento.Equals(memento));
         if (fact == null)
             return null;
         else
             return fact.IdentifiedFactMemento.Id;
     }
 }
コード例 #17
0
            public CorrespondenceFact CreateFact(FactMemento memento)
            {
                EnableToastNotification newFact = new EnableToastNotification(memento);

                // Create a memory stream from the memento data.
                using (MemoryStream data = new MemoryStream(memento.Data))
                {
                    using (BinaryReader output = new BinaryReader(data))
                    {
                    }
                }

                return(newFact);
            }
コード例 #18
0
            public CorrespondenceFact CreateFact(FactMemento memento)
            {
                Link newFact = new Link(memento);

                // Create a memory stream from the memento data.
                using (MemoryStream data = new MemoryStream(memento.Data))
                {
                    using (BinaryReader output = new BinaryReader(data))
                    {
                    }
                }

                return(newFact);
            }
コード例 #19
0
            public CorrespondenceFact CreateFact(FactMemento memento)
            {
                DisableToastNotification newFact = new DisableToastNotification(memento);

                // Create a memory stream from the memento data.
                using (MemoryStream data = new MemoryStream(memento.Data))
                {
                    using (BinaryReader output = new BinaryReader(data))
                    {
                        newFact._unique = (Guid)_fieldSerializerByType[typeof(Guid)].ReadData(output);
                    }
                }

                return(newFact);
            }
コード例 #20
0
            public CorrespondenceFact CreateFact(FactMemento memento)
            {
                Tune newFact = new Tune(memento);

                // Create a memory stream from the memento data.
                using (MemoryStream data = new MemoryStream(memento.Data))
                {
                    using (BinaryReader output = new BinaryReader(data))
                    {
                        newFact._name = (string)_fieldSerializerByType[typeof(string)].ReadData(output);
                    }
                }

                return(newFact);
            }
コード例 #21
0
			public CorrespondenceFact CreateFact(FactMemento memento)
			{
				Identity newFact = new Identity(memento);

				// Create a memory stream from the memento data.
				using (MemoryStream data = new MemoryStream(memento.Data))
				{
					using (BinaryReader output = new BinaryReader(data))
					{
						newFact._anonymousId = (string)_fieldSerializerByType[typeof(string)].ReadData(output);
					}
				}

				return newFact;
			}
コード例 #22
0
        private IdentifiedFactMemento DeserlializeIdentifiedFactMemento(BinaryReader factReader, long factId)
        {
            short dataSize;

            byte[] data;
            short  predecessorCount;

            CorrespondenceFactType factType = GetFactType(BinaryHelper.ReadShort(factReader));

            dataSize = BinaryHelper.ReadShort(factReader);
            if (dataSize > MaxDataLength)
            {
                throw new CorrespondenceException("Maximum data length exceeded.");
            }
            data             = dataSize > 0 ? factReader.ReadBytes(dataSize) : new byte[0];
            predecessorCount = BinaryHelper.ReadShort(factReader);
            if (predecessorCount > MaxPredecessorCount)
            {
                throw new CorrespondenceException("Maximum predecessor count exceeded.");
            }

            FactMemento factMemento = new FactMemento(factType);

            factMemento.Data = data;
            for (short i = 0; i < predecessorCount; i++)
            {
                bool isPivot;
                long predecessorFactId;

                RoleMemento role = GetRole(BinaryHelper.ReadShort(factReader));
                isPivot           = BinaryHelper.ReadBoolean(factReader);
                predecessorFactId = BinaryHelper.ReadLong(factReader);

                factMemento.AddPredecessor(
                    role,
                    new FactID()
                {
                    key = predecessorFactId
                },
                    isPivot
                    );
            }

            return(new IdentifiedFactMemento(new FactID {
                key = factId
            }, factMemento));
        }
コード例 #23
0
        private static FactMemento TranslateMemento(Dictionary <FactID, FactID> localIdByRemoteId, IdentifiedFactMemento identifiedFact)
        {
            FactMemento translatedMemento = new FactMemento(identifiedFact.Memento.FactType);

            translatedMemento.Data = identifiedFact.Memento.Data;
            foreach (PredecessorMemento remote in identifiedFact.Memento.Predecessors)
            {
                FactID localPredecessorId;
                if (!localIdByRemoteId.TryGetValue(remote.ID, out localPredecessorId))
                {
                    return(null);
                }

                translatedMemento.AddPredecessor(remote.Role, localPredecessorId, remote.IsPivot);
            }
            return(translatedMemento);
        }
コード例 #24
0
 public FactID?FindExistingFact(string domain, FactMemento memento)
 {
     lock (this)
     {
         // See if the fact already exists.
         FactRecord fact = _factTable.FirstOrDefault(o =>
                                                     o.IdentifiedFactMemento.Memento.Equals(memento));
         if (fact == null)
         {
             return(null);
         }
         else
         {
             return(fact.IdentifiedFactMemento.Id);
         }
     }
 }
コード例 #25
0
        public FactID InsertFact(FactMemento fact, int typeId)
        {
            _session.Command.CommandText = "INSERT Fact (FKTypeID, Data, Hashcode) VALUES (@TypeID, @Data, @Hashcode)";
            AddParameter("@TypeID", typeId);
            AddParameter("@Data", fact.Data);
            AddParameter("@Hashcode", fact.GetHashCode());
            _session.Command.ExecuteNonQuery();
            _session.Command.Parameters.Clear();

            _session.Command.CommandText = "SELECT @@IDENTITY";
            decimal result = (decimal)_session.Command.ExecuteScalar();

            _session.Command.Parameters.Clear();
            return(new FactID {
                key = (Int64)result
            });
        }
コード例 #26
0
        public List <IdentifiedFactMemento> GetEqualFactsByHashCode(FactMemento memento, bool readCommitted, int typeId)
        {
            _session.Command.CommandText = HEAD_SELECT +
                                           (readCommitted ? "" : "WITH (NOLOCK) ") +
                                           "WHERE f.FKTypeID = @TypeID AND f.Hashcode = @Hashcode " +
                                           TAIL_JOIN +
                                           "ORDER BY ff.FactID, p.PredecessorID";
            AddParameter("@TypeID", typeId);
            AddParameter("@Hashcode", memento.GetHashCode());
            using (var loader = new Loader(_session.Command.ExecuteReader()))
            {
                _session.Command.Parameters.Clear();

                return(loader.LoadMementos()
                       .Where(im => im.Memento.Equals(memento))
                       .ToList());
            }
        }
コード例 #27
0
        private bool FindExistingFact(FactMemento memento, out FactID id, Session session, bool readCommitted)
        {
            var existingFacts = FindExistingFacts(memento, session, readCommitted);

            if (existingFacts.Count > 1)
            {
                throw new CorrespondenceException(string.Format("More than one fact matched the given {0}.", memento.FactType));
            }
            if (existingFacts.Count == 1)
            {
                id = existingFacts[0].Id;
                return(true);
            }
            else
            {
                id = new FactID();
                return(false);
            }
        }
コード例 #28
0
        private List <IdentifiedFactMemento> FindExistingFacts(FactMemento memento, Session session, bool readCommitted)
        {
            int typeId = SaveType(session, memento.FactType);

            // Load all candidates that have the same hash code.
            session.Command.CommandText = HEAD_SELECT +
                                          (readCommitted ? "" : "WITH (NOLOCK) ") +
                                          "WHERE f.FKTypeID = @TypeID AND f.Hashcode = @Hashcode " +
                                          TAIL_JOIN +
                                          "ORDER BY ff.FactID, p.PredecessorID";
            AddParameter(session.Command, "@TypeID", typeId);
            AddParameter(session.Command, "@Hashcode", memento.GetHashCode());
            using (IDataReader factReader = session.Command.ExecuteReader())
            {
                session.Command.Parameters.Clear();

                return(LoadMementosFromReader(factReader).Where(im => im.Memento.Equals(memento)).ToList());
            }
        }
コード例 #29
0
        private static FactTreeMemento CreateTreeWithMultipleFacts()
        {
            FactTreeMemento tree = CreateTreeWithSingleFact();
            var             game = new FactMemento(
                new CorrespondenceFactType("TestModel.Game", 1))
                                   .AddPredecessor(
                CreateRoleDomain(),
                new FactID {
                key = 42
            },
                true);

            game.Data = new byte[] { 1, 2, 3, 4 };
            tree.Add(new IdentifiedFactMemento(
                         new FactID {
                key = 73
            },
                         game));
            return(tree);
        }
コード例 #30
0
 // Hydration constructor
 private Message(FactMemento memento)
 {
     InitializeResults();
     _messageBoard = new PredecessorObj<MessageBoard>(this, RoleMessageBoard, memento);
     _domain = new PredecessorObj<Domain>(this, RoleDomain, memento);
 }
コード例 #31
0
 // Hydration constructor
 private Individual(FactMemento memento)
 {
     InitializeResults();
 }
コード例 #32
0
 // Hydration constructor
 private Company(FactMemento memento)
 {
     InitializeResults();
 }
コード例 #33
0
 // Hydration constructor
 private Individual__name(FactMemento memento)
 {
     InitializeResults();
     _individual = new PredecessorObj <Individual>(this, GetRoleIndividual(), memento, Individual.GetUnloadedInstance, Individual.GetNullInstance);
     _prior      = new PredecessorList <Individual__name>(this, GetRolePrior(), memento, Individual__name.GetUnloadedInstance, Individual__name.GetNullInstance);
 }
コード例 #34
0
 // Hydration constructor
 private DeprovisionFrontOffice(FactMemento memento)
 {
     InitializeResults();
     _provision = new PredecessorObj<ProvisionFrontOffice>(this, RoleProvision, memento);
 }
コード例 #35
0
        public FactID Save(string domain, FactMemento fact, Guid clientGuid)
        {
            // Retry on concurrency failure.
            while (true)
            {
                using (var session = new Session(_connectionString))
                {
                    session.BeginTransaction();

                    // First see if the fact is already in storage.
                    FactID id;
                    if (FindExistingFact(fact, out id, session, readCommitted: true))
                    {
                        return(id);
                    }

                    // It isn't there, so store it.
                    int typeId = SaveType(session, fact.FactType);
                    session.Command.CommandText = "INSERT Fact (FKTypeID, Data, Hashcode) VALUES (@TypeID, @Data, @Hashcode)";
                    AddParameter(session.Command, "@TypeID", typeId);
                    AddParameter(session.Command, "@Data", fact.Data);
                    AddParameter(session.Command, "@Hashcode", fact.GetHashCode());
                    session.Command.ExecuteNonQuery();
                    session.Command.Parameters.Clear();

                    session.Command.CommandText = "SELECT @@IDENTITY";
                    decimal result = (decimal)session.Command.ExecuteScalar();
                    session.Command.Parameters.Clear();
                    id.key = (Int64)result;

                    // Store the predecessors.
                    foreach (PredecessorMemento predecessor in fact.Predecessors)
                    {
                        int roleId = SaveRole(session, predecessor.Role);
                        session.Command.CommandText = "INSERT Predecessor (FKFactID, FKRoleID, FKPredecessorFactID, IsPivot) VALUES (@FactID, @RoleID, @PredecessorFactID, @IsPivot)";
                        AddParameter(session.Command, "@FactID", id.key);
                        AddParameter(session.Command, "@RoleID", roleId);
                        AddParameter(session.Command, "@PredecessorFactID", predecessor.ID.key);
                        AddParameter(session.Command, "@IsPivot", predecessor.IsPivot);
                        session.Command.ExecuteNonQuery();
                        session.Command.Parameters.Clear();
                    }

                    // Store a message for each pivot.
                    FactID newFactId = id;
                    List <MessageMemento> pivotMessages = fact.Predecessors
                                                          .Where(predecessor => predecessor.IsPivot)
                                                          .Select(predecessor => new MessageMemento(predecessor.ID, newFactId))
                                                          .ToList();

                    // Store messages for each non-pivot. This fact belongs to all predecessors' pivots.
                    string[] nonPivots = fact.Predecessors
                                         .Where(predecessor => !predecessor.IsPivot)
                                         .Select(predecessor => predecessor.ID.key.ToString())
                                         .ToArray();
                    List <MessageMemento> nonPivotMessages;
                    if (nonPivots.Length > 0)
                    {
                        string nonPivotGroup = string.Join(",", nonPivots);
                        session.Command.CommandText = string.Format(
                            "SELECT DISTINCT PivotId FROM Message WHERE FactId IN ({0})",
                            nonPivotGroup);
                        List <FactID> predecessorsPivots;
                        using (IDataReader predecessorPivotReader = session.Command.ExecuteReader())
                        {
                            session.Command.Parameters.Clear();
                            predecessorsPivots = LoadIDsFromReader(predecessorPivotReader).ToList();
                        }

                        nonPivotMessages = predecessorsPivots
                                           .Select(predecessorPivot => new MessageMemento(predecessorPivot, newFactId))
                                           .ToList();
                    }
                    else
                    {
                        nonPivotMessages = new List <MessageMemento>();
                    }

                    int clientId = SaveClient(session, clientGuid);
                    var messages = pivotMessages.Union(nonPivotMessages).Distinct().ToList();
                    SaveMessages(session, messages, clientId);

                    // Optimistic concurrency check.
                    // Make sure we don't find more than one.
                    var existingFacts = FindExistingFacts(fact, session, readCommitted: false);
                    if (existingFacts.Count == 1)
                    {
                        session.Commit();

                        if (messages.Any() && PivotAffected != null)
                        {
                            foreach (var message in messages)
                            {
                                PivotAffected(domain, message.PivotId);
                            }
                        }
                        return(id);
                    }
                    else
                    {
                        _retried = true;
                    }
                }
            }
        }
コード例 #36
0
 // Hydration constructor
 private Share(FactMemento memento)
 {
     InitializeResults();
     _individual = new PredecessorObj<Individual>(this, RoleIndividual, memento);
     _messageBoard = new PredecessorObj<MessageBoard>(this, RoleMessageBoard, memento);
 }
コード例 #37
0
            public CorrespondenceFact CreateFact(FactMemento memento)
            {
                Message newFact = new Message(memento);

                // Create a memory stream from the memento data.
                using (MemoryStream data = new MemoryStream(memento.Data))
                {
                    using (BinaryReader output = new BinaryReader(data))
                    {
                        newFact._unique = (Guid)_fieldSerializerByType[typeof(Guid)].ReadData(output);
                        newFact._text = (string)_fieldSerializerByType[typeof(string)].ReadData(output);
                    }
                }

                return newFact;
            }
コード例 #38
0
 // Hydration constructor
 private ContactInformation(FactMemento memento)
 {
     InitializeResults();
     _order = new PredecessorObj<Order>(this, RoleOrder, memento);
     _prior = new PredecessorList<ContactInformation>(this, RolePrior, memento);
 }
コード例 #39
0
 // Hydration constructor
 private Tune(FactMemento memento)
 {
     InitializeResults();
 }
コード例 #40
0
 // Hydration constructor
 private Like(FactMemento memento)
 {
     InitializeResults();
     _individual = new PredecessorObj <Individual>(this, GetRoleIndividual(), memento, Individual.GetUnloadedInstance, Individual.GetNullInstance);
     _tune       = new PredecessorObj <Tune>(this, GetRoleTune(), memento, Tune.GetUnloadedInstance, Tune.GetNullInstance);
 }
コード例 #41
0
 // Hydration constructor
 private MessageBoard(FactMemento memento)
 {
     InitializeResults();
 }
コード例 #42
0
 // Hydration constructor
 private CakeDetail(FactMemento memento)
 {
     InitializeResults();
     _order = new PredecessorObj<Order>(this, RoleOrder, memento);
     _size = new PredecessorObj<CakeSize>(this, RoleSize, memento);
     _cakeFlavor = new PredecessorObj<CakeFlavor>(this, RoleCakeFlavor, memento);
     _frostingFlavor = new PredecessorObj<FrostingFlavor>(this, RoleFrostingFlavor, memento);
     _mainColor = new PredecessorObj<FrostingColor>(this, RoleMainColor, memento);
     _decorationColor = new PredecessorObj<FrostingColor>(this, RoleDecorationColor, memento);
     _prior = new PredecessorList<CakeDetail>(this, RolePrior, memento);
 }
コード例 #43
0
 // Hydration constructor
 private ProvisionFrontOffice(FactMemento memento)
 {
     InitializeResults();
     _machine = new PredecessorObj<Machine>(this, RoleMachine, memento);
     _company = new PredecessorObj<Company>(this, RoleCompany, memento);
 }
コード例 #44
0
 // Hydration constructor
 private Pull(FactMemento memento)
 {
     InitializeResults();
     _order = new PredecessorObj<Order>(this, RoleOrder, memento);
     _kitchen = new PredecessorObj<Kitchen>(this, RoleKitchen, memento);
 }
コード例 #45
0
 // Hydration constructor
 private DeliveryDetail(FactMemento memento)
 {
     InitializeResults();
     _order = new PredecessorObj<Order>(this, RoleOrder, memento);
     _city = new PredecessorObj<City>(this, RoleCity, memento);
     _prior = new PredecessorList<DeliveryDetail>(this, RolePrior, memento);
 }
コード例 #46
0
 // Hydration constructor
 private Closed(FactMemento memento)
 {
     InitializeResults();
     _delivered = new PredecessorObj<Delivered>(this, RoleDelivered, memento);
 }
コード例 #47
0
 // Hydration constructor
 private DeprovisionKitchen(FactMemento memento)
 {
     InitializeResults();
     _provision = new PredecessorObj<ProvisionKitchen>(this, RoleProvision, memento);
 }
コード例 #48
0
 // Hydration constructor
 private Individual(FactMemento memento)
 {
     InitializeResults();
 }
コード例 #49
0
 // Hydration constructor
 private Machine(FactMemento memento)
 {
     InitializeResults();
 }
コード例 #50
0
 // Hydration constructor
 private DisableToastNotification(FactMemento memento)
 {
     InitializeResults();
     _enable = new PredecessorList<EnableToastNotification>(this, RoleEnable, memento);
 }
コード例 #51
0
 // Hydration constructor
 private ProvisionKitchen(FactMemento memento)
 {
     InitializeResults();
     _machine = new PredecessorObj<Machine>(this, RoleMachine, memento);
     _kitchen = new PredecessorObj<Kitchen>(this, RoleKitchen, memento);
 }
コード例 #52
0
 // Hydration constructor
 private Domain(FactMemento memento)
 {
     InitializeResults();
 }
コード例 #53
0
 // Hydration constructor
 private City(FactMemento memento)
 {
     InitializeResults();
     _company = new PredecessorObj<Company>(this, RoleCompany, memento);
 }
コード例 #54
0
            public CorrespondenceFact CreateFact(FactMemento memento)
            {
                Domain newFact = new Domain(memento);

                // Create a memory stream from the memento data.
                using (MemoryStream data = new MemoryStream(memento.Data))
                {
                    using (BinaryReader output = new BinaryReader(data))
                    {
                    }
                }

                return newFact;
            }
コード例 #55
0
 // Hydration constructor
 private Commitment(FactMemento memento)
 {
     InitializeResults();
     _pull = new PredecessorObj<Pull>(this, RolePull, memento);
     _cakeDetail = new PredecessorList<CakeDetail>(this, RoleCakeDetail, memento);
     _prior = new PredecessorList<Commitment>(this, RolePrior, memento);
 }
コード例 #56
0
 // Hydration constructor
 private EnableToastNotification(FactMemento memento)
 {
     InitializeResults();
     _individual = new PredecessorObj<Individual>(this, RoleIndividual, memento);
 }
コード例 #57
0
 // Hydration constructor
 private Completed(FactMemento memento)
 {
     InitializeResults();
     _commitment = new PredecessorObj<Commitment>(this, RoleCommitment, memento);
 }
コード例 #58
0
            public CorrespondenceFact CreateFact(FactMemento memento)
            {
                EnableToastNotification newFact = new EnableToastNotification(memento);

                // Create a memory stream from the memento data.
                using (MemoryStream data = new MemoryStream(memento.Data))
                {
                    using (BinaryReader output = new BinaryReader(data))
                    {
                        newFact._unique = (Guid)_fieldSerializerByType[typeof(Guid)].ReadData(output);
                    }
                }

                return newFact;
            }
コード例 #59
0
 // Hydration constructor
 private Delivered(FactMemento memento)
 {
     InitializeResults();
     _completed = new PredecessorObj<Completed>(this, RoleCompleted, memento);
     _deliveryDetail = new PredecessorObj<DeliveryDetail>(this, RoleDeliveryDetail, memento);
 }
コード例 #60
0
        public FactID Save(string domain, FactMemento fact, Guid clientGuid)
        {
            FactID factId;
            List<FactID> affectedPivots;

            lock (this)
            {
                // See if the fact already exists.
                FactRecord existingFact = _factTable.FirstOrDefault(o =>
                    o.IdentifiedFactMemento.Memento.Equals(fact));
                if (existingFact == null)
                {
                    // It doesn't, so create it.
                    FactID newFactID = new FactID() { key = _factTable.Count + 1 };
                    factId = newFactID;
                    existingFact = new FactRecord()
                    {
                        IdentifiedFactMemento = new IdentifiedFactMemento(factId, fact)
                    };

                    _factTable.Add(existingFact);

                    // Store a message for each pivot.
                    var pivots = fact.Predecessors
                        .Where(predecessor => predecessor.IsPivot);
                    _messageTable.AddRange(pivots
                        .Select(predecessor => new MessageRecord(
                            new MessageMemento(predecessor.ID, newFactID),
                            newFactID,
                            predecessor.Role,
                            clientGuid)));

                    // Store messages for each non-pivot. This fact belongs to all predecessors' pivots.
                    List<FactID> nonPivots = fact.Predecessors
                        .Where(predecessor => !predecessor.IsPivot)
                        .Select(predecessor => predecessor.ID)
                        .ToList();
                    List<MessageRecord> predecessorsPivots = _messageTable
                        .Where(message => nonPivots.Contains(message.Message.FactId))
                        .Distinct()
                        .ToList();
                    _messageTable.AddRange(predecessorsPivots
                        .Select(predecessorPivot => new MessageRecord(
                            new MessageMemento(predecessorPivot.Message.PivotId, newFactID),
                            predecessorPivot.AncestorFact,
                            predecessorPivot.AncestorRole,
                            clientGuid)));

                    affectedPivots =
                        pivots
                            .Select(pivot => pivot.ID)
                        .Union(predecessorsPivots
                            .Select(predecessorPivot => predecessorPivot.Message.PivotId))
                        .ToList();
                }
                else
                {
                    factId = existingFact.IdentifiedFactMemento.Id;
                    affectedPivots = null;
                }
            }

            if (affectedPivots != null && affectedPivots.Any() && PivotAffected != null)
                foreach (var pivotId in affectedPivots)
                    PivotAffected(domain, pivotId, factId, clientGuid);

            return factId;
        }