Example #1
0
        public List <PersistSchema> GetList(UInt64 processId, string schema)
        {
            try
            {
                using (var txRef = core.Transactions.Begin(processId))
                {
                    PersistSchema schemaMeta = VirtualPathToMeta(txRef.Transaction, schema, LockOperation.Read);
                    if (schemaMeta == null || schemaMeta.Exists == false)
                    {
                        throw new DokdexSchemaDoesNotExistException(schema);
                    }

                    var list = new List <PersistSchema>();

                    var filePath         = Path.Combine(schemaMeta.DiskPath, Constants.SchemaCatalogFile);
                    var namespaceCatalog = core.IO.GetJson <PersistSchemaCatalog>(txRef.Transaction, filePath, LockOperation.Read);

                    foreach (var item in namespaceCatalog.Collection)
                    {
                        list.Add(item);
                    }

                    txRef.Commit();

                    return(list);
                }
            }
            catch (Exception ex)
            {
                core.Log.Write(String.Format("Failed to get namespace list for session {0}.", processId), ex);
                throw;
            }
        }
Example #2
0
        public List <PersistSchema> GetChildrenMeta(Transaction transaction, PersistSchema node, LockOperation intendedOperation)
        {
            List <PersistSchema> metaList = new List <PersistSchema>();

            string namespaceCatalogDiskPath = Path.Combine(node.DiskPath, Constants.SchemaCatalogFile);

            if (core.IO.FileExists(transaction, namespaceCatalogDiskPath, intendedOperation))
            {
                var namespaceCatalog = core.IO.GetJson <PersistSchemaCatalog>(transaction, namespaceCatalogDiskPath, intendedOperation);

                foreach (var catalogItem in namespaceCatalog.Collection)
                {
                    metaList.Add(new PersistSchema()
                    {
                        DiskPath    = node.DiskPath + "\\" + catalogItem.Name,
                        Exists      = true,
                        Id          = catalogItem.Id,
                        Name        = catalogItem.Name,
                        VirtualPath = node.VirtualPath + ":" + catalogItem.Name
                    });
                }
            }

            return(metaList);
        }
Example #3
0
        public PersistSchema VirtualPathToMeta(Transaction transaction, string schemaPath, LockOperation intendedOperation)
        {
            try
            {
                schemaPath = schemaPath.Trim(new char[] { ':' }).Trim();

                if (schemaPath == string.Empty)
                {
                    return(RootSchemaMeta);
                }
                else
                {
                    var    segments   = schemaPath.Split(':');
                    string schemaName = segments[segments.Count() - 1];

                    string namespaceDiskPath    = Path.Combine(core.settings.DataRootPath, String.Join("\\", segments));
                    string parentSchemaDiskPath = Directory.GetParent(namespaceDiskPath).FullName;

                    string parentCatalogDiskPath = Path.Combine(parentSchemaDiskPath, Constants.SchemaCatalogFile);

                    if (core.IO.FileExists(transaction, parentCatalogDiskPath, intendedOperation) == false)
                    {
                        throw new DokdexInvalidSchemaException(string.Format("The schema [{0}] does not exist.", schemaPath));
                    }

                    var parentCatalog = core.IO.GetJson <PersistSchemaCatalog>(transaction,
                                                                               Path.Combine(parentSchemaDiskPath, Constants.SchemaCatalogFile), intendedOperation);

                    var namespaceMeta = parentCatalog.GetByName(schemaName);
                    if (namespaceMeta != null)
                    {
                        namespaceMeta.Name        = schemaName;
                        namespaceMeta.DiskPath    = namespaceDiskPath;
                        namespaceMeta.VirtualPath = schemaPath;
                        namespaceMeta.Exists      = true;
                    }
                    else
                    {
                        namespaceMeta = new PersistSchema()
                        {
                            Name        = schemaName,
                            DiskPath    = core.settings.DataRootPath + "\\" + schemaPath.Replace(':', '\\'),
                            VirtualPath = schemaPath,
                            Exists      = false
                        };
                    }

                    transaction.LockDirectory(intendedOperation, namespaceMeta.DiskPath);

                    return(namespaceMeta);
                }
            }
            catch (Exception ex)
            {
                core.Log.Write("Failed to translate virtual path to namespace meta.", ex);
                throw;
            }
        }
Example #4
0
 public PersistSchema GetParentMeta(Transaction transaction, PersistSchema child, LockOperation intendedOperation)
 {
     try
     {
         if (child == RootSchemaMeta)
         {
             return(null);
         }
         var segments = child.VirtualPath.Split(':').ToList();
         segments.RemoveAt(segments.Count - 1);
         string parentNs = string.Join(":", segments);
         return(VirtualPathToMeta(transaction, parentNs, intendedOperation));
     }
     catch (Exception ex)
     {
         core.Log.Write("Failed to get parent namespace meta.", ex);
         throw;
     }
 }
Example #5
0
 public void Add(PersistSchema namespaceMeta)
 {
     this.Collection.Add(namespaceMeta);
 }