Пример #1
0
        public BlamEngine()
        {
            Name =
                "";

            BuildRepository   = new EngineBuildRepository();
            mSystemPrototypes = new Dictionary <Values.KGuid, BlamEngineSystem>();
        }
Пример #2
0
        static int BranchIdResolver(EngineBuildRepository repo, string name)
        {
            int id = TypeExtensions.kNone;

            if (!string.IsNullOrEmpty(name))
            {
                id = repo.Branches.FindIndex(x => x.Name == name);

                if (id.IsNone())
                {
                    throw new KeyNotFoundException(string.Format("Engine {0} doesn't define a branch named {1}",
                                                                 repo.Engine.Name, name));
                }
            }

            return(id);
        }
Пример #3
0
        /// <summary>Serialize a build handle, using a 'baseline' to populate or cull (from writing) root build information</summary>
        /// <param name="s"></param>
        /// <param name="baseline">Root build information (ie, engine, or engine and branch)</param>
        /// <param name="value"></param>
        public static void SerializeWithBaseline <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                                 EngineBuildHandle baseline,
                                                                 ref EngineBuildHandle value)
            where TDoc : class
            where TCursor : class
        {
            int engine_index             = baseline.EngineIndex;
            int branch_index             = baseline.BranchIndex;
            int revisn_index             = baseline.RevisionIndex;
            EngineBuildRepository repo   = null;
            EngineBuildBranch     branch = null;

            if (s.IsWriting)
            {
                #region prepare engine_index
                if (value.EngineIndex == engine_index)
                {
                    repo = EngineRegistry.Engines[engine_index].BuildRepository;
                    // cause engine_index not to be written
                    engine_index = TypeExtensions.kNone;
                }
                else
                {
                    engine_index = value.EngineIndex;
                }
                #endregion

                #region prepare branch_index
                if (value.BranchIndex == branch_index)
                {
                    branch = repo.Branches[branch_index];
                    // cause branch_index not to be written
                    branch_index = TypeExtensions.kNone;
                }
                else
                {
                    branch_index = value.BranchIndex;
                }
                #endregion

                #region prepare revisn_index
                if (value.BranchIndex == revisn_index)
                {
                    // cause branch_index not to be written
                    branch_index = TypeExtensions.kNone;
                }
                else
                {
                    revisn_index = value.RevisionIndex;
                }
                #endregion
            }

            // This is a logic driven mess, but having branches for both IsReading and IsWriting would result in more copy&paste code

            // reading: baseline EngineIndex is valid, or index is serialized
            // writing: value EngineIndex mismatches baseline
            if (engine_index.IsNotNone() || BlamEngine.SerializeId(s, kAttributeNameEngine, ref engine_index, true))
            {
                repo = EngineRegistry.Engines[engine_index].BuildRepository;
            }

            // precondition: someone's EngineIndex was valid
            // reading: baseline BranchIndex is valid, or index is serialized
            // writing: value BranchIndex mismatches baseline
            if (repo != null && (branch_index.IsNotNone() || repo.SerializeBranchId(s, kAttributeNameBranch, ref branch_index, true)))
            {
                branch = repo.Branches[branch_index];
            }

            // precondition: someone's BranchIndex was valid
            // reading: baseline RevisionIndex is valid
            // writing: value RevisionIndex mismatches baseline
            if (branch != null && (revisn_index.IsNotNone() || s.IsReading))
            {
                branch.SerializeRevisionId(s, kAttributeNameRevisn, ref revisn_index, true);
            }

            if (s.IsReading)
            {
                if (engine_index.IsNotNone())
                {
                    value = new EngineBuildHandle(engine_index, branch_index, revisn_index);
                }
                else                 // engine_index is NONE, don't even bother trying to encode a new handle that should be all NONE anyway
                {
                    value = EngineBuildHandle.None;
                }
            }
        }