Esempio n. 1
0
        internal DataSet(Xid id, Variant variant)
        {
            Id = id;
            Variant = variant;
            Cache = Variant.Cache;

            // Check dataset is defined in database
            using (var query = new DatabaseQuery(DatabaseQueryString.Create("DataSetCheck")) { Type = CommandType.StoredProcedure }) {
                query.Bind("dataSetId", Id.ToGuid());
                query.BindOutput("exists", SqlDbType.Int);
                query.Execute();
            }
        }
Esempio n. 2
0
 public Xid SystemCreateDomain(Xid requestingNodeId)
 {
     // Ask server to create node
     Xid domainId;
     using (var query = new DatabaseQuery(DatabaseQueryString.Create("DomainCreate")) { Type = CommandType.StoredProcedure }) {
         query.Bind("dataSetId", Id.ToGuid());
         query.Bind("requestingNodeId", requestingNodeId.ToGuid());
         query.BindOutput("id", SqlDbType.UniqueIdentifier);
         query.Execute();
         domainId = new Xid((Guid)query.Parameters["id"].Value);
     }
     return domainId;
 }
Esempio n. 3
0
        public GenericNode SystemCreateNode(Xid domainId, Xid nodeTypeId, Xid requestingNodeId)
        {
            // Ask server to create node
            Xid nodeId;
            using (var query = new DatabaseQuery(DatabaseQueryString.Create("NodeCreate")) { Type = CommandType.StoredProcedure }) {
                query.Bind("domainId", domainId.ToGuid());
                query.Bind("typeId", nodeTypeId.ToGuid());
                query.Bind("requestingNodeId", requestingNodeId.ToGuid());
                query.BindOutput("id", SqlDbType.UniqueIdentifier);
                query.Execute();
                nodeId = new Xid((Guid)query.Parameters["id"].Value);
            }

            // Preseed cache - BONUS PERFORMANCE
            Variant.Cache.Set("node-" + Id.ToString(), new NRecordLoader(nodeId, domainId, nodeTypeId, Id), Variant.GetCacheStoragePolicy());

            // Return node
            return GetNode(nodeId, requestingNodeId, MaxAge.Any);
        }
Esempio n. 4
0
        public GenericAsset SystemCreateAsset(Stream inputStream, string fileName, string contentType, Xid domainId, Xid requestingNodeId, Xid? derivedFromId = null)
        {
            // Generate key
            var key = Token.Generate().ToString();

            // Ask server to create asset
            Xid assetId;
            using (var query = new DatabaseQuery(DatabaseQueryString.Create("AssetCreate")) { Type = CommandType.StoredProcedure }) {
                query.Bind("domainId", domainId.ToGuid());
                query.Bind("fileName", fileName);
                query.Bind("contentType", contentType);
                query.Bind("length", inputStream.Length);
                if (derivedFromId.HasValue) {
                    query.Bind("derivedFrom", derivedFromId.Value.ToGuid());
                } else {
                    query.Bind("derivedFrom", DBNull.Value);
                }
                query.Bind("key", key);
                query.Bind("requestingNodeId", requestingNodeId.ToGuid());
                query.BindOutput("id", SqlDbType.UniqueIdentifier);
                query.Execute();
                assetId = new Xid((Guid)query.Parameters["id"].Value);
            }

            // Create arecord
            var record = new ARecordLoader(assetId, domainId, fileName, contentType, inputStream.Length, derivedFromId, key);

            // Upload blob
            Variant.BlobContainer.Get(record.Key).Put(inputStream, fileName, contentType, -1);

            // Preseed cache - BONUS PERFORMANCE
            Variant.Cache.Set("asset-" + Id.ToString(), record, Variant.GetCacheStoragePolicy());

            return GetAsset(assetId, requestingNodeId, MaxAge.Any);
        }