本文整理汇总了C#中Newtonsoft.Json.Linq.JObject.TryGetThen方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.TryGetThen方法的具体用法?C# JObject.TryGetThen怎么用?C# JObject.TryGetThen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JObject
的用法示例。
在下文中一共展示了JObject.TryGetThen方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BroadcastChannel
private string BroadcastChannel(
int? yellowPageId,
string sourceUri,
string contentReader,
JObject info,
JObject track,
string sourceStream=null)
{
IYellowPageClient yp = null;
if (yellowPageId.HasValue) {
yp = PeerCast.YellowPages.FirstOrDefault(y => GetObjectId(y)==yellowPageId.Value);
if (yp==null) throw new RPCError(RPCErrorCode.InvalidParams, "Yellow page not found");
}
if (sourceUri==null) throw new RPCError(RPCErrorCode.InvalidParams, "source uri required");
Uri source;
try {
source = new Uri(sourceUri);
}
catch (UriFormatException) {
throw new RPCError(RPCErrorCode.InvalidParams, "Invalid Uri");
}
var content_reader = PeerCast.ContentReaderFactories.FirstOrDefault(reader => reader.Name==contentReader);
if (content_reader==null) throw new RPCError(RPCErrorCode.InvalidParams, "Content reader not found");
var source_stream = PeerCast.SourceStreamFactories
.Where(sstream => (sstream.Type & SourceStreamType.Broadcast)!=0)
.FirstOrDefault(sstream => sstream.Name==sourceStream);
if (source_stream==null) {
source_stream = PeerCast.SourceStreamFactories
.Where(sstream => (sstream.Type & SourceStreamType.Broadcast)!=0)
.FirstOrDefault(sstream => sstream.Scheme==source.Scheme);
}
if (source_stream==null) throw new RPCError(RPCErrorCode.InvalidParams, "Source stream not found");
var new_info = new AtomCollection();
if (info!=null) {
info.TryGetThen("name", v => new_info.SetChanInfoName(v));
info.TryGetThen("url", v => new_info.SetChanInfoURL(v));
info.TryGetThen("genre", v => new_info.SetChanInfoGenre(v));
info.TryGetThen("desc", v => new_info.SetChanInfoDesc(v));
info.TryGetThen("comment", v => new_info.SetChanInfoComment(v));
}
var channel_info = new ChannelInfo(new_info);
if (channel_info.Name==null || channel_info.Name=="") {
throw new RPCError(RPCErrorCode.InvalidParams, "Channel name must not be empty");
}
var channel_id = PeerCastStation.Core.BroadcastChannel.CreateChannelID(
PeerCast.BroadcastID,
channel_info.Name,
channel_info.Genre ?? "",
source.ToString());
var channel = PeerCast.BroadcastChannel(yp, channel_id, channel_info, source, source_stream, content_reader);
if (track!=null) {
var new_track = new AtomCollection(channel.ChannelTrack.Extra);
track.TryGetThen("name", v => new_track.SetChanTrackTitle(v));
track.TryGetThen("genre", v => new_track.SetChanTrackGenre(v));
track.TryGetThen("album", v => new_track.SetChanTrackAlbum(v));
track.TryGetThen("creator", v => new_track.SetChanTrackCreator(v));
track.TryGetThen("url", v => new_track.SetChanTrackURL(v));
channel.ChannelTrack = new ChannelTrack(new_track);
}
return channel.ChannelID.ToString("N").ToUpper();
}
示例2: SetSettings
private void SetSettings(JObject settings)
{
var acc = PeerCast.AccessController;
settings.TryGetThen("maxRelays", v => acc.MaxRelays = v);
settings.TryGetThen("maxRelaysPerChannel", v => acc.MaxRelaysPerChannel = v);
settings.TryGetThen("maxDirects", v => acc.MaxPlays = v);
settings.TryGetThen("maxDirectsPerChannel", v => acc.MaxPlaysPerChannel = v);
settings.TryGetThen("maxUpstreamRate", v => acc.MaxUpstreamRate = v);
settings.TryGetThen("maxUpstreamRatePerChannel", v => acc.MaxUpstreamRatePerChannel = v);
settings.TryGetThen("channelCleaner", (JObject channel_cleaner) => {
channel_cleaner.TryGetThen("inactiveLimit", v => ChannelCleaner.InactiveLimit = v);
channel_cleaner.TryGetThen("mode", v => ChannelCleaner.Mode = (ChannelCleaner.CleanupMode)v);
});
settings.TryGetThen("portMapper", (JObject mapper) => {
var port_mapper = PeerCastApplication.Current.Plugins.GetPlugin<PeerCastStation.UI.PortMapperPlugin>();
if (port_mapper!=null) {
mapper.TryGetThen("enabled", v => port_mapper.Enabled = v);
port_mapper.DiscoverAsync();
}
});
owner.Application.SaveSettings();
}
示例3: setLogSettings
private void setLogSettings(JObject settings)
{
settings.TryGetThen("level", v => {
Logger.Level = (LogLevel)v;
owner.Application.SaveSettings();
});
}
示例4: AddBroadcastHistory
public void AddBroadcastHistory(JObject info)
{
var obj = new PeerCastStation.UI.BroadcastInfo();
info.TryGetThen("streamType", v => obj.StreamType = v);
info.TryGetThen("streamUrl", v => obj.StreamUrl = v);
info.TryGetThen("bitrate", v => obj.Bitrate = v);
info.TryGetThen("contentType", v => obj.ContentType = v);
info.TryGetThen("yellowPage", v => obj.YellowPage = v);
info.TryGetThen("channelName", v => obj.ChannelName = v);
info.TryGetThen("genre", v => obj.Genre = v);
info.TryGetThen("description", v => obj.Description = v);
info.TryGetThen("comment", v => obj.Comment = v);
info.TryGetThen("contactUrl", v => obj.ContactUrl = v);
info.TryGetThen("trackTitle", v => obj.TrackTitle = v);
info.TryGetThen("trackAlbum", v => obj.TrackAlbum = v);
info.TryGetThen("trackArtist", v => obj.TrackArtist = v);
info.TryGetThen("trackGenre", v => obj.TrackGenre = v);
info.TryGetThen("trackUrl", v => obj.TrackUrl = v);
info.TryGetThen("favorite", v => obj.Favorite = v);
var settings = PeerCastApplication.Current.Settings.Get<UISettings>();
var item = settings.FindBroadcastHistroryItem(obj);
if (item!=null) {
info.TryGetThen("favorite", v => item.Favorite = v);
}
else {
settings.AddBroadcastHistory(obj);
}
}