Example #1
0
        /// <summary>
        /// 从指定数据库中抓取相关容器
        /// </summary>
        /// <param name="conn">指定的数据库</param>
        /// <returns>迭代返回抓取结果</returns>
        protected virtual IEnumerable <Model.Container> FetchContainersHelper(Predicate <Model.Container> predicate)
        {
            SQLiteCommand cmd = new SQLiteCommand(DataBase);

            cmd.CommandText = $@"Select *
                                 From {APM.ContainersTable}
                                 Where {APM.ContainerFilter} == {FilterUID}";

            using (SQLiteDataReader results = cmd.ExecuteReader()) {
                while (results.Read())
                {
                    Model.Container source = ContainerHelper.FetchFrom(results);
                    if (predicate(source))
                    {
                        yield return(source);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// 依据条件抓取Container
        /// </summary>
        /// <param name="predicate">谓词回调</param>
        /// <returns>抓取结果的迭代器</returns>
        protected virtual IEnumerable <Model.Container> FetchContainersSource(Predicate <Model.Container> predicate)
        {
            SQLiteCommand cmd = new SQLiteCommand(_database);

            foreach (Model.Filter filter in FetchFiltersSource((f) => true))
            {
                cmd.CommandText = $@"Select * 
                                     From {APM.ContainersTable}
                                     Where {APM.ContainerFilter} == {filter.FilterUID}";
                using (SQLiteDataReader results = cmd.ExecuteReader()) {
                    while (results.Read())
                    {
                        Model.Container container = ContainerHelper.FetchFrom(results);
                        if (predicate(container))
                        {
                            yield return(container);
                        }
                    }
                }
            }
        }
        private void CreateContainer()
        {
            if (comboBoxImage.SelectedItem != null)
            {
                string command = "docker run";
                command += string.Format(" -p {0}:{1}", numericUpDownPortFrom.Value, numericUpDownPortTo.Value);
                if (!string.IsNullOrEmpty(textBoxName.Text))
                {
                    command += string.Format(" --name {0}", textBoxName.Text);
                }
                if (comboBoxNetwork.SelectedItem != null)
                {
                    command += string.Format(" --network {0}", ((Network)(comboBoxNetwork.SelectedItem)).Name);
                }
                if (!string.IsNullOrEmpty(textBoxIp.Text))
                {
                    command += string.Format(" --ip {0}", textBoxIp.Text);
                }
                if (!string.IsNullOrEmpty(textBoxAlias.Text))
                {
                    command += string.Format(" --network-alias {0}", textBoxAlias.Text);
                }
                if (checkBoxRootRights.Checked)
                {
                    command += " --privileged -e \"container = docker\" -v /sys/fs/cgroup:/sys/fs/cgroup";
                }
                command += " -itd " + ((((Model.Image)comboBoxImage.SelectedItem).Repository != null) ? ((Model.Image)comboBoxImage.SelectedItem).Repository : ((Model.Image)comboBoxImage.SelectedItem).Id);
                command += string.IsNullOrEmpty(textBoxCommand.Text) ? "  /usr/sbin/init" : textBoxCommand.Text;

                if (_adapter != null && _adapter.Engine != null && _adapter.Engine.CurrentMachine != null)
                {
                    Model.Container c = new Model.Container();
                    c.Create(command);
                    RefreshData();
                }
            }
        }