using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Sockeye.Util; using Sockeye.Api.ControllerHelpers; using Sockeye.Models; using System.Collections.Generic; using System; using System.Text; using System.IO; using System.Net.Http; using System.Linq; using Microsoft.Extensions.Logging; //JSON KEY using Org.BouncyCastle.Security; using Org.BouncyCastle.OpenSsl; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Net.Http.Headers; namespace Sockeye.Biz { internal class GlobalBizSettingsBiz : BizObject { internal GlobalBizSettingsBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles) { ct = dbcontext; UserId = currentUserId; UserTranslationId = userTranslationId; CurrentUserRoles = UserRoles; BizType = SockType.Global; } internal static GlobalBizSettingsBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null) { if (httpContext != null) return new GlobalBizSettingsBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items)); else return new GlobalBizSettingsBiz(ct, 1, ServerBootConfig.SOCKEYE_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdmin); } //////////////////////////////////////////////////////////////////////////////////////////////// /// GET //Get one internal async Task GetAsync(bool logTheGetEvent = true) { //first try to fetch from db var ret = await ct.GlobalBizSettings.AsNoTracking().SingleOrDefaultAsync(m => m.Id == 1); if (logTheGetEvent && ret != null) { //Log await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, 1, BizType, SockEvent.Retrieved), ct); } //not in db then get the default if (ret == null) { throw new System.Exception("GlobalBizSettingsBiz::GetAsync -> Global settings object not found in database!!"); } return ret; } //////////////////////////////////////////////////////////////////////////////////////////////// //UPDATE // internal async Task PutAsync(GlobalBizSettings putObject) { var dbObject = await GetAsync(false); if (dbObject == null) throw new System.Exception("GlobalBizSettingsBiz::PutAsync -> Global settings object not found in database. Contact support immediately!"); if (dbObject.Concurrency != putObject.Concurrency) { AddError(ApiErrorCode.CONCURRENCY_CONFLICT); return null; } Validate(putObject, dbObject); if (HasErrors) return null; List originalTags = dbObject.AllTags(); List newTags = putObject.AllTags(); ct.Replace(dbObject, putObject); try { await ct.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { AddError(ApiErrorCode.CONCURRENCY_CONFLICT); return null; } //Update cache ServerGlobalBizSettings.Initialize(putObject, null); //Log modification and save context await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, 1, BizType, SockEvent.Modified), ct); await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newTags, originalTags); return putObject; } //////////////////////////////////////////////////////////////////////////////////////////////// //VALIDATION // //Can save or update? private void Validate(GlobalBizSettings proposedObj, GlobalBizSettings currentObj) { //currently nothing to validate } //IMPORT FROM ROCKFISH public async Task ImportRockfish(AyContext ct, ILogger log) { log.LogInformation("Start import from rockfish, authenticating"); //Authenticate to rockfish //string sUrl = $"{LICENSE_SERVER_URL_ROCKFISH}rvr"; string URL_ROCKFISH = "https://rockfish.ayanova.com/"; try { //var content = new StringContent("login=john&password=b43698c255365ee739c05ba0d42855e96c2365c76bb2f9b9eb149cec7b52174c"); var content = new StringContent(JsonConvert.SerializeObject(new { login = "john", password = "b43698c255365ee739c05ba0d42855e96c2365c76bb2f9b9eb149cec7b52174c" }), Encoding.UTF8, "application/json"); var client = ServiceProviderProvider.HttpClientFactory.CreateClient(); //AUTHENTICATE var res = await client.PostAsync($"{URL_ROCKFISH}authenticate?login=john&password=b43698c255365ee739c05ba0d42855e96c2365c76bb2f9b9eb149cec7b52174c", content); var responseText = await res.Content.ReadAsStringAsync(); if (!res.IsSuccessStatusCode) throw new Exception($"E1020 - Error authenticating to rockfish: {res.ReasonPhrase}"); var responseJson = JObject.Parse(responseText); var authToken = responseJson["token"].Value(); var dlKey = responseJson["dlkey"].Value(); var userId = responseJson["id"].Value(); //client.DefaultRequestHeaders.Add("Bearer", authToken); var contentType = new MediaTypeWithQualityHeaderValue("application/json"); client.DefaultRequestHeaders.Accept.Add(contentType); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken); #region CUSTOMERS log.LogInformation("RFImport customers"); res = await client.GetAsync($"{URL_ROCKFISH}api/customer/list"); responseText = await res.Content.ReadAsStringAsync(); var jaCustomerList = JArray.Parse(responseText); foreach (JObject jCustomerListItem in jaCustomerList) { res = await client.GetAsync($"{URL_ROCKFISH}api/customer/{jCustomerListItem["id"].Value()}"); var jCustomer = JObject.Parse(await res.Content.ReadAsStringAsync()); //SITES res = await client.GetAsync($"{URL_ROCKFISH}api/customer/{jCustomerListItem["id"].Value()}/sites"); var jaSiteList = JArray.Parse(await res.Content.ReadAsStringAsync()); bool multiSite = jaSiteList.Count() > 1; foreach (JObject jSite in jaSiteList) { var CustomerName = jCustomer["name"].Value(); if (multiSite) CustomerName += " - " + jSite["name"].Value(); long CurrentCustomerId = 0; //Create customer if we don't have one already if (await ct.Customer.AnyAsync(z => z.Name == CustomerName)) continue;//already have this one so no need to process it again { //CREATE CUSTOMER Customer c = new Customer(); c.Active = jCustomerListItem["active"].Value(); c.Name = CustomerName; c.Country = jSite["country"].Value(); c.Region = jSite["stateProvince"].Value(); c.DoNotContact = jCustomer["doNotContact"].Value(); c.Notes = jCustomer["notes"].Value(); c.DbId = jSite["dbId"].Value(); if (c.DbId == "v7_no_dbid") { c.DbId = null; c.Tags.Add("v7"); } else c.Tags.Add("raven"); if (jSite["hosted"].Value() == true) c.Tags.Add("hosted"); var adminEmail = jCustomer["adminEmail"].Value(); if (!string.IsNullOrWhiteSpace(adminEmail)) c.Notes += "\nAdmin Email: " + adminEmail; c.EmailAddress = jCustomer["adminEmail"].Value(); CustomerBiz biz = CustomerBiz.GetBiz(ct); var NewObject = await biz.CreateAsync(c); CurrentCustomerId = NewObject.Id; }//customer creation //SITE PURCHASES res = await client.GetAsync($"{URL_ROCKFISH}api/site/{jSite["id"].Value()}/purchases"); var jaPurchaseList = JArray.Parse(await res.Content.ReadAsStringAsync()); foreach (JObject jPurchase in jaPurchaseList) { //create product if not exist then import //Get product id if exists var ProductName = jPurchase["name"].Value(); ProductName = ProductName.Replace("- Renewal", "").Replace(" Renewal", "").Replace(" RENEWAL", "").Replace("CANCELLED ", "").Replace("CANCELED ", ""); var p = await ct.Product.AsNoTracking().FirstOrDefaultAsync(z => z.VendorCode == jPurchase["productCode"].Value()); if (p == null) { //Create it here p = new Product(); p.Name = ProductName; p.Active = true;//not entirely true but we can always deactivate there aren't many products p.VendorId = 1; p.OurCode = p.VendorCode = jPurchase["productCode"].Value(); p.PGroup = ProductGroupFromProductCode(p.OurCode); if (p.VendorCode == "301028468")//subscription yearly { p.LicenseInterval = new TimeSpan(365, 0, 0, 0); //actual length, in license is where I pad to cover them } if (p.VendorCode == "301028467")//subscription monthly { p.LicenseInterval = new TimeSpan(31, 0, 0, 0);//there is no concept beyond days for timespan so a month is 31 days max p.MaintInterval = new TimeSpan(31, 0, 0, 0);//the only product less than one year of maintenance save the ones with no maintenance which can be edited manually later as there are so few of them } else p.MaintInterval = new TimeSpan(365, 0, 0, 0); ProductBiz biz = ProductBiz.GetBiz(ct); p = await biz.CreateAsync(p); } //Now we can add the sale that we have the product if (!await ct.Purchase.AnyAsync(z => z.SalesOrderNumber == jPurchase["salesOrderNumber"].Value())) { var s = new Purchase(); s.VendorId = 1; s.ProductId = p.Id; s.PGroup = p.PGroup; s.CustomerId = CurrentCustomerId; s.CancelDate = DateUtil.EpochToDateNullIsNull(jPurchase["cancelDate"].Value()); s.CouponCode = jPurchase["couponCode"].Value(); s.ExpireDate = DateUtil.EpochToDateNullIsNull(jPurchase["expireDate"].Value()); s.Name = p.Name; s.ProcessedDate = s.PurchaseDate = DateUtil.EpochToDateNullIsMin(jPurchase["purchaseDate"].Value()); s.Quantity = jPurchase["quantity"].Value(); s.RenewNoticeSent = jPurchase["renewNoticeSent"].Value(); s.SalesOrderNumber = jPurchase["salesOrderNumber"].Value(); s.Notes = jPurchase["notes"].Value(); PurchaseBiz biz = PurchaseBiz.GetBiz(ct); await biz.CreateAsync(s); } } }//site loop }//end of all customers iteration #endregion customers #region VENDOR NOTIFICATIONS log.LogInformation("RFImport Vendor notifications"); { res = await client.GetAsync($"{URL_ROCKFISH}api/vendor-notifications/list"); responseText = await res.Content.ReadAsStringAsync(); var jaVendorNotificationList = JArray.Parse(responseText); foreach (JObject jVendorNotificationItem in jaVendorNotificationList.Reverse()) { /*[] "{\n \"creation_date\": \"2022-12-28T20:20:24Z\",\n \ "id\": 356247074,\n \ "order_notification\": {\n \ "purchase\": {\n \"customer_data\": {\n \"billing_contact\": {\n \"address\": {\n \"city\": \"Alpharetta\",\n \"country\": \"USA\",\n \"country_id\": \"US\",\n \"postal_code\": \"30009\",\n \"state\": \"Georgia\",\n \"state_id\": \"GA\",\n \"street1\": \"11675 Rainwater Dr., Suite 350\"\n }, \n …tart\": \"\",\n \"renewal_type\": \"auto\",\n \"retention_discount_count\": \"\",\n \"retention_discount_percent\": \"\",\n \ "start_date\": \"2022-12-28T00:00:00\",\n \"status\": \"ToProcess\",\n \"status_id\": \"TOP\"\n },\n \ "vat_pct\": 0.0,\n \"your_product_id\": \"perpetual\"\n }\n ],\n \"purchase_origin\": \"online\",\n \"sequential_invoice_no\": \"e5-US-2022-00001637070\"\n }\n }\n}" { "id": 25, "dtCreated": 1670375661, "vendor": "shareit", "data": "{\n \"creation_date\": \"2022-12-07T01:14:19Z\",\n \"id\": 354935062,\n \"order_notification\": {\n \"purchase\": {\n \"customer_data\": {\n \"billing_contact\": {\n \"address\": {\n \"city\": \"Abbotsford\",\n \"country\": \"Canada\",\n \"country_id\": \"CA\",\n \"postal_code\": \"V2S 8M1\",\n \"state\": \"British Columbia\",\n \"state_id\": \"BC\",\n \"street1\": \"35355 McKee Rd\"\n },\n \"company\": \"Adtech Systems Inc.\",\n \"email\": \"erling@myadtech.com\",\n \"first_name\": \"Erling\",\n \"last_name\": \"Lassesen\"\n },\n \"customer_payment_data\": {\n \"currency\": \"USD\",\n \"payment_method\": \"PayPal\"\n },\n \"delivery_contact\": {\n \"address\": {\n \"city\": \"Abbotsford\",\n \"country\": \"Canada\",\n \"country_id\": \"CA\",\n \"postal_code\": \"V2S 8M1\",\n \"state\": \"British Columbia\",\n \"state_id\": \"BC\",\n \"street1\": \"35355 McKee Rd\"\n },\n \"company\": \"Adtech Systems Inc.\",\n \"email\": \"erling@myadtech.com\",\n \"first_name\": \"Erling\",\n \"last_name\": \"Lassesen\"\n },\n \"language\": \"English\",\n \"language_iso\": \"en\",\n \"reg_name\": \"Adtech Systems Inc.\",\n \"shopper_id\": \"50862261\",\n \"subscribe_newsletter\": true,\n \"user_id\": \"erling@adtech-systems.com-4\"\n },\n \"is_test\": false,\n \"payment_complete_date\": \"2022-12-07T01:14:19Z\",\n \"payment_status\": \"complete\",\n \"payment_status_id\": \"PCA\",\n \"purchase_date\": \"2022-12-07T01:14:16Z\",\n \"purchase_id\": 833707313,\n \"purchase_item\": [\n {\n \"accounting\": {\n \"currency\": \"USD\",\n \"product_net\": 55.65,\n \"discount\": 0.0,\n \"product_vat\": 6.68,\n \"shipping\": 0.0,\n \"shipping_vat\": 0.0,\n \"eu_vat\": -6.68,\n \"margin_net\": -5.44,\n \"your_revenue\": 50.21\n },\n \"additional_information\": [\n {\n \"additional_id\": \"ADDITIONAL1\",\n \"additional_value\": \"YES\"\n },\n {\n \"additional_id\": \"ADDITIONAL2\",\n \"additional_value\": \"YES\"\n },\n {\n \"additional_id\": \"ADDITIONAL3\",\n \"additional_value\": \"YES\"\n }\n ],\n \"currency\": \"USD\",\n \"delivery_type\": \"Electronically\",\n \"discount\": 0.0,\n \"extended_download_price\": 0.0,\n \"manual_order_price\": 0.0,\n \"notification_no\": 7926,\n \"product_id\": 300740315,\n \"product_name\": \"Single AyaNova schedulable resource 1 year subscription license\",\n \"product_single_price\": 55.65,\n \"purchase_item_key\": [],\n \"quantity\": 1,\n \"running_no\": 1,\n \"shipping_price\": 0.0,\n \"shipping_vat_pct\": 0.0,\n \"subscription\": {\n \"expiration_date\": \"2023-12-07T17:28:16Z\",\n \"id\": \"550286373-1\",\n \"interval\": \"Yearly without end\",\n \"original_notification_no\": \"6872\",\n \"original_purchase_id\": \"550286373\",\n \"original_running_no\": \"1\",\n \"renewal_discount_count\": \"\",\n \"renewal_discount_start\": \"\",\n \"renewal_type\": \"auto\",\n \"retention_discount_count\": \"\",\n \"retention_discount_percent\": \"\",\n \"start_date\": \"2017-12-07T00:00:00\",\n \"status\": \"ToProcess\",\n \"status_id\": \"TOP\"\n },\n \"vat_pct\": 12.0\n }\n ],\n \"purchase_origin\": \"Subscription\",\n \"sequential_invoice_no\": \"e5-DE-2022-00002647549\"\n }\n }\n}", "dtProcessed": null, "processed": false }, */ var jData = JObject.Parse(jVendorNotificationItem["data"].Value()); var salesOrderNumber = jData["order_notification"]["purchase"]["purchase_id"].Value(); var p = await ct.Purchase.FirstOrDefaultAsync(z => z.SalesOrderNumber == salesOrderNumber); if (p == null) { log.LogError($"RFImport Vendor notifications can't match sales order number {salesOrderNumber}"); log.LogError(jData["order_notification"].ToString()); } else { if (!string.IsNullOrWhiteSpace(p.VendorData)) p.VendorData += ",\n"; p.VendorData += jVendorNotificationItem["data"].Value(); await ct.SaveChangesAsync(); } }// all vendor notifications loop } #endregion vendor notifications #region CASES log.LogInformation("RFImport Cases"); //case projects to be tags List CaseProjectList = new List(); { res = await client.GetAsync($"{URL_ROCKFISH}api/rfcaseproject"); responseText = await res.Content.ReadAsStringAsync(); var jaRFCaseProjectList = JArray.Parse(responseText); foreach (JObject jRFCaseProject in jaRFCaseProjectList) { CaseProjectList.Add(new NameIdItem() { Name = jRFCaseProject["name"].Value(), Id = jRFCaseProject["id"].Value() }); } } { res = await client.GetAsync($"{URL_ROCKFISH}api/rfcase/list"); responseText = await res.Content.ReadAsStringAsync(); var jaRFCaseList = JArray.Parse(responseText); //some cases are missing the start date so substitute a close other case date (not critical but sb at least in the ballpark for list viewing purposes) DateTime dtTempCreated = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); foreach (JObject jRFCase in jaRFCaseList.Reverse()) { var g = new GZCase(); g.CaseId = jRFCase["id"].Value(); g.Closed = DateUtil.EpochToDateNullIsNull(jRFCase["dtClosed"].Value()); //NOTE: closed in rockfish was the date at midnight in GMT //so to be in the same day as here need to add a few hours, let's say 8 am for each so add 8 hours if (g.Closed != null) { g.Closed = ((DateTime)g.Closed).AddHours(16); } //fuckery to try to insert a at least semi close date when created date is missing DateTime? dtTemp = DateUtil.EpochToDateNullIsNull(jRFCase["dtCreated"].Value()); if (dtTemp == null) { dtTemp = dtTempCreated; } else { dtTempCreated = (DateTime)dtTemp; } g.Created = (DateTime)dtTemp; g.Name = jRFCase["title"].Value(); g.Notes = jRFCase["notes"].Value(); var ver = jRFCase["releaseVersion"].Value(); if (!string.IsNullOrWhiteSpace(ver)) g.Notes += $"\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\nReleased on version:{ver}"; var releaseNotes = jRFCase["releaseNotes"].Value(); if (!string.IsNullOrWhiteSpace(releaseNotes)) g.Notes += $"\nRelease notes:{releaseNotes}"; //Project name to tags g.Tags.Add(CaseProjectList.FirstOrDefault(z => z.Id == jRFCase["rfCaseProjectId"].Value()).Name.Replace("z_", "legacy-")); //priority to tags g.Tags.Add($"{jRFCase["priority"].Value()}-priority"); //check for attachments and just add as a note, don't bother with actual transfer of attachment, there aren't a lot and most are way in the past and not required for anything //if needed in future can manually xfer it over from the rockfish.sqlite db directly using DB BRowser for sqlite which allows opening the blob from the rfcaseblob table and saving it res = await client.GetAsync($"{URL_ROCKFISH}api/rfcase/{g.CaseId}/attachments"); responseText = await res.Content.ReadAsStringAsync(); var jAttachments = JObject.Parse(responseText); if (jAttachments["attach"].Count() > 0) { g.Notes += "\n********\nRockfish attachments\n"; foreach (JObject jAttachmentRecord in jAttachments["attach"]) { g.Notes += $"File: \"{jAttachmentRecord["name"].Value()}\", rfcaseblob table id: {jAttachmentRecord["id"].Value()}\n"; } g.Notes += "\n********\n"; } GZCaseBiz biz = GZCaseBiz.GetBiz(ct); await biz.CreateAsync(g); //attachments example 86400000 // /api/rfcase/4360/attachments //{"dlkey":"ZFkAUpo1L0Gi3Q9aO5szkA","attach":[{"id":259,"name":"desired weight calcs.txt"}]} //{"dlkey":"iR6ncD70CkzkozyT0otA","attach":[]} }// all cases loop //Start next case with a new sequence caseid of 4444 using (var command = ct.Database.GetDbConnection().CreateCommand()) { command.CommandText = $"ALTER SEQUENCE agzcase_caseid_seq RESTART WITH 4444;"; await ct.Database.OpenConnectionAsync(); await command.ExecuteNonQueryAsync(); await ct.Database.CloseConnectionAsync(); } } #endregion cases #region LICENSES log.LogInformation("RFImport Licenses"); { res = await client.GetAsync($"{URL_ROCKFISH}api/license/list"); responseText = await res.Content.ReadAsStringAsync(); var jaLicenseList = JArray.Parse(responseText); //some cases are missing the start date so substitute a close other case date (not critical but sb at least in the ballpark for list viewing purposes) DateTime dtTempCreated = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); foreach (JObject jLicenseListItem in jaLicenseList.Reverse()) { res = await client.GetAsync($"{URL_ROCKFISH}api/license/{jLicenseListItem["id"].Value()}"); responseText = await res.Content.ReadAsStringAsync(); var jLicense = JObject.Parse(responseText); // log.LogInformation($"Importing license:{responseText}"); /* {"regTo":"PDI Technologies","customerName":"PDI Technologies","dtcreated":1672261044,"email":"jberkel@pdisoftware.com","code":"na","fetched":true,"dtfetched":1672262347,"fetchFrom":null, "key":"[KEY\n{\n \"Key\": {\n \"LicenseFormat\": \"8\",\n \"Id\": \"1672261044\",\n \"RegisteredTo\": \"PDI Technologies\",\n \"DBID\": \"R6U37uNUN2hSQideG6Gg+MqoQY8vuUeyHFI6Kv7VDsE=\",\n \"Perpetual\": true,\n \"LicenseExpiration\": \"5555-01-01T00:00:00\",\n \"MaintenanceExpiration\": \"2023-12-28T00:00:00\",\n \"Features\": [\n {\n \"Name\": \"ActiveInternalUsers\",\n \"Count\": 5\n }\n ]\n }\n}\nKEY]\n[SIGNATURE\nkzVs8GH0MSIfsR7ZYQ5x+5wdVDJqpfOYvTfBCx32Vs+zqP7h89uUKI17jTx5rMvkOYX40GyJt0pTWOzltljzf+MaoTzoSvTsSPkWtdVWv8ZGOXUUdaZhzMoTJGxTg0JHka/8S5tLkTiuct3x+voiLAKXuFCp9TSZo4+UnejB6U2Bp6MfdZxLtKVZ/1RLu/h4SnP8ZbczuwbQReB1z4k4IRwjh5GHnUUm6YqZg/04m1X9FEeKQZQfGZk/qZ788jONbLQb4CLnq0/ZmIteeocDDBz59TYaC9BHwHp73y8jyPfEugVfyH2AE0J8ZILiFiozYQ7meP5X4ZOmd1nhTA8MkA==\nSIGNATURE]\n" } */ var l = new License(); l.RegTo = jLicense["regTo"].Value(); //try to match customer; rockfish didn't track customer id in the license so this is a bit wishy washy Customer cust = null; cust = await ct.Customer.AsNoTracking().FirstOrDefaultAsync(z => z.Name == jLicense["customerName"].Value()); if (cust == null)//email? cust = await ct.Customer.AsNoTracking().FirstOrDefaultAsync(z => z.EmailAddress.Contains(jLicense["email"].Value())); if (cust != null) l.CustomerId = cust.Id; var KeyText = jLicense["key"].Value(); if (KeyText.Contains("AyaNovaLicenseKey")) { //v7 key /* [KEY { "AyaNovaLicenseKey": { "SchemaVersion": "7", "Id": "1517418112", "Created": "2018-01-31T09:01:52.1878494-08:00", "Sub": "true", "RegisteredTo": "Direct Telecom Services", "EmailAddress": "chrisw@dts.solutions", "FetchCode": "AgYuDnjDyQ", "Source": "5246494432", "InstallableUntil": "2019-01-31T09:01:52.089767-08:00", "TotalScheduleableUsers": "15", "Expires": "2019-01-31T00:00:00", "RequestedTrial": "False", "Plugins": { "Plugin": [ { "Item": "MBI - Minimal browser interface", "SubscriptionExpires": "2018-06-13T00:00:00" }, { "Item": "WBI - Web browser interface", "SubscriptionExpires": "2018-06-13T00:00:00" }, { "Item": "OutlookSchedule", "SubscriptionExpires": "2018-06-13T00:00:00" }, { "Item": "AyaNovaOLI", "SubscriptionExpires": "2018-06-13T00:00:00" }, { "Item": "RI - Responsive Interface", "SubscriptionExpires": "2018-06-13T00:00:00" } ] } } } KEY] [SIGNATURE uBjnooIDd6MOiqT/z4tDQfeafkQiWDBtxDHXOxhZ7av1oWS72yPoe8BrAnDZiYbxE4+cHR3C0sPCgEVva5miV1foyi7P6YKkxkKQMxTUR5IssgWVHM59KnO1lR2ndCHWaqH3gHgSsb/sdvYfuHg8luTl1RgjNDZRdQqbPl4NLMcGGW86LoXjpLjsRRxImckBEJFnntd+aXCRmQjXEZWmfxDVW84qa6h+ZCOwL3KYJHuPQDcCmhcpp3MIR3OHoeYhmNG7TWuELsJ4hrsROcqSbEC/CdZD8hoZwtrysu/ZvNZOKchwFsiBaN47+DxK0K/fL/X8CDcG+w3iqgH/x5ipIw== SIGNATURE] */ string keyNoWS = System.Text.RegularExpressions.Regex.Replace(StringUtil.Extract(KeyText, "[KEY", "KEY]").Trim(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1"); var jKey = JObject.Parse(keyNoWS); l.LicenseExpire = DateTime.MaxValue.ToUniversalTime(); l.MaintenanceExpire = jKey["AyaNovaLicenseKey"]["Expires"].Value().ToUniversalTime(); l.PGroup = ProductGroup.AyaNova7; l.FetchCode = jLicense["code"].Value(); l.Tags.Add("v7"); } else if (KeyText.Contains("AyaNovaLiteLicenseKey")) { /* "[KEY\n{\n \"AyaNovaLiteLicenseKey\": {\n \"SchemaVersion\": \"7\",\n \"Id\": \"1648506791\",\n \"Created\": \"2022-03-28T15:33:11.6010225-07:00\",\n \"Sub\": \"true\",\n \"RegisteredTo\": \"Duncan Electric\",\n \"EmailAddress\": \"sandrajod@att.net\",\n \"FetchCode\": \"hGAmScqYcU\",\n \"Source\": \"5246494431\",\n \"InstallableUntil\": \"2023-03-28T15:33:11.6009851-07:00\",\n \"TotalScheduleableUsers\": \"1\",\n \"Expires\": \"2023-03-29T00:00:00\",\n \"RequestedTrial\": \"False\",\n \"Plugins\": {\n \"Plugin\": []\n }\n }\n}\nKEY]\n [SIGNATURE\nKuOF/SpBL1d8AFebvm2lipmKeGdbR6WzbhN68fun+ffVGRjXNX1jWI3rbf9P/shs2/M8gHqW/B7T0vVovGqosmNsGtvaYo30TKlZj9Eicr2+zDf7ojwZiBCeEnFzXr9+7aZrsZSvN20Pqof0xf/J4BVp1T66ecuZywMzH0NGsXXZtXhWYhGvLAZAR1X5/j5gqysSdysmV9j8Euz91zs/BRyfdU0uwwrdQzrJzI4V1MFl+/mIkhMUNcJ5bzjisWS2xeyNYCYnGpMF5oaGPaIcEtmTAdf5fPNNvw3sNhPaZgwlzN8FjfK6T0VgS19PcHCMOA1bTAiLLFNk6wkcjGp2Cw==\nSIGNATURE]\n" */ string keyNoWS = System.Text.RegularExpressions.Regex.Replace(StringUtil.Extract(KeyText, "[KEY", "KEY]").Trim(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1"); var jKey = JObject.Parse(keyNoWS); l.LicenseExpire = DateTime.MaxValue.ToUniversalTime(); l.MaintenanceExpire = jKey["AyaNovaLiteLicenseKey"]["Expires"].Value().ToUniversalTime(); l.PGroup = ProductGroup.AyaNova7; l.FetchCode = jLicense["code"].Value(); l.Tags.Add("v7"); l.Tags.Add("lite"); } else { //RAVEN KEY /* {{ "Key": { "LicenseFormat": "8", "Id": "1672261044", "RegisteredTo": "PDI Technologies", "DBID": "R6U37uNUN2hSQideG6Gg+MqoQY8vuUeyHFI6Kv7VDsE=", "Perpetual": true, "LicenseExpiration": "5555-01-01T00:00:00", "MaintenanceExpiration": "2023-12-28T00:00:00", "Features": [ { "Name": "ActiveInternalUsers", "Count": 5 } ] } }} */ string keyNoWS = System.Text.RegularExpressions.Regex.Replace(StringUtil.Extract(KeyText, "[KEY", "KEY]").Trim(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1"); var jKey = JObject.Parse(keyNoWS); l.DbId = jKey["Key"]["DBID"].Value(); l.LicenseExpire = jKey["Key"]["LicenseExpiration"].Value().ToUniversalTime(); //if (jKey["Key"]["Perpetual"].Value()) if ((bool?)jKey["Key"]["Perpetual"] ?? true) l.PGroup = ProductGroup.RavenPerpetual; else l.PGroup = ProductGroup.RavenSubscription; l.MaintenanceExpire = jKey["Key"]["MaintenanceExpiration"].Value().ToUniversalTime(); l.Tags.Add("raven"); } l.Created = (DateTime)DateUtil.EpochToDateNullIsNull(jLicense["dtcreated"].Value()); l.FetchedOn = DateUtil.EpochToDateNullIsNull(jLicense["dtfetched"].Value()); l.FetchEmail = jLicense["email"].Value(); l.Key = jLicense["key"].Value(); l.Active=true;//active here means it's been fully prepared and is viable for use, all prior licenses fit this description so all are active LicenseBiz biz = LicenseBiz.GetBiz(ct); await biz.CreateAsync(l); }// all licenses loop } #endregion licenses #region TRIAL LICENSE REQUESTS log.LogInformation("RFImport Raven trial requests"); { res = await client.GetAsync($"{URL_ROCKFISH}api/trial/list"); responseText = await res.Content.ReadAsStringAsync(); var jaTrialRequestList = JArray.Parse(responseText); foreach (JObject jTrialRequestItem in jaTrialRequestList.Reverse()) { /* /api/trial/list [ { "id": 296, "dbId": "R6U37uNUN2hSQideG6Gg+MqoQY8vuUeyHFI6Kv7VDsE=", "perpetual": true, "companyName": "PDI Technologies", "contactName": "Jason Berkel", "notes": null, "email": "jberkel@pdisoftware.com", "emailConfirmCode": "296RuWFbzuEps", "emailValidated": true, "dtRequested": 1672257483, "dtProcessed": 1672257587, "status": 1, "rejectReason": null, "key": "[KEY\n{\n \"Key\": {\n \"LicenseFormat\": \"8\",\n \"Id\": \"1672257587\",\n \"RegisteredTo\": \"PDI Technologies\",\n \"DBID\": \"R6U37uNUN2hSQideG6Gg+MqoQY8vuUeyHFI6Kv7VDsE=\",\n \"Perpetual\": true,\n \"LicenseExpiration\": \"2023-01-04T19:59:47.6170429Z\",\n \"MaintenanceExpiration\": \"2023-01-04T19:59:47.6170429Z\",\n \"Features\": [\n {\n \"Name\": \"TrialMode\"\n },\n {\n \"Name\": \"ActiveInternalUsers\",\n \"Count\": 5000\n }\n ]\n }\n}\nKEY]\n[SIGNATURE\ng/9yvrUi18PsllDyc4SJSlngmW3n411OtlFaGl3nK5SznCMf7CFDxH6eRqrvpI4452RblqAquHmsUUwFHIzKjaIj1VF3z1X9RHz7BcPrNX7lvWM8ErJb0jJjylKxvecaalMPXVxR1QLULDBFdVT5Gv0QUIzkFKVSwAF2mLUg1JNut939YoG2u95ABeQNe4SH7WQ3+gcsI/qSLcbzz/PmRMrWqPOzXi7jVbZTigfZLdbSC+DlUbNsCvkSgraEwBBnCpE8ZfCG1oFjdbP64qF1ArY7DbPUuxHNfPSZcDlhQz8D7JIqLTQwEijqvKfLy/KNMSlcfQtv5VBJtlwCP9ggdQ==\nSIGNATURE]\n", "dtFetched": 1672257635 }, */ var l = new TrialLicenseRequest(); l.DbId = jTrialRequestItem["dbId"].Value(); l.Perpetual = jTrialRequestItem["perpetual"].Value(); l.CompanyName = jTrialRequestItem["companyName"].Value(); l.ContactName = jTrialRequestItem["contactName"].Value(); l.Email = jTrialRequestItem["email"].Value(); l.EmailConfirmCode = jTrialRequestItem["emailConfirmCode"].Value(); l.EmailValidated = jTrialRequestItem["emailValidated"].Value(); l.Requested = (DateTime)DateUtil.EpochToDateNullIsNull(jTrialRequestItem["dtRequested"].Value()); l.Processed = DateUtil.EpochToDateNullIsNull(jTrialRequestItem["dtProcessed"].Value()); l.FetchedOn = DateUtil.EpochToDateNullIsNull(jTrialRequestItem["dtFetched"].Value()); l.Status = (TrialRequestStatus)jTrialRequestItem["status"].Value(); l.RejectReason = jTrialRequestItem["rejectReason"].Value(); l.Key = jTrialRequestItem["key"].Value(); var biz = TrialLicenseRequestBiz.GetBiz(ct); await biz.CreateAsync(l); }// all trial requests loop } #endregion trial requests log.LogInformation("RockFish import succeeded"); } catch (Exception ex) { var msg = "*** RockFish import FAILED ***"; log.LogError(ex, msg); } //in the correct order retrieve every object and if it's not already present in sockeye, import it //this should be callable any time and it will just update so it can be test live in sync / parallel until ready to switch over //await Task.CompletedTask; } private static ProductGroup ProductGroupFromProductCode(string productCode) { switch (productCode) { case "300740321"://wbi case "300740317"://up to 5 case "300740314"://RI case "300740328"://Quick notification case "300784766"://QBOI case "300740315"://Single case "300740323"://QBI case "300740318"://Up to 10 case "300740327"://Export to XLS case "300740329"://ImportExport CSV duplicate case "300740319"://Up to 20 case "300740322"://MBI case "300740324"://PTI case "300740325"://OLI case "300807973"://Up to 15 case "300740326"://Outlook Schedule Export case "300740316"://AyaNova LITE case "999"://Up to 999 return ProductGroup.AyaNova7; case "300093112"://Key administration case "301010670"://Custom 733918243 case "300151145"://Custom 539230073 return ProductGroup.Misc; case "301028317"://AyaNova perpetual single user license includes one year maintenance plan return ProductGroup.RavenPerpetual; case "301028468"://AyaNova subscription one user YEARLY case "301028467"://AyaNova subscription one user MONTHLY return ProductGroup.RavenSubscription; default: throw new Exception($"Uknown product code {productCode}"); } } /* "id" "name" "active" "vendorid" "licenseinterval" "maintinterval" "vendorcode" "ourcode" "wiki" "tags" 1 "WBI" true 1 "00:00:00" "365 days" "300740321" "300740321" "{}" 2 "Up to 5" true 1 "00:00:00" "365 days" "300740317" "300740317" "{}" 3 "RI" true 1 "00:00:00" "365 days" "300740314" "300740314" "{}" 4 "Quick Notification" true 1 "00:00:00" "365 days" "300740328" "300740328" "{}" 5 "QBOI" true 1 "00:00:00" "365 days" "300784766" "300784766" "{}" 6 "Single" true 1 "00:00:00" "365 days" "300740315" "300740315" "{}" 7 "QBI" true 1 "00:00:00" "365 days" "300740323" "300740323" "{}" 8 "Up to 10" true 1 "00:00:00" "365 days" "300740318" "300740318" "{}" 9 "Export to XLS" true 1 "00:00:00" "365 days" "300740327" "300740327" "{}" 10 "Importexport.csv duplicate" true 1 "00:00:00" "365 days" "300740329" "300740329" "{}" 11 "Up to 20" true 1 "00:00:00" "365 days" "300740319" "300740319" "{}" 12 "MBI" true 1 "00:00:00" "365 days" "300740322" "300740322" "{}" 13 "Key Administration" true 1 "00:00:00" "365 days" "300093112" "300093112" "{}" 14 "PTI " true 1 "00:00:00" "365 days" "300740324" "300740324" "{}" 15 "OLI" true 1 "00:00:00" "365 days" "300740325" "300740325" "{}" 16 "Up to 15" true 1 "00:00:00" "365 days" "300807973" "300807973" "{}" 17 "Outlook Schedule Export" true 1 "00:00:00" "365 days" "300740326" "300740326" "{}" 18 "AyaNova Lite" true 1 "00:00:00" "365 days" "300740316" "300740316" "{}" 19 "Up to 999" true 1 "00:00:00" "365 days" "999" "999" "{}" 20 "AyaNova perpetual single user license includes one year maintenance plan" true 1 "00:00:00" "365 days" "301028317" "301028317" "{}" 21 "Custom 733918243" true 1 "00:00:00" "365 days" "301010670" "301010670" "{}" 22 "AyaNova subscription one user monthly" true 1 "31 days" "31 days" "301028467" "301028467" "{}" 23 "Custom 539230073" true 1 "00:00:00" "365 days" "300151145" "300151145" "{}" 24 "AyaNova subscription one user yearly" true 1 "365 days" "365 days" "301028468" "301028468" "{}" */ ///////////////////////////////////////////////////////////////////// }//eoc }//eons