Ejemplo n.º 1
0
        bool ShowDependencies(IList<AddIn> addIns, ShowDependencyMode mode)
        {
            List<AddInReference> dependencies = new List<AddInReference>(); // only used with enable=true
            List<KeyValuePair<AddIn, AddInReference>> dependenciesToSel = new List<KeyValuePair<AddIn, AddInReference>>();
            Dictionary<string, Version> addInDict = new Dictionary<string, Version>();
            Dictionary<string, Version> modifiedAddIns = new Dictionary<string, Version>();

            // add available addins
            foreach (AddIn addIn in AddInTree.AddIns)
            {
                if (addIn.Action != AddInAction.Enable && addIn.Action != AddInAction.Install)
                    continue;
                if (addIns.Contains(addIn))
                    continue;
                foreach (KeyValuePair<string, Version> pair in addIn.Manifest.Identities)
                {
                    addInDict[pair.Key] = pair.Value;
                }
            }

            // create list of modified addin names
            foreach (AddIn addIn in addIns)
            {
                foreach (KeyValuePair<string, Version> pair in addIn.Manifest.Identities)
                {
                    modifiedAddIns[pair.Key] = pair.Value;
                }
            }

            // add new addins
            if (mode != ShowDependencyMode.Disable)
            {
                foreach (AddIn addIn in addIns)
                {
                    if (mode == ShowDependencyMode.CancelUpdate && !addIn.Enabled)
                    {
                        continue;
                    }
                    foreach (KeyValuePair<string, Version> pair in addIn.Manifest.Identities)
                    {
                        addInDict[pair.Key] = pair.Value;
                    }
                    foreach (AddInReference dep in addIn.Manifest.Dependencies)
                    {
                        if (!dependencies.Contains(dep))
                            dependencies.Add(dep);
                    }
                }
            }

            // add dependencies to the to-be-changed addins
            foreach (AddIn addIn in AddInTree.AddIns)
            {
                if (addIn.Action != AddInAction.Enable && addIn.Action != AddInAction.Install)
                    continue;
                if (addIns.Contains(addIn))
                    continue;
                foreach (AddInReference dep in addIn.Manifest.Dependencies)
                {
                    if (modifiedAddIns.ContainsKey(dep.Name))
                    {
                        dependenciesToSel.Add(new KeyValuePair<AddIn, AddInReference>(addIn, dep));
                    }
                }
            }

            foreach (Control ctl in dependencyTable.Controls)
            {
                ctl.Dispose();
            }
            dependencyTable.Controls.Clear();
            bool allDepenciesOK = true;
            if (dependencies.Count > 0 || dependenciesToSel.Count > 0)
            {
                if (dependencies.Count == 0)
                {
                    dependencyTable.RowCount = 1 + dependenciesToSel.Count;
                }
                else if (dependenciesToSel.Count == 0)
                {
                    dependencyTable.RowCount = 1 + dependencies.Count;
                }
                else
                {
                    dependencyTable.RowCount = 2 + dependencies.Count + dependenciesToSel.Count;
                }
                while (dependencyTable.RowStyles.Count < dependencyTable.RowCount)
                {
                    dependencyTable.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                }
                int rowIndex = 0;
                if (dependencies.Count > 0)
                {
                    AddLabelRow(rowIndex++, ResourceService.GetString("AddInManager.RequiredDependencies"));
                    foreach (AddInReference dep in dependencies)
                    {
                        if (!AddDependencyRow(addInDict, dep, rowIndex++, null))
                            allDepenciesOK = false;
                    }
                }
                if (dependenciesToSel.Count > 0)
                {
                    AddLabelRow(rowIndex++, ResourceService.GetString("AddInManager.RequiredBy"));
                    foreach (KeyValuePair<AddIn, AddInReference> pair in dependenciesToSel)
                    {
                        if (!AddDependencyRow(addInDict, pair.Value, rowIndex++, pair.Key.Name))
                            allDepenciesOK = false;
                    }
                }
                dependencyTable.Visible = true;
            }
            return allDepenciesOK;
        }
Ejemplo n.º 2
0
        bool ShowDependencies(IList <AddIn> addIns, ShowDependencyMode mode)
        {
            List <AddInReference> dependencies = new List <AddInReference>();           // only used with enable=true
            List <KeyValuePair <AddIn, AddInReference> > dependenciesToSel = new List <KeyValuePair <AddIn, AddInReference> >();
            Dictionary <string, Version> addInDict      = new Dictionary <string, Version>();
            Dictionary <string, Version> modifiedAddIns = new Dictionary <string, Version>();

            // add available addins
            foreach (AddIn addIn in AddInTree.AddIns)
            {
                if (addIn.Action != AddInAction.Enable && addIn.Action != AddInAction.Install)
                {
                    continue;
                }
                if (addIns.Contains(addIn))
                {
                    continue;
                }
                foreach (KeyValuePair <string, Version> pair in addIn.Manifest.Identities)
                {
                    addInDict[pair.Key] = pair.Value;
                }
            }

            // create list of modified addin names
            foreach (AddIn addIn in addIns)
            {
                foreach (KeyValuePair <string, Version> pair in addIn.Manifest.Identities)
                {
                    modifiedAddIns[pair.Key] = pair.Value;
                }
            }

            // add new addins
            if (mode != ShowDependencyMode.Disable)
            {
                foreach (AddIn addIn in addIns)
                {
                    if (mode == ShowDependencyMode.CancelUpdate && !addIn.Enabled)
                    {
                        continue;
                    }
                    foreach (KeyValuePair <string, Version> pair in addIn.Manifest.Identities)
                    {
                        addInDict[pair.Key] = pair.Value;
                    }
                    foreach (AddInReference dep in addIn.Manifest.Dependencies)
                    {
                        if (!dependencies.Contains(dep))
                        {
                            dependencies.Add(dep);
                        }
                    }
                }
            }

            // add dependencies to the to-be-changed addins
            foreach (AddIn addIn in AddInTree.AddIns)
            {
                if (addIn.Action != AddInAction.Enable && addIn.Action != AddInAction.Install)
                {
                    continue;
                }
                if (addIns.Contains(addIn))
                {
                    continue;
                }
                foreach (AddInReference dep in addIn.Manifest.Dependencies)
                {
                    if (modifiedAddIns.ContainsKey(dep.Name))
                    {
                        dependenciesToSel.Add(new KeyValuePair <AddIn, AddInReference>(addIn, dep));
                    }
                }
            }

            foreach (Control ctl in dependencyTable.Controls)
            {
                ctl.Dispose();
            }
            dependencyTable.Controls.Clear();
            bool allDepenciesOK = true;

            if (dependencies.Count > 0 || dependenciesToSel.Count > 0)
            {
                if (dependencies.Count == 0)
                {
                    dependencyTable.RowCount = 1 + dependenciesToSel.Count;
                }
                else if (dependenciesToSel.Count == 0)
                {
                    dependencyTable.RowCount = 1 + dependencies.Count;
                }
                else
                {
                    dependencyTable.RowCount = 2 + dependencies.Count + dependenciesToSel.Count;
                }
                while (dependencyTable.RowStyles.Count < dependencyTable.RowCount)
                {
                    dependencyTable.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                }
                int rowIndex = 0;
                if (dependencies.Count > 0)
                {
                    AddLabelRow(rowIndex++, ResourceService.GetString("AddInManager.RequiredDependencies"));
                    foreach (AddInReference dep in dependencies)
                    {
                        if (!AddDependencyRow(addInDict, dep, rowIndex++, null))
                        {
                            allDepenciesOK = false;
                        }
                    }
                }
                if (dependenciesToSel.Count > 0)
                {
                    AddLabelRow(rowIndex++, ResourceService.GetString("AddInManager.RequiredBy"));
                    foreach (KeyValuePair <AddIn, AddInReference> pair in dependenciesToSel)
                    {
                        if (!AddDependencyRow(addInDict, pair.Value, rowIndex++, pair.Key.Name))
                        {
                            allDepenciesOK = false;
                        }
                    }
                }
                dependencyTable.Visible = true;
            }
            return(allDepenciesOK);
        }