예제 #1
0
        List <ILaunchPlan> planRepo; // current plan repo

        //void terminateFromConstructor()
        //{
        //    Load += (s, e) => Close();
        //}

        /// <summary>
        /// Dirigent Agent GUI main form constructor
        /// </summary>
        /// <param name="ctrl">instance of object providing dirigent operations</param>
        /// <param name="planRepo">planRepo to be used until a new one is received from the master; null if none</param>
        /// <param name="machineId">machine id (part of application id in launch plans); informative only; used to be presented to the user</param>
        /// <param name="clientId">name of network client used to mark the network messages; informative only; used to recognize incoming errors caused by request from this agent</param>
        /// <param name="notifyIcon">instance of notify icon</param>
        /// <param name="allowLocalIfDisconnected">if true, apps and plans can be operated locally even if not connected to master</param>
        /// <param name="callbacks">bunch of callbacks</param>
        public frmMain(
            IDirigentControl ctrl,
            IEnumerable <ILaunchPlan> planRepo,
            string machineId,
            string clientId,
            NotifyIcon notifyIcon,
            bool allowLocalIfDisconnected,
            GuiAppCallbacks callbacks
            )
        {
            this.ctrl       = ctrl;
            this.machineId  = machineId;
            this.clientId   = clientId;
            this.callbacks  = callbacks;
            this.notifyIcon = notifyIcon;
            this.allowLocalIfDisconnected = allowLocalIfDisconnected;

            InitializeComponent();

            registerHotKeys();

            //setDoubleBuffered(gridApps, true); // not needed anymore, DataViewGrid does not flicker

            //this.plan = null;
            if (planRepo != null)
            {
                this.planRepo = new List <ILaunchPlan>(planRepo);
                populatePlanLists();
            }

            // start ticking
            tmrTick.Enabled = true;
        }
예제 #2
0
파일: MainForm.cs 프로젝트: pjanec/dirigent
        List<ILaunchPlan> planRepo; // current plan repo

        #endregion Fields

        #region Constructors

        //void terminateFromConstructor()
        //{
        //    Load += (s, e) => Close();
        //}
        /// <summary>
        /// Dirigent Agent GUI main form constructor
        /// </summary>
        /// <param name="ctrl">instance of object providing dirigent operations</param>
        /// <param name="planRepo">planRepo to be used until a new one is received from the master; null if none</param>
        /// <param name="machineId">machine id (part of application id in launch plans); informative only; used to be presented to the user</param>
        /// <param name="clientId">name of network client used to mark the network messages; informative only; used to recognize incoming errors caused by request from this agent</param>
        /// <param name="notifyIcon">instance of notify icon</param>
        /// <param name="allowLocalIfDisconnected">if true, apps and plans can be operated locally even if not connected to master</param>
        /// <param name="callbacks">bunch of callbacks</param>
        public frmMain(
            IDirigentControl ctrl,
            IEnumerable<ILaunchPlan> planRepo,
            string machineId,
            string clientId,
            NotifyIcon notifyIcon,
            bool allowLocalIfDisconnected,
            GuiAppCallbacks callbacks
            )
        {
            this.ctrl = ctrl;
            this.machineId = machineId;
            this.clientId = clientId;
            this.callbacks = callbacks;
            this.notifyIcon = notifyIcon;
            this.allowLocalIfDisconnected = allowLocalIfDisconnected;

            InitializeComponent();

            //setDoubleBuffered(gridApps, true); // not needed anymore, DataViewGrid does not flicker

            this.plan = null;
            if (planRepo != null)
            {
                this.planRepo = new List<ILaunchPlan>(planRepo);
                populatePlanLists();
            }

            // start ticking
            tmrTick.Enabled = true;
        }
예제 #3
0
        public FolderWatcher(System.Xml.Linq.XElement rootXml, IDirigentControl ctrl, string rootForRelativePaths)
        {
            this.ctrl              = ctrl;
            this.conditions        = (string)rootXml.Attribute("Conditions");
            this.RelativePathsRoot = rootForRelativePaths;

            if (String.IsNullOrEmpty(rootForRelativePaths))
            {
                RelativePathsRoot = System.IO.Directory.GetCurrentDirectory();
            }
            else
            {
                RelativePathsRoot = rootForRelativePaths;
            }

            var inclSubdirs = X.getBoolAttr(rootXml, "IncludeSubdirs");
            var path        = X.getStringAttr(rootXml, "Path");
            var filter      = X.getStringAttr(rootXml, "Filter");

            if (String.IsNullOrEmpty(path))
            {
                log.Error("Path not defined or empty!");
                return;
            }

            var absPath = BuildAbsolutePath(path);

            if (!System.IO.Directory.Exists(absPath))
            {
                log.Error("Path does not exist!");
                return;
            }

            watcher.Path = absPath;
            watcher.IncludeSubdirectories = inclSubdirs;

            if (!String.IsNullOrEmpty(filter))
            {
                watcher.Filter = filter;
            }

            if (conditions == "NewFile")
            {
                watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.CreationTime | NotifyFilters.LastWrite;
                watcher.Created     += new FileSystemEventHandler(OnFileCreated);
            }

            foreach (var actXml in rootXml.Descendants("Action"))
            {
                actionXmls.Add(actXml);
            }

            log.DebugFormat("FolderWatcher initialized. Path={0}, Filter={1}, Conditions={2}", watcher.Path, watcher.Filter, conditions);
            Initialized = true;

            watcher.EnableRaisingEvents = true;
        }
예제 #4
0
 /// <summary>
 /// Client needs to be already connected or autoconnecting!
 /// </summary>
 /// <param name="client"></param>
 /// <param name="localOps"></param>
 public NetworkProxy(
             string machineId,
             IClient client,
             IDirigentControl localOps )
 {
     this.machineId = machineId;
     this.client = client;
     this.localOps = localOps;
 }
예제 #5
0
 /// <summary>
 /// Client needs to be already connected or autoconnecting!
 /// </summary>
 /// <param name="client"></param>
 /// <param name="localOps"></param>
 public NetworkProxy(
     string machineId,
     IClient client,
     IDirigentControl localOps)
 {
     this.machineId = machineId;
     this.client    = client;
     this.localOps  = localOps;
 }
예제 #6
0
        /// <summary>
        /// The "message broker" for forwarding messages to clients.
        /// Just instantiate the class to make the server working.
        /// The clients remotely access the MasterService via the IDirigentMasterContract interface.
        /// </summary>
        /// <param name="port"></param>
        public Server(int port, IDirigentControl localAgent, IEnumerable <ILaunchPlan> planRepo = null, string startupPlanName = "")
        {
            this.port = port;

            var uri     = new Uri(string.Format("net.tcp://0.0.0.0:{0}", port));
            var binding = new NetTcpBinding();

            binding.Name = "MasterConnBinding";
            binding.MaxReceivedMessageSize = Int32.MaxValue;  // default 65535 is not enough for long plans
            binding.Security.Mode          = SecurityMode.None;
            var service  = new MasterService(localAgent);
            var host     = new ServiceHost(service, uri);
            var endpoint = host.AddServiceEndpoint(typeof(IDirigentMasterContract), binding, "");

            //endpoint.Behaviors.Add(new ClientTrackerEndpointBehavior());
            host.Open(); // never closed as the server runs forever

            // although there can't be any clients connected, this caches the planRepo internally
            // this cached one is then sent to the client when it first connects
            if (planRepo != null)
            {
                log.InfoFormat("Forcing plan repository ({0} items)", planRepo.Count());
                service.BroadcastMessage(MasterSenderName, new PlanRepoMessage(planRepo));
            }

            // start the initial launch plan if specified
            if (planRepo != null && startupPlanName != null && startupPlanName != "")
            {
                ILaunchPlan startupPlan;
                try
                {
                    startupPlan = planRepo.First((i) => i.Name == startupPlanName);
                }
                catch
                {
                    throw new UnknownPlanName(startupPlanName);
                }

                if (startupPlan != null)
                {
                    log.InfoFormat("Forcing plan '{0}'", startupPlanName);
                    service.BroadcastMessage(MasterSenderName, new CurrentPlanMessage(startupPlanName));
                }
            }
        }
예제 #7
0
        public MyCommandRepo(IDirigentControl ctrl)
        {
            this.ctrl = ctrl;
            //var cmdClasses = Assembly.GetExecutingAssembly().GetTypes().Where(t =>  t.IsSubclassOf(typeof(Commands.DirigentControlCommand)));
            //foreach( cmdClass in cmdClasses )
            //{
            //    Register( new cmd ????
            //}

            Register(new Commands.StartPlan(ctrl));
            Register(new Commands.StopPlan(ctrl));
            Register(new Commands.KillPlan(ctrl));
            Register(new Commands.RestartPlan(ctrl));
            Register(new Commands.LaunchApp(ctrl));
            Register(new Commands.KillApp(ctrl));
            Register(new Commands.RestartApp(ctrl));
            Register(new Commands.SelectPlan(ctrl));
        }
예제 #8
0
        public MyCommandRepo(IDirigentControl ctrl)
        {
            this.ctrl = ctrl;
            //var cmdClasses = Assembly.GetExecutingAssembly().GetTypes().Where(t =>  t.IsSubclassOf(typeof(Commands.DirigentControlCommand)));
            //foreach( cmdClass in cmdClasses )
            //{
            //    Register( new cmd ????
            //}

            Register(new Commands.StartPlan(ctrl));
            Register(new Commands.StopPlan(ctrl));
            Register(new Commands.KillPlan(ctrl));
            Register(new Commands.RestartPlan(ctrl));
            Register(new Commands.LaunchApp(ctrl));
            Register(new Commands.KillApp(ctrl));
            Register(new Commands.RestartApp(ctrl));
            //Register(new Commands.SelectPlan(ctrl));
        }
예제 #9
0
            public TRequest(TClient client, IDirigentControl ctrl, string cmdLine)
            {
                this.ctrl = ctrl;
                Client    = client;
                Commands  = new Queue <ICommand>();
                cmdRepo   = new MyCommandRepo(ctrl);

                // parse commands and fill cmd queue
                List <string> tokens = null;
                string        restAfterUid;

                SplitToUuidAndRest(cmdLine, out Uid, out restAfterUid);

                try
                {
                    if (!string.IsNullOrEmpty(restAfterUid))
                    {
                        SplitToWordTokens(restAfterUid, out tokens);
                    }
                    if (tokens != null && tokens.Count > 0)
                    {
                        var cmdList = cmdRepo.ParseCmdLineTokens(tokens, WriteResponseLine);
                        Commands = new Queue <ICommand>(cmdList);
                    }
                }
                catch (Exception e)
                {
                    // take just first line of exception description
                    string excMsg = e.ToString();
                    var    crPos  = excMsg.IndexOf('\r');
                    var    lfPos  = excMsg.IndexOf('\n');
                    if (crPos >= 0 || lfPos >= 0)
                    {
                        excMsg = excMsg.Substring(0, Math.Min(crPos, lfPos));
                    }

                    WriteResponseLine("ERROR: " + Tools.JustFirstLine(e.Message));

                    Finished = true;
                }
            }
예제 #10
0
 public void SwitchImpl(IDirigentControl newImpl)
 {
     impl = newImpl;
 }
예제 #11
0
 public KillApp(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
예제 #12
0
 public SelectPlan(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
예제 #13
0
 public DirigentControlSwitchableProxy(IDirigentControl initialImpl)
 {
     impl = initialImpl;
 }
 public GetPlanState(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
 public GetAllAppsState(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
예제 #16
0
 public RestartPlan(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
예제 #17
0
 public DirigentControlCommand(IDirigentControl ctrl)
 {
     this.name = this.GetType().Name;
     this.ctrl = ctrl;
 }
예제 #18
0
 public RestartPlan(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
예제 #19
0
 public StopPlan(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
예제 #20
0
 public StopPlan(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
예제 #21
0
 public RestartApp(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
예제 #22
0
 public KillApp(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
예제 #23
0
 public KillPlan(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
예제 #24
0
 public LaunchApp(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
예제 #25
0
 public DirigentControlCommand(IDirigentControl ctrl)
 {
     this.name = this.GetType().Name;
     this.ctrl = ctrl;
 }
예제 #26
0
 public CLIServer(string localIPstr, int port, IDirigentControl ctrl)
 {
     this.localIPstr = localIPstr;
     this.port       = port;
     this.ctrl       = ctrl;
 }
예제 #27
0
 public KillPlan(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
 public DirigentControlSwitchableProxy(IDirigentControl initialImpl)
 {
     impl = initialImpl;
 }
예제 #29
0
 public LaunchApp(IDirigentControl ctrl)
     : base(ctrl)
 {
 }
 public void SwitchImpl(IDirigentControl newImpl)
 {
     impl = newImpl;
 }
예제 #31
0
 public MasterService(IDirigentControl localAgent)
 {
     this.localAgent = localAgent;
     disconTimer     = new Timer(DetectDisconnections, null, 0, 1000);
 }
예제 #32
0
 public RestartApp(IDirigentControl ctrl)
     : base(ctrl)
 {
 }