コード例 #1
0
        /// <summary>
        /// Adds an executable interface by id.
        /// </summary>
        /// <returns>The full mod id if added to the game, <c>null</c> otherwise.</returns>
        /// <param name="id">The Executable Identifier to try and add.</param>
        /// <param name="inter">The interface object.</param>
        public static string RegisterExecutable(string id, IInterface inter)
        {
            if (Pathfinder.CurrentMod == null && !Extension.Handler.CanRegister)
            {
                throw new InvalidOperationException("RegisterExecutable can not be called outside of mod or extension loading.");
            }
            id = Pathfinder.CurrentMod != null?Utility.GetId(id, throwFindingPeriod : true) : Extension.Handler.ActiveInfo.Id + "." + id;

            Logger.Verbose("{0} {1} is attempting to add executable interface {2} with id {3}",
                           Pathfinder.CurrentMod != null ? "Mod" : "Extension",
                           Pathfinder.CurrentMod?.GetCleanId() ?? Extension.Handler.ActiveInfo.Id,
                           inter.GetType().FullName,
                           id);
            if (ModExecutables.ContainsKey(id))
            {
                return(null);
            }
            var type     = inter.GetType();
            var fileData = id + "\nldloc.args\ncall Pathfinder.Executable.Instance [" + type.Assembly.GetName().Name + ".dll]"
                           + type.FullName + "=" + id + "()";

            if (fileData.Length < 1 || ModExecutables.Any(pair => pair.Value.Item2 == fileData))
            {
                throw new ArgumentException("created data for '" + id + "' is not unique");
            }
            ModExecutables.Add(id, new Tuple <IInterface, string>(inter, fileData));
            return(id);
        }
コード例 #2
0
        public void RegisterAsInterface()
        {
            var container = new Container();

            container.RegisterType <IInterface, InterfaceImplementor>();

            IInterface a = container.Resolve <IInterface>();

            Assert.AreEqual(typeof(InterfaceImplementor), a.GetType());
        }
コード例 #3
0
ファイル: KeepAlive.cs プロジェクト: jsuen123/openpetragit
 /// <summary>
 /// overload
 /// </summary>
 /// <param name="ARemotedObject"></param>
 public static void UnRegister(IInterface ARemotedObject)
 {
     if (ARemotedObject is IKeepAlive)
     {
         UnRegister((IKeepAlive)ARemotedObject);
     }
     else
     {
         TLogging.Log("KeepAlive UnRegister: " + ARemotedObject.GetType().ToString() + " does not implement IKeepAlive");
     }
 }
コード例 #4
0
        public static void ReturnObject(IInterface obj)
        {
            if (obj != null)
            {
                // TODO: Put the pool it belongs to inside IInterfaceImpl
                Stack <IInterfaceImpl> pool;
                if (pools.TryGetValue(obj.GetType(), out pool))
                {
                    IInterfaceImpl objImpl = (IInterfaceImpl)obj;
                    objImpl.ResetInterface();
                    objImpl.SetObj((UObjectRef)null);

                    // TODO: Set a cap on how many objects should be available in the stack?
                    pool.Push(objImpl);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Registers a daemon interface.
        /// </summary>
        /// <returns>The daemon's full id if added to the game, <c>null</c> otherwise.</returns>
        /// <param name="id">The daemon interface id to insert.</param>
        /// <param name="inter">The interface to add.</param>
        public static string RegisterDaemon(string id, IInterface inter)
        {
            if (Pathfinder.CurrentMod == null && !Extension.Handler.CanRegister)
            {
                throw new InvalidOperationException("RegisterDaemon can not be called outside of mod or extension loading.");
            }
            id = Pathfinder.CurrentMod != null?Utility.GetId(id, throwFindingPeriod : true) : Extension.Handler.ActiveInfo.Id + "." + id;

            Logger.Verbose("{0} {1} attempting to add daemon interface {2} with id {3}",
                           Pathfinder.CurrentMod != null ? "Mod" : "Extension",
                           Pathfinder.CurrentMod?.GetCleanId() ?? Extension.Handler.ActiveInfo.Id,
                           inter.GetType().FullName,
                           id);
            if (ModDaemons.ContainsKey(id))
            {
                return(null);
            }
            ModDaemons.Add(id, inter);
            return(id);
        }
コード例 #6
0
ファイル: KeepAlive.cs プロジェクト: js1987/openpetragit
 /// <summary>
 /// overload
 /// </summary>
 /// <param name="ARemotedObject"></param>
 public static void UnRegister(IInterface ARemotedObject)
 {
     if (ARemotedObject is IKeepAlive)
     {
         UnRegister((IKeepAlive)ARemotedObject);
     }
     else
     {
         TLogging.Log("KeepAlive UnRegister: " + ARemotedObject.GetType().ToString() + " does not implement IKeepAlive");
     }
 }