public virtual void FromNameValueCollection(NameValueCollection collection) { if (!string.IsNullOrEmpty(collection["OT"])) { ObjectType = Helper.GetObjectTypeNumericID(collection["OT"]); } if (!string.IsNullOrEmpty(collection["OTS"])) { ObjectType = 0; ObjectTypes = QuickParameters.GetDelimitedObjectTypeIDs(collection["OTS"], ','); } string paramCtyId = string.Empty; if (collection["XCN"] != null) { paramCtyId = collection["XCN"]; } else if (!string.IsNullOrEmpty(collection["CN"])) { paramCtyId = collection["CN"]; } if (!string.IsNullOrEmpty(paramCtyId)) { if (!paramCtyId.IsGuid()) { CommunityID = DataObjectCommunity.GetCommunityIDByVirtualURL(paramCtyId); } else { CommunityID = paramCtyId.ToGuid(); } } if (!string.IsNullOrEmpty(collection["CNS"])) { CommunityID = null; Communities = QuickParameters.GetDelimitedCommunityIDs(collection["CNS"], ','); } string paramUserId = string.Empty; if (collection["XUI"] != null) { paramUserId = collection["XUI"]; } else if (!string.IsNullOrEmpty(collection["UI"])) { paramUserId = collection["UI"]; } if (!string.IsNullOrEmpty(paramUserId)) { if (!paramUserId.IsGuid()) { UserID = DataObjectUser.GetUserIDByNickname(paramUserId); } else { UserID = paramUserId.ToGuid(); } } if (!string.IsNullOrEmpty(collection["TG"])) { TagID = HttpUtility.UrlDecode(collection["TG"]).ToNullableGuid(); } if (!string.IsNullOrEmpty(collection["TGL1"])) { TagID = null; RawTags1 = collection["TGL1"]; Tags1 = QuickParameters.GetDelimitedTagIds(HttpUtility.UrlDecode(collection["TGL1"]), ','); } if (!string.IsNullOrEmpty(collection["TGL2"])) { TagID = null; RawTags2 = collection["TGL2"]; Tags2 = QuickParameters.GetDelimitedTagIds(HttpUtility.UrlDecode(collection["TGL2"]), ','); } if (!string.IsNullOrEmpty(collection["TGL3"])) { TagID = null; RawTags3 = collection["TGL3"]; Tags3 = QuickParameters.GetDelimitedTagIds(HttpUtility.UrlDecode(collection["TGL3"]), ','); } if (!string.IsNullOrEmpty(collection["SO"])) { SortBy = (QuickSort)Enum.Parse(typeof(QuickSort), collection["SO"], true); } if (!string.IsNullOrEmpty(collection["SD"])) { Direction = (QuickSortDirection)Enum.Parse(typeof(QuickSortDirection), collection["SD"], true); } if (!string.IsNullOrEmpty(collection["SO2"])) { SortBySecond = (QuickSort)Enum.Parse(typeof(QuickSort), collection["SO2"], true); } if (!string.IsNullOrEmpty(collection["SD2"])) { DirectionSecond = (QuickSortDirection)Enum.Parse(typeof(QuickSortDirection), collection["SD2"], true); } if (!string.IsNullOrEmpty(collection["AM"])) { int temp; if (int.TryParse(collection["AM"], out temp)) { amount = temp; } } if (!string.IsNullOrEmpty(collection["PN"])) { int.TryParse(collection["PN"], out pageNumber); } if (!string.IsNullOrEmpty(collection["PS"])) { int.TryParse(collection["PS"], out pageSize); pageSize = Math.Min(pageSize, 100); } if (!string.IsNullOrEmpty(collection["SS"])) { ShowState = (ObjectShowState)Enum.Parse(typeof(ObjectShowState), collection["SS"], true); } if (!string.IsNullOrEmpty(collection["FI"])) { DateTime formInserted; if (DateTime.TryParse(collection["FI"], out formInserted)) { fromInserted = formInserted; } } if (!string.IsNullOrEmpty(collection["TI"])) { DateTime toInserted; if (DateTime.TryParse(collection["TI"], out toInserted)) { this.toInserted = toInserted; } } if (!string.IsNullOrEmpty(collection["FE"])) { int featured; if (int.TryParse(collection["FE"], out featured)) { this.featured = featured; } } if (!string.IsNullOrEmpty(collection["WC"])) { bool withCopy; if (bool.TryParse(collection["WC"], out withCopy)) { this.withCopy = withCopy; } } if (!string.IsNullOrEmpty(collection["FS"])) { DateTime fromStartDate; if (DateTime.TryParse(collection["FS"], out fromStartDate)) { this.fromStartDate = fromStartDate; } } if (!string.IsNullOrEmpty(collection["TS"])) { DateTime toEndDate; if (DateTime.TryParse(collection["TS"], out toEndDate)) { this.toEndDate = toEndDate; } } if (!string.IsNullOrEmpty(collection["TSD"])) { DateTime toStartDate; if (DateTime.TryParse(collection["TSD"], out toStartDate)) { this.toStartDate = toStartDate.GetStartOfDay(); } } if (!string.IsNullOrEmpty(collection["FED"])) { DateTime fromEndDate; if (DateTime.TryParse(collection["FED"], out fromEndDate)) { this.fromEndDate = fromEndDate.GetEndOfDay(); } } if (!string.IsNullOrEmpty(collection["DM"])) { DateQueryMethode = (QuickDateQueryMethode)Enum.Parse(typeof(QuickDateQueryMethode), collection["DM"], true); } if (!string.IsNullOrEmpty(collection["CO"])) { Country = collection["CO"]; } if (!string.IsNullOrEmpty(collection["ZP"])) { Zip = collection["ZP"]; } if (!string.IsNullOrEmpty(collection["CI"])) { City = HttpUtility.UrlDecode(collection["CI"]); } if (!string.IsNullOrEmpty(collection["GC"])) { string[] coordsList = collection["GC"].Split(new char[] { ',' }); if (coordsList.Length == 2) { GeoLat = float.Parse(coordsList[0]); GeoLong = float.Parse(coordsList[1]); } } if (!string.IsNullOrEmpty(collection["DI"])) { DistanceKm = float.Parse(collection["DI"]); } if (!string.IsNullOrEmpty(collection["OC"])) { bool onlyConverted; if (bool.TryParse(collection["OC"], out onlyConverted)) { this.onlyConverted = onlyConverted; } } if (!string.IsNullOrEmpty(collection["OI"])) { bool onlyWithImage; if (bool.TryParse(collection["OI"], out onlyWithImage)) { this.onlyWithImage = onlyWithImage; } } if (!string.IsNullOrEmpty(collection["NI"])) { Nickname = HttpUtility.UrlDecode(collection["NI"]); } if (!string.IsNullOrEmpty(collection["TL"])) { Title = HttpUtility.UrlDecode(collection["TL"]); } if (!string.IsNullOrEmpty(collection["DE"])) { Description = HttpUtility.UrlDecode(collection["DE"]); } if (!string.IsNullOrEmpty(collection["SU"])) { UserSearch = HttpUtility.UrlDecode(collection["SU"]); } if (!string.IsNullOrEmpty(collection["IG"])) { bool boolVal; if (bool.TryParse(collection["IG"], out boolVal)) { IncludeGroups = boolVal; } } if (!string.IsNullOrEmpty(collection["IC"])) { bool boolVal; if (bool.TryParse(collection["IC"], out boolVal)) { IgnoreCache = boolVal; } } if (!string.IsNullOrEmpty(collection["GT"])) { bool boolVal; if (bool.TryParse(collection["GT"], out boolVal)) { OnlyGeoTagged = boolVal; } } if (!string.IsNullOrEmpty(collection["SG"])) { GeneralSearch = HttpUtility.UrlDecode(collection["SG"]); } if (!string.IsNullOrEmpty(collection["OID"])) { ObjectID = collection["OID"].ToGuid(); } if (!string.IsNullOrEmpty(collection["COID"])) { CurrentObjectID = collection["COID"].ToGuid(); } if (!string.IsNullOrEmpty(collection["RPID"])) { if (RelationParams == null) { RelationParams = new RelationParams(); } RelationParams.ParentObjectID = collection["RPID"].ToGuid(); } }
public static string GetFeed(QuickParameters quickParameters, string type) { string urlPrefix = System.Configuration.ConfigurationManager.AppSettings["HostName"] + HttpContext.Current.Request.ApplicationPath; UserDataContext udc = UserDataContext.GetUserDataContext(); quickParameters.Udc = udc; quickParameters.ObjectTypes = QuickParameters.GetDelimitedObjectTypeIDs(rssEngineConfig.ObjectTypes, ','); quickParameters.SortBy = QuickSort.StartDate; //quickParameters.FromStartDate = DateTime.Now - new TimeSpan(rssEngineConfig.Days, 0, 0, 0); quickParameters.Amount = rssEngineConfig.MaxItems; quickParameters.PageSize = rssEngineConfig.MaxItems; StringBuilder sb; List <string> titleSegments = new List <string>(); SyndicationFeed feed = new SyndicationFeed(); if (quickParameters.CommunityID.HasValue) { DataObjectCommunity channelCommunity = DataObject.Load <DataObjectCommunity>(quickParameters.CommunityID); if (channelCommunity.State != ObjectState.Added) { if (channelCommunity.ObjectType == Helper.GetObjectTypeNumericID("ProfileCommunity")) { titleSegments.Add(string.Format("Von {0}", channelCommunity.Nickname)); } else { titleSegments.Add(string.Format("Von {0}", channelCommunity.Title)); } } } else if (quickParameters.UserID.HasValue) { Business.DataObjectUser channelUser = DataObject.Load <DataObjectUser>(quickParameters.UserID); if (channelUser.State != ObjectState.Added) { titleSegments.Add(string.Format("Von {0}", channelUser.Nickname)); } } if (!string.IsNullOrEmpty(quickParameters.RawTags1) || !string.IsNullOrEmpty(quickParameters.RawTags2) || !string.IsNullOrEmpty(quickParameters.RawTags3)) { titleSegments.Add(string.Format("Tags {0}", Helper.GetTagWordString(new List <string>() { quickParameters.RawTags1, quickParameters.RawTags2, quickParameters.RawTags3 }))); } sb = new StringBuilder(); if (titleSegments.Count > 0) { for (int i = 0; i < titleSegments.Count; i++) { sb.Append(titleSegments[i]); if (i < titleSegments.Count - 1) { sb.Append(", "); } } } else { sb.Append("Alles"); } string title = string.Format("{0} Feed - {1}", siteName, sb.ToString()); string description = "RSS Feed von " + siteName; feed.Title = TextSyndicationContent.CreatePlaintextContent(title); feed.Description = TextSyndicationContent.CreatePlaintextContent(description); feed.Links.Add(new SyndicationLink(new Uri(urlPrefix))); feed.Language = "de-CH"; List <SyndicationItem> items = new List <SyndicationItem>(); DataObjectList <DataObject> rssItems = DataObjects.Load <DataObject>(quickParameters); foreach (DataObject rssItem in rssItems) { SyndicationItem item = new SyndicationItem(); // Add prefix to title item.Title = TextSyndicationContent.CreatePlaintextContent("[" + Helper.GetObjectName(rssItem.ObjectType, true) + "] " + rssItem.Title); // Set owner as author SyndicationPerson author = new SyndicationPerson(); author.Name = rssItem.Nickname; item.Authors.Add(author); // Set object's guid item.Id = rssItem.objectID.Value.ToString(); // Link to the object string itemUrl = urlPrefix + Helper.GetDetailLink(rssItem.ObjectType, rssItem.objectID.Value.ToString()); item.AddPermalink(new Uri(itemUrl)); // Take start date as publish date item.PublishDate = rssItem.StartDate; // Image if available if (!string.IsNullOrEmpty(rssItem.GetImage(PictureVersion.S)) && rssItem.GetImage(PictureVersion.S).ToLower() != Helper.GetDefaultURLImageSmall(rssItem.ObjectType).ToLower()) { item.Content = SyndicationContent.CreateXhtmlContent("<div><a href=\"" + itemUrl + "\"><img src=\"" + System.Configuration.ConfigurationManager.AppSettings["MediaDomainName"] + rssItem.GetImage(PictureVersion.S) + "\"></a></div><div>" + rssItem.Description.StripHTMLTags().CropString(rssEngineConfig.MaxDescriptionLength) + "</div>"); } else { item.Content = TextSyndicationContent.CreatePlaintextContent(rssItem.Description.StripHTMLTags().CropString(rssEngineConfig.MaxDescriptionLength)); } items.Add(item); } feed.Items = items; sb = new StringBuilder(); XmlWriter xmlWriter = XmlWriter.Create(sb); if (type == "rss") { feed.SaveAsRss20(xmlWriter); } else if (type == "atom") { feed.SaveAsAtom10(xmlWriter); } xmlWriter.Close(); string feedXml = sb.ToString(); feedXml = Regex.Replace(feedXml, @"^<.*?xml.*?>\s*", ""); return(feedXml); }