示例#1
0
    public DialogSet(string name,
                     DialogSet parent = null,
                     Dictionary <string, float> variables    = null,
                     Dictionary <string, DialogBase> states  = null,
                     Dictionary <string, string> transitions = null,
                     string startStateName            = "1",
                     EventDelegate handleEvent        = null,
                     SkipDelegate onSkipped           = null,
                     StartDelegate onStarted          = null,
                     ChildSkipDelegate onChildSkipped = null
                     ) : base(name, parent, variables, handleEvent, onSkipped, onStarted)
    {
        this._states = states ?? new Dictionary <string, DialogBase>();
        foreach (DialogBase b in _states.Values)
        {
            b.Parent = this;
        }
        this._transitions   = transitions ?? GetDefaultTransitions(_states.Count);
        this.startStateName = startStateName;

        this.HandleEvent = handleEvent ?? defaultHandleEvent;
        this.OnStarted   = onStarted ?? defaultOnStarted;
        this.OnSkipped   = onSkipped ?? defaultOnSkipped;

        this.OnChildSkipped = onChildSkipped ?? defaultOnChildSkipped;
    }
示例#2
0
 public void onStart(StartDelegate fn)
 {
     onEvent("ASYNC-START", delegate(object a)
     {
         fn();
     });
 }
示例#3
0
        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (_disposed)
            {
                return;
            }
            // If disposing equals true, dispose all managed
            // and unmanaged resources.
            if (disposing)
            {
                // Dispose managed resources.
                _dllhandle     = IntPtr.Zero;
                _open          = null;
                _close         = null;
                _start         = null;
                _reset         = null;
                _config        = null;
                _read          = null;
                _write         = null;
                _checkTx       = null;
                _getDeviceList = null;
            }
            // Dispose native ( unmanaged ) resources, if exits

            // Note disposing has been done.
            _disposed = true;
        }
示例#4
0
 public XAudio2SourceVoice(IntPtr instance, AudioChannelFormat channelFormat, int frequency) : base(instance)
 {
     ChannelFormat            = channelFormat;
     Frequency                = frequency;
     StartNative              = GetDelegateForVTable <StartDelegate>(19);
     SubmitSourceBufferNative = GetDelegateForVTable <SubmitSourceBufferDelegate>(21);
     GetStateNative           = GetDelegateForVTable <GetStateDelegate>(25);
 }
示例#5
0
        /// <summary>
        ///     Start transforming all work items in the queue async. The
        ///     <see cref="ProcessingCompleted" /> event will fire when done.
        /// </summary>
        public void StartAsync()
        {
            StartDelegate startDelegate = new StartDelegate(Start);
            IAsyncResult  asyncResult;
            AsyncCallback asyncCallback = new AsyncCallback(startCallback);

            asyncResult = startDelegate.BeginInvoke(asyncCallback, startDelegate);
        }
示例#6
0
 public void onStartThreaded(StartDelegate fn)
 {
     onEvent("ASYNC-START-THREADED", delegate(object a)
     {
         Async.runInThread(delegate()
         {
             fn();
         });
     });
 }
示例#7
0
 protected void SetDelegates(
     StartDelegate start
     , CloseDelegate close
     )
 {
     /* We just receive the core Delegates. Which we will
      * turn around and handle the Invocation ourselves. */
     _start = start;
     _close = close;
 }
示例#8
0
 /// <summary>
 /// Start animation
 /// </summary>
 /// <param name="delay"></param>
 /// <returns></returns>
 public bool Start(int delay)
 {
     if (this.InvokeRequired)
     {
         StartDelegate startDelegate = new StartDelegate(this.Start);
         return((bool)this.Invoke(startDelegate, delay));
     }
     _AnimDelay = delay;
     return(StartAnimation(delay));
 }
示例#9
0
        public void StartChecking()
        {
            _running = true;
            StartDelegate sd = new StartDelegate(Start);

            sd.BeginInvoke((ar) =>
            {
                Debug.WriteLine("All tasks started!");
            }, null);
        }
示例#10
0
 private static extern string Speak(
     string text,
     string voice,
     StartDelegate startCallback,
     EndDelegate endCallback,
     BoundaryDelegate boundaryCallback,
     PauseDelegate pauseCallback,
     ResumeDelegate resumeCallback,
     string lang
     );
示例#11
0
        public EventDemo()
        {
            Button clickMe = new Button();

            clickMe.Parent   = this;
            clickMe.Text     = "Click me";
            clickMe.Location = new Point(ClientSize.Width / 2, ClientSize.Height / 2);
            //The += syntax registers a delegate with an event.
            //To unregister with an event, use the -= with the same syntax
            clickMe.Click   += new EventHandler(OnClick);
            StartEvent      += new StartDelegate(OnStartEvent);
        }
示例#12
0
        public static void InitializeDelegates()
        {
            delCreate  = Create;
            delReceive = Receive;
            delDestroy = Destroy;
            delStart   = Start;

            InitializeDelegatesOnNative(Marshal.GetFunctionPointerForDelegate(delCreate),
                                        Marshal.GetFunctionPointerForDelegate(delReceive),
                                        Marshal.GetFunctionPointerForDelegate(delDestroy),
                                        Marshal.GetFunctionPointerForDelegate(delStart));
        }
示例#13
0
 public Ability(string theName, int theDamage, float theMaxCoolDown,
     int requiredStamina, float castTime = 1, StartDelegate startAbility = null, float windDownResetTime = 0)
 {
     name = theName;
     damage = theDamage;
     maxCoolDown = theMaxCoolDown;
     stamina = requiredStamina;
     castTimer = castTime;
     castResetTime = castTime;
     this.windDownResetTime = windDownResetTime;
     windDownTime = windDownResetTime;
     PlayAbility += startAbility;
 } //Ability constructor
示例#14
0
 private void EndValidation(IAsyncResult result)
 {
     try
     {
         AsyncResult   ar = (AsyncResult)result;
         StartDelegate st = (StartDelegate)ar.AsyncDelegate;
         st.EndInvoke(ar);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Fail(ex.Message, ex.ToString());
         throw ex;
     }
 }
示例#15
0
 public void Start(StartDelegate dlg)
 {
     foreach (KeyValuePair <string, ArrayList> entry in dic)
     {
         foreach (TimeElement i in entry.Value)
         {
             if (!tt.CheckOverlap(i))
             {
                 tt.Add(i);
             }
             dlg(tt);
             tt.Del(i);
         }
     }
 }
示例#16
0
        /// <summary>
        ///     Callback function used when running StartAsync.
        /// </summary>
        /// <param name="asyncResult">
        ///     The AsyncResult.
        /// </param>
        private void startCallback(IAsyncResult asyncResult)
        {
            Exception     e             = null;
            StartDelegate startDelegate = (StartDelegate)asyncResult.AsyncState;

            try
            {
                startDelegate.EndInvoke(asyncResult);
            }
            catch (Exception ex)
            {
                e = ex;
            }
            OnProcessingCompleted(new AsyncCompletedEventArgs(e, asyncResult.IsCompleted, asyncResult.AsyncState));
        }
示例#17
0
 public void StartWithArray(StartDelegate dlg)
 {
     ArrayList[] ala = KVPairToArrayList();
     for (int i = 0; i < ala.Length; i++)
     {
         for (int j = 0; j < ala[i].Count; j++)
         {
             if (!tt.CheckOverlap((TimeElement)ala[i][j]))
             {
                 tt.Add((TimeElement)ala[i][j]);
             }
             StartWithArray(dlg);
             dlg(tt);
             tt.Del((TimeElement)ala[i][j]);
         }
     }
 }
示例#18
0
    public DialogBase(string name,
                      DialogSet parent = null,
                      Dictionary <string, float> variables = null,
                      EventDelegate handleEvent            = null,
                      SkipDelegate onSkipped  = null,
                      StartDelegate onStarted = null
                      )
    {
        this._name       = name;
        this._parent     = parent;
        this._variables  = variables ?? new Dictionary <string, float>();
        this.HandleEvent = handleEvent ?? defaultHandleEvent;
        this.OnSkipped   = onSkipped ?? defaultOnSkipped;
        this.OnStarted   = onStarted ?? defaultOnStarted;

        DeclareVariable("#starttime", 0f);
    }
示例#19
0
 private void PerformValidation(Schema schema)
 {
     try
     {
         _evaluationctx.Schema = schema;
         //_evaluationctx.Start();
         StartDelegate st = new StartDelegate(_evaluationctx.Start);
         WaitHandle    wh = st.BeginInvoke(new AsyncCallback(EndValidation),
                                           _evaluationctx).AsyncWaitHandle;
         wh.WaitOne();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Fail(ex.Message, ex.ToString());
         throw ex;
     }
 }
示例#20
0
文件: Form1.cs 项目: Grukz/Sample
        // 非同期処理完了後のコールバックメソッドAsyncCallbackFunc.
        public void AsyncCallbackFunc(IAsyncResult ar)
        {
            // IAsyncResult型arをAsyncResultにキャスト.
            AsyncResult asyncRes = (AsyncResult)ar; // arをAsyncResult型asyncResにキャスト.

            // 非同期処理で使ったデリゲートを取得.
            AsyncButtonDelegate asyncButton = (AsyncButtonDelegate)asyncRes.AsyncDelegate;   // asyncRes.AsyncDelegateをキャストしてasyncButtonを取得.

            // 非同期処理の完了.
            asyncButton.EndInvoke(ar); // asyncButton.EndInvokeで完了.

            // 3秒待つ.(元に戻す処理.)
            Thread.Sleep(3000);    // Thread.Sleepで3秒休止.

            // StartDelegateの生成.
            StartDelegate start = new StartDelegate(Start);   // startの生成.
            IAsyncResult  iar3  = button1.BeginInvoke(start); //  button1.BeginInvokeでstartが持つメソッドに委譲.

            button1.EndInvoke(iar3);                          // button1.EndInvokeで完了.
        }
示例#21
0
        /// <summary>
        /// Binds the class instance methods to the dll functions.
        /// </summary>
        /// <param name="hDll">A dll to bind to.</param>
        private void BindToDll(IntPtr hDll)
        {
            IntPtr pProcPtr = GetProcAddress(hDll, "EnumVideoInputDevices");

            this._enumVideoInputDevices =
                (EnumVideoInputDevicesDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(EnumVideoInputDevicesDelegate));

            pProcPtr = GetProcAddress(hDll, "BuildCaptureGraph");
            this._buildCaptureGraph =
                (BuildCaptureGraphDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(BuildCaptureGraphDelegate));

            pProcPtr = GetProcAddress(hDll, "AddRenderFilter");
            this._addRenderFilter =
                (AddRenderFilterDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(AddRenderFilterDelegate));

            pProcPtr = GetProcAddress(hDll, "AddCaptureFilter");
            this._addCaptureFilter =
                (AddCaptureFilterDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(AddCaptureFilterDelegate));

            pProcPtr = GetProcAddress(hDll, "ResetCaptureGraph");
            this._resetCaptureGraph =
                (ResetCaptureGraphDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(ResetCaptureGraphDelegate));

            pProcPtr    = GetProcAddress(hDll, "Start");
            this._start = (StartDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(StartDelegate));

            pProcPtr = GetProcAddress(hDll, "GetCurrentImage");
            this._getCurrentImage =
                (GetCurrentImageDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(GetCurrentImageDelegate));

            pProcPtr           = GetProcAddress(hDll, "GetVideoSize");
            this._getVideoSize =
                (GetVideoSizeDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(GetVideoSizeDelegate));

            pProcPtr   = GetProcAddress(hDll, "Stop");
            this._stop = (StopDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(StopDelegate));

            pProcPtr = GetProcAddress(hDll, "DestroyCaptureGraph");
            this._destroyCaptureGraph =
                (DestroyCaptureGraphDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(DestroyCaptureGraphDelegate));
        }
示例#22
0
        public EventDemo()
        {
            Button clickMe = new Button();

            clickMe.Parent   = this;
            clickMe.Text     = "Click Me";
            clickMe.Location = new Point(
                (ClientSize.Width - clickMe.Width) / 2,
                (ClientSize.Height - clickMe.Height) / 2);

            // Assign EventHandler delegate to button click event
            clickMe.Click += new EventHandler(OnClickMeClicked);

            // Assign StartEvent delegate to Start event
            StartEvent += new StartDelegate(OnStartEvent);

            // Fire StartEvent
            StartEvent();

            CheckHandlers();
        }
示例#23
0
文件: EventDemo.cs 项目: 3141592/vs
        public EventDemo()
        {
            Button clickMe = new Button();

            clickMe.Parent = this;
            clickMe.Text = "Click Me";
            clickMe.Location = new Point(
                (ClientSize.Width - clickMe.Width) / 2,
                (ClientSize.Height - clickMe.Height) / 2);

            // Assign EventHandler delegate to button click event
            clickMe.Click += new EventHandler(OnClickMeClicked);

            // Assign StartEvent delegate to Start event
            StartEvent += new StartDelegate(OnStartEvent);

            // Fire StartEvent
            StartEvent();

            CheckHandlers();
        }
示例#24
0
    public EventDemo()
    {
        Button clickMe = new Button();

        clickMe.Parent   = this;
        clickMe.Text     = "Click Me";
        clickMe.Location = new Point(
            (ClientSize.Width - clickMe.Width) / 2,
            (ClientSize.Height - clickMe.Height) / 2);

        // an EventHandler delegate is assigned
        // to the button's Click event
        clickMe.Click += new EventHandler(OnClickMeClicked);

        // our custom "StartDelegate" delegate is assigned
        // to our custom "StartEvent" event.
        StartEvent += new StartDelegate(OnStartEvent);

        // fire our custom event
        StartEvent();
    }
示例#25
0
    public DialogState(string name,
                       string text,
                       Dictionary <string, UIProp <object> > uiProps = null,
                       Dictionary <string, float> variables          = null,
                       List <DialogChoice> choices = null,
                       DialogSet parent            = null,
                       ChoiceDelegate onChoice     = null,
                       EventDelegate handleEvent   = null,
                       SkipDelegate onSkipped      = null,
                       StartDelegate onStarted     = null) : base(name, parent, variables, handleEvent, onSkipped, onStarted)
    {
        this.text    = text;
        this.uiProps = uiProps ?? new Dictionary <string, UIProp <object> >();
        this.choices = choices ?? new List <DialogChoice>();

        this.OnChoice    = onChoice ?? defaultOnChoice;
        this.HandleEvent = handleEvent ?? defaultHandleEvent;
        this.OnStarted   = onStarted ?? defaultOnStarted;
        this.OnSkipped   = onSkipped ?? defaultOnSkipped;

        _active = false;
    }
示例#26
0
        /// <summary>
        /// Binds the class instance methods to the dll functions.
        /// </summary>
        /// <param name="hDll">A dll to bind to.</param>
        private void BindToDll(IntPtr hDll)
        {
            IntPtr pProcPtr = GetProcAddress(hDll, "EnumVideoInputDevices");
            _enumVideoInputDevices =
                (EnumVideoInputDevicesDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(EnumVideoInputDevicesDelegate));

            pProcPtr = GetProcAddress(hDll, "BuildCaptureGraph");
            _buildCaptureGraph =
                (BuildCaptureGraphDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(BuildCaptureGraphDelegate));

            pProcPtr = GetProcAddress(hDll, "AddRenderFilter");
            _addRenderFilter =
                (AddRenderFilterDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(AddRenderFilterDelegate));

            pProcPtr = GetProcAddress(hDll, "AddCaptureFilter");
            _addCaptureFilter =
                (AddCaptureFilterDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(AddCaptureFilterDelegate));

            pProcPtr = GetProcAddress(hDll, "ResetCaptureGraph");
            _resetCaptureGraph =
                (ResetCaptureGraphDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(ResetCaptureGraphDelegate));

            pProcPtr = GetProcAddress(hDll, "Start");
            _start = (StartDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(StartDelegate));

            pProcPtr = GetProcAddress(hDll, "GetCurrentImage");
            _getCurrentImage =
                (GetCurrentImageDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(GetCurrentImageDelegate));

            pProcPtr = GetProcAddress(hDll, "GetVideoSize");
            _getVideoSize =
                (GetVideoSizeDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(GetVideoSizeDelegate));

            pProcPtr = GetProcAddress(hDll, "Stop");
            _stop = (StopDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(StopDelegate));

            pProcPtr = GetProcAddress(hDll, "DestroyCaptureGraph");
            _destroyCaptureGraph =
                (DestroyCaptureGraphDelegate)Marshal.GetDelegateForFunctionPointer(pProcPtr, typeof(DestroyCaptureGraphDelegate));
        }
        /// <summary>
        /// Starts a process asynchronously so the GUI thread isn't tied up waiting
        /// for the app to start (the app could be the Flash IDE for instance).
        /// </summary>
        public static void StartAsync(string path)
        {
            StartDelegate del = new StartDelegate(Start);

            del.BeginInvoke(path, null, null);
        }
示例#28
0
        public void StartAsync(BackupDataSource source, BackupDataSource destination)
        {
            StartDelegate startDelegate = new StartDelegate(StartInternal);

            startDelegate.BeginInvoke(source, destination, OnError, null, null);
        }
示例#29
0
 /// <summary>
 /// Start animation
 /// </summary>
 /// <param name="delay"></param>
 /// <returns></returns>
 public bool Start(int delay)
 {
     if (this.InvokeRequired)
     {
         StartDelegate startDelegate = new StartDelegate(this.Start);
         return (bool)this.Invoke(startDelegate, delay);
     }
     _AnimDelay = delay;
     return StartAnimation(delay);
 }
示例#30
0
 public void StartAsync(BackupDataSource source, BackupDataSource destination)
 {
     StartDelegate startDelegate = new StartDelegate(StartInternal);
     startDelegate.BeginInvoke(source, destination, OnError, null, null);
 }
示例#31
0
		/// <summary>
		/// Starts a process asynchronously so the GUI thread isn't tied up waiting
		/// for the app to start (the app could be the Flash IDE for instance).
		/// </summary>
		public static void StartAsync(string path)
		{
			StartDelegate del = new StartDelegate(Start);
			del.BeginInvoke(path,null,null);
		}
示例#32
0
 public static void Main_Service_Console <T>(StartDelegate _StartDelegate, StopDelegate _StopDelegate)
 {
     Main_Service_Console <T>(_StartDelegate, _StopDelegate, string.Empty, true);
 }
示例#33
0
        private static Command CreateRootCommand()
        {
            // Create a root command with some options
            var rootCommand = new RootCommand("C2CS - C to C# bindings code generator.");

            var inputFilePathOption = new Option <string>(
                new[] { "--inputFilePath", "-i" },
                "File path of the input .h file.")
            {
                IsRequired = true
            };

            rootCommand.AddOption(inputFilePathOption);

            var additionalPathsOption = new Option <string>(
                new[] { "--additionalInputPaths", "-p" },
                "Directory paths and/or file paths of additional .h files to bundle together before parsing C code.")
            {
                IsRequired = false
            };

            rootCommand.AddOption(additionalPathsOption);

            var outputFilePathOption = new Option <string>(
                new[] { "--outputFilePath", "-o" },
                "File path of the output .cs file.")
            {
                IsRequired = true
            };

            rootCommand.AddOption(outputFilePathOption);

            var unattendedOption = new Option <bool>(
                new[] { "--unattended", "-u" },
                "Don't ask for further input.")
            {
                IsRequired = false
            };

            rootCommand.AddOption(unattendedOption);

            var libraryNameOption = new Option <string>(
                new[] { "--libraryName", "-l" },
                "The name of the dynamic link library (without the file extension) used for P/Invoke with C#.")
            {
                IsRequired = false
            };

            rootCommand.AddOption(libraryNameOption);

            var includeDirectoriesOption = new Option <IEnumerable <string>?>(
                new[] { "--includeDirectories", "-s" },
                "Search directories for `#include` usages to use when parsing C code.")
            {
                IsRequired = false
            };

            rootCommand.AddOption(includeDirectoriesOption);

            var definesOption = new Option <IEnumerable <string>?>(
                new[] { "--defines", "-d" },
                "Object-like macros to use when parsing C code.")
            {
                IsRequired = false
            };

            rootCommand.AddOption(definesOption);

            var clangArgsOption = new Option <IEnumerable <string>?>(
                new[] { "--clangArgs", "-a" },
                "Additional Clang arguments to use when parsing C code.")
            {
                IsRequired = false
            };

            rootCommand.AddOption(clangArgsOption);

            var startDelegate = new StartDelegate(Start);

            rootCommand.Handler = CommandHandler.Create(startDelegate);
            return(rootCommand);
        }
示例#34
0
        public static void Main_Service_Console <T>(StartDelegate _StartDelegate, StopDelegate _StopDelegate, string _sApplicationName, bool _bShouldRunAsSingleInstance)
        {
            if (Environment.UserInteractive)
            {
                try
                {
                    bool createdNew = true;

                    Process currentProcess = Process.GetCurrentProcess();
                    string  sAppName       = (string.IsNullOrWhiteSpace(_sApplicationName) == true) ? currentProcess.ProcessName : _sApplicationName.RemoveWhiteSpace();

                    using (Mutex mutex = new Mutex(true, sAppName, out createdNew))
                    {
                        // SKislyuk 11/3/2016 2:23:09 PM
                        // if the app can run as multiple instances app then disregard the mutex
                        createdNew = (_bShouldRunAsSingleInstance == true) ? createdNew : true;

                        if (createdNew)
                        {
                            //@cmnt SKislyuk: [03 November 16, 14:33:02]   [161103_143302]
                            // running as console app
                            //
                            //if (_StartDelegate != null)
                            //{
                            //	_StartDelegate();
                            //}
                            // the following like equivalent to code commented above
                            _StartDelegate?.Invoke();


                            Console.WriteLine("Press any key to stop...");
                            Console.ReadKey(true);
                            // SKislyuk 5/4/2018 11:42:43 AM
                            // stopping app
                            //
                            //if (_StopDelegate != null)
                            //{
                            //_StopDelegate();
                            //}
                            // the following like equivalent to code commented above
                            _StopDelegate?.Invoke();
                        }
                        else
                        {
                            ShowProcess();
                        }
                    }
                }
                catch (Exception exp)
                {
                    Logger.WriteErrorLogOnly(exp, "cc27108e-0987-4cbf-b9de-69001127b72f");
                }
            }
            else
            {
                try
                {
                    // running as service
                    using (ServiceBase service = (ServiceBase)Activator.CreateInstance(typeof(T)))
                    {
                        ServiceBase.Run(service);
                    }
                }
                catch (Exception exp)
                {
                    Logger.WriteErrorLogOnly(exp, "ed78d049-1bc4-47f9-8f21-8c25376714fe");
                }
            }
        }
示例#35
0
        private static Command CreateRootCommand()
        {
            // Create a root command with some options
            var rootCommand = new RootCommand("C# Platform Invoke Code Generator");

            var inputFilePathOption = new Option <string>(
                new[] { "--inputFilePath", "-i" },
                "File path of the input .h file.")
            {
                IsRequired = true
            };

            rootCommand.AddOption(inputFilePathOption);

            var outputFilePathOption = new Option <string>(
                new[] { "--outputFilePath", "-o" },
                "File path of the output .cs file.")
            {
                IsRequired = true
            };

            rootCommand.AddOption(outputFilePathOption);

            var unattendedOption = new Option <bool>(
                new[] { "--unattended", "-u" },
                "Don't ask for further input.")
            {
                IsRequired = false
            };

            rootCommand.AddOption(unattendedOption);

            var libraryNameOption = new Option <string?>(
                new[] { "--libraryName", "-l" },
                "The name of the library. Default value is the file name of the input file path.")
            {
                IsRequired = false
            };

            rootCommand.AddOption(libraryNameOption);

            var includeDirectoriesOption = new Option <IEnumerable <string>?>(
                new[] { "--includeDirectories", "-s" },
                "Include directories to use for parsing C code.")
            {
                IsRequired = false
            };

            rootCommand.AddOption(includeDirectoriesOption);

            var defineMacrosOption = new Option <IEnumerable <string>?>(
                new[] { "--defineMacros", "-d" },
                "Macros to define for parsing C code.")
            {
                IsRequired = false
            };

            rootCommand.AddOption(defineMacrosOption);

            var additionalArgsOption = new Option <IEnumerable <string>?>(
                new[] { "--additionalArgs", "-a" },
                "Additional arguments for parsing C code.")
            {
                IsRequired = false
            };

            rootCommand.AddOption(additionalArgsOption);

            var startDelegate = new StartDelegate(Start);

            rootCommand.Handler = CommandHandler.Create(startDelegate);
            return(rootCommand);
        }
示例#36
0
 /// <summary>
 ///     Start transforming all work items in the queue async. The 
 ///     <see cref="ProcessingCompleted" /> event will fire when done.
 /// </summary>
 public void StartAsync()
 {
     StartDelegate startDelegate = new StartDelegate(Start);
     IAsyncResult asyncResult;
     AsyncCallback asyncCallback = new AsyncCallback(startCallback);
     asyncResult = startDelegate.BeginInvoke(asyncCallback, startDelegate);
 }
示例#37
0
        /// <summary>
        /// Подпрограмма открытия платы
        /// </summary>
        /// <param name="serialNumber"></param>
        public int Open(ushort serialNumber)
        {
            // Выделение памяти в неуправляемой памяти процесса
            // var pnt = Marshal.AllocHGlobal( Marshal.SizeOf( zzz ) );
            // Копирование структуры zzz в неуправляемую память
            // Marshal.StructureToPtr( zzz, pnt, false );
            // Возврат структуры из неупраяляемой памяти
            // var zzz1 = ( pci429_4_tag) Marshal.PtrToStructure( pnt, typeof( pci429_4_tag ) );
            // Освобождение неуправляемой памяти
            // Marshal.FreeHGlobal( pnt );

            var error = 0;

            // Synchronously wait to enter the Semaphore.
            SemaphoreSlim.Wait();
            // Get handle to .dll file
            _dllhandle = NativeMethods.LoadLibrary(NameDll);
            if (_dllhandle == IntPtr.Zero)
            {
                // Handle error loading
                error = 1;
            }
            else
            {
                // Get handle to Open method in .dll file
                var open_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_open");
                if (open_handle == IntPtr.Zero)
                {
                    error = 2;
                }
                else
                {
                    _open = ( OpenDelegate )Marshal.GetDelegateForFunctionPointer(
                        open_handle, typeof(OpenDelegate));
                    if (_open == null)
                    {
                        error = 3;
                    }
                }
                // Get handle to Close method in .dll file
                var close_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_close");
                if (close_handle == IntPtr.Zero)
                {
                    error = 4;
                }
                else
                {
                    _close = ( CloseDelegate )Marshal.GetDelegateForFunctionPointer(close_handle,
                                                                                    typeof(CloseDelegate));
                    if (_close == null)
                    {
                        error = 5;
                    }
                }
                // Get handle to Start method in .dll file
                var start_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_start");
                if (start_handle == IntPtr.Zero)
                {
                    error = 6;
                }
                else
                {
                    _start = ( StartDelegate )Marshal.GetDelegateForFunctionPointer(start_handle,
                                                                                    typeof(StartDelegate));
                    if (_start == null)
                    {
                        error = 7;
                    }
                }
                // Get handle to Reset method in .dll file
                var reset_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_reset");
                if (reset_handle == IntPtr.Zero)
                {
                    error = 8;
                }
                else
                {
                    _reset = ( ResetDelegate )Marshal.GetDelegateForFunctionPointer(reset_handle,
                                                                                    typeof(ResetDelegate));
                    if (_reset == null)
                    {
                        error = 9;
                    }
                }
                // Get handle to Config method in .dll file
                var config_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_set_freq");
                if (config_handle == IntPtr.Zero)
                {
                    error = 10;
                }
                else
                {
                    _config = ( ConfigDelegate )Marshal.GetDelegateForFunctionPointer(config_handle,
                                                                                      typeof(ConfigDelegate));
                    if (_config == null)
                    {
                        error = 11;
                    }
                }
                // Get handle to Read method in .dll file
                var read_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_read_rx");
                if (read_handle == IntPtr.Zero)
                {
                    error = 12;
                }
                else
                {
                    _read = ( ReadDelegate )Marshal.GetDelegateForFunctionPointer(read_handle,
                                                                                  typeof(ReadDelegate));
                    if (_read == null)
                    {
                        error = 13;
                    }
                }
                // Get handle to Write method in .dll file
                var write_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_write_tx");
                if (write_handle == IntPtr.Zero)
                {
                    error = 14;
                }
                else
                {
                    _write = ( WriteDelegate )Marshal.GetDelegateForFunctionPointer(write_handle,
                                                                                    typeof(WriteDelegate));
                    if (_write == null)
                    {
                        error = 15;
                    }
                }
                // Get handle to CheckTx method in .dll file
                var check_tx_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_check_tx");
                if (check_tx_handle == IntPtr.Zero)
                {
                    error = 16;
                }
                else
                {
                    _checkTx = ( CheckTxDelegate )Marshal.GetDelegateForFunctionPointer(check_tx_handle,
                                                                                        typeof(CheckTxDelegate));
                    if (_checkTx == null)
                    {
                        error = 17;
                    }
                }
                // Get handle to GetDevice method in .dll file
                var get_device_handle = NativeMethods.GetProcAddress(_dllhandle, "pci429_4_get_dev_list");
                if (get_device_handle == IntPtr.Zero)
                {
                    error = 18;
                }
                else
                {
                    _getDeviceList = ( GetDeviceDelegate )Marshal.GetDelegateForFunctionPointer(get_device_handle,
                                                                                                typeof(GetDeviceDelegate));
                    if (_getDeviceList == null)
                    {
                        error = 19;
                    }
                }
                // Открытие устройства
                error += _open?.Invoke(serialNumber, out _device) ?? int.MaxValue;
                if (_device.handle == ( IntPtr )0)
                {
                    error = 18;
                }
            }
            // Release the Semaphore.
            SemaphoreSlim.Release();
            return(error);
        }