public async Task Initialize() { if (string.IsNullOrWhiteSpace(this.options.ConnectionString)) { throw new ArgumentNullException(nameof(this.options.ConnectionString)); } // Retrieve the storage account from the connection string. var storageAccount = CloudStorageAccount.Parse(this.options.ConnectionString); // Create the table if not exists. CloudTableClient creationClient = storageAccount.CreateCloudTableClient(); // TODO - do not hard code DefaultRequestOptions in rewrite. creationClient.DefaultRequestOptions.RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(1), 60); creationClient.DefaultRequestOptions.ServerTimeout = TimeSpan.FromMinutes(3); creationClient.DefaultRequestOptions.PayloadFormat = TablePayloadFormat.JsonNoMetadata; CloudTable creationTable = creationClient.GetTableReference(this.options.TableName); await creationTable.CreateIfNotExistsAsync().ConfigureAwait(false); // get table for operations CloudTableClient operationClient = storageAccount.CreateCloudTableClient(); // TODO - do not hard code DefaultRequestOptions in rewrite. operationClient.DefaultRequestOptions.RetryPolicy = new LinearRetry(TimeSpan.FromMilliseconds(100), 5); operationClient.DefaultRequestOptions.ServerTimeout = TimeSpan.FromSeconds(3); operationClient.DefaultRequestOptions.PayloadFormat = TablePayloadFormat.JsonNoMetadata; this.table = operationClient.GetTableReference(this.options.TableName); var query = new TableQuery <StartRow>().Where(TableQuery.CombineFilters( TableQuery.GenerateFilterCondition(PartitionKey, QueryComparisons.Equal, StartRowPartitionKey), TableOperators.And, TableQuery.GenerateFilterCondition(RowKey, QueryComparisons.LessThanOrEqual, StartRowRowKey))); var queryResult = await table.ExecuteQuerySegmentedAsync(query, null).ConfigureAwait(false); if (queryResult.Results.Count == 0) { // This is a fresh deployment, the StartRecord isn't created yet. // Create it here. var row = new StartRow(0); var operation = TableOperation.Insert(row); await table.ExecuteAsync(operation).ConfigureAwait(false); startRecordValue = 0; } else { startRecordValue = queryResult.Results[0].AllocatedTransactionIds; } }
public override int GetHashCode() { int hashcode = 157; unchecked { if (__isset.startRow) { hashcode = (hashcode * 397) + StartRow.GetHashCode(); } if (__isset.stopRow) { hashcode = (hashcode * 397) + StopRow.GetHashCode(); } if (__isset.timestamp) { hashcode = (hashcode * 397) + Timestamp.GetHashCode(); } if (__isset.columns) { hashcode = (hashcode * 397) + TCollections.GetHashCode(Columns); } if (__isset.caching) { hashcode = (hashcode * 397) + Caching.GetHashCode(); } if (__isset.filterString) { hashcode = (hashcode * 397) + FilterString.GetHashCode(); } if (__isset.batchSize) { hashcode = (hashcode * 397) + BatchSize.GetHashCode(); } if (__isset.sortColumns) { hashcode = (hashcode * 397) + SortColumns.GetHashCode(); } if (__isset.reversed) { hashcode = (hashcode * 397) + Reversed.GetHashCode(); } if (__isset.cacheBlocks) { hashcode = (hashcode * 397) + CacheBlocks.GetHashCode(); } } return(hashcode); }
public override int GetHashCode() { int hash = 1; if (ProtocolVersion != 0) { hash ^= ProtocolVersion.GetHashCode(); } if (MessageType != 0) { hash ^= MessageType.GetHashCode(); } if (Side != 0) { hash ^= Side.GetHashCode(); } if (StartRow != 0) { hash ^= StartRow.GetHashCode(); } if (StartCol != 0) { hash ^= StartCol.GetHashCode(); } if (EndRow != 0) { hash ^= EndRow.GetHashCode(); } if (EndCol != 0) { hash ^= EndCol.GetHashCode(); } if (GameOutcome != 0) { hash ^= GameOutcome.GetHashCode(); } return(hash); }
public bool Load(DataTable data_source, IWorksheet worksheet) { if (data_source.Rows.Count <= 0) { // No data was found in the data source table. This will be an empty worksheet. Logger.Write("Worksheet.Process", "DISCARDING WORKSHEET: NO DATA ", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); return(false); } else { Logger.Write("Worksheet.Process", " LOADING DATA: ROW COUNT " + data_source.Rows.Count, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); } if (string.IsNullOrEmpty(StartColumn)) { throw new Exception(string.Format("SheetNumber [{0}] SheetTableName [{1}] does not contain a StartDataColumn", SheetNumber, SourceDataTable.Name)); } if (string.IsNullOrEmpty(StartRow)) { throw new Exception(string.Format("SheetNumber [{0}] SheetTableName [{1}] does not contain a StartDataRow", SheetNumber, SourceDataTable.Name)); } // Set the sheets header. if (!string.IsNullOrEmpty(Header)) { worksheet.PageSetup.CenterHeader = TextParser.Parse(Header, DrivingData, SharedData, ModuleCommands); } // Set the sheets footer. if (!string.IsNullOrEmpty(Footer)) { worksheet.PageSetup.CenterFooter = TextParser.Parse(Footer, DrivingData, SharedData, ModuleCommands); } // Check the start row for commands. if (StartRow.ToLower() == "%lastusedrow%") { StartRow = worksheet.UsedRange.RowCount.ToString(); } else if (StartRow.ToLower() == "%firstnewrow%") { StartRow = (worksheet.UsedRange.RowCount + 1).ToString(); } // Check to see if only certain columns are desired. if (SourceDataTable.CacheColumnCollection != null && SourceDataTable.CacheColumnCollection.Count > 0) { object[,] values = null; if (!string.IsNullOrEmpty(SourceDataTable.AggregateExpression)) { values = new object[0, SourceDataTable.CacheColumnCollection.Length]; if (SourceDataTable.Aggregate.Expression.ToLower() == "sum") { for (int i = 0; i < SourceDataTable.CacheColumnCollection.Length; i++) { values[0, i] = 0; } for (int row = 0; row < data_source.Rows.Count; row++) { for (int col = 0; col < SourceDataTable.CacheColumnCollection.Count; col++) { values[0, col] = Convert.ToInt32(values[0, col]) + Convert.ToInt32(data_source.Rows[row][SourceDataTable.CacheColumnCollection.GetColumn(col).Name]); } } } else { throw new Exception("DataTableColumnAggregate [" + SourceDataTable.Aggregate.Expression + "] is unknown."); } } else if (SourceDataTable.CacheColumnCollection != null && SourceDataTable.CacheColumnCollection.Count > 0) { values = new object[data_source.Rows.Count, SourceDataTable.CacheColumnCollection.Count]; for (int row = 0; row < data_source.Rows.Count; row++) { for (int col = 0; col < SourceDataTable.CacheColumnCollection.Count; col++) { values[row, col] = data_source.Rows[row][SourceDataTable.CacheColumnCollection.GetColumn(col).Name]; } } } else { values = new object[data_source.Rows.Count - 1, SharedData.Data.Tables(TextParser.Parse(SourceDataTable.Name, DrivingData, SharedData, ModuleCommands)).Columns.Count - 1]; for (int row = 0; row < data_source.Rows.Count; row++) { for (int col = 0; col < SharedData.Data.Tables(TextParser.Parse(SourceDataTable.Name, DrivingData, SharedData, ModuleCommands)).Columns.Count; col++) { values[row, col] = data_source.Rows[row][col]; } } } int column_index = worksheet.Cells[StartColumn + StartRow].Column; if (values.GetUpperBound(0) == 0 && values.GetUpperBound(1) == 0) { worksheet.Cells[Convert.ToInt32(StartRow) - 1, column_index, (Convert.ToInt32(StartRow) - 1) + values.GetUpperBound(0), column_index + values.GetUpperBound(1)].Value = values[0, 0]; } else { worksheet.Cells[Convert.ToInt32(StartRow) - 1, column_index, (Convert.ToInt32(StartRow) - 1) + values.GetUpperBound(0), column_index + values.GetUpperBound(1)].Value = values; } } else { // Set the worksheet to wrap to a new sheet if there is too much data for one sheet. worksheet.Cells[StartColumn + StartRow].CopyFromDataTable(data_source, SpreadsheetGear.Data.SetDataFlags.WrapToNewWorksheet | SpreadsheetGear.Data.SetDataFlags.NoColumnHeaders); } return(true); }
public bool Process(IWorksheet worksheet) { bool contains_data = false; int start_row = -1; try { Logger.Aquire(); Logger.Write("Worksheet.Process", "", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.Write("Worksheet.Process", "PROCESSING WORKSHEET: " + worksheet.Name, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.Write("Worksheet.Process", " SOURCE MODULE: " + SourceDataTable.Name, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.Write("Worksheet.Process", " FILTER: " + SourceDataTable.FilterExpression, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); if (StartRow.ToLower() == "%lastusedrow%") { start_row = worksheet.UsedRange.RowCount; } else if (StartRow.ToLower() == "%firstnewrow%") { start_row = worksheet.UsedRange.Row + 1; } else { start_row = Convert.ToInt32(StartRow); } Logger.Write("Worksheet.Process", " START COLUMN|ROW: " + StartColumn + start_row, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); } catch (Exception ex) { throw ex; } finally { Logger.Release(); } // Rename the worksheet if applicable. if (!string.IsNullOrEmpty(NewSheetName)) { Logger.WriteLine("Worksheet.Process", " CHANGING NAME: " + TextParser.Parse(NewSheetName, DrivingData, SharedData, ModuleCommands), System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); worksheet.Name = TextParser.Parse(NewSheetName, DrivingData, SharedData, ModuleCommands); if (worksheet.Name.Length > 31) { throw new Exception("The worksheet name (" + worksheet.Name + ") cannot have more than 31 characters."); } } // If the worksheet does not have a source table defined then return false. // Without a source table the worksheet will be empty. if (HasSourceTable) { if (!SharedData.Data.Contains(SourceDataTable.Name)) { throw new Exception(string.Format("The source data table '{0}' for sheet at index '{1}' was not found in the global cache set.", SourceDataTable.Name, SheetNumber)); } // Load the worksheet with the source table's data. if (!Load(SourceDataTable.Process(ConditionalTables), worksheet)) { // No data wasloaded into the worksheet. contains_data = false; } else { // Perform any required formatting. Format(worksheet); contains_data = true; } } else { contains_data = false; } return(contains_data); }