public Tuple <JabberId, XmlStanzas.Stanza <PresenceProcessingType> > ToFSharp() { var elem = XElement.Parse(Content); var presenceStanza = Parsing.parsePresenceStanza("jabber:server", elem); var from = JabberId.Parse(FromJid); return(Tuple.Create(from, presenceStanza)); }
public async Task <FSharpOption <StoredPreferenceInfo> > GetUserPreferences() { using (var context = this.CreateContext()) { var user = await GetUser(context); var isDefaultModeUnset = user.OtrMode == Model.OtrMode.NotSet && user.SaveMode == Model.SaveMode.NotSet && user.Expire == null; var isAnyArchivingModeUnset = user.LocalPreference == Model.ArchivingMode.NotSet || user.ManualPreference == Model.ArchivingMode.NotSet || user.AutoPreference == Model.ArchivingMode.NotSet; var isAllUnset = isDefaultModeUnset && user.ItemPreferences.Count == 0 && isAnyArchivingModeUnset && user.AutomaticArchiving == null; if (isAllUnset) { return(FSharpOption <StoredPreferenceInfo> .None); } var archivingModePrefs = !isAnyArchivingModeUnset ? FSharpOption <AllMethodSettings> .Some( new AllMethodSettings ( ToFSharp(user.AutoPreference), ToFSharp(user.LocalPreference), ToFSharp(user.ManualPreference))) : FSharpOption <AllMethodSettings> .None; var result = new StoredPreferenceInfo( FSharpHelper.ToFSharpS(user.AutomaticArchiving), new OtrSaveMode( FSharpHelper.ToFSharpS <Int64> (user.Expire), ToFSharp(user.OtrMode), ToFSharp(user.SaveMode)), ListModule.OfSeq <Tuple <JabberId, OtrSaveMode> > (user.ItemPreferences.Select(item => Tuple.Create( JabberId.Parse(item.Jid), new OtrSaveMode( FSharpHelper.ToFSharpS <Int64> (item.Expire), ToFSharp(item.OtrMode), ToFSharp(item.SaveMode))))), archivingModePrefs ); return(FSharpOption <StoredPreferenceInfo> .Some(result)); } }
public RosterItem ToFSharp() { Microsoft.FSharp.Core.FSharpOption <AskType> approved = null; Microsoft.FSharp.Core.FSharpOption <SubscriptionType> subs = null; switch (Ask) { case Yaaf.Xmpp.IM.Sql.Model.DbAskType.Subscribe: approved = new Microsoft.FSharp.Core.FSharpOption <AskType>(AskType.Subscribe); break; default: break; } switch (Subscription) { case Yaaf.Xmpp.IM.Sql.Model.DbSubscriptionType.Both: subs = new Microsoft.FSharp.Core.FSharpOption <SubscriptionType>(SubscriptionType.Both); break; case Yaaf.Xmpp.IM.Sql.Model.DbSubscriptionType.None: subs = new Microsoft.FSharp.Core.FSharpOption <SubscriptionType>(SubscriptionType.SubsNone); break; case Yaaf.Xmpp.IM.Sql.Model.DbSubscriptionType.To: subs = new Microsoft.FSharp.Core.FSharpOption <SubscriptionType>(SubscriptionType.To); break; case Yaaf.Xmpp.IM.Sql.Model.DbSubscriptionType.From: subs = new Microsoft.FSharp.Core.FSharpOption <SubscriptionType>(SubscriptionType.From); break; default: break; } var list = ListModule.OfSeq(from g in Groups select g.RosterGroup.Name); return(new RosterItem( JabberId.Parse(Jid), SqlRosterStore.ToFSharp(Name), !Approved ? null : (SqlRosterStore.ToFSharp(true)), approved, subs, list)); }
public async Task <Microsoft.FSharp.Collections.FSharpList <Tuple <RosterChange, string> > > ChangesSince(string value) { using (var context = CreateContext()) { var lastVersion = int.Parse(value); var latestChanges = /* * // Not working in MySql * from change in context.RosterChanges * where change.ApplicationUserId == user.Id * where change.Version > lastVersion * group change by change.Jid into g * let latest = * (from item in g * orderby item.Version descending * select item) * .FirstOrDefault() * orderby latest.Version * select latest; * * // Not working in MySql * context.RosterChanges * .Where (c => c.ApplicationUserId == user.Id && c.Version > lastVersion) * .GroupBy (c => c.Jid) * .Select (g => g.OrderByDescending(i => i.Version).FirstOrDefault()) * .OrderBy(i => i.Version); */ from change in context.RosterChanges join gro in (from c in context.RosterChanges group c by c.Jid into g select new { Name = g.Key, MaxVer = g.Select(i => i.Version).Max() }) on change.Jid equals gro.Name where change.ApplicationUserId == user && change.Version > lastVersion && change.Version == gro.MaxVer orderby change.Version select change; var list = new List <Tuple <RosterChange, string> > (); foreach (var item in await latestChanges.ToListAsync()) { // build list RosterChange change = null; switch (item.ChangeType) { case DbChangeType.Set: var items = await(from i in context.RosterItems where i.ApplicationUserId == user where i.Jid == item.Jid select i) .FirstOrDefaultAsync(); change = RosterChange.NewSetItem(items.ToFSharp()); break; case DbChangeType.Delete: change = RosterChange.NewDeleteItem(JabberId.Parse(item.Jid)); break; default: throw new InvalidOperationException("Invalid ChangeType"); } var t = Tuple.Create(change, VersionString(item.Version)); list.Add(t); } return(ListModule.OfSeq(list)); //return null; } }