void Start() {
		if (PlayerPrefs.HasKey("checkForContent") && PlayerPrefs.GetInt("checkForContent") == 0) {
			finishedDownload = true;
		}
		_client = Client;
		S3BucketName = "captain-cillian-bucket";
	}
        public static DataContext GetDataContext(IAmazonDynamoDB dynamoDbClient, string tablePrefix)
        {
            var dataContext = new DataContext(dynamoDbClient, tablePrefix);
            dataContext.OnLog += DataContextLogger.Debug;

            return dataContext;
        }
 public DynamoDbTodoExample()
 {
     awsDb = CreateDynamoDbClient();
     db = new PocoDynamo(awsDb);
     db.RegisterTable<Todo>();
     db.InitSchema();
 }
        public override void SetUp()
        {
            TablePrefix = typeof(TableManagementTests).Name + Guid.NewGuid();

            DynamoDbClient = TestConfiguration.GetDynamoDbClient();
            Context = TestConfiguration.GetDataContext(DynamoDbClient, TablePrefix);
        }
Example #5
0
 private DynamoDBConnection(RegionEndpoint endpoint = null)
 {
     if (endpoint == null) {
         endpoint = RegionEndpoint.USEast1;
     }
     client = new AmazonDynamoDBClient(endpoint);
 }
Example #6
0
        public static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("Setting up DynamoDB client");
            client = new AmazonDynamoDBClient(RegionEndpoint.USWest2);

            Console.WriteLine();
            Console.WriteLine("Creating sample tables");
            CreateSampleTables();

            Console.WriteLine();
            Console.WriteLine("Running DataModel sample");
            RunDataModelSample();

            Console.WriteLine();
            Console.WriteLine("Running DataModel sample");
            RunDocumentModelSample();

            Console.WriteLine();
            Console.WriteLine("Removing sample tables");
            DeleteSampleTables();

            Console.WriteLine();
            Console.WriteLine("Press Enter to continue...");
            Console.Read();
        }
Example #7
0
 public static void WaitUntilTableCreated(string tableName, IAmazonDynamoDB client)
 {
     Common.WaitUntil(() =>
     {
         string status = GetTableStatus(tableName, client);
         return !status.Equals("CREATING") && !status.Equals(string.Empty);
     });
 }
Example #8
0
 internal static void LoadTableAsync(IAmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer, DynamoDBEntryConversion conversion, AmazonDynamoDBCallback<Table> callback, AsyncOptions asyncOptions = null)
 {
     asyncOptions = asyncOptions??new AsyncOptions();
     DynamoDBAsyncExecutor.ExecuteAsync<Table>(
     ()=>{
         return LoadTable(ddbClient,tableName,consumer,conversion);
     },asyncOptions,callback);
 }
 void Awake()
 {
     back.onClick.AddListener(BackListener);
     createOperation.onClick.AddListener(PerformCreateOperation);
     updateOperation.onClick.AddListener(PerformUpdateOperation);
     deleteOperation.onClick.AddListener(PerformDeleteOperation);
     _client = Client;
 }
        PollWriterManager()
        {
            this._snsClient = new AmazonSimpleNotificationServiceClient();

            this._dynamoDBClient = new AmazonDynamoDBClient();
            this._dbContext = new DynamoDBContext(this._dynamoDBClient, new DynamoDBContextConfig { Conversion = DynamoDBEntryConversion.V2 });

            this._swfClient = new AmazonSimpleWorkflowClient();
        }
 void Start()
 {
     back.onClick.AddListener(BackListener);
     loadTable.onClick.AddListener(LoadTableListener);
     findRepliesInLast15DaysWithConfig.onClick.AddListener(FindRepliesInLast15DaysWithConfigListener);
     findRepliesWithLimit.onClick.AddListener(FindRepliesForAThreadSpecifyOptionsLimitListener);
     findProductsWithPriceLessThanZero.onClick.AddListener(FindProductsForPriceLessThanZeroListener);
     _client = Client;
 }
        public DynamoDbSourceAdapter(IAmazonDynamoDB client, IDynamoDbSourceAdapterInstanceConfiguration configuration)
        {
            Guard.NotNull("client", client);
            Guard.NotNull("configuration", configuration);

            dataProvider = IsQueryRequest(configuration.Request)
                ? (IDataPageProvider)new QueryDataPageProvider(client,
                    RequestReader.Instance.Read<QueryRequest>(configuration.Request))
                : new ScanDataPageProvider(client,
                    RequestReader.Instance.Read<ScanRequest>(configuration.Request));
        }
Example #13
0
        private static string WaitUntilTableStable(string tableName, IAmazonDynamoDB client, string tableStatus)
        {
            Common.WaitUntil(() =>
            {
                tableStatus = GetTableStatus(tableName, client);
                if (tableStatus == null)
                    return true;

                return
                    !tableStatus.Equals("DELETING", StringComparison.OrdinalIgnoreCase) &&
                    !tableStatus.Equals("CREATING", StringComparison.OrdinalIgnoreCase);
            });
            return tableStatus;
        }
        static ReviewsDataContext()
        {
            string accessKey, secretKey;
            GetAwsCredentials(out accessKey, out secretKey);

            // creating a MemcacheD client (it's thread-safe and can be reused)

            // creating a DynamoDb client in some region (AmazonDynamoDBClient is thread-safe and can be reused)
            DynamoDbClient = new AmazonDynamoDBClient
                (
                accessKey,
                secretKey,
                new AmazonDynamoDBConfig {RegionEndpoint = RegionEndpoint.APSoutheast1, MaxErrorRetry = 6}
                );

            // creating tables
            CreateTablesIfTheyDoNotExist();
        }
Example #15
0
        public static void ConfirmTableExistence(string tableName, IAmazonDynamoDB client, List<KeySchemaElement> tableSchema, List<AttributeDefinition> attributeDefinitions, int reads, int writes)
        {
            Console.WriteLine("Confirming table " + tableName + " existence");
            string tableStatus = null;
            tableStatus = WaitUntilTableStable(tableName, client, tableStatus);

            if (string.IsNullOrEmpty(tableStatus))
            {
                Console.WriteLine("Creating table " + tableName);
                var tableDescription = client.CreateTable(new CreateTableRequest
                {
                    TableName = tableName,
                    ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = reads, WriteCapacityUnits = writes },
                    KeySchema = tableSchema,
                    AttributeDefinitions = attributeDefinitions
                }).TableDescription;
                WaitUntilTableCreated(tableName, client);
            }
            else
            {
                Console.WriteLine("Not creating table " + tableName + ", status is " + tableStatus);
            }
        }
Example #16
0
        public static void DeleteTables(IAmazonDynamoDB client, Predicate<string> tableNameMatch)
        {
            try
            {
                var tableNames = client.ListTables().TableNames;
                foreach (var tableName in tableNames)
                {
                    DescribeTableResponse descResponse = client.DescribeTable(new DescribeTableRequest { TableName = tableName });
                    if (descResponse.Table == null)
                        continue;

                    TableDescription table = descResponse.Table;

                    if (table.TableStatus == TableStatus.ACTIVE && tableNameMatch(table.TableName))
                    {
                        Console.WriteLine("Table: {0}, {1}, {2}, {3}", table.TableName, table.TableStatus, table.ProvisionedThroughput.ReadCapacityUnits, table.ProvisionedThroughput.WriteCapacityUnits);
                        Console.WriteLine("Deleting table " + table.TableName + "...");
                        try
                        {
                            client.DeleteTable(new DeleteTableRequest { TableName = table.TableName });
                            WaitUntilTableDeleted(table.TableName, client);
                            Console.WriteLine("Succeeded!");
                        }
                        catch
                        {
                            Console.WriteLine("Failed!");
                        }
                    }
                }
                Console.WriteLine(tableNames.Count);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
        }
Example #17
0
 /// <summary>
 /// Creates a Table object with the specified name, using the
 /// passed-in client to load the table definition.
 ///
 /// This method return an exception if the table does not exist within the callback.
 /// </summary>
 /// <param name="ddbClient">Client to use to access DynamoDB.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
 /// <param name="callback">The callback that will be invoked when the asynchronous operation completes.</param>
 /// <param name="asyncOptions">An instance of AsyncOptions that specifies how the async method should be executed.</param>
 public static void LoadTableAsync(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion, AmazonDynamoDBCallback <Table> callback, AsyncOptions asyncOptions = null)
 {
     LoadTableAsync(ddbClient, tableName, DynamoDBConsumer.DocumentModel, conversion, callback, asyncOptions);
 }
Example #18
0
        private Table(IAmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer, DynamoDBEntryConversion conversion)
        {
#if (WIN_RT || WINDOWS_PHONE || AWSSDK_UNITY)
            DDBClient = ddbClient as AmazonDynamoDBClient;
#else
            DDBClient = ddbClient;
#endif
            TableInfoCache = SdkCache.GetCache<string, TableDescription>(ddbClient, TableInfoCacheIdentifier, StringComparer.Ordinal);
            LoggerInstance = Logger.GetLogger(typeof(SdkCache));

            TableConsumer = consumer;
            TableName = tableName;
            Conversion = conversion;
            ClearTableData();
        }
Example #19
0
 public LocalizationResponder(IGitHubClient gitHubClient, IAmazonDynamoDB dynamoDb, IHttpClientFactory httpClientFactory)
 {
     _gitHubClient      = gitHubClient;
     _dynamoDb          = dynamoDb;
     _httpClientFactory = httpClientFactory;
 }
Example #20
0
 public DynamoDbDataUploader(ILogger <DynamoDbDataUploader> logger, IAmazonDynamoDB dynamoDb, IOptions <AppSettings> appSettings)
 {
     _logger      = logger ?? throw new ArgumentNullException(nameof(logger));
     _dynamoDb    = dynamoDb ?? throw new ArgumentNullException(nameof(dynamoDb));
     _appSettings = appSettings?.Value ?? throw new ArgumentNullException(nameof(appSettings));
 }
 VoterProcessor()
 {
     this._dynamoDBClient = new AmazonDynamoDBClient();
 }
Example #22
0
 public DynamoDbTableService(IAmazonDynamoDB dynamoDbClient)
 {
     DynamoDbClient = dynamoDbClient;
 }
 public LocalizationResponder(IGitHubClient gitHubClient, IAmazonDynamoDB dynamoDb, HttpClient httpClient)
 {
     this.gitHubClient = gitHubClient;
     this.httpClient   = httpClient;
     this.dynamoDb     = dynamoDb;
 }
Example #24
0
 public DynamoDbService(IAmazonDynamoDB amazonDynamoDbClient, ILogger <DynamoDbService> logger)
 {
     AmazonDynamoDbClient = amazonDynamoDbClient;
     _logger = logger;
 }
        private async Task EnsureInitializedImplAsync(IAmazonDynamoDB client, string rolesTableName)
        {
            var defaultProvisionThroughput = new ProvisionedThroughput
            {
                ReadCapacityUnits  = 5,
                WriteCapacityUnits = 5
            };
            var globalSecondaryIndexes = new List <GlobalSecondaryIndex>
            {
                new GlobalSecondaryIndex
                {
                    IndexName = "NormalizedName-DeletedOn-index",
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement("NormalizedName", KeyType.HASH),
                        new KeySchemaElement("DeletedOn", KeyType.RANGE)
                    },
                    ProvisionedThroughput = defaultProvisionThroughput,
                    Projection            = new Projection
                    {
                        ProjectionType = ProjectionType.ALL
                    }
                }
            };

            var tablesResponse = await client.ListTablesAsync();

            if (tablesResponse.HttpStatusCode != HttpStatusCode.OK)
            {
                throw new Exception("Couldn't get list of tables");
            }
            var tableNames = tablesResponse.TableNames;

            if (!tableNames.Contains(rolesTableName))
            {
                await CreateTableAsync(client, rolesTableName, defaultProvisionThroughput, globalSecondaryIndexes);

                return;
            }

            var response = await client.DescribeTableAsync(new DescribeTableRequest { TableName = rolesTableName });

            var table = response.Table;

            var indexesToAdd =
                globalSecondaryIndexes.Where(
                    g => !table.GlobalSecondaryIndexes.Exists(gd => gd.IndexName.Equals(g.IndexName)));
            var indexUpdates = indexesToAdd.Select(index => new GlobalSecondaryIndexUpdate
            {
                Create = new CreateGlobalSecondaryIndexAction
                {
                    IndexName             = index.IndexName,
                    KeySchema             = index.KeySchema,
                    ProvisionedThroughput = index.ProvisionedThroughput,
                    Projection            = index.Projection
                }
            }).ToList();

            if (indexUpdates.Count > 0)
            {
                await UpdateTableAsync(client, rolesTableName, indexUpdates);
            }
        }
 public DynamoDbService(IAmazonDynamoDB client, IDynamoDBContext context)
 {
     _client  = client;
     _context = context;
 }
 public GroceryListRepository(IAmazonDynamoDB dynamoDBClient)
 {
     _context = new DynamoDBContext(dynamoDBClient);
 }
Example #28
0
 public SiteGeneratorFunction(IAmazonDynamoDB dynamoDb, IAmazonS3 s3Site, IAmazonS3 s3Images)
 {
     _dynamoDb = dynamoDb;
     _s3Site   = s3Site;
     _s3Images = s3Images;
 }
Example #29
0
 public LowLevelOperations(IAmazonDynamoDB dynamoDBClient)
 {
     _dynamoDBClient = dynamoDBClient;
 }
 public DynamoDBContextBuilder(IAmazonDynamoDB dynamo)
 {
     _dynamoClient = dynamo;
 }
        /// <summary>
        /// Queries the data using the queryRequest and returns a complete list of data matching the query.
        /// </summary>
        /// <remarks>
        /// NOTE: the ExclusiveStartKey and Limit values of the queryRequest will be overridden by this method.
        ///
        /// CAUTION: this method will return all values without concern for memory
        /// </remarks>
        /// <param name="dynamoDB">The DynamoDB client.</param>
        /// <param name="queryRequest">The query request.</param>
        /// <returns>A complete list of matching records.</returns>
        public static async Task <List <Dictionary <string, AttributeValue> > > QueryAllAsync(this IAmazonDynamoDB dynamoDB, QueryRequest queryRequest)
        {
            var items = new List <Dictionary <string, AttributeValue> >();

            Dictionary <string, AttributeValue> exclusiveStartKey = null;

            do
            {
                var batch = await queryBatchAsync();

                items.AddRange(batch);
            } while (exclusiveStartKey != null && exclusiveStartKey.Count != 0);

            return(items);

            async Task <List <Dictionary <string, AttributeValue> > > queryBatchAsync()
            {
                queryRequest.ExclusiveStartKey = exclusiveStartKey;
                queryRequest.Limit             = int.MaxValue;

                var result = await dynamoDB.QueryAsync(queryRequest);

                exclusiveStartKey = result.LastEvaluatedKey;
                return(result.Items);
            }
        }
Example #32
0
 public RepositoryBenchmark(IAmazonDynamoDB amazonDynamo)
 {
     repository = new Repository(amazonDynamo);
 }
Example #33
0
 private Amazon.DynamoDBv2.Model.ExecuteStatementResponse CallAWSServiceOperation(IAmazonDynamoDB client, Amazon.DynamoDBv2.Model.ExecuteStatementRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon DynamoDB", "ExecuteStatement");
     try
     {
         #if DESKTOP
         return(client.ExecuteStatement(request));
         #elif CORECLR
         return(client.ExecuteStatementAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
 public PutItem(IAmazonDynamoDB amazonDynamoDB)
 {
     this.amazonDynamoDB = amazonDynamoDB;
 }
Example #35
0
 public DeleteItem(IAmazonDynamoDB dynamoClient)
 {
     _dynamoClient = dynamoClient;
 }
Example #36
0
 public OrdersController(IAmazonDynamoDB dynamoDb, ILogger <OrdersController> logger)
 {
     _ddbClient = dynamoDb;
     _logger    = logger;
 }
        public static async Task <BatchWriteItemResponse> AddItemsAsync(bool debug, IAmazonDynamoDB client, string table, string[] inputs, int index)
        {
            var writeRequests = new List <WriteRequest>();

            string[] headers    = inputs[0].Split(",");
            int      numcolumns = headers.Length;

            string line;

            // Read the rest of the file, line by line
            for (int input = 1; input < inputs.Length; input++)
            {
                line = inputs[input];

                // Split line into columns
                string[] values = line.Split(',');

                // If we don't have the right number of parts, something's wrong
                if (values.Length != numcolumns)
                {
                    Console.WriteLine("Did not have " + numcolumns.ToString() + " columns in: ");
                    Console.WriteLine(line);
                    return(null);
                }

                var item = new Dictionary <string, AttributeValue>
                {
                    { "ID", new AttributeValue {
                          S = index.ToString()
                      } }
                };

                DebugPrint(debug, "Set ID string attribute to " + index.ToString());

                for (int i = 0; i < numcolumns; i++)
                {
                    if ((headers[i] == "Customer_ID") || (headers[i] == "Order_ID") || (headers[i] == "Order_Customer") || (headers[i] == "Order_Product") || (headers[i] == "Product_ID") || (headers[i] == "Product_Quantity") || (headers[i] == "Product_Cost"))
                    {
                        item.Add(headers[i], new AttributeValue {
                            N = values[i]
                        });
                        DebugPrint(debug, "Set " + headers[i] + " int attribute to " + values[i]);
                    }
                    else if (headers[i] == "Order_Date")
                    {
                        // The datetime format is:
                        // YYYY-MM-DD HH:MM:SS
                        DateTime MyDateTime = DateTime.ParseExact(values[i], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

                        TimeSpan timeSpan = MyDateTime - new DateTime(1970, 1, 1, 0, 0, 0);

                        item.Add(headers[i], new AttributeValue {
                            N = ((long)timeSpan.TotalSeconds).ToString()
                        });
                        DebugPrint(debug, "Set " + headers[i] + " int (long) attribute to " + ((long)timeSpan.TotalSeconds).ToString());
                    }
                    else
                    {
                        item.Add(headers[i], new AttributeValue {
                            S = values[i]
                        });
                        DebugPrint(debug, "Set " + headers[i] + " string attribute to " + values[i]);
                    }
                }

                DebugPrint(debug, "");

                index++;

                WriteRequest putRequest = new WriteRequest(new PutRequest(item));

                writeRequests.Add(putRequest);
            }

            var requestItems = new Dictionary <string, List <WriteRequest> >
            {
                { table, writeRequests }
            };

            var request = new BatchWriteItemRequest
            {
                ReturnConsumedCapacity = "TOTAL",
                RequestItems           = requestItems
            };

            var response = await client.BatchWriteItemAsync(request);

            return(response);
        }
 public PutItem()
 {
     amazonDynamoDB = new AmazonDynamoDBClient(RegionEndpoint.USWest2);
 }
Example #39
0
 public DynamoDbRepository(IAmazonDynamoDB client)
 {
     Context = new DynamoDBContext(client);
 }
Example #40
0
 private async Task DeleteTable(IAmazonDynamoDB dynamoDBClient, string tableName)
 {
     await dynamoDBClient.DeleteTableAsync(tableName);
 }
Example #41
0
 /// <summary>
 /// Creates a Table object with the specified name, using the
 /// passed-in client to load the table definition.
 /// The returned table will use the conversion specified by
 /// AWSConfigs.DynamoDBConfig.ConversionSchema
 /// 
 /// This method will throw an exception if the table does not exist.
 /// </summary>
 /// <param name="ddbClient">Client to use to access DynamoDB.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <returns>Table object representing the specified table.</returns>
 public static Table LoadTable(IAmazonDynamoDB ddbClient, string tableName)
 {
     return LoadTable(ddbClient, tableName, DynamoDBEntryConversion.CurrentConversion);
 }
Example #42
0
 public TableDescriptionSource(IAmazonDynamoDB dynamoDb)
 {
     _dynamoDb = dynamoDb;
 }
Example #43
0
        private async Task<string> SetupTable(IAmazonDynamoDB dynamoDBClient)
        {
            string tableName = "aws-sdk-dotnet-truncate-test-" + DateTime.Now.Ticks;

            await dynamoDBClient.CreateTableAsync(
                tableName,
                new List<KeySchemaElement>
                {
                    new KeySchemaElement { KeyType = KeyType.HASH, AttributeName = "Id" }
                },
                new List<AttributeDefinition>
                {
                    new AttributeDefinition { AttributeName = "Id", AttributeType = ScalarAttributeType.S }
                },
                new ProvisionedThroughput { ReadCapacityUnits = 10, WriteCapacityUnits = 10 });

            DescribeTableResponse response = null;
            do
            {
                System.Threading.Thread.Sleep(300);
                response = await dynamoDBClient.DescribeTableAsync(tableName);
            } while (response.Table.TableStatus != TableStatus.ACTIVE);

            return tableName;
        }
 public ProjectController(IAmazonDynamoDB dynamoDbClient)
 {
     _dynamoDbClient = dynamoDbClient;
 }
        /// <summary>
        /// Initializes the provider by pulling the config info from the web.config and validate/create the DynamoDB table.
        /// If the table is being created this method will block until the table is active.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="config"></param>
        public override void Initialize(string name, NameValueCollection config)
        {
            if (config == null)
                throw new ArgumentNullException("config");

            base.Initialize(name, config);

            GetConfigSettings(config);


            var region = RegionEndpoint.GetBySystemName(this._regionName);
            if (!string.IsNullOrEmpty(this._accessKey))
            {
                this._ddbClient = new AmazonDynamoDBClient(this._accessKey, this._secretKey, region);
            }
            else
            {
                this._ddbClient = new AmazonDynamoDBClient(region);
            }

            SetupTable();
        }
 public DynamoDbTimelineEventAttachmentRepository(IAmazonDynamoDB client, string tenantId) : base(tenantId, client)
 {
     ;
 }
Example #47
0
 /// <summary>
 /// Creates a Table object with the specified name, using the
 /// passed-in client to load the table definition.
 /// The returned table will use the conversion specified by
 /// AWSConfigs.DynamoDBConfig.ConversionSchema
 ///
 /// This method will throw an exception if the table does not exist.
 /// </summary>
 /// <param name="ddbClient">Client to use to access DynamoDB.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <returns>Table object representing the specified table.</returns>
 public static Table LoadTable(IAmazonDynamoDB ddbClient, string tableName)
 {
     return(LoadTable(ddbClient, tableName, DynamoDBEntryConversion.CurrentConversion));
 }
Example #48
0
 public DynamoDbFeatureSourceData(IConfiguration configuration, IAmazonDynamoDB dynamoDbConnection)
 {
     _dynamoDbConnection = dynamoDbConnection;
 }
Example #49
0
 public UserRepository(IAmazonDynamoDB amazonDynamoDb)
 {
     this.amazonDynamoDb = amazonDynamoDb;
 }
Example #50
0
        /// <summary>
        /// Creates a Table object with the specified name, using the
        /// passed-in client to load the table definition.
        ///
        /// This method will return false if the table does not exist.
        /// </summary>
        /// <param name="ddbClient">Client to use to access DynamoDB.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
        /// <param name="table">Loaded table.</param>
        /// <returns>
        /// True if table was successfully loaded; otherwise false.
        /// </returns>
        public static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion, out Table table)
        {
            var config = new TableConfig(tableName, conversion, DynamoDBConsumer.DocumentModel, storeAsEpoch: null);

            return(TryLoadTable(ddbClient, config, out table));
        }
Example #51
0
 /// <summary>
 /// Creates a Table object with the specified name, using the
 /// passed-in client to load the table definition.
 ///
 /// This method will throw an exception if the table does not exist.
 /// </summary>
 /// <param name="ddbClient">Client to use to access DynamoDB.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
 /// <returns>Table object representing the specified table.</returns>
 public static Table LoadTable(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion)
 {
     return(LoadTable(ddbClient, tableName, DynamoDBConsumer.DocumentModel, conversion));
 }
        /// <summary>
        /// Initializes the provider by pulling the config info from the web.config and validate/create the DynamoDB table.
        /// If the table is being created this method will block until the table is active.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="config"></param>
        public override void Initialize(string name, NameValueCollection config)
        {
            _logger.InfoFormat("Initialize : Initializing Session provider {0}", name);

            if (config == null)
                throw new ArgumentNullException("config");

            base.Initialize(name, config);

            GetConfigSettings(config);

            RegionEndpoint region = null;
            if(!string.IsNullOrEmpty(this._regionName))
                region = RegionEndpoint.GetBySystemName(this._regionName);

            AWSCredentials credentials = null;
            if (!string.IsNullOrEmpty(this._accessKey))
            {
                credentials = new BasicAWSCredentials(this._accessKey, this._secretKey);
            }
            else if (!string.IsNullOrEmpty(this._profileName))
            {
                if (string.IsNullOrEmpty(this._profilesLocation))
                    credentials = new StoredProfileAWSCredentials(this._profileName);
                else
                    credentials = new StoredProfileAWSCredentials(this._profileName, this._profilesLocation);
            }

            AmazonDynamoDBConfig ddbConfig = new AmazonDynamoDBConfig();

            if (region != null)
                ddbConfig.RegionEndpoint = region;
            if (!string.IsNullOrEmpty(this._serviceURL))
                ddbConfig.ServiceURL = this._serviceURL;

            if (credentials != null)
            {
                this._ddbClient = new AmazonDynamoDBClient(credentials, ddbConfig);
            }
            else
            {
                this._ddbClient = new AmazonDynamoDBClient(ddbConfig);
            }

            ((AmazonDynamoDBClient)this._ddbClient).BeforeRequestEvent += DynamoDBSessionStateStore_BeforeRequestEvent;

            SetupTable();
        }
Example #53
0
 /// <summary>
 /// Creates a Table object with the specified name, using the
 /// passed-in client to load the table definition.
 /// The returned table will use the conversion specified by
 /// AWSConfigs.DynamoDBConfig.ConversionSchema
 ///
 /// This method will return false if the table does not exist.
 /// </summary>
 /// <param name="ddbClient">Client to use to access DynamoDB.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="table">Loaded table.</param>
 /// <returns>
 /// True if table was successfully loaded; otherwise false.
 /// </returns>
 public static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, out Table table)
 {
     return(TryLoadTable(ddbClient, tableName, DynamoDBEntryConversion.CurrentConversion, out table));
 }
 /// <summary>
 /// A utility method for cleaning up expired sessions that IIS failed to delete. The method performs a scan on the ASP.NET_SessionState table
 /// with a condition that the expiration date is in the past and calls delete on all the keys returned. Scans can be costly on performance
 /// so use this method sparingly like a nightly or weekly clean job.
 /// </summary>
 /// <param name="dbClient">The AmazonDynamoDB client used to find a delete expired sessions.</param>
 public static void DeleteExpiredSessions(IAmazonDynamoDB dbClient)
 {
     LogInfo("DeleteExpiredSessions");
     DeleteExpiredSessions(dbClient, DEFAULT_TABLENAME);
 }
 /// <summary>
 /// Constructor for testing.
 /// </summary>
 /// <param name="ddbClient"></param>
 public DynamoDBSessionStateStore(IAmazonDynamoDB ddbClient)
 {
     this._ddbClient = ddbClient;
     SetupTable();
 }
Example #56
0
 /// <summary>
 /// Creates a Table object with the specified name, using the
 /// passed-in client to load the table definition.
 /// 
 /// This method will return false if the table does not exist.
 /// </summary>
 /// <param name="ddbClient">Client to use to access DynamoDB.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
 /// <param name="table">Loaded table.</param>
 /// <returns>
 /// True if table was successfully loaded; otherwise false.
 /// </returns>
 public static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion, out Table table)
 {
     try
     {
         table = LoadTable(ddbClient, tableName, conversion);
         return true;
     }
     catch
     {
         table = null;
         return false;
     }
 }
Example #57
0
 /// <summary>
 /// Creates a Table object with the specified name, using the
 /// passed-in client to load the table definition.
 /// The returned table will use the conversion specified by
 /// AWSConfigs.DynamoDBConfig.ConversionSchema
 ///
 /// This method will return false if the table does not exist.
 /// </summary>
 /// <param name="ddbClient">Client to use to access DynamoDB.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="table">Loaded table.</param>
 /// <returns>
 /// True if table was successfully loaded; otherwise false.
 /// </returns>
 public static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, out Table table)
 {
     return TryLoadTable(ddbClient, tableName, DynamoDBEntryConversion.CurrentConversion, out table);
 }
        /// <summary>
        /// A utility method for cleaning up expired sessions that IIS failed to delete. The method performs a scan on the table
        /// with a condition that the expiration date is in the past and calls delete on all the keys returned. Scans can be costly on performance
        /// so use this method sparingly like a nightly or weekly clean job.
        /// </summary>
        /// <param name="dbClient">The AmazonDynamoDB client used to find a delete expired sessions.</param>
        /// <param name="tableName">The table to search.</param>
        public static void DeleteExpiredSessions(IAmazonDynamoDB dbClient, string tableName)
        {
            LogInfo("DeleteExpiredSessions");
            Table table = Table.LoadTable(dbClient, tableName, DynamoDBEntryConversion.V1);

            ScanFilter filter = new ScanFilter();
            filter.AddCondition(ATTRIBUTE_EXPIRES, ScanOperator.LessThan, DateTime.Now);

            ScanOperationConfig config = new ScanOperationConfig();
            config.AttributesToGet = new List<string> { ATTRIBUTE_SESSION_ID };
            config.Select = SelectValues.SpecificAttributes;
            config.Filter = filter;

            DocumentBatchWrite batchWrite = table.CreateBatchWrite();
            Search search = table.Scan(config);

            do
            {
                List<Document> page = search.GetNextSet();
                foreach (var document in page)
                {
                    batchWrite.AddItemToDelete(document);
                }
            } while (!search.IsDone);

            batchWrite.Execute();
        }
Example #59
-1
 internal static Table LoadTable(IAmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer, DynamoDBEntryConversion conversion)
 {
     Table table = new Table(ddbClient, tableName, consumer, conversion);
     table.LoadTableInfo();
     return table;
 }
Example #60
-1
 /// <summary>
 /// Creates a Table object with the specified name, using the
 /// passed-in client to load the table definition.
 /// 
 /// This method will throw an exception if the table does not exist.
 /// </summary>
 /// <param name="ddbClient">Client to use to access DynamoDB.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
 /// <returns>Table object representing the specified table.</returns>
 public static Table LoadTable(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion)
 {
     return LoadTable(ddbClient, tableName, DynamoDBConsumer.DocumentModel, conversion);
 }