예제 #1
0
        public PersistSchemaCatalog Clone()
        {
            var catalog = new PersistSchemaCatalog();

            lock (this)
            {
                foreach (var obj in Collection)
                {
                    catalog.Collection.Add(obj.Clone());
                }
            }

            return(catalog);
        }
예제 #2
0
        private void CreateSingle(UInt64 processId, string schema)
        {
            try
            {
                using (var txRef = core.Transactions.Begin(processId))
                {
                    Guid newSchemaId = Guid.NewGuid();

                    var schemaMeta = VirtualPathToMeta(txRef.Transaction, schema, LockOperation.Write);
                    if (schemaMeta.Exists)
                    {
                        txRef.Commit();
                        //The namespace already exists.
                        return;
                    }

                    var parentSchemaMeta = GetParentMeta(txRef.Transaction, schemaMeta, LockOperation.Write);
                    if (parentSchemaMeta.Exists == false)
                    {
                        throw new Exception("The parent namespace does not exists. use CreateLineage() instead of CreateSingle().");
                    }

                    string parentSchemaCatalogFile     = Path.Combine(parentSchemaMeta.DiskPath, Constants.SchemaCatalogFile);
                    PersistSchemaCatalog parentCatalog = null;

                    parentCatalog = core.IO.GetJson <PersistSchemaCatalog>(txRef.Transaction, parentSchemaCatalogFile, LockOperation.Write);

                    string filePath = string.Empty;

                    core.IO.CreateDirectory(txRef.Transaction, schemaMeta.DiskPath);

                    //Create default namespace catalog file.
                    filePath = Path.Combine(schemaMeta.DiskPath, Constants.SchemaCatalogFile);
                    if (core.IO.FileExists(txRef.Transaction, filePath, LockOperation.Write) == false)
                    {
                        core.IO.PutJson(txRef.Transaction, filePath, new PersistSchemaCatalog());
                    }

                    //Create default document catalog file.
                    filePath = Path.Combine(schemaMeta.DiskPath, Constants.DocumentCatalogFile);
                    if (core.IO.FileExists(txRef.Transaction, filePath, LockOperation.Write) == false)
                    {
                        core.IO.PutJson(txRef.Transaction, filePath, new PersistDocumentCatalog());
                    }

                    //Create default index catalog file.
                    filePath = Path.Combine(schemaMeta.DiskPath, Constants.IndexCatalogFile);
                    if (core.IO.FileExists(txRef.Transaction, filePath, LockOperation.Write) == false)
                    {
                        core.IO.PutJson(txRef.Transaction, filePath, new PersistIndexCatalog());
                    }

                    if (parentCatalog.ContainsName(schema) == false)
                    {
                        parentCatalog.Add(new PersistSchema
                        {
                            Id   = newSchemaId,
                            Name = schemaMeta.Name
                        });

                        core.IO.PutJson(txRef.Transaction, parentSchemaCatalogFile, parentCatalog);
                    }

                    txRef.Commit();
                }
            }
            catch (Exception ex)
            {
                core.Log.Write(String.Format("Failed to create single namespace for session {0}.", processId), ex);
                throw;
            }
        }