//if( !launchSequencerEnabled )
        //    return;

        bool areAllDepsSatisfied(AppDef appDef)
        {
            // pokud jsou vsechny aplikace na kterych ta nase zavisi spousteny
            bool allDepsSatisfied = true;

            if (appDef.Dependencies != null)
            {
                foreach (var depName in appDef.Dependencies)
                {
                    AppIdTuple depId = AppIdTuple.fromString(depName, appDef.AppIdTuple.MachineId);

                    if (!appsState.ContainsKey(depId))
                    {
                        // throw exception "Unknown dependency"
                        throw new UnknownDependencyException(depName);
                    }

                    var dep = appsState[depId];
                    if (!dep.Initialized)
                    {
                        allDepsSatisfied = false;
                        break;
                    }
                }
            }
            return(allDepsSatisfied);
        }
        /// <summary>
        /// Update the list of apps by doing minimal changes to avoid losing focus.
        /// Adding what is not yet there and deleting what has disappeared.
        /// </summary>
        void refreshAppList_smart()
        {
            DataGridViewRow selected = null;

            var plan = ctrl.GetCurrentPlan();

            var planAppDefsDict = (plan != null) ? (from ad in plan.getAppDefs() select ad).ToDictionary(ad => ad.AppIdTuple, ad => ad) : new Dictionary <AppIdTuple, AppDef>();
            var planAppIdTuples = (plan != null) ? (from ad in plan.getAppDefs() select ad.AppIdTuple).ToList() : new List <AppIdTuple>();
            var appStates       = ctrl.GetAllAppsState();

            // remember apps from plan
            Dictionary <string, AppIdTuple> newApps = new Dictionary <string, AppIdTuple>();

            foreach (AppIdTuple a in appStates.Keys)
            {
                newApps[a.ToString()] = a;
            }

            // remember apps from list
            Dictionary <string, DataGridViewRow> oldApps = new Dictionary <string, DataGridViewRow>();

            foreach (DataGridViewRow item in gridApps.Rows)
            {
                string id = item.Cells[appTabColName].Value as string;
                oldApps[id] = item;

                if (item.Selected)
                {
                    if (selected == null)
                    {
                        selected = item;
                    }
                }
            }

            // determine what to add and what to remove
            List <DataGridViewRow> toRemove = new List <DataGridViewRow>();
            List <object[]>        toAdd    = new List <object[]>();

            foreach (DataGridViewRow item in gridApps.Rows)
            {
                string id = item.Cells[0].Value as string;
                if (!newApps.ContainsKey(id))
                {
                    toRemove.Add(item);
                }
            }

            foreach (var x in appStates)
            {
                var id = x.Key.ToString();
                if (!oldApps.ContainsKey(id))
                {
                    var appIdTuple = x.Key;
                    var appState   = x.Value;
                    var item       = new object[appTabNumCols];
                    item[appTabColName]        = id;
                    item[appTabColStatus]      = getAppStatusCode(appIdTuple, appState, planAppIdTuples.Contains(appIdTuple));
                    item[appTabColIconStart]   = ResizeImage(new Bitmap(Dirigent.Agent.Gui.Resource1.play), new Size(20, 20));
                    item[appTabColIconKill]    = ResizeImage(new Bitmap(Dirigent.Agent.Gui.Resource1.delete), new Size(20, 20));
                    item[appTabColIconRestart] = ResizeImage(new Bitmap(Dirigent.Agent.Gui.Resource1.refresh), new Size(20, 20));
                    item[appTabColEnabled]     = false;
                    toAdd.Add(item);
                }
            }

            foreach (var i in toRemove)
            {
                gridApps.Rows.Remove(i);
            }

            foreach (var i in toAdd)
            {
                gridApps.Rows.Add(i);
            }

            Dictionary <DataGridViewRow, string> toUpdate = new Dictionary <DataGridViewRow, string>();

            foreach (var o in oldApps)
            {
                if (!toRemove.Contains(o.Value))
                {
                    toUpdate[o.Value] = getAppStatusCode(newApps[o.Key], ctrl.GetAppState(newApps[o.Key]), planAppIdTuples.Contains(newApps[o.Key]));
                }
            }

            foreach (var tu in toUpdate)
            {
                var row = tu.Key;
                row.Cells[appTabColStatus].Value = tu.Value;
            }

            // colorize the background of items from current plan
            List <string> planAppIds = (from ad in planAppIdTuples select ad.ToString()).ToList();

            foreach (DataGridViewRow item in gridApps.Rows)
            {
                string id         = item.Cells[0].Value as string;
                var    appIdTuple = AppIdTuple.fromString(id, "");

                if (planAppIds.Contains(id))
                {
                    item.DefaultCellStyle.BackColor = Color.LightGoldenrodYellow;
                }
                else
                {
                    item.DefaultCellStyle.BackColor = SystemColors.Control;
                }

                // set checkbox based on Enabled attribute od the appDef from current plan
                var appDef  = planAppDefsDict.ContainsKey(appIdTuple) ? planAppDefsDict[appIdTuple] : null;
                var chkCell = item.Cells[appTabColEnabled] as DataGridViewCheckBoxCell;
                chkCell.Value = appDef != null ? !appDef.Disabled : false;
                // emulate "Disabled" grayed appearance
                chkCell.FlatStyle       = appDef != null ? FlatStyle.Standard: FlatStyle.Flat;
                chkCell.Style.ForeColor = appDef != null ? Color.Black : Color.DarkGray;
                chkCell.ReadOnly        = appDef == null;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update the list of apps by doing minimal changes to avoid losing focus.
        /// Adding what is not yet there and deleting what has disappeared.
        /// </summary>
        void refreshAppList_smart()
        {
            DataGridViewRow selected = null;

            var plan = _currentPlan;

            var planAppDefsDict = (plan != null) ? (from ad in plan.AppDefs select ad).ToDictionary(ad => ad.Id, ad => ad) : new Dictionary <AppIdTuple, AppDef>();
            var planAppIdTuples = (plan != null) ? (from ad in plan.AppDefs select ad.Id).ToList() : new List <AppIdTuple>();

            Dictionary <AppIdTuple, AppState> appStates;

            if (ShowJustAppFromCurrentPlan)
            {
                appStates = (from i in _ctrl.GetAllAppStates() where planAppIdTuples.Contains(i.Key) select i).ToDictionary(mc => mc.Key, mc => mc.Value);
            }
            else             // show from all plans
            {
                appStates = new Dictionary <AppIdTuple, AppState>(_ctrl.GetAllAppStates());
            }

            // remember apps from plan
            Dictionary <string, AppIdTuple> newApps = new Dictionary <string, AppIdTuple>();

            foreach (AppIdTuple a in appStates.Keys)
            {
                newApps[a.ToString()] = a;
            }

            // remember apps from list
            Dictionary <string, DataGridViewRow> oldApps = new Dictionary <string, DataGridViewRow>();

            foreach (DataGridViewRow item in gridApps.Rows)
            {
                string id = item.Cells[appTabColName].Value as string;
                oldApps[id] = item;

                if (item.Selected)
                {
                    if (selected == null)
                    {
                        selected = item;
                    }
                }
            }

            // determine what to add and what to remove
            List <DataGridViewRow> toRemove = new List <DataGridViewRow>();
            List <object[]>        toAdd    = new List <object[]>();

            foreach (DataGridViewRow item in gridApps.Rows)
            {
                string id = item.Cells[0].Value as string;
                if (!newApps.ContainsKey(id))
                {
                    toRemove.Add(item);
                }
            }

            foreach (var x in appStates)
            {
                var idStr = x.Key.ToString();
                if (!oldApps.ContainsKey(idStr))
                {
                    var id       = x.Key;
                    var appState = x.Value;
                    var item     = new object[appTabNumCols];
                    item[appTabColName] = idStr;
                    //item[appTabColStatus] = getAppStatusCode( id, appState, planAppIdTuples.Contains( id ) );
                    item[appTabColStatus]      = Tools.GetAppStateText(appState, _ctrl.GetPlanState(appState.PlanName), _ctrl.GetAppDef(id));
                    item[appTabColIconStart]   = ResizeImage(new Bitmap(Resource1.play), new Size(20, 20));
                    item[appTabColIconKill]    = ResizeImage(new Bitmap(Resource1.delete), new Size(20, 20));
                    item[appTabColIconRestart] = ResizeImage(new Bitmap(Resource1.refresh), new Size(20, 20));
                    item[appTabColEnabled]     = false;
                    item[appTabColPlan]        = GetPlanForApp(id);
                    toAdd.Add(item);
                }
            }

            foreach (var i in toRemove)
            {
                gridApps.Rows.Remove(i);
            }

            foreach (var i in toAdd)
            {
                gridApps.Rows.Add(i);
            }

            Dictionary <DataGridViewRow, UPD> toUpdate = new Dictionary <DataGridViewRow, UPD>();

            foreach (var o in oldApps)
            {
                if (!toRemove.Contains(o.Value))
                {
                    var id       = newApps[o.Key];
                    var appState = _ctrl.GetAppState(id);
                    var upd      = new UPD()
                    {
                        //Status = getAppStatusCode( id, appState, planAppIdTuples.Contains( id ) ),
                        Status   = Tools.GetAppStateText(appState, _ctrl.GetPlanState(appState.PlanName), _ctrl.GetAppDef(id)),
                        PlanName = null
                    };
                    if (appState.PlanName != null)
                    {
                        upd.PlanName = appState.PlanName;
                    }
                    toUpdate[o.Value] = upd;
                }
            }

            foreach (var tu in toUpdate)
            {
                var row = tu.Key;
                var upd = tu.Value;

                row.Cells[appTabColStatus].Value = upd.Status;

                if (upd.PlanName != null)
                {
                    row.Cells[appTabColPlan].Value = upd.PlanName;
                }
            }

            // colorize the background of items from current plan
            List <string> planAppIds = (from ad in planAppIdTuples select ad.ToString()).ToList();

            foreach (DataGridViewRow item in gridApps.Rows)
            {
                string idStr = item.Cells[0].Value as string;
                var    id    = AppIdTuple.fromString(idStr, "");

                if (planAppIds.Contains(idStr))
                {
                    item.DefaultCellStyle.BackColor = Color.LightGoldenrodYellow;
                }
                else
                {
                    item.DefaultCellStyle.BackColor = SystemColors.Control;
                }

                // set checkbox based on Enabled attribute od the appDef from current plan
                var appDef = planAppDefsDict.ContainsKey(id) ? planAppDefsDict[id] : null;
                {
                    var chkCell = item.Cells[appTabColEnabled] as DataGridViewCheckBoxCell;
                    chkCell.Value = appDef != null ? !appDef.Disabled : false;
                    // emulate "Disabled" grayed appearance
                    chkCell.FlatStyle       = appDef != null ? FlatStyle.Standard : FlatStyle.Flat;
                    chkCell.Style.ForeColor = appDef != null ? Color.Black : Color.DarkGray;
                    chkCell.ReadOnly        = appDef == null;
                }
                // put app state into a tooltip
                {
                    var appStatusCell = item.Cells[appTabColStatus];                     // as DataGridViewCell;
                    appStatusCell.ToolTipText = Tools.GetAppStateString(id, _ctrl.GetAppState(id));
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Builds the list of waves as the result of application interdependencies.
        ///
        /// The first wawe will contain apps that do not depend on any other app.
        /// The second wave will contain the apps that depend on those from the first wave.
        /// Etc. untill all apps are processed.
        /// </summary>
        public static List <AppWave> build(IEnumerable <AppDef> launchPlan)
        {
            // seznam zbyvajicich aplikaci
            // seznam uz pouzitych aplikaci (ktere uz byly vlozeny do vln)
            // Prochazim seznam zbylych aplikaci a pro kazdou hledam, zda vsechny jeji zavislosti uz se nachazi
            // v seznamu pouzitych aplikaci. Pokud ano, zkopiruju aplikaci do aktualni vlny. Pro projiti
            // vsech aplikaci pak vezmu aplikace z aktulne vytvorene vlny, smazu je ze zbyvajicich a vlozim do pouzitych.

            List <AppDef> remaining = (from t in launchPlan where !t.Disabled select t).ToList(); // those not yet moved to any of the waves
            List <AppDef> used      = new List <AppDef>();                                        // those already moved to some of waves

            // allow fast lookup of appdef by its name
            Dictionary <AppIdTuple, AppDef> dictApps = new Dictionary <AppIdTuple, AppDef>();

            foreach (var app in remaining)
            {
                dictApps[app.AppIdTuple] = app;
            }

            var waves = new List <AppWave>(); // the resulting list of waves

            // For each of the remaining apps check whether all its dependencias were already moved to some of prevoiusly
            // built waves; if so, add the app to the current wave and move it from remaining to used.
            while (remaining.Count > 0)
            {
                List <AppDef> currentWave = new List <AppDef>(); // the wave currently being built

                foreach (var app in remaining)
                {
                    bool allDepsSatisfied = true;

                    if (app.Dependencies != null)
                    {
                        foreach (var depName in app.Dependencies)
                        {
                            AppIdTuple depId = AppIdTuple.fromString(depName, app.AppIdTuple.MachineId);

                            if (!dictApps.ContainsKey(depId))
                            {
                                // throw exception "Unknown dependency"
                                throw new UnknownDependencyException(depName);
                            }

                            var dep = dictApps[depId];
                            if (!used.Contains(dep))
                            {
                                allDepsSatisfied = false;
                                break;
                            }
                        }
                    }
                    if (allDepsSatisfied)
                    {
                        currentWave.Add(app);
                    }
                }

                // if there are no app in current wave, there must be some circular dependency
                // as there is no app that does not depend on
                if (currentWave.Count == 0)
                {
                    // throw exception "Circular dependency somewhere"
                    throw new CircularDependencyException();
                }

                // move apps that were added to the current wave from remaining to used
                foreach (var app in currentWave)
                {
                    remaining.Remove(app);
                    used.Add(app);
                }

                // add current wave to the resulting list of wawes
                waves.Add(new AppWave(currentWave));
            }

            return(waves);
        }