private static void ConvertCsvToMongo <T>(Context context, TemporalId dataset, string csvFile) where T : Record { string fileContent = File.ReadAllText(csvFile); var records = CsvRecordsSerializer <T> .Deserialize(fileContent); context.SaveMany(records, dataset); }
private static void ProcessDirectory(Context context, string path, TemporalId parentDataset) { var dirName = Path.GetFileName(path); // Do not create dataset for Common var currentDataset = dirName != "Common" ? context.CreateDataSet(dirName) : parentDataset; foreach (var csvFile in Directory.GetFiles(path, "*.csv")) { var type = Path.GetFileNameWithoutExtension(csvFile); Type recordType = ActivatorUtil.ResolveType(type, ActivatorSettings.Assemblies) ?? throw new ArgumentException($"Type '{type}' not found"); MethodInfo convertToMongo = typeof(CsvConvertCommand) .GetMethod(nameof(ConvertCsvToMongo), BindingFlags.Static | BindingFlags.NonPublic) ?.MakeGenericMethod(recordType); convertToMongo?.Invoke(null, new object[] { context, currentDataset, csvFile }); } var directories = Directory.GetDirectories(path); foreach (string directory in directories) { ProcessDirectory(context, directory, currentDataset); } }
public void Publish(string msg, string type, string route = "") { _log.InfoFormat("Publishing {0} for type{1} on route {2}", msg, type, route); Message m = new Message { ContentType = type, Route = route, Content = msg }; var textMessage = JsonConvert.SerializeObject(m); if (textMessage.Length >= CloudQueueMessage.MaxMessageSize) { var id = new TemporalId(); m.Reference = id.Id; m.Content = null; _dblog.InfoFormat("Pocketing message at length {0} to reference {1}", textMessage.Length, id.Id); CloudBlob blob = null; lock (containerLock) blob = _container.GetBlobReference(m.Reference); blob.UploadText(msg); textMessage = JsonConvert.SerializeObject(m); } lock (qLock) _q.AddMessage(new CloudQueueMessage(textMessage)); }
public void TestParse() { // Lowercase and uppercase var recordId1 = TemporalId.Parse("2003-05-01T10:15:00.000Z0000010002000abc"); var recordId2 = TemporalId.Parse("2003-05-01T10:15:00.000Z0000010002000ABC"); Assert.True(recordId1.ToByteArray().SequenceEqual(recordId2.ToByteArray())); // ToString returns lower case Assert.True(recordId1.ToString() == "2003-05-01T10:15:00.000Z0000010002000abc"); Assert.True(recordId1.ToString() == recordId2.ToString()); }
public void TestTryParse() { // Lowercase and uppercase TemporalId recordId1, recordId2; Assert.True(TemporalId.TryParse("2003-05-01T10:15:00.000Z0000010002000abc", out recordId1)); Assert.True(TemporalId.TryParse("2003-05-01T10:15:00.000Z0000010002000ABC", out recordId2)); Assert.True(recordId1.ToByteArray().SequenceEqual(recordId2.ToByteArray())); // ToString returns lower case Assert.True(recordId1.ToString() == "2003-05-01T10:15:00.000Z0000010002000abc"); Assert.True(recordId1.ToString() == recordId2.ToString()); }
/// <summary> /// Helper method to create and init instance of handler class. /// </summary> private static TRecord CreateHandler <TKey, TBaseRecord, TRecord>(Context context, RunCommand command) where TKey : TypedKey <TKey, TBaseRecord>, new() where TRecord : TBaseRecord where TBaseRecord : TypedRecord <TKey, TBaseRecord> { TKey key = Activator.CreateInstance <TKey>(); key.PopulateFrom(command.Key); TemporalId dataSet = context.GetDataSet(command.Dataset); TRecord record = (TRecord)context.LoadOrNull(key, dataSet); record.Init(context); return(record); }
public void CutoffTime() { using (var context = CreateMethodContext()) { // Create two versions in DataSet0 var dataSet0 = context.CreateDataSet("DataSet0"); TemporalId objA0 = SaveMinimalRecord(context, "DataSet0", "A", 0, 0); TemporalId objA1 = SaveMinimalRecord(context, "DataSet0", "A", 0, 1); // Create two versions in DataSet1 var dataSet1 = context.CreateDataSet("DataSet1", new TemporalId[] { dataSet0 }); TemporalId objB0 = SaveMinimalRecord(context, "DataSet1", "B", 0, 0); TemporalId objB1 = SaveMinimalRecord(context, "DataSet1", "B", 0, 1); TemporalId cutoffTemporalId = context.DataSource.CreateOrderedTemporalId(); // Create third version of the records TemporalId objA2 = SaveMinimalRecord(context, "DataSet0", "A", 0, 2); TemporalId objB2 = SaveMinimalRecord(context, "DataSet1", "B", 0, 2); // Create new records that did not exist before TemporalId objC0 = SaveMinimalRecord(context, "DataSet0", "C", 0, 0); TemporalId objD0 = SaveMinimalRecord(context, "DataSet1", "D", 0, 0); // Load each record by TemporalId context.Log.Verify("Load records by TemporalId without constraint"); context.Log.Verify($"Found for TemporalId(A0)={context.LoadOrNull<BaseSample>(objA0) != null}"); context.Log.Verify($"Found for TemporalId(A1)={context.LoadOrNull<BaseSample>(objA1) != null}"); context.Log.Verify($"Found for TemporalId(A2)={context.LoadOrNull<BaseSample>(objA2) != null}"); context.Log.Verify($"Found for TemporalId(C0)={context.LoadOrNull<BaseSample>(objC0) != null}"); // Load each record by string key if (true) { var loadedA0 = context.LoadOrNull(new BaseSampleKey() { RecordName = "A", RecordIndex = 0 }, dataSet1); var loadedC0 = context.LoadOrNull(new BaseSampleKey() { RecordName = "C", RecordIndex = 0 }, dataSet1); context.Log.Verify("Load records by string key without constraint"); if (loadedA0 != null) { context.Log.Verify($" Version found for key=A;0: {loadedA0.Version}"); } if (loadedC0 != null) { context.Log.Verify($" Version found for key=C;0: {loadedC0.Version}"); } } // Query for all records if (true) { var query = context.GetQuery <BaseSample>(dataSet1) .SortBy(p => p.RecordName) .SortBy(p => p.RecordIndex) .AsEnumerable(); context.Log.Verify("Query records without constraint"); foreach (var obj in query) { var dataSetName = context.LoadOrNull <DataSet>(obj.DataSet).DataSetName; context.Log.Verify($" Key={obj.Key} DataSet={dataSetName} Version={obj.Version}"); } } // Set revision time constraint context.DataSource.CastTo <TemporalMongoDataSource>().CutoffTime = cutoffTemporalId; // Get each record by TemporalId context.Log.Verify("Load records by TemporalId with CutoffTime constraint"); context.Log.Verify($"Found for TemporalId(A0)={context.LoadOrNull<BaseSample>(objA0) != null}"); context.Log.Verify($"Found for TemporalId(A1)={context.LoadOrNull<BaseSample>(objA1) != null}"); context.Log.Verify($"Found for TemporalId(A2)={context.LoadOrNull<BaseSample>(objA2) != null}"); context.Log.Verify($"Found for TemporalId(C0)={context.LoadOrNull<BaseSample>(objC0) != null}"); // Load each record by string key if (true) { var loadedA0 = context.LoadOrNull(new BaseSampleKey() { RecordName = "A", RecordIndex = 0 }, dataSet1); var loadedC0 = context.LoadOrNull(new BaseSampleKey() { RecordName = "C", RecordIndex = 0 }, dataSet1); context.Log.Verify("Load records by string key with CutoffTime constraint"); if (loadedA0 != null) { context.Log.Verify($" Version found for key=A;0: {loadedA0.Version}"); } if (loadedC0 != null) { context.Log.Verify($" Version found for key=C;0: {loadedC0.Version}"); } } // Query for revised before the cutoff time if (true) { var query = context.GetQuery <BaseSample>(dataSet1) .SortBy(p => p.RecordName) .SortBy(p => p.RecordIndex) .AsEnumerable(); context.Log.Verify("Query records with CutoffTime constraint"); foreach (var obj in query) { var dataSetName = context.LoadOrNull <DataSet>(obj.DataSet).DataSetName; context.Log.Verify($" Key={obj.Key} DataSet={dataSetName} Version={obj.Version}"); } } // Clear revision time constraint before exiting to avoid an error // about deleting readonly database. The error occurs because // revision time constraint makes the data source readonly. context.DataSource.CastTo <TemporalMongoDataSource>().CutoffTime = null; } }
protected override string BuildPaymentButton(string trxInfo, BillingPlan bp, BrokerTransactionType tt) { Debug.Assert(!string.IsNullOrEmpty(trxInfo)); Debug.Assert(null != bp); _logger.InfoFormat( "Building payment button with transaction info {0}, billing plan {1} and transaction type {2}", trxInfo, bp.Name, tt); PayPalEncryptedButton subscribeButton = new PayPalEncryptedButton(); IConfig config = Catalog.Factory.Resolve <IConfig>(); var businessID = config[PayPalConfiguration.BusinessId]; var cancelReturnUrl = config[PayPalConfiguration.CancelReturnUrl]; var notificationUrl = config[PayPalConfiguration.NotificationUrl]; string itemName, returnUrl, invoice; TemporalId payId = new TemporalId(); if (tt == BrokerTransactionType.Upgrade) { itemName = config[PayPalConfiguration.UpgradeItem]; returnUrl = config[PayPalConfiguration.UpgradeReturnUrl]; invoice = string.Format("{0}:{1}:{2}", UpgradePrefix, bp.Name, payId); } else { itemName = config[PayPalConfiguration.ExpressItem]; returnUrl = config[PayPalConfiguration.ExpressReturnUrl]; invoice = string.Format("{0}:{1}:{2}", ExpressPrefix, bp.Name, payId); } _logger.InfoFormat("invoice: {0}", invoice); const int one = 1; subscribeButton.AddParameter(PayPal.Command, PayPal.ClickSubscription) .AddParameter(PayPal.Business, businessID) .AddParameter(PayPal.SubscribeButtonLanguage, PayPal.USEnglishLanguage) .AddParameter(PayPal.ItemName, itemName) .AddParameter(PayPal.BuyerIncludeNoteWithPayment, PayPal.HideNoteFromUser) .AddParameter(PayPal.ShippingAddressMode, PayPal.ShippingModeHideAddress) .AddParameter(PayPal.ReturnToAppMethod, PayPal.ReturnMethodGetNoVariables) .AddParameter(PayPal.GoToOnPayment, returnUrl) .AddParameter(PayPal.SubscriptionRecurrence, PayPal.SubscriptionRecurs) .AddParameter(PayPal.SubscriptionPrice, string.Format("{0:0.00}", bp.Rate)) .AddParameter(PayPal.SubscriptionDuration, one.ToString()) .AddParameter(PayPal.SubscriptionUnits, PayPal.TimeUnitMonth) .AddParameter(PayPal.CurrencyCode, PayPal.CurrencyUSDollar) .AddParameter(PayPal.TransactionNotificationGatewayURL, notificationUrl) .AddParameter(PayPal.GotoOnCancel, cancelReturnUrl) .AddParameter(PayPal.Custom, trxInfo) .AddParameter(PayPal.InvoiceIdentifier, invoice); if (bp.GracePeriodDays > 0) { subscribeButton.AddParameter(PayPal.TrialPeriodPrice, "0.00") .AddParameter(PayPal.TrialPeriodDuration, bp.GracePeriodDays.ToString()) .AddParameter(PayPal.TrialPeriodUnits, PayPal.TimeUnitDay); } _dblogger.InfoFormat("subscription button: {0}", subscribeButton.Plain); return(subscribeButton.Encrypted); }
/// <summary>Insert M copies of each of N versioned instances B.</summary> private void InsertRecordsB(Context context) { var db = GetDb(context); var collection = db.GetCollection <B>("B"); if (false) { var indexOptions = new CreateIndexOptions(); var indexKeys = Builders <B> .IndexKeys.Descending(p => p.DataSet).Descending(p => p.Id); var indexModel = new CreateIndexModel <B>(indexKeys, indexOptions); collection.Indexes.CreateOne(indexModel); } if (true) { var indexOptions = new CreateIndexOptions(); var indexKeys = Builders <B> .IndexKeys.Ascending(p => p.KeyElement).Descending(p => p.DataSet).Descending(p => p.Id); var indexModel = new CreateIndexModel <B>(indexKeys, indexOptions); collection.Indexes.CreateOne(indexModel); } if (true) { var indexOptions = new CreateIndexOptions(); var indexKeys = Builders <B> .IndexKeys .Ascending(p => p.StringElement1) .Ascending(p => p.StringElement2) .Ascending(p => p.DoubleElement) .Ascending(p => p.IntElement) // .Ascending(p => p.KeyElement) .Descending(p => p.DataSet).Descending(p => p.Id); var indexModel = new CreateIndexModel <B>(indexKeys, indexOptions); collection.Indexes.CreateOne(indexModel); } List <B> records = new List <B>(); for (int dataSetIndex = 0; dataSetIndex < dataSetCount_; ++dataSetIndex) { TemporalId dataSet = TemporalId.Next(); for (int versionIndex = 0; versionIndex < versionCount_; ++versionIndex) { for (int recordIndex = 0; recordIndex < recordCount_; ++recordIndex) { var rec = new B(); rec.Id = TemporalId.Next(); rec.DataSet = dataSet; rec.KeyElement = String.Concat("KeyPrefix", recordIndex); rec.StringElement1 = (recordIndex % 2).ToString(); rec.StringElement2 = (recordIndex % 3).ToString(); rec.DoubleElement = recordIndex; rec.IntElement = recordIndex; if (arraySize_ > 0) { rec.ArrayElement = new List <double>(); for (int i = 0; i < arraySize_; ++i) { rec.ArrayElement.Add(i); } } rec.VersionElement = versionIndex; records.Add(rec); } } } collection.InsertMany(records); context.Log.Verify($"Inserted {records.Count} record versions."); }