public void LoadGoogleGroups() { GroupsQuery query = new GroupsQuery(GroupsQuery.CreateGroupsUri("default")); query.NumberToRetrieve = 256; query.StartIndex = 0; query.ShowDeleted = false; GroupsFeed feed; feed = _googleService.Query(query); _googleGroups = feed.Entries; while (feed.Entries.Count == query.NumberToRetrieve) { query.StartIndex = _googleGroups.Count; feed = _googleService.Query(query); foreach (AtomEntry a in feed.Entries) { _googleGroups.Add(a); } } }
public void LoadGoogleContacts() { ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default")); query.NumberToRetrieve = 256; query.StartIndex = 0; query.ShowDeleted = false; //query.OrderBy = "lastmodified"; ContactsFeed feed; feed = _googleService.Query(query); _googleContacts = feed.Entries; while (feed.Entries.Count == query.NumberToRetrieve) { query.StartIndex = _googleContacts.Count; feed = _googleService.Query(query); foreach (AtomEntry a in feed.Entries) { _googleContacts.Add(a); } } }
// 内部消化掉错误 private void ImportContents(AtomEntryCollection entries, ChannelInfo channelInfo, int taxis, int importStart, int importCount, bool isCheckedBySettings, bool isChecked, int checkedLevel, bool isOverride, string adminName) { if (importStart > 1 || importCount > 0) { var theEntries = new AtomEntryCollection(); if (importStart == 0) { importStart = 1; } if (importCount == 0) { importCount = entries.Count; } var firstIndex = entries.Count - importStart - importCount + 1; if (firstIndex <= 0) { firstIndex = 0; } var addCount = 0; for (var i = 0; i < entries.Count; i++) { if (addCount >= importCount) { break; } if (i >= firstIndex) { theEntries.Add(entries[i]); addCount++; } } entries = theEntries; } var tableName = ChannelManager.GetTableName(_siteInfo, channelInfo); foreach (AtomEntry entry in entries) { try { taxis++; var lastEditDate = AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.LastEditDate); var groupNameCollection = AtomUtility.GetDcElementContent(entry.AdditionalElements, new List <string> { ContentAttribute.GroupNameCollection, "ContentGroupNameCollection" }); if (isCheckedBySettings) { isChecked = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.IsChecked)); checkedLevel = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.CheckedLevel)); } var hits = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.Hits)); var hitsByDay = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.HitsByDay)); var hitsByWeek = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.HitsByWeek)); var hitsByMonth = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.HitsByMonth)); var lastHitsDate = AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.LastHitsDate); var title = AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.Title); var isTop = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.IsTop)); var isRecommend = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.IsRecommend)); var isHot = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.IsHot)); var isColor = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.IsColor)); var linkUrl = AtomUtility.Decrypt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.LinkUrl)); var addDate = AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.AddDate); var topTaxis = 0; if (isTop) { topTaxis = taxis - 1; taxis = DataProvider.ContentDao.GetMaxTaxis(tableName, channelInfo.Id, true) + 1; } var tags = AtomUtility.Decrypt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.Tags)); var dict = new Dictionary <string, object> { { ContentAttribute.SiteId, _siteInfo.Id }, { ContentAttribute.ChannelId, channelInfo.Id }, { ContentAttribute.AddUserName, adminName }, { ContentAttribute.AddDate, TranslateUtils.ToDateTime(addDate) } }; var contentInfo = new ContentInfo(dict); contentInfo.LastEditUserName = contentInfo.AddUserName; contentInfo.LastEditDate = TranslateUtils.ToDateTime(lastEditDate); contentInfo.GroupNameCollection = groupNameCollection; contentInfo.Tags = tags; contentInfo.IsChecked = isChecked; contentInfo.CheckedLevel = checkedLevel; contentInfo.Hits = hits; contentInfo.HitsByDay = hitsByDay; contentInfo.HitsByWeek = hitsByWeek; contentInfo.HitsByMonth = hitsByMonth; contentInfo.LastHitsDate = TranslateUtils.ToDateTime(lastHitsDate); contentInfo.Title = AtomUtility.Decrypt(title); contentInfo.IsTop = isTop; contentInfo.IsRecommend = isRecommend; contentInfo.IsHot = isHot; contentInfo.IsColor = isColor; contentInfo.LinkUrl = linkUrl; var attributes = AtomUtility.GetDcElementNameValueCollection(entry.AdditionalElements); foreach (string attributeName in attributes.Keys) { if (!contentInfo.ContainsKey(attributeName.ToLower())) { contentInfo.Set(attributeName, AtomUtility.Decrypt(attributes[attributeName])); } } var isInsert = false; if (isOverride) { var existsIDs = DataProvider.ContentDao.GetIdListBySameTitle(tableName, contentInfo.ChannelId, contentInfo.Title); if (existsIDs.Count > 0) { foreach (int id in existsIDs) { contentInfo.Id = id; DataProvider.ContentDao.Update(_siteInfo, channelInfo, contentInfo); } } else { isInsert = true; } } else { isInsert = true; } if (isInsert) { var contentId = DataProvider.ContentDao.InsertWithTaxis(tableName, _siteInfo, channelInfo, contentInfo, taxis); if (!string.IsNullOrEmpty(tags)) { var tagCollection = TagUtils.ParseTagsString(tags); TagUtils.AddTags(tagCollection, _siteInfo.Id, contentId); } } if (isTop) { taxis = topTaxis; } } catch { // ignored } } }
private async Task ImportContentsAsync(AtomEntryCollection entries, Channel channel, int taxis, int importStart, int importCount, bool isCheckedBySettings, bool isChecked, int checkedLevel, bool isOverride, int adminId, string guid) { if (importStart > 1 || importCount > 0) { var theEntries = new AtomEntryCollection(); if (importStart == 0) { importStart = 1; } if (importCount == 0) { importCount = entries.Count; } var firstIndex = entries.Count - importStart - importCount + 1; if (firstIndex <= 0) { firstIndex = 0; } var addCount = 0; for (var i = 0; i < entries.Count; i++) { if (addCount >= importCount) { break; } if (i >= firstIndex) { theEntries.Add(entries[i]); addCount++; } } entries = theEntries; } var contents = new List <Content>(); foreach (AtomEntry entry in entries) { try { taxis++; var groupNames = AtomUtility.GetDcElementContent(entry.AdditionalElements, new List <string> { nameof(Content.GroupNames), "GroupNameCollection", "ContentGroupNameCollection" }); var tagNames = AtomUtility.Decrypt(AtomUtility.GetDcElementContent(entry.AdditionalElements, new List <string> { nameof(Content.TagNames), "Tags" })); if (isCheckedBySettings) { isChecked = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, new List <string> { nameof(Content.Checked), "IsChecked" })); checkedLevel = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(Content.CheckedLevel))); } var hits = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(Content.Hits))); var hitsByDay = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(Content.HitsByDay))); var hitsByWeek = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(Content.HitsByWeek))); var hitsByMonth = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(Content.HitsByMonth))); var lastHitsDate = AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(Content.LastHitsDate)); var downloads = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(Content.Downloads))); var title = AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(Content.Title)); var isTop = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, new List <string> { nameof(Content.Top), "IsTop" })); var isRecommend = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, new List <string> { nameof(Content.Recommend), "IsRecommend" })); var isHot = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, new List <string> { nameof(Content.Hot), "IsHot" })); var isColor = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, new List <string> { nameof(Content.Color), "IsColor" })); var linkUrl = AtomUtility.Decrypt(AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(Content.LinkUrl))); var addDate = AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(Content.AddDate)); var body = AtomUtility.Decrypt(AtomUtility.GetDcElementContent(entry.AdditionalElements, new List <string> { nameof(Content.Body), "Content" })); var topTaxis = 0; if (isTop) { topTaxis = taxis - 1; taxis = await _databaseManager.ContentRepository.GetMaxTaxisAsync(_site, channel, true) + 1; } var dict = new Dictionary <string, object>(); var attributes = AtomUtility.GetDcElementNameValueCollection(entry.AdditionalElements); foreach (string attributeName in attributes.Keys) { dict[attributeName] = AtomUtility.Decrypt(attributes[attributeName]); } var content = new Content(); content.LoadDict(dict); content.SiteId = _site.Id; content.ChannelId = channel.Id; content.AddDate = TranslateUtils.ToDateTime(addDate); content.AdminId = adminId; content.LastEditAdminId = adminId; content.GroupNames = ListUtils.GetStringList(groupNames); content.TagNames = ListUtils.GetStringList(tagNames); content.Checked = isChecked; content.CheckedLevel = checkedLevel; content.Hits = hits; content.HitsByDay = hitsByDay; content.HitsByWeek = hitsByWeek; content.HitsByMonth = hitsByMonth; content.LastHitsDate = TranslateUtils.ToDateTime(lastHitsDate); content.Downloads = downloads; content.Title = AtomUtility.Decrypt(title); content.Top = isTop; content.Recommend = isRecommend; content.Hot = isHot; content.Color = isColor; content.LinkUrl = linkUrl; content.Body = body; var isInsert = false; if (isOverride) { var existsIDs = await _databaseManager.ContentRepository.GetContentIdsBySameTitleAsync(_site, channel, content.Title); if (existsIDs.Count > 0) { foreach (var id in existsIDs) { content.Id = id; contents.Add(content); } } else { isInsert = true; } } else { isInsert = true; } if (isInsert) { content.Taxis = taxis; contents.Add(content); if (!string.IsNullOrEmpty(tagNames)) { foreach (var tagName in ListUtils.GetStringList(tagNames)) { await _databaseManager.ContentTagRepository.InsertAsync(_site.Id, tagName); } } } if (isTop) { taxis = topTaxis; } } catch (Exception ex) { await _databaseManager.ErrorLogRepository.AddErrorLogAsync(ex, "导入内容"); } } foreach (var content in contents) { _caching.SetProcess(guid, $"导入内容: {content.Title}"); if (content.Id > 0) { await _databaseManager.ContentRepository.UpdateAsync(_site, channel, content); } else { await _databaseManager.ContentRepository.InsertWithTaxisAsync(_site, channel, content, content.Taxis); } } }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>creates a number or rows and delets them again</summary> ////////////////////////////////////////////////////////////////////// [Test] public void DefaultHostMassiveInsertAndDelete() { Tracing.TraceMsg("Entering DefaultHostMassiveInsertAndDelete"); int iCount = 0; FeedQuery query = new FeedQuery(); Service service = new Service(); service.RequestFactory = this.factory; query.Uri = new Uri(this.defaultHost); AtomFeed returnFeed = service.Query(query); AtomEntry entry; iCount = returnFeed.Entries.Count; AtomEntryCollection newEntries = new AtomEntryCollection(null); // now we have all we need. for (int i = 0; i < this.iIterations; i++) { entry = ObjectModelHelper.CreateAtomEntry(i); entry = returnFeed.Insert(entry); newEntries.Add(entry); } Tracing.TraceMsg("DefaultHostMassiveInsert: inserted lot's of entries"); // done doing the inserts... // now query the guy again. returnFeed = service.Query(query); Assert.AreEqual(iCount + this.iIterations, returnFeed.Entries.Count, "feed should have " + this.iIterations + " more entries now"); // now udpate the 100 entries we have added for (int i = 0; i < this.iIterations; i++) { entry = newEntries[i]; entry.Title.Text = Guid.NewGuid().ToString(); entry.Update(); } Tracing.TraceMsg("DefaultHostMassiveInsert: updated lot's of entries"); returnFeed = service.Query(query); Assert.AreEqual(iCount + this.iIterations, returnFeed.Entries.Count, "feed should have " + this.iIterations + " more entries now"); // let's find them and delete them... for (int i = 0; i < this.iIterations; i++) { entry = newEntries[i]; foreach (AtomEntry feedEntry in returnFeed.Entries) { if (String.Compare(feedEntry.Title.Text, entry.Title.Text) == 0) { // got him Tracing.TraceMsg("trying to delete entry: " + feedEntry.Title.Text + " = " + entry.Title.Text); feedEntry.Delete(); break; } } } // and a last time returnFeed = service.Query(query); Assert.AreEqual(iCount, returnFeed.Entries.Count, "feed should have the same number again"); Tracing.TraceMsg("DefaultHostMassiveInsertAndDelete: deleted lot's of entries"); }
// 内部消化掉错误 private void ImportContents(AtomEntryCollection entries, NodeInfo nodeInfo, int taxis, int importStart, int importCount, bool isCheckedBySettings, bool isChecked, int checkedLevel, bool isOverride) { if (importStart > 1 || importCount > 0) { var theEntries = new AtomEntryCollection(); if (importStart == 0) { importStart = 1; } if (importCount == 0) { importCount = entries.Count; } var firstIndex = entries.Count - importStart - importCount + 1; if (firstIndex <= 0) { firstIndex = 0; } var addCount = 0; for (var i = 0; i < entries.Count; i++) { if (addCount >= importCount) { break; } if (i >= firstIndex) { theEntries.Add(entries[i]); addCount++; } } entries = theEntries; } var tableName = NodeManager.GetTableName(_publishmentSystemInfo, nodeInfo); foreach (AtomEntry entry in entries) { try { taxis++; var contentIdFromFile = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.Id)); var lastEditDate = AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.LastEditDate); var contentGroupNameCollection = AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.ContentGroupNameCollection); if (isCheckedBySettings) { isChecked = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.IsChecked)); checkedLevel = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.CheckedLevel)); } var comments = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.Comments)); var photos = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.Photos)); var hits = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.Hits)); var hitsByDay = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.HitsByDay)); var hitsByWeek = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.HitsByWeek)); var hitsByMonth = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.HitsByMonth)); var lastHitsDate = AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.LastHitsDate); var title = AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.Title); var isTop = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.IsTop)); var addDate = AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.AddDate); var topTaxis = 0; if (isTop) { topTaxis = taxis - 1; taxis = BaiRongDataProvider.ContentDao.GetMaxTaxis(tableName, nodeInfo.NodeId, true) + 1; } var tags = AtomUtility.Decrypt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.Tags)); var starSetting = AtomUtility.GetDcElementContent(entry.AdditionalElements, BackgroundContentAttribute.StarSetting); var contentInfo = new ContentInfo { NodeId = nodeInfo.NodeId, PublishmentSystemId = _publishmentSystemInfo.PublishmentSystemId, AddUserName = RequestBody.CurrentAdministratorName, AddDate = TranslateUtils.ToDateTime(addDate) }; contentInfo.LastEditUserName = contentInfo.AddUserName; contentInfo.LastEditDate = TranslateUtils.ToDateTime(lastEditDate); contentInfo.ContentGroupNameCollection = contentGroupNameCollection; contentInfo.Tags = tags; contentInfo.IsChecked = isChecked; contentInfo.CheckedLevel = checkedLevel; contentInfo.Comments = comments; contentInfo.Photos = photos; contentInfo.Hits = hits; contentInfo.HitsByDay = hitsByDay; contentInfo.HitsByWeek = hitsByWeek; contentInfo.HitsByMonth = hitsByMonth; contentInfo.LastHitsDate = TranslateUtils.ToDateTime(lastHitsDate); contentInfo.Title = AtomUtility.Decrypt(title); contentInfo.IsTop = isTop; var attributes = AtomUtility.GetDcElementNameValueCollection(entry.AdditionalElements); foreach (string attributeName in attributes.Keys) { if (!contentInfo.ContainsKey(attributeName.ToLower())) { contentInfo.Attributes[attributeName] = AtomUtility.Decrypt(attributes[attributeName]); } } var isInsert = false; if (isOverride) { var existsIDs = DataProvider.ContentDao.GetIdListBySameTitleInOneNode(tableName, contentInfo.NodeId, contentInfo.Title); if (existsIDs.Count > 0) { foreach (int id in existsIDs) { contentInfo.Id = id; DataProvider.ContentDao.Update(tableName, _fso.PublishmentSystemInfo, contentInfo); } } else { isInsert = true; } } else { isInsert = true; } if (isInsert) { var contentId = DataProvider.ContentDao.Insert(tableName, _publishmentSystemInfo, contentInfo, false, taxis); if (photos > 0) { _photoIe.ImportPhoto(contentIdFromFile, contentId); } if (_publishmentSystemInfo.Additional.IsRelatedByTags && !string.IsNullOrEmpty(tags)) { var tagCollection = TagUtils.ParseTagsString(tags); TagUtils.AddTags(tagCollection, _publishmentSystemInfo.PublishmentSystemId, contentId); } if (!string.IsNullOrEmpty(starSetting)) { var settings = starSetting.Split('_'); if (settings != null && settings.Length == 2) { var totalCount = TranslateUtils.ToInt(settings[0]); var pointAverage = TranslateUtils.ToDecimal(settings[1]); StarsManager.SetStarSetting(_publishmentSystemInfo.PublishmentSystemId, contentInfo.NodeId, contentId, totalCount, pointAverage); } } } //this.FSO.AddContentToWaitingCreate(contentInfo.NodeID, contentID); if (isTop) { taxis = topTaxis; } } catch { // ignored } } }