コード例 #1
0
ファイル: HelpCommand.cs プロジェクト: janproch/datadmin
            public override void RunCommand()
            {
                ICommandLineCommand cmd = CmdLine.FindCommand(Command);

                if (cmd == null)
                {
                    throw new CommandLineError("DAE-00154 Unknown command:" + Command);
                }
                ICommandLineCommandInstance inst      = cmd.CreateInstance();
                List <CmdLine.ParamHolder>  holders   = CmdLine.LoadHolders(new object[] { inst });
                Dictionary <int, string>    posparams = new Dictionary <int, string>();

                foreach (CmdLine.ParamHolder holder in holders)
                {
                    if (holder.Position != null)
                    {
                        posparams[holder.Position.Value] = holder.Name;
                    }
                }
                List <string> posparamslist = new List <string>();

                while (posparams.Count > 0)
                {
                    int min = PyList.Minimum(posparams.Keys);
                    posparamslist.Add(posparams[min]);
                    posparams.Remove(min);
                }
                Console.Out.WriteLine("Usage: daci " + Command + " " + String.Join(" ", posparamslist.ToArray()) + " [--param1 value1 --param2 value2...]");
                Console.Out.WriteLine(cmd.Description);
                foreach (CmdLine.ParamHolder holder in holders)
                {
                    Console.WriteLine("  " + holder.Name + " - " + holder.Description);
                }
            }
コード例 #2
0
 public static string UTF8ArrayToString(byte[] b)
 {
     if (b.Length >= 3 && b[0] == 239 && b[1] == 187 && b[2] == 191) // UTF-8 chars
     {
         b = PyList.SliceFrom(b, 3);
     }
     return(Encoding.UTF8.GetString(b));
 }
コード例 #3
0
        public virtual void RecreateTable(ITableStructure oldTable, ITableStructure newTable)
        {
            if (oldTable.GroupId != newTable.GroupId)
            {
                throw new InternalError("DAE-00040 Recreate is not possible: oldTable.GroupId != newTable.GroupId");
            }
            var    columnMap = GetColumnMap(oldTable, newTable);
            int    id        = System.Threading.Interlocked.Increment(ref m_lastAlterTableId);
            string tmptable  = ConnTools.GenerateTempTableName(id);

            // remove constraints
            //DropConstraints(oldTable.GetReferencedFrom(), DropFlags.None);
            DropConstraints(oldTable.Constraints, DropFlags.None);

            RenameTable(oldTable.FullName, tmptable);

            TableStructure old = new TableStructure(oldTable);

            old.FullName = new NameWithSchema(oldTable.FullName.Schema, tmptable);

            CreateTable(newTable);

            var  idcol    = newTable.FindAutoIncrementColumn();
            bool hasident = idcol != null && columnMap[idcol.ColumnOrder] >= 0;

            if (hasident)
            {
                AllowIdentityInsert(newTable.FullName, true);
            }
            PutCmd("^insert ^into %f (%,i) select %,s ^from %f", newTable.FullName,
                   from c in newTable.Columns
                   where columnMap[c.ColumnOrder] >= 0
                   select c.ColumnName,
                   from dstindex in
                   (
                       from i in PyList.Range(newTable.Columns.Count)
                       where columnMap[i] >= 0
                       select i
                   )
                   let srcindex = columnMap[dstindex]
                                  select
                                      (srcindex < 0
                                      // srcindex < 0 should not occur thanks to filtering
                    ? Format("^null ^as %i", newTable.Columns[dstindex].ColumnName)
                    : Format("^%i ^as %i", old.Columns[srcindex].ColumnName, newTable.Columns[dstindex].ColumnName)),
                   old.FullName);
            if (hasident)
            {
                AllowIdentityInsert(newTable.FullName, false);
            }

            // newTable.Constraints are allready created
            //CreateConstraints(newTable.GetReferencedFrom());

            PutCmd("^drop ^table %i", tmptable);
        }
コード例 #4
0
 public MenuItemInfo FindOrCreateItem(string[] path)
 {
     if (path.Length == 0)
     {
         return(this);
     }
     if (!Items.ContainsKey(path[0]))
     {
         var newitem = new MenuItemInfo();
         newitem.Name   = path[0];
         Items[path[0]] = newitem;
         ItemsNaturalOrder.Add(newitem);
     }
     return(Items[path[0]].FindOrCreateItem(PyList.SliceFrom(path, 1)));
 }
コード例 #5
0
        private TreeNode FindOrCreate(TreeNode parent, TreeNodeCollection parentNodes, string[] subpath, SettingsPageStruct page)
        {
            if (subpath.Length == 0)
            {
                return(parent);
            }
            //TreeNode[] childs = parentNodes.Find(Texts.Get(subpath[0]), false);
            TreeNode child = null;

            foreach (TreeNode n in parentNodes)
            {
                if (n.Text == Texts.Get(subpath[0]))
                {
                    child = n;
                    break;
                }
            }
            //if (childs.Length > 0) child = childs[0];
            if (child != null)
            {
                return(FindOrCreate(child, child.Nodes, PyList.SliceFrom(subpath, 1), page));
            }
            child = new TreeNode();
            if (page != null && page.Attribute.ImageName != null)
            {
                child.ImageIndex = m_imgCache.GetImageIndex(ImageTool.ImageFromName(page.Attribute.ImageName, CoreIcons.settings));
            }
            else
            {
                child.ImageIndex = m_imgCache.GetImageIndex(CoreIcons.settings);
            }
            child.SelectedImageIndex = child.ImageIndex;
            parentNodes.Add(child);
            child.Text = Texts.Get(subpath[0]);
            if (subpath.Length == 1)
            {
                child.Tag = page;
                if ((page.Attribute.Targets & Target) == 0)
                {
                    parentNodes.Remove(child);
                }
            }
            return(FindOrCreate(child, child.Nodes, PyList.SliceFrom(subpath, 1), page));
        }
コード例 #6
0
ファイル: CmdLine.cs プロジェクト: janproch/datadmin
        public static ICommandLineCommandInstance LoadCommand(string[] args)
        {
            if (args.Length < 1)
            {
                throw new CommandLineError("DAE-00260 Missing command parameter");
            }
            ICommandLineCommand cmd = FindCommand(args[0]);

            if (cmd != null)
            {
                ICommandLineCommandInstance res       = cmd.CreateInstance();
                Dictionary <string, string> extparams = null;
                if (cmd.AllowExtParams)
                {
                    extparams = new Dictionary <string, string>();
                }
                LoadParameters(PyList.SliceFrom(args, 1), new object[] { res }, extparams);
                res.ExtParams = extparams;
                return(res);
            }
            throw new CommandLineError("DAE-00261 Command not defined:" + args[0]);
        }
コード例 #7
0
ファイル: ZipFileSystem.cs プロジェクト: janproch/datadmin
        private ZFolder FindZFolder(string[] items, ZFolder root, int start, int count)
        {
            if (count <= 0)
            {
                return(root);
            }
            foreach (var child in root.Folders)
            {
                if (child.Name == items[start])
                {
                    return(FindZFolder(items, child, start + 1, count - 1));
                }
            }
            string pth  = PyList.Slice(items, 0, start + 1).CreateDelimitedText("/");
            var    newf = new ZFolder {
                Path = pth
            };

            root.Folders.Add(newf);
            m_dirIndex[pth] = newf;
            return(FindZFolder(items, newf, start + 1, count - 1));
        }
コード例 #8
0
ファイル: InMemoryTable.cs プロジェクト: janproch/datadmin
 public InMemoryTableOperation(ITableStructure table)
 {
     m_table      = new TableStructure(table);
     m_colIndexes = new List <int>(PyList.Range(m_table.Columns.Count));
 }