public static string GetValue(FieldInfo fieldInfo, LogInfo logInfo) { var value = string.Empty; if (logInfo.ContainsKey(fieldInfo.Title)) { if (fieldInfo.FieldType == InputType.CheckBox.Value || fieldInfo.FieldType == InputType.SelectMultiple.Value) { value = string.Join(",", PollUtils.JsonDeserialize <List <string> >(logInfo.Get <string>(fieldInfo.Title))); } else if (fieldInfo.FieldType == InputType.Date.Value) { var date = logInfo.Get <DateTime?>(fieldInfo.Title); if (date.HasValue) { value = date.Value.ToString("yyyy-MM-dd"); } } else if (fieldInfo.FieldType == InputType.DateTime.Value) { var datetime = logInfo.Get <DateTime?>(fieldInfo.Title); if (datetime.HasValue) { value = datetime.Value.ToString("yyyy-MM-dd HH:mm"); } } else { value = logInfo.Get <string>(fieldInfo.Title); } } return(value); }
public IHttpActionResult Get() { try { var request = Context.AuthenticatedRequest; var siteId = request.GetQueryInt("siteId"); if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(siteId, PollUtils.PluginId)) { return(Unauthorized()); } var formInfoList = PollManager.GetPollInfoList(siteId, 0); var type = request.GetQueryString("type"); var name = request.GetQueryString("name"); var templateInfoList = TemplateManager.GetTemplateInfoList(type); var templateInfo = templateInfoList.FirstOrDefault(x => PollUtils.EqualsIgnoreCase(name, x.Name)); return(Ok(new { Value = templateInfo, PollInfoList = formInfoList })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public static void ExportPoll(int siteId, string directoryPath, int pollId) { var pollInfo = PollManager.GetPollInfo(siteId, pollId); var filePath = PollUtils.PathCombine(directoryPath, pollInfo.Id + ".xml"); var feed = GetEmptyFeed(); foreach (var tableColumn in PollManager.Repository.TableColumns) { SetValue(feed.AdditionalElements, tableColumn, pollInfo); } var styleDirectoryPath = PollUtils.PathCombine(directoryPath, pollInfo.Id.ToString()); ExportFields(pollInfo.Id, styleDirectoryPath); var logInfoList = LogManager.Repository.GetLogInfoList(pollInfo.Id, 0, 0); foreach (var logInfo in logInfoList) { var entry = GetAtomEntry(logInfo); feed.Entries.Add(entry); } feed.Save(filePath); }
public static void SetTemplateHtml(TemplateInfo templateInfo, string html) { var directoryPath = GetTemplatesDirectoryPath(); var htmlPath = PollUtils.PathCombine(directoryPath, templateInfo.Name, templateInfo.Main); PollUtils.WriteText(htmlPath, html); }
public void ThenInNameTableFollowingEntriesAreCreated(Table table) { var imis = Context <IMIS>(IMIS); var pc = Ctx.PrimaryContact; var account = PollUtils.Poll <Account>( $"Get initial name entries since {ImisStartTime}", DB_TIMEOUT, DB_INTERVAL, () => new Account(imis, pc.CompanyName, pc.FirstName, pc.LastName), (acct) => table.Rows.All(row => { var n = Int32.Parse(row["Count"]); return(acct[row["MemberType"]] .Where(o => o.LAST_UPDATED >= ImisStartTime) .Count() >= n); }) ); account.ShouldNotBeNull(); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10)); var coId = account["CM"].First().ID; account = new Account(imis, coId); foreach (var row in table.Rows) { var t = row["MemberType"]; var n = Int32.Parse(row["Count"]); account[t].Where(o => o.LAST_UPDATED >= ImisStartTime).Count().ShouldBe(n); } }
public static string GetTemplateHtml(TemplateInfo templateInfo) { var directoryPath = GetTemplatesDirectoryPath(); var htmlPath = PollUtils.PathCombine(directoryPath, templateInfo.Name, templateInfo.Main); return(CacheGetFileContent(htmlPath)); }
public void ThenSubscriptionEntriesAreCreatedAsFollows(Table table) { var imis = Context <IMIS>(IMIS); var pc = Ctx.PrimaryContact; var coId = imis.NamesByCompanyAndUser(pc.CompanyName, pc.FirstName, pc.LastName).First().CO_ID; Console.WriteLine($"CO_ID={coId}"); var expectedCount = Ctx.NewAccount ? 1 : Ctx.Capacities.Count(); PollUtils.Poll <IEnumerable <Subscription> >( $"Querying subscriptions table for CO_ID={coId}", DB_TIMEOUT, DB_INTERVAL, () => imis.SubscriptionsForCompany(coId), x => table.Rows.All(row => x.Where(o => o.DATE_ADDED > ImisStartTime && o.PRODUCT_CODE == row["ProductCode"]) .Count() == Int32.Parse(row["Count"]) ) ); // Wait 10 more seconds just in case database changes further. System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10)); var subs = imis.SubscriptionsForCompany(coId).Where(o => o.DATE_ADDED >= ImisStartTime); var expectedTotal = table.Rows.Sum(o => Int32.Parse(o["Count"])); var extra = Ctx.NewAccount ? 0 : subs.Where(o => o.PRODUCT_CODE == "PC_AN_CAP").Count(); subs.Count().ShouldBe(expectedTotal + extra); foreach (var row in table.Rows) { subs.Where(o => o.PRODUCT_CODE == row["ProductCode"]) .Count().ShouldBe(Int32.Parse(row["Count"])); } }
private static bool IsSelectFieldType(string fieldType) { return(PollUtils.EqualsIgnoreCase(fieldType, InputType.CheckBox.Value) || PollUtils.EqualsIgnoreCase(fieldType, InputType.Radio.Value) || PollUtils.EqualsIgnoreCase(fieldType, InputType.SelectMultiple.Value) || PollUtils.EqualsIgnoreCase(fieldType, InputType.SelectOne.Value)); }
public void ThenIReceiveTheWelcomeKitEmail() { var host = TestSetup.TestAccountImapHost; var port = TestSetup.TestAccountImapPort; var email = TestSetup.TestAccountEmail; var password = TestSetup.TestAccountEmailPassword; var imis = Context <IMIS>(ContextKeys.IMIS); var pc = Ctx.PrimaryContact; var coId = PollUtils.Poll <IEnumerable <Name> >( $"Query name entry by company and primary: {pc.CompanyName} {pc.FirstName} {pc.LastName}", TestSetup.DbTimeout, TestSetup.DbPollInterval, () => imis.NamesByCompanyAndUser(pc.CompanyName, pc.FirstName, pc.LastName), x => x.Where(o => o.LAST_UPDATED > ImisStartTime).Count() > 0 ).First().CO_ID; PollUtils.Poll <bool>( $"Search Welcome Kit in inbox for CO_ID={coId}", 180, 30, () => { var mail = new Mail.MailClient(host, port, email, password); var r = mail.ReceivedWelcomeKit(Ctx.StartTime, coId, pc.CompanyName); mail.Disconnect(); return(r); }, x => x == true ).ShouldBeTrue(); }
public static void Edit(TemplateInfo templateInfo) { var directoryPath = Context.PluginApi.GetPluginPath(PollUtils.PluginId, "templates"); var configJson = Context.UtilsApi.JsonSerialize(templateInfo); var configPath = PollUtils.PathCombine(directoryPath, templateInfo.Name, "config.json"); PollUtils.WriteText(configPath, configJson); }
public void ThenICheckThisPrefixIsNotInCompanyPrefixTable() { var prefix = Setup.TestSetup.UiisContext.PrefixToVendOrHold; PollUtils.Poll( $"Querying prefix {prefix}", 60, 5, () => Setup.TestSetup.UiisDb.GetPrefixByValue(prefix), o => o.Count() == 0 ).ShouldBeEmpty(); }
public void WhenICheckThisIdentifierAvailableInCompanyPrefixHoldTable() { var prefix = Setup.TestSetup.UiisContext.PrefixToVendOrHold; PollUtils.Poll( $"Querying held prefix {prefix}", 60, 5, () => Setup.TestSetup.UiisDb.GetHeldPrefixByValue(prefix), o => o.Count() > 0 ).First().Value.ShouldBe(prefix); }
public IHttpActionResult Import() { try { var request = Context.AuthenticatedRequest; var pollInfo = PollManager.GetPollInfo(request); if (pollInfo == null) { return(NotFound()); } if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(pollInfo.SiteId, PollUtils.PluginId)) { return(Unauthorized()); } foreach (string name in HttpContext.Current.Request.Files) { var postFile = HttpContext.Current.Request.Files[name]; if (postFile == null) { return(BadRequest("Could not read zip from body")); } var filePath = Context.UtilsApi.GetTemporaryFilesPath("poll.zip"); PollUtils.DeleteFileIfExists(filePath); if (!PollUtils.EqualsIgnoreCase(Path.GetExtension(postFile.FileName), ".zip")) { return(BadRequest("zip file extension is not correct")); } postFile.SaveAs(filePath); var directoryPath = Context.UtilsApi.GetTemporaryFilesPath("poll"); PollUtils.DeleteDirectoryIfExists(directoryPath); Context.UtilsApi.ExtractZip(filePath, directoryPath); var isHistoric = PollBox.IsHistoric(directoryPath); PollBox.ImportFields(pollInfo.SiteId, pollInfo.Id, directoryPath, isHistoric); //FieldManager.Import(pollInfo.SiteId, pollInfo.Id, filePath); } return(Ok(new { Value = true })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public void ThenRelationshipEntriesAreCreatedCorrectly() { var imis = Context <IMIS>(IMIS); var pc = Ctx.PrimaryContact; PollUtils.Poll( $"Query relationships for company {pc.CompanyName}", DB_TIMEOUT, DB_INTERVAL, () => { var coId = imis.NamesByCompanyAndUser(pc.CompanyName, pc.FirstName, pc.LastName).First().CO_ID; return(imis.RelationshipsByCoId(coId)); }, (e) => { try { return(f(e)); } catch { return(false); }; } ); bool f(IEnumerable <Relationship> entries) { var keyRel = entries.Where((o) => o.RELATION_TYPE == "KEY").First(); var billRel = entries.Where((o) => o.RELATION_TYPE == "BILL").First(); var ceoRel = entries.Where((o) => o.RELATION_TYPE == "CEO").First(); var result = true; var coId = imis.NamesByCompanyAndUser(pc.CompanyName, pc.FirstName, pc.LastName).First().CO_ID; var names = imis.NamesByCoId(coId); var pName = names.Where(o => o.ID == keyRel.TARGET_ID).First(); result = result && pName.FIRST_NAME == pc.FirstName; result = result && pName.LAST_NAME == pc.LastName; result = keyRel.TARGET_ID == billRel.TARGET_ID; if (result == false) { return(false); } var ec = Ctx.ExecutiveContact; var eName = names.Where(o => o.ID == ceoRel.TARGET_ID).First(); result = result && eName.FIRST_NAME == ec.FirstName; result = result && eName.LAST_NAME == ec.LastName; return(result); } }
public void ThenISeeThisRangeInCompanyPrefixAvailableRangeTable() { var range = Setup.TestSetup.UiisContext.Range; var ars = PollUtils.Poll( $"Query available range for {range}", 60, 5, () => Setup.TestSetup.UiisDb.AvailableRangeByPredicate(range), xs => xs.Count() > 0 ); ars.Count().ShouldBe(1); }
public void ThenISeeInCompanyPrefixRangeTableAutoAssignIs1(int autoAssign) { var range = Setup.TestSetup.UiisContext.Range; var prs = PollUtils.Poll( $"Query open range for {range}", 60, 5, () => Setup.TestSetup.UiisDb.OpenRangeByPredicate(range), xs => xs.Count() > 0 ); prs.All(o => o.AutoAssign); }
public void ThenTheRangePredicateGetsRemovedFromCompanyPrefixRangeTable() { var range = Setup.TestSetup.UiisContext.Range; var ars = PollUtils.Poll( $"Query open range for {range}", 60, 5, () => Setup.TestSetup.UiisDb.OpenRangeByPredicate(range), xs => xs.Count() == 0 ); ars.Count().ShouldBe(0); }
public void ThenTheRangePredicateGetAddedToCompanyPrefixRangeTable() { var range = Setup.TestSetup.UiisContext.Range; var ranges = PollUtils.Poll( $"Query open range for {range}", 60, 5, () => Setup.TestSetup.UiisDb.OpenRangeByPredicate(range), xs => xs.Count() > 0 ); ranges.Count().ShouldBe(1); }
public IHttpActionResult Get() { try { var request = Context.AuthenticatedRequest; var pollInfo = PollManager.GetPollInfo(request); if (pollInfo == null) { return(NotFound()); } if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(pollInfo.SiteId, PollUtils.PluginId)) { return(Unauthorized()); } var fieldInfoList = FieldManager.GetFieldInfoList(pollInfo.Id); var listAttributeNames = PollUtils.StringCollectionToStringList(pollInfo.ListAttributeNames); var allAttributeNames = PollManager.GetAllAttributeNames(fieldInfoList); var pages = Convert.ToInt32(Math.Ceiling((double)pollInfo.TotalCount / PollUtils.PageSize)); if (pages == 0) { pages = 1; } var page = request.GetQueryInt("page", 1); if (page > pages) { page = pages; } var logInfoList = LogManager.Repository.GetLogInfoList(pollInfo, page); var logs = new List <Dictionary <string, object> >(); foreach (var logInfo in logInfoList) { logs.Add(LogManager.GetDict(fieldInfoList, logInfo)); } return(Ok(new { Value = logs, Count = pollInfo.TotalCount, Pages = pages, Page = page, FieldInfoList = fieldInfoList, AllAttributeNames = allAttributeNames, ListAttributeNames = listAttributeNames })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public void ThenICheckThisPrefixIsNotAvailableInCompanyPrefixHoldTable() { var prefix = Setup.TestSetup.UiisContext.PrefixToVendOrHold; Console.WriteLine($"prefix {prefix}"); PollUtils.Poll( $"Querying held prefix {prefix}", 60, 5, () => Setup.TestSetup.UiisDb.GetHeldPrefixByValue(prefix), o => o.Count() == 0 ).ShouldBeEmpty(); }
public static bool IsHistoric(string directoryPath) { if (!PollUtils.IsFileExists(PollUtils.PathCombine(directoryPath, VersionFileName))) { return(true); } PollUtils.DeleteFileIfExists(PollUtils.PathCombine(directoryPath, VersionFileName)); return(false); }
public void ThenICheckThisPrefixInCompanyPrefixTable() { var page = new Pages.Confirmation(Setup.TestSetup.Driver); var prefix = page.GetVendedPrefix(); Console.WriteLine($"prefix = {prefix}"); PollUtils.Poll( $"Querying prefix {prefix}", 60, 5, () => Setup.TestSetup.UiisDb.GetPrefixByValue(prefix), o => o.Count() > 0 ).First().Value.ShouldBe(prefix); }
public static void DeleteTemplate(string name) { if (string.IsNullOrEmpty(name)) { return; } var directoryPath = GetTemplatesDirectoryPath(); var templatePath = PollUtils.PathCombine(directoryPath, name); PollUtils.DeleteDirectoryIfExists(templatePath); }
public void ThenInSubscriptionsTableBillingAmountsAreCorrect() { var imis = Context <IMIS>(IMIS); var pc = Ctx.PrimaryContact; var coId = imis.NamesByCompanyAndUser(pc.CompanyName, pc.FirstName, pc.LastName).First().CO_ID; Console.WriteLine($"CO_ID={coId}"); int expectedCount; if (Ctx.NewAccount) { expectedCount = 2; } else { var cm = imis.NamesByCoId(coId).Where(o => o.MEMBER_TYPE == "CM").First(); var multiplier = cm.PAID_THRU.Month == DateTime.Now.Month ? 2 : 3; expectedCount = multiplier * Ctx.Capacities.Count(); } var subs = PollUtils.Poll <IEnumerable <Subscription> >( $"Querying subscriptions table for CO_ID={coId}", DB_TIMEOUT, DB_INTERVAL, () => imis.SubscriptionsForCompany(coId), x => { var list = x.Where(o => o.DATE_ADDED >= ImisStartTime); if (!Ctx.NewAccount) { list = list.Where(o => o.PRODUCT_CODE != "PC_AN_CAP"); } return(list.Count() == expectedCount); } ).Where(o => o.DATE_ADDED >= ImisStartTime); var(fee1, fee2, fee3) = Ctx.BillingAmounts(); subs.Where(o => o.PRODUCT_CODE == "PC_AN_CAP" || o.PRODUCT_CODE == "PC_AN_CAP_A") .Select(o => o.BILL_AMOUNT) .Sum() .ShouldBeInRange(fee1 - 0.1, fee1 + 0.1); subs.Where(o => o.PRODUCT_CODE == "PC_AN_CAP1" || o.PRODUCT_CODE == "PC_AN_CAP_A1") .Select(o => o.BILL_AMOUNT) .Sum() .ShouldBeInRange(fee2 - 0.1, fee2 + 0.1); subs.Where(o => o.PRODUCT_CODE == "PC_AN_CAP_A2") .Select(o => o.BILL_AMOUNT) .Sum() .ShouldBeInRange(fee3 - 0.1, fee3 + 0.1); }
private static TemplateInfo GetTemplateInfo(string templatesDirectoryPath, string name) { TemplateInfo templateInfo = null; var configPath = PollUtils.PathCombine(templatesDirectoryPath, name, "config.json"); if (PollUtils.IsFileExists(configPath)) { templateInfo = Context.UtilsApi.JsonDeserialize <TemplateInfo>(PollUtils.ReadText(configPath)); templateInfo.Name = name; } return(templateInfo); }
public IHttpActionResult Get() { try { var request = Context.AuthenticatedRequest; var pollInfo = PollManager.GetPollInfo(request); if (pollInfo == null) { return(NotFound()); } if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(pollInfo.SiteId, PollUtils.PluginId)) { return(Unauthorized()); } var logId = request.GetQueryInt("logId"); var fieldInfoList = FieldManager.GetFieldInfoList(pollInfo.Id); if (logId > 0) { var logInfo = LogManager.Repository.GetLogInfo(logId); foreach (var fieldInfo in fieldInfoList) { if (fieldInfo.FieldType == InputType.CheckBox.Value || fieldInfo.FieldType == InputType.SelectMultiple.Value) { fieldInfo.Value = PollUtils.JsonDeserialize <List <string> >(logInfo.Get <string>(fieldInfo.Title)); } else if (fieldInfo.FieldType == InputType.Date.Value || fieldInfo.FieldType == InputType.DateTime.Value) { fieldInfo.Value = logInfo.Get <DateTime>(fieldInfo.Title); } else { fieldInfo.Value = logInfo.Get <string>(fieldInfo.Title); } } } return(Ok(new { Value = fieldInfoList })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult Clone() { try { var request = Context.AuthenticatedRequest; var siteId = request.GetQueryInt("siteId"); if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(siteId, PollUtils.PluginId)) { return(Unauthorized()); } var type = request.GetQueryString("type"); var originalName = request.GetPostString("originalName"); var name = request.GetPostString("name"); var description = request.GetPostString("description"); var templateHtml = request.GetPostString("templateHtml"); var templateInfoList = TemplateManager.GetTemplateInfoList(type); var originalTemplateInfo = templateInfoList.First(x => PollUtils.EqualsIgnoreCase(originalName, x.Name)); if (templateInfoList.Any(x => PollUtils.EqualsIgnoreCase(name, x.Name))) { return(BadRequest($"标识为 {name} 的模板已存在,请更换模板标识!")); } var templateInfo = new TemplateInfo { Name = name, Main = originalTemplateInfo.Main, Publisher = string.Empty, Description = description, Icon = originalTemplateInfo.Icon }; templateInfoList.Add(templateInfo); TemplateManager.Clone(originalName, templateInfo, templateHtml); return(Ok(new { Value = true })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult Upload() { try { var request = Context.AuthenticatedRequest; var pollInfo = PollManager.GetPollInfo(request); if (pollInfo == null) { return(NotFound()); } if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(pollInfo.SiteId, PollUtils.PluginId)) { return(Unauthorized()); } var imageUrl = string.Empty; foreach (string name in HttpContext.Current.Request.Files) { var postFile = HttpContext.Current.Request.Files[name]; if (postFile == null) { return(BadRequest("Could not read image from body")); } var filePath = Context.SiteApi.GetUploadFilePath(pollInfo.SiteId, postFile.FileName); if (!PollUtils.IsImage(Path.GetExtension(filePath))) { return(BadRequest("image file extension is not correct")); } postFile.SaveAs(filePath); imageUrl = Context.SiteApi.GetSiteUrlByFilePath(filePath); } return(Ok(new { Value = imageUrl })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public static string GetListHtml() { var directoryPath = GetTemplatesDirectoryPath(); var htmlPath = PollUtils.PathCombine(directoryPath, "list.html"); var html = CacheUtils.Get <string>(htmlPath); if (html != null) { return(html); } html = PollUtils.ReadText(htmlPath); CacheUtils.Insert(htmlPath, html, 24); return(html); }
public static void Clone(string nameToClone, TemplateInfo templateInfo, string templateHtml = null) { var directoryPath = Context.PluginApi.GetPluginPath(PollUtils.PluginId, "templates"); PollUtils.CopyDirectory(PollUtils.PathCombine(directoryPath, nameToClone), PollUtils.PathCombine(directoryPath, templateInfo.Name), true); var configJson = Context.UtilsApi.JsonSerialize(templateInfo); var configPath = PollUtils.PathCombine(directoryPath, templateInfo.Name, "config.json"); PollUtils.WriteText(configPath, configJson); if (templateHtml != null) { SetTemplateHtml(templateInfo, templateHtml); } }