Ejemplo n.º 1
0
        //private static IEnumerable<INodeFactory> EnumFactories()
        //{
        //    foreach (var item in NodeFactoryAddonType.Instance.CommonSpace.GetAllAddons())
        //    {
        //        yield return (INodeFactory)item.InstanceModel;
        //    }
        //}

        //public static ITreeNode FromFile(ITreeNode parent, string file)
        //{
        //    foreach (INodeFactory fact in EnumFactories())
        //    {
        //        ITreeNode node = fact.FromFile(parent, file);
        //        if (node != null) return node;
        //    }
        //    return null;
        //}
        //public static ITreeNode FromVirtualFile(ITreeNode parent, IVirtualFile file)
        //{
        //    foreach (INodeFactory fact in EnumFactories())
        //    {
        //        ITreeNode node = fact.FromVirtualFile(parent, file);
        //        if (node != null) return node;
        //    }
        //    return null;
        //}

        public static ITreeNode FromFile(ITreeNode parent, IVirtualFile file)
        {
            var han = FileHandlerAddonType.FindFileHandler(file, h => h.Caps.CreateNode);

            if (han == null)
            {
                return(null);
            }
            return(han.CreateNode(parent));
        }
Ejemplo n.º 2
0
 public IDatabaseSource GetConnection()
 {
     if (Driver != null)
     {
         if (Connection == null)
         {
             throw new CommandLineError("DAE-00266 missing connection parameter");
         }
         var sc   = (IStoredConnection)StoredConnectionAddonType.Instance.FindHolder(Driver).CreateInstance();
         var conn = sc.CreatePhysicalConnection(Connection);
         if (Database != null)
         {
             var srv = new GenericServerSource(conn);
             var db  = new GenericDatabaseSource(srv, conn, Database);
             return(db);
         }
         else
         {
             var db = new GenericDatabaseSource(null, conn, null);
             return(db);
         }
     }
     if (DbFile != null)
     {
         string fn;
         if (DbFile.StartsWith("data:"))
         {
             fn = Path.Combine(Core.DataDirectory, DbFile.Substring(5));
         }
         else
         {
             fn = DbFile;
         }
         if (fn.ToLower().EndsWith(".con"))
         {
             var doc = new XmlDocument();
             doc.Load(fn);
             var sc   = (IStoredConnection)StoredConnectionAddonType.Instance.LoadAddon(doc.DocumentElement);
             var conn = sc.CreatePhysicalConnection();
             if (sc.DatabaseMode == ConnectionDatabaseMode.All)
             {
                 if (Database == null)
                 {
                     throw new CommandLineError("DAE-00267 database parameter missing");
                 }
                 var srv = new GenericServerSource(conn);
                 var db  = new GenericDatabaseSource(srv, conn, Database);
                 return(db);
             }
             else
             {
                 return(new GenericDatabaseSource(null, conn, null));
             }
         }
         foreach (var hld in FileHandlerAddonType.Instance.CommonSpace.GetAllAddons())
         {
             IFileHandler hnd = FileHandlerAddonType.FindFileHandler(new DiskFile(fn), han => han.Caps.OpenDatabase);
             if (hnd != null)
             {
                 return(hnd.OpenDatabase());
             }
         }
         throw new CommandLineError("DAE-00268 Not registered dbfile extension, file must have extension .con, or one of listed in command \"daci list dbfilehandler\"");
     }
     throw new CommandLineError("DAE-00269 You must provide one of driver or dbfile parameters");
 }