/// <summary>
        /// Get store from container identifier
        /// </summary>
        /// <param name="containerIdentifier">Container identifier</param>
        /// <returns>CT store</returns>
        public async Task <CTStore> GetStore(ContainerIdentifier containerIdentifier)
        {
            // refuse to provide the store if the version check fails, or if it has not been executed
            if (this.initialized == false)
            {
                return(null);
            }

            ContainerDescriptor containerDescriptor = ContainerTableDescriptorProvider.Containers[containerIdentifier];
            string azureStorageConnectionString     = await this.connectionStringProvider.GetTablesAzureStorageConnectionString(containerDescriptor.AzureStorageInstanceType);

            string redisConnectionString = await this.connectionStringProvider.GetRedisConnectionString(containerDescriptor.RedisInstanceType);

            string uniqueStoreIdentity = string.Join(":", azureStorageConnectionString, redisConnectionString);

            // cachedStoreObjects is a thread-safe dictionary (ConcurrentDictionary). If uniqueStoreIdentity is not present
            // in cachedStoreObects, try adding it. Since GetStore can be called concurrently by
            // different threads, it is possible for two (or more) threads to attempt inserting uniqueStoreIdentity
            // concurrently in the cachedStoreObjects. That's ok, because the call to TryAdd is guaranteed to be thread-safe.
            // One of the threads will not be able to insert (i.e., TryAdd will return false), but the code will happily execute
            // and fall through to the return statement.
            // This code makes no use of locking on the common path (i.e., reads of cachedStoreObjects).
            if (!this.cachedStoreObjects.ContainsKey(uniqueStoreIdentity))
            {
                AzureTableStorage azureTableStorage = new AzureTableStorage(azureStorageConnectionString);
                azureTableStorage.TableRequestOptions = AzureStorageConfiguration.GetTableRequestOptions();
                RedisCache redisCache = new RedisCache(redisConnectionString);

                CTStore store = new CTStore(azureTableStorage, redisCache);
                this.cachedStoreObjects.TryAdd(uniqueStoreIdentity, store);
            }

            return(this.cachedStoreObjects[uniqueStoreIdentity]);
        }
Example #2
0
 public void Awake()
 {
     containerDescriptor = gameObject.GetComponent <ContainerDescriptor>();
     // Populate requirements for this item to be examined.
     requirements = new ReqPermitExamine(gameObject);
     requirements = new ReqMaxRange(requirements, 0f);
     requirements = new ReqObstacleCheck(requirements);
     requirements = new ReqItemCheck(requirements, "banana_peel");
 }
        /// <summary>
        /// Get table from container identifier and table identifier
        /// </summary>
        /// <param name="containerIdentifier">Container identifier</param>
        /// <param name="tableIdentifier">Table identifier</param>
        /// <returns>Store table</returns>
        public Table GetTable(ContainerIdentifier containerIdentifier, TableIdentifier tableIdentifier)
        {
            // refuse to provide the table if the version check fails, or if it has not been executed
            if (this.initialized == false)
            {
                return(null);
            }

            ContainerDescriptor containerDescriptor = ContainerTableDescriptorProvider.Containers[containerIdentifier];
            TableDescriptor     tableDescriptor     = containerDescriptor.Tables[tableIdentifier];

            if (tableDescriptor.TableType == TableType.Object)
            {
                return(Table.GetObjectTable(
                           containerDescriptor.ContainerName,
                           containerDescriptor.ContainerInitial,
                           tableDescriptor.TableName,
                           tableDescriptor.TableInitial,
                           tableDescriptor.StorageMode));
            }

            if (tableDescriptor.TableType == TableType.Count)
            {
                return(Table.GetCountTable(
                           containerDescriptor.ContainerName,
                           containerDescriptor.ContainerInitial,
                           tableDescriptor.TableName,
                           tableDescriptor.TableInitial,
                           tableDescriptor.StorageMode));
            }

            if (tableDescriptor.TableType == TableType.Feed)
            {
                return(Table.GetFeedTable(
                           containerDescriptor.ContainerName,
                           containerDescriptor.ContainerInitial,
                           tableDescriptor.TableName,
                           tableDescriptor.TableInitial,
                           tableDescriptor.StorageMode,
                           tableDescriptor.MaxFeedSizeInCache));
            }

            if (tableDescriptor.TableType == TableType.RankFeed)
            {
                return(Table.GetRankFeedTable(
                           containerDescriptor.ContainerName,
                           containerDescriptor.ContainerInitial,
                           tableDescriptor.TableName,
                           tableDescriptor.TableInitial,
                           tableDescriptor.StorageMode,
                           tableDescriptor.MaxFeedSizeInCache));
            }

            return(null);
        }
Example #4
0
    public void OnEnable()
    {
        TitleStyle                  = new GUIStyle();
        TitleStyle.fontSize         = 13;
        TitleStyle.fontStyle        = FontStyle.Bold;
        TitleStyle.normal.textColor = Color.white;

        containerDescriptor = (ContainerDescriptor)target;
        AddBase();

        attachedContainer    = containerDescriptor.attachedContainer;
        containerInteractive = containerDescriptor.containerInteractive;
        containerItemDisplay = containerDescriptor.containerItemDisplay;
    }
Example #5
0
        /// <summary>
        /// Lookup the table by name
        /// </summary>
        /// <param name="tableName">table name</param>
        /// <param name="desc">container descriptor</param>
        /// <returns>table descriptor object if it exists</returns>
        private static TableDescriptor LookupTable(string tableName, ContainerDescriptor desc)
        {
            if (desc == null)
            {
                return(null);
            }

            foreach (TableIdentifier tableId in desc.Tables.Keys)
            {
                if (desc.Tables[tableId].TableName == tableName)
                {
                    Console.WriteLine($"Found table {tableName}.");
                    return(desc.Tables[tableId]);
                }
            }

            Console.WriteLine($"Table {tableName} not found.");
            return(null);
        }
Example #6
0
 public TakeInteraction(ContainerDescriptor containerDescriptor)
 {
     this.containerDescriptor = containerDescriptor;
 }
Example #7
0
        private IList<ContainerDescriptor> ParseContainerDescriptors()
        {
            var documet = new HtmlDocument();
            documet.LoadHtml(File.ReadAllText("Data/container.html"));

            return documet.DocumentNode.SelectSingleNode("//table")
                .Descendants("tr")
                .Skip(1)//skipp header
                .Select(tr =>
                {
                    var columns = tr.Elements("td").Select(td => td.InnerText).ToArray();
                    var res = new ContainerDescriptor()
                    {
                        Name = columns[0].Trim(),
                        Weight = float.Parse(columns[1].Trim(), CultureInfo.InvariantCulture),
                    };
                    descriptorMaping.Add(GetKey(res.Name), res);
                    return res;
                })
                .ToArray();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Actions"/> class.
 /// </summary>
 /// <param name="cache">redis cache</param>
 /// <param name="container">valid container</param>
 /// <param name="table">valid table</param>
 public Actions(RedisCache cache, ContainerDescriptor container, TableDescriptor table)
 {
     this.redisCache = cache;
     this.container  = container;
     this.table      = table;
 }
 public ViewContainerInteraction(ContainerDescriptor containerDescriptor)
 {
     this.containerDescriptor = containerDescriptor;
 }