/// <summary> /// Binds the statistics. /// </summary> private void BindStatistics() { // calculate number of entries int recordsCount = 0; CatalogContext.Current.FindItemsDto(new CatalogSearchParameters(), new CatalogSearchOptions(), ref recordsCount); EntriesCount.InnerHtml = recordsCount > 0 ? recordsCount.ToString() : "0"; // calculate number of nodes recordsCount = 0; CatalogContext.Current.FindNodesDto(new CatalogSearchParameters(), new CatalogSearchOptions(), ref recordsCount); NodesCount.InnerHtml = recordsCount > 0 ? recordsCount.ToString() : "0"; // Calculate number of orders OrderSearchOptions orderoptions = new OrderSearchOptions(); orderoptions.Namespace = "Mediachase.Commerce.Orders"; orderoptions.Classes.Add("PurchaseOrder"); OrderContext.Current.FindPurchaseOrders(new OrderSearchParameters(), orderoptions, out recordsCount); OrdersCount.InnerHtml = recordsCount > 0 ? recordsCount.ToString() : "0"; // Calculate number of customers ProfileSearchOptions profileOptions = new ProfileSearchOptions(); profileOptions.Namespace = "Mediachase.Commerce.Profile"; profileOptions.Classes.Add("Account"); ProfileContext.Current.FindAccounts(new ProfileSearchParameters(), profileOptions, out recordsCount); CustomerCount.InnerHtml = recordsCount > 0 ? recordsCount.ToString() : "0"; // Calculate number of promotions recordsCount = PromotionManager.GetPromotionDto().Promotion.Count; PromotionCount.InnerHtml = recordsCount > 0 ? recordsCount.ToString() : "0"; }
/// <summary> /// Loads the organization items. /// </summary> /// <param name="iStartIndex">Start index of the i.</param> /// <param name="iNumItems">The i num items.</param> /// <param name="sFilter">The s filter.</param> private void LoadOrganizationItems(int iStartIndex, int iNumItems, string sFilter) { int total = 0; ProfileSearchParameters pars = new ProfileSearchParameters(); ProfileSearchOptions options = new ProfileSearchOptions(); pars.FreeTextSearchPhrase = sFilter; options.Namespace = "Mediachase.Commerce.Profile"; options.Classes.Add("Organization"); Organization[] orgs = ProfileContext.Current.FindOrganizations(pars, options, out total); total = orgs.Length; OrganizationFilter.Items.Clear(); foreach (Organization org in orgs) { ComboBoxItem item = new ComboBoxItem(org.Name); item.Value = org.Id.ToString(); OrganizationFilter.Items.Add(item); } OrganizationFilter.ItemCount = total; }
/// <summary> /// Binds the form. /// </summary> private void BindForm() { if (PrincipalId != Guid.Empty) { //first check permissions //if permissions not present, deny SecurityManager.CheckRolePermission("profile:org:mng:edit"); Organization org = ProfileContext.Current.GetOrganization(PrincipalId); if (org != null) { Name.Text = org.Name; Description.Text = org.Description; ProfileSearchParameters pars = new ProfileSearchParameters(); ProfileSearchOptions options = new ProfileSearchOptions(); pars.SqlMetaWhereClause = String.Format("OrganizationId = {0}", org.Id); options.Namespace = "Mediachase.Commerce.Profile"; options.Classes.Add("Account"); Account[] accounts = ProfileContext.Current.FindAccounts(pars, options); OrgMemberList.DataSource = accounts; OrgMemberList.DataBind(); ManagementHelper.SelectListItem(AccountState, org.State); } } else { //if permissions not present, deny SecurityManager.CheckRolePermission("profile:org:mng:create"); } }
/// <summary> /// Finds the organizations. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="options">The options.</param> /// <param name="totalRecords">The total records.</param> /// <returns></returns> public Organization[] FindOrganizations(ProfileSearchParameters parameters, ProfileSearchOptions options, out int totalRecords) { ProfileSearch search = new ProfileSearch(this); search.SearchOptions = options; search.SearchParameters = parameters; MetaStorageCollectionBase <Organization> orgs = Organization.Search(search, out totalRecords); return(orgs.ToArray()); }
/// <summary> /// Finds the accounts. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="options">The options.</param> /// <param name="totalRecords">The total records.</param> /// <returns></returns> public Account[] FindAccounts(ProfileSearchParameters parameters, ProfileSearchOptions options, out int totalRecords) { ProfileSearch search = new ProfileSearch(this); search.SearchOptions = options; search.SearchParameters = parameters; MetaStorageCollectionBase <Account> accounts = Account.Search(search, out totalRecords); return(accounts.ToArray()); }
/// <summary> /// Gets the total records. /// </summary> /// <returns></returns> private int GetTotalRecords() { int numRecords = 0; // Get Catalog Nodes ProfileSearchParameters pars = new ProfileSearchParameters(); ProfileSearchOptions options = new ProfileSearchOptions(); options.CacheResults = false; options.RecordsToRetrieve = 1; options.StartingRecord = 0; int totalCount = 0; ProfileContext.Current.FindAccounts(pars, options, out totalCount); numRecords += totalCount; return(numRecords); }
void BindOrganizationsList() { int total = 0; ProfileSearchParameters pars = new ProfileSearchParameters(); ProfileSearchOptions options = new ProfileSearchOptions(); //pars.FreeTextSearchPhrase = sFilter; options.Namespace = "Mediachase.Commerce.Profile"; options.Classes.Add("Organization"); Organization[] orgs = ProfileContext.Current.FindOrganizations(pars, options, out total); ddlOrganizations.Items.Clear(); ddlOrganizations.Items.Add(new ListItem("[all]", "[all]")); if (orgs != null) { foreach (Organization org in orgs) { ddlOrganizations.Items.Add(new ListItem(org.Name, org.Id.ToString())); } } }
/// <summary> /// Loads the member items. /// </summary> /// <param name="iStartIndex">Start index of the i.</param> /// <param name="iNumItems">The i num items.</param> /// <param name="sFilter">The s filter.</param> private void LoadMemberItems(int iStartIndex, int iNumItems, string sFilter) { int total = 0; ProfileSearchParameters pars = new ProfileSearchParameters(); ProfileSearchOptions options = new ProfileSearchOptions(); options.Namespace = "Mediachase.Commerce.Profile"; pars.FreeTextSearchPhrase = sFilter; options.Classes.Add("Account"); Account[] accounts = ProfileContext.Current.FindAccounts(pars, options, out total); foreach (Account acc in accounts) { ComboBoxItem newItem = new ComboBoxItem(); newItem.Text = acc.Name; newItem.Value = acc.PrincipalId.ToString(); CustomerName.Items.Add(newItem); } //CustomerName.DataSource = ProfileContext.Current.FindAccounts(pars, options, out total); CustomerName.ItemCount = total + 1; }
/// <summary> /// Loads the member items. /// </summary> /// <param name="iStartIndex">Start index of the i.</param> /// <param name="iNumItems">The i num items.</param> /// <param name="sFilter">The s filter.</param> private void LoadMemberItems(int iStartIndex, int iNumItems, string sFilter) { int total = 0; ProfileSearchParameters pars = new ProfileSearchParameters(); ProfileSearchOptions options = new ProfileSearchOptions(); options.Namespace = "Mediachase.Commerce.Profile"; options.Classes.Add("Account"); int totalAccounts = 0; Account[] accounts = ProfileContext.Current.FindAccounts(pars, options, out totalAccounts); total += totalAccounts; options.Classes.Clear(); options.Classes.Add("Organization"); Organization[] orgs = ProfileContext.Current.FindOrganizations(pars, options, out totalAccounts); total += totalAccounts; MembershipFilter.Items.Clear(); foreach (Account account in accounts) { ComboBoxItem item = new ComboBoxItem(account.Name); item.Value = account.PrincipalId.ToString(); MembershipFilter.Items.Add(item); } foreach (Organization org in orgs) { ComboBoxItem item = new ComboBoxItem(org.Name); item.Value = org.PrincipalId.ToString(); MembershipFilter.Items.Add(item); } MembershipFilter.ItemCount = total; }
/// <summary> /// Finds the organizations. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="options">The options.</param> /// <returns></returns> public Organization[] FindOrganizations(ProfileSearchParameters parameters, ProfileSearchOptions options) { int totalRecords = 0; return(FindOrganizations(parameters, options, out totalRecords)); }
/// <summary> /// Finds the accounts. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="options">The options.</param> /// <returns></returns> public Account[] FindAccounts(ProfileSearchParameters parameters, ProfileSearchOptions options) { int totalRecords = 0; return(FindAccounts(parameters, options, out totalRecords)); }
/// <summary> /// Builds the index. /// </summary> /// <param name="rebuild">if set to <c>true</c> [rebuild].</param> public override void BuildIndex(bool rebuild) { OnEvent(String.Format("ProfileIndexBuilder Started"), 0); IndexBuilder indexer = this.Indexer; DateTime lastBuild = DateTime.MinValue; // On complete rebuild no need to check date if (!rebuild) { lastBuild = indexer.GetBuildConfig().LastBuildDate; } double percentage = 0; bool incremental = false; int allRecords = 0; int allCurrentRecord = 0; int allRecordsCount = GetTotalRecords(); // If date is set, we do incremental rebuild if (lastBuild != DateTime.MinValue) { incremental = true; } int startingRecord = 0; // remove deleted items first if (incremental) { int totalRemoved = 0; while (true) { int count = 0; LogDto dto = LogManager.GetAppLog("profile", DataRowState.Deleted.ToString(), "ACCOUNT", lastBuild.ToUniversalTime(), startingRecord, 100, ref count); // add up to a total number to calculate percentage correctly if (startingRecord == 0) { allRecordsCount += count; } if (count <= 0) { break; } foreach (LogDto.ApplicationLogRow row in dto.ApplicationLog) { allCurrentRecord++; if (allCurrentRecord % 20 == 0) { percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100; OnEvent(String.Format("Removing old profile from index ({1}/{2}) ...", allCurrentRecord, count), percentage); } totalRemoved += indexer.DeleteContent("_id", row.ObjectKey); } startingRecord += 100; } percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100; OnEvent(String.Format("ProfileIndexBuilder Removed {0} records.", totalRemoved), percentage); } int currentRecord = 0; startingRecord = 0; int totalIndexed = 0; while (true) { ProfileSearchParameters pars = new ProfileSearchParameters(); ProfileSearchOptions options = new ProfileSearchOptions(); options.CacheResults = false; options.RecordsToRetrieve = 100; options.StartingRecord = startingRecord; if (incremental) { pars.SqlMetaWhereClause = String.Format("META.Modified > '{0}'", lastBuild.ToUniversalTime().ToString("s")); } int count = 0; Account[] accounts = ProfileContext.Current.FindAccounts(pars, options, out count); if (accounts == null) { break; } if (count <= 0) { break; } startingRecord += options.RecordsToRetrieve; foreach (Account account in accounts) { currentRecord++; allCurrentRecord++; // In case of incremental, check if item already exists and delete it if (incremental) { indexer.DeleteContent("_id", account.PrincipalId.ToString()); } totalIndexed += IndexAccount(indexer, account); if (allCurrentRecord % 20 == 0) { percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100; OnEvent(String.Format("Indexing profiles ({0}/{1}) ...", allCurrentRecord, allRecordsCount), percentage); } } if (startingRecord > count) { break; } } percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100; allRecords += totalIndexed; OnEvent(String.Format("ProfileIndexBuilder Indexed {0} records", allRecords.ToString()), 99); OnEvent(String.Format("ProfileIndexBuilder Finished"), 100); }