Inheritance: IDisposable
 public bool ExecuteApi(string args, IntPtr streamHandle, IntPtr eventHandle)
 {
     IncreaseUse();
     try
     {
         using (var stream = new Native.Stream(new Native.switch_stream_handle(streamHandle, false)))
         using (var evt = eventHandle == IntPtr.Zero ? null : new Native.Event(new Native.switch_event(eventHandle, false), 0))
         {
             try
             {
                 var context = new ApiContext(args, stream, evt);
                 var plugin = createPlugin();
                 plugin.Execute(context);
                 return true;
             }
             catch (Exception ex)
             {
                 LogException("Execute", Name, ex);
                 return false;
             }
         }
     }
     finally
     {
         DecreaseUse();
     }
 }
        public static bool List(string command, IntPtr streamHandle, IntPtr eventHandle)
        {
            try {
                if (streamHandle != IntPtr.Zero) {
                    using (var stream = new Native.Stream(new Native.switch_stream_handle(streamHandle, false))) {
                        stream.Write("Available APIs:\n");

                        getApiExecs().Values.ForEach(x => stream.Write(string.Format("{0}: {1}\n", x.Name, String.Join(",", x.Aliases.ToArray()))));

                        stream.Write("Available Apps:\n");
                        getAppExecs().Values.ForEach(x => stream.Write(string.Format("{0}: {1}\n", x.Name, String.Join(",", x.Aliases.ToArray()))));
                    }
                } else {
                    Log.WriteLine(LogLevel.Info, "Available APIs:");
                    getApiExecs().Values.ForEach(x => Log.WriteLine(LogLevel.Info, "{0}: {1}", x.Name, String.Join(",", x.Aliases.ToArray())));
                    Log.WriteLine(LogLevel.Info, "Available Apps:");
                    getAppExecs().Values.ForEach(x => Log.WriteLine(LogLevel.Info, "{0}: {1}", x.Name, String.Join(",", x.Aliases.ToArray())));
                }
                return true;
            } catch (Exception ex) {
                Log.WriteLine(LogLevel.Error, "Exception listing managed modules: {0}", ex.ToString());
                return false;
            }
        }
Beispiel #3
0
 public ApiContext(string arguments, Native.Stream stream, Native.Event evt) {
     this.arguments = arguments;
     this.stream = stream;
     this.evt = evt;
 }