Пример #1
0
        /// <summary>
        /// Tries to load.
        /// Returns false iff the default loader(s) could not be bound to a compatible loadable class.
        /// </summary>
        private bool TryLoadModelCore <TRes, TSig>(IHostEnvironment env, out TRes result, params object[] extra)
            where TRes : class
        {
            _ectx.AssertValue(env, "env");
            _ectx.Assert(Reader.BaseStream.Position == FpMin + Header.FpModel);

            var args = ConcatArgsRev(extra, this);

            object tmp;
            string sig = ModelHeader.GetLoaderSig(ref Header);

            if (!string.IsNullOrWhiteSpace(sig) &&
                ComponentCatalog.TryCreateInstance <object, TSig>(env, out tmp, sig, "", args))
            {
                result = tmp as TRes;
                if (result != null)
                {
                    Done();
                    return(true);
                }
                // REVIEW: Should this fall through?
            }
            _ectx.Assert(Reader.BaseStream.Position == FpMin + Header.FpModel);

            string sigAlt = ModelHeader.GetLoaderSigAlt(ref Header);

            if (!string.IsNullOrWhiteSpace(sigAlt) &&
                ComponentCatalog.TryCreateInstance <object, TSig>(env, out tmp, sigAlt, "", args))
            {
                result = tmp as TRes;
                if (result != null)
                {
                    Done();
                    return(true);
                }
                // REVIEW: Should this fall through?
            }

            ComponentCatalog.TryCreateInstance <object, TSig>(env, out tmp, "NopTransform", "", args);
            result = tmp as TRes;
            Console.WriteLine("We convert the unsupported transform ({0}) to NoOp ;)", sig);
            return(true);

            /*
             * _ectx.Assert(Reader.BaseStream.Position == FpMin + Header.FpModel);
             *
             * Reader.BaseStream.Position = FpMin;
             * result = null;
             * return false;
             */
        }
Пример #2
0
        /// <summary>
        /// Tries to load.
        /// Returns false iff the default loader(s) could not be bound to a compatible loadable class.
        /// </summary>
        private bool TryLoadModelCore <TRes, TSig>(IHostEnvironment env, out TRes result, params object[] extra)
            where TRes : class
        {
            _ectx.AssertValue(env, "env");
            _ectx.Assert(Reader.BaseStream.Position == FpMin + Header.FpModel);

            var args = ConcatArgsRev(extra, this);

            EnsureLoaderAssemblyIsRegistered(env.ComponentCatalog);

            object tmp;
            string sig = ModelHeader.GetLoaderSig(ref Header);

            if (!string.IsNullOrWhiteSpace(sig) &&
                ComponentCatalog.TryCreateInstance <object, TSig>(env, out tmp, sig, "", args))
            {
                result = tmp as TRes;
                if (result != null)
                {
                    Done();
                    return(true);
                }
                // REVIEW: Should this fall through?
            }
            _ectx.Assert(Reader.BaseStream.Position == FpMin + Header.FpModel);

            string sigAlt = ModelHeader.GetLoaderSigAlt(ref Header);

            if (!string.IsNullOrWhiteSpace(sigAlt) &&
                ComponentCatalog.TryCreateInstance <object, TSig>(env, out tmp, sigAlt, "", args))
            {
                result = tmp as TRes;
                if (result != null)
                {
                    Done();
                    return(true);
                }
                // REVIEW: Should this fall through?
            }
            _ectx.Assert(Reader.BaseStream.Position == FpMin + Header.FpModel);

            Reader.BaseStream.Position = FpMin;
            result = null;
            return(false);
        }