Example #1
0
        /// <summary>
        /// Gets the list of all resources of a certain type.
        ///
        /// We will provide "read commited" isolation here, buy locking the record during the read
        /// and then unlocking it as soon as we are done with the read.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="rType"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool Read(Transaction context, RID.Type rType, out List <Resource> data)
        {
            StorageContext storageContext = this.aGetStorageContext(context);

            if (null == storageContext)
            {
                throw new Exception();
            }

            data = new List <Resource>();
            foreach (var id in storageContext.ResourceIndex.GetIdList())
            {
                if (id.getType() != rType)
                {
                    continue;
                }

                // lock the resource
                this.LockResource(context, MyLM.LockMode.Read, id);

                Resource resource = null;
                if (!Read <RID, Resource>(
                        context, storageContext, storageContext.ResourceIndex, id, false, out resource))
                {
                    continue;
                }

                // unlock the resource
                this.UnLockResource(context, MyLM.LockMode.Read, id);

                data.Add(resource);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// List the resouces of a type
        /// </summary>
        /// <param name="context"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public String[] ListResources(Transaction context, RID.Type type)
        {
            WaitForReady();
            Enlist(context);

            List <string> result = new List <string>();

            foreach (Resource resource in _transactionStorage.GetResources(context))
            {
                if (type == resource.getType())
                {
                    result.Add(resource.ToString());
                }
            }
            return(result.ToArray());
        }
Example #3
0
        public string[] ListResources(Transaction context, RID.Type type)
        {
            // enlist with TM
            this.Enlist(context);

            List <Resource> resourceList = null;
            bool            result       = this.dataStore.Read(context, type, out resourceList);

            if (!result)
            {
                throw new InvalidOperationException("Could not retrieve resource list!");
            }

            // convert to string
            return(resourceList
                   .Select(c => c.ToString())
                   .ToArray());
        }