Esempio n. 1
0
 static private bool EditChannel2View(IOChannel ch)
 {
     foreach (DataGridViewRow row in _dgv.Rows)
     {
         if (row.Cells[0].Value.ToString().Trim().ToUpper() == ch.INameInbound.Trim().ToUpper())
         {
             row.Cells[1].Value = ch.EventTypeListStrInbound;
             row.Cells[2].Value = ch.INameInbound + "_" + _Config.INameOutbound + "_trigger";
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// Process keyboard input
        /// </summary>
        static bool HandleKeyboard(IOChannel source, IOCondition condition)
        {
            if (source.ReadLine(out string str) != IOStatus.Normal)
            {
                return(true);
            }
            switch (Char.ToLower(str[0]))
            {
            case 'p':
                _data.Playing = !_data.Playing;
                var newState = _data.Playing ? State.Playing : State.Paused;
                _data.Pipeline.SetState(newState);
                Console.WriteLine("Setting state to {0}", newState);
                break;

            case 's':
                if (str[0] == 'S')
                {
                    _data.Rate *= 2.0;
                }
                else
                {
                    _data.Rate /= 2.0;
                }
                SendSeekEvent();
                break;

            case 'd':
                _data.Rate *= -1.0;
                SendSeekEvent();
                break;

            case 'n':
                if (_data.VideoSink == null)
                {
                    //If we have not done so, obtain the sink through which we will send the step events
                    _data.VideoSink = (Element)_data.Pipeline["video-sink"];
                }
                var stepEvent = Gst.Event.NewStep(Format.Buffers, 10, Math.Abs(_data.Rate), true, false);
                _data.VideoSink.SendEvent(stepEvent);
                Console.WriteLine("Stepping one frame");
                break;

            case 'q':
                _data.Loop.Quit();
                break;
            }
            return(true);
        }
 static void AsyncWithPipesTest()
 {
     Console.WriteLine("AsyncWithPipesTest:");
     try {
         Process proc;
         int     stdin  = Process.IgnorePipe;
         int     stdout = Process.RequestPipe;
         int     stderr = Process.IgnorePipe;
         GLib.Process.SpawnAsyncWithPipes(null, new string[] { "pwd" }, null, SpawnFlags.SearchPath, null, out proc, ref stdin, ref stdout, ref stderr);
         channel = new IOChannel(stdout);
         channel.AddWatch(0, IOCondition.In | IOCondition.Hup, new IOFunc(ReadStdout));
     } catch (Exception e) {
         Console.WriteLine("Exception in SpawnSync: " + e);
     }
     Console.WriteLine("returning");
 }
Esempio n. 4
0
        /// <summary>
        /// Сортировка каналов устройства для соответствия.
        /// </summary>
        public void sortChannels()
        {
            if (dType == DeviceType.V)
            {
                if (DI.Count > 1)
                {
                    List <IOChannel> tmp = new List <IOChannel>();

                    foreach (string descr in new string[] { "Открыт", "Закрыт" })
                    {
                        IOChannel resCh = DI.Find(delegate(IOChannel ch)
                        {
                            return(ch.Comment == descr);
                        });

                        if (resCh != null)
                        {
                            tmp.Add(resCh);
                        }
                    }

                    DI = tmp;
                }

                if (DO.Count > 1)
                {
                    List <IOChannel> tmp2 = new List <IOChannel>();

                    foreach (string descr in new string[] { "Открыть", "Открыть мини", "Открыть ВС",
                                                            "Открыть НС", "Закрыть" })
                    {
                        IOChannel resCh = DO.Find(delegate(IOChannel ch)
                        {
                            return(ch.Comment == descr);
                        });

                        if (resCh != null)
                        {
                            tmp2.Add(resCh);
                        }
                    }

                    DO = tmp2;
                }
            }
        }
 static bool ReadStdout(IOChannel source, IOCondition condition)
 {
     if ((condition & IOCondition.In) == IOCondition.In)
     {
         string txt;
         if (source.ReadToEnd(out txt) == IOStatus.Normal)
         {
             Console.WriteLine("[AsyncWithPipesTest output] " + txt);
         }
     }
     if ((condition & IOCondition.Hup) == IOCondition.Hup)
     {
         source.Dispose();
         ml.Quit();
         return(true);
     }
     return(true);
 }
Esempio n. 6
0
            public static int Compare(IOChannel wx, IOChannel wy)
            {
                if (wx == null && wy == null)
                {
                    return(0);
                }

                if (wx == null)
                {
                    return(-1);
                }

                if (wy == null)
                {
                    return(1);
                }

                return(wx.ToInt().CompareTo(wy.ToInt()));
            }
Esempio n. 7
0
        static public bool DeleteChannel(string sInboundName)
        {
            IOChannel ch = _chs.FindChannel(sInboundName);

            if (ch != null)
            {
                _chs.Remove(ch);
                for (int i = 0; i < _dgv.Rows.Count; i++)
                {
                    DataGridViewRow row = _dgv.Rows[i];
                    if (row.Cells[0].Value.ToString().Trim().ToUpper() ==
                        sInboundName.Trim().ToUpper())
                    {
                        _dgv.Rows.Remove(row);
                    }
                }
            }
            return(true);
        }
Esempio n. 8
0
        /// <summary>
        /// update a existed channel, refresh datagridview and iochannels
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        static public bool EditChannel(IOChannel ch)
        {
            if (!EditChannel2View(ch))
            {
                AddChannel2View(ch);
            }
            IOChannel tempch = _chs.FindChannel(ch.INameInbound);

            if (tempch == null)
            {
                _chs.Add(ch);
            }
            else
            {
                tempch = ch;
            }

            return(true);
        }
		public InternalProcess (string path, string [] args)
		{
			IntPtr error;

			if (args[args.Length -1] != null) {
				string [] nargs = new string [args.Length + 1];
				Array.Copy (args, nargs, args.Length);
				args = nargs;
			}
			
			g_spawn_async_with_pipes (path, args, null, InternalProcessFlags.SearchPath, 
						  IntPtr.Zero, IntPtr.Zero, IntPtr.Zero,
						  ref stdin, ref stdout, IntPtr.Zero, out error);

			if (error != IntPtr.Zero)
				throw new GException (error);

			input = new IOChannel (stdin);
			output = new IOChannel (stdout);
			//errorput = new IOChannel (stderr);
		}
Esempio n. 10
0
        private bool InitChannel()
        {
            string sName = cbInboundInterface.Text;

            if (sName.Trim() == "")
            {
                _CurrIOChannel = null;
                return(false);
            }

            if (_FormType != FormType.ftAdd)
            {
                _CurrIOChannel = OutboundDBConfigMgt.Config.IOChannels.FindChannel(sName);
                return(true);
            }

            _CurrIOChannel = new IOChannel();
            _CurrIOChannel.INameInbound            = sName;
            _CurrIOChannel.EventTypeListStrInbound = OutboundDBConfigMgt.GWDBInfo.InboundInterfaceList[sName].ToString();

            // _CurrIOChannel.EventTypeListStrInbound = OutboundDBConfigMgt.GWDBInfo.InboundInterfaceList[sName].ToString();

            return(true);
        }
Esempio n. 11
0
        static void Init(Connection conn, IOFunc dispatchHandler)
        {
            IOChannel channel = new IOChannel((int)conn.Transport.SocketHandle);

            IO.AddWatch(channel, IOCondition.In | IOCondition.Hup, dispatchHandler);
        }
Esempio n. 12
0
 /// <summary>
 /// Add channel to iochannels and datagrid
 /// </summary>
 /// <param name="ch"></param>
 /// <returns></returns>
 static public bool AddChannel(IOChannel ch)
 {
     AddChannel2View(ch);
     _chs.Add(ch);
     return(true);
 }
Esempio n. 13
0
 static public bool DeleteChannel(IOChannel ch)
 {
     return(DeleteChannel(ch.INameInbound));
 }
Esempio n. 14
0
            static public bool Run(string script, Loop caller = null)
            {
                if (StatusMonitor.waiting && !script.StartsWith("*"))
                {
                    StatusMonitor.pausedScr.Add(script);
                    return(true);
                }

                DbgOutput.Write(script);

                List <string> cachecopy;
                string        _script = script.Trim().TrimStart('*');

                if (_script == "" || _script.StartsWith("#"))
                {
                    return(true);
                }

                if (_script.StartsWith("@"))
                {
                    new Loop(_script.Trim('@'));
                    return(true);
                }

                if (_script.Contains("?"))
                {
                    if (!_script.Split('?')[0].Contains(":")) // this is added because sometimes the argument for a command contains ?
                    {
                        if (!ConditionParser.Parse(_script.Split('?')[0]))
                        {
                            return(true);
                        }
                        else
                        {
                            _script = script.Split('?')[1];
                        }
                    }
                }

                if (_script.Contains(";"))
                {
                    RunFromList(new List <string>(_script.Split(';')));
                    return(true);
                }


                if (_script.Contains("=") && !_script.Contains("?") && !_script.Contains(":"))
                {
                    //local variable
                    if (_script.StartsWith("$"))
                    {
                        if (localVars.ContainsKey(_script.Split('=')[0].Trim()))
                        {
                            localVars[_script.Split('=')[0].Trim()] = ValueParser.Parse(_script.Substring(_script.IndexOf('=') + 1, _script.Length - _script.IndexOf('=') - 1).Trim());
                        }
                        else
                        {
                            localVars.Add(_script.Split('=')[0].Trim(), ValueParser.Parse(_script.Substring(_script.IndexOf('=') + 1, _script.Length - _script.IndexOf('=') - 1).Trim()));
                        }
                    }
                    else if (Configuration.usrDef.ContainsKey(_script.Split('=')[0].Trim()))
                    {
                        Configuration.usrDef[_script.Split('=')[0].Trim()] = ValueParser.Parse(_script.Substring(_script.IndexOf('=') + 1, _script.Length - _script.IndexOf('=') - 1).Trim());
                    }
                    else
                    {
                        Configuration.usrDef.Add(_script.Split('=')[0].Trim(), ValueParser.Parse(_script.Substring(_script.IndexOf('=') + 1, _script.Length - _script.IndexOf('=') - 1).Trim()));
                    }
                    return(true);
                }


                Script scr = new Script(_script);

                switch (scr.Command.Trim())
                {
                case "":

                    break;

                case "WAIT":
                    if (caller != null)
                    {
                        System.Threading.Thread.Sleep(Convert.ToInt32(scr.Args));
                    }
                    else
                    {
                        StatusMonitor.waiting  = true;
                        StatusMonitor.waittime = Convert.ToInt32(scr.Args);
                    }
                    break;

                case "WAITFORRESP":
                    StatusMonitor.CurrentStatus = "WAITFORRESP";
                    break;

                case "END":
                    return(false);

                case "BREAK":
                    if (caller != null)
                    {
                        caller.Break();
                    }
                    break;

                case "SHOWFRM":
                    if (!parent.Visible)
                    {
                        frm.ShowForm();
                    }
                    break;

                case "HIDEFRM":
                    if (parent.Visible)
                    {
                        frm.HideForm();
                        StatusMonitor.CurrentStatus = "HIDDEN";
                    }
                    break;

                case "CLOSEFRM":
                    frm.CloseForm();
                    break;

                case "RESTART":
                    Application.Restart();
                    break;

                case "EXEC":
                    if (scr.Args.Contains("$"))
                    {
                        if (scr.Args.Split('$')[0].Trim().EndsWith(".exe") && !scr.Args.Trim().StartsWith("*"))
                        {
                            IOChannel Eng = new IOChannel(scr.Args.Split('$')[0].Trim(), scr.Args.Split('$')[0].Trim(), scr.Args.Split('$')[1].Trim());
                            Eng.Start();
                        }
                        else
                        {
                            Process.Start(scr.Args.Split('$')[0].Trim().Trim('*'), scr.Args.Split('$')[1].Trim());
                        }
                    }
                    else
                    {
                        if (scr.Args.Trim().EndsWith(".exe") && !scr.Args.Trim().StartsWith("*"))
                        {
                            IOChannel Eng = new IOChannel(scr.Args.Trim(), scr.Args.Trim(), "");
                            Eng.Start();
                        }
                        else
                        {
                            Process.Start(scr.Args.Trim().Trim('*'));
                        }
                    }
                    break;
                //case "LOCK":
                //    StatusMonitor.LockedStatus.Push(StatusMonitor.CurrentStatus);
                //    break;
                //case "JOIN":
                //    if (StatusMonitor.LockedStatus.Count != 0)
                //    {
                //        StatusMonitor.CurrentStatus = StatusMonitor.LockedStatus.Pop();
                //        if (StatusMonitor.CurrentStatus != "WAITFORRESP")
                //        {
                //            StatusMonitor.waitingforresp = false;

                //            cachecopy = new List<string>(cache);
                //            foreach (string line in cachecopy)
                //            {
                //                DbgOutput.Write(line);
                //            }
                //            RunFromList(cachecopy);
                //            foreach (string line in cachecopy)
                //            {
                //                cache.Remove(line);
                //            }

                //        }
                //    }
                //    break;
                case "IMG":
                    StatusMonitor.currentAniFrames.Clear();
                    frm.PutImg(scr.Args.Trim());
                    break;

                case "_IMG":     //internal use only, for putting animation frames
                    frm.PutImg(scr.Args.Trim());
                    break;

                case "ANIMATE":
                    StatusMonitor.currentAniFrames.Clear();
                    StatusMonitor.currentFrame = 0;
                    foreach (string path in Directory.EnumerateFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Media\img\" + scr.Args.Trim().Trim('\\') + @"\", "*.png", SearchOption.TopDirectoryOnly))
                    {
                        StatusMonitor.currentAniFrames.Add(path.Replace(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Media\img\", ""));
                    }
                    break;

                case "MSG":
                    Notifier.ShowMsg(scr.Args);
                    break;

                case "POSX":
                    frm.PosX(Convert.ToInt32(scr.Args.Trim()));
                    break;

                case "POSY":
                    frm.PosY(Convert.ToInt32(scr.Args.Trim()));
                    break;

                case "ACTIVATE":
                    frm.Activate();
                    break;

                case "ERROR":
                    Notifier.ErrorMsg(scr.Args);
                    break;

                case "SCRIPT":
                    if (scr.Args.Contains("."))
                    {
                        RunFromFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Scripts\" + scr.Args.Split('.')[0].Trim(), scr.Args.Split('.')[1]);
                    }
                    else
                    {
                        RunFromFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Scripts\" + scr.Args.Trim());
                    }
                    break;

                case "STATUS":
                    StatusMonitor.CurrentStatus = scr.Args.Trim();
                    if (StatusMonitor.CurrentStatus != "WAITFORRESP")
                    {
                        cachecopy = new List <string>(cache);
                        foreach (string line in cachecopy)
                        {
                            DbgOutput.Write(line);
                            cache.Remove(line);
                        }
                        RunFromList(cachecopy);
                    }
                    break;

                case "SOUND":
                    SoundPlayer.Play(scr.Args.Trim());
                    break;

                default:
                    try
                    {
                        IOChannel Eng = new IOChannel(scr.Command.Trim(), Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Routines\" + scr.Command.Trim() + ".exe", scr.Args);
                        Eng.Start();
                    }
                    catch
                    {
                        Notifier.ErrorMsg("Unable to " + scr.Command.Trim() + " " + scr.Args.Trim() + ". \nMake sure all necessary files are under \"Routines\".");
                    }
                    break;
                }

                return(true);
            }
Esempio n. 15
0
        public IOPool()
        {
            //set default configuration
            Configuration = new PoolConfiguration();

            _iochannel = new IOChannel(this);

            _eventThread = new Thread(_iochannel.ProcessEvents);
            _eventThread.Start();
        }