Ejemplo n.º 1
0
 private int GetOrCreateYellowPagesIdAwait(PeercastStationDao dao, YellowPages yellowPages)
 {
     var ypName = yellowPages.Name;
     var ypInfo = dao.GetYellowPagesAsync().Result.FirstOrDefault(x => x.Item2 == ypName);
     if (ypInfo == null)
     {
         return dao.AddYellowPageAsync("pcp", yellowPages.Name, "pcp://" + yellowPages.Url).Result;
     }
     if (ypInfo.Item3 != yellowPages.Url)
     {
         dao.RemoveYellowPageAsync(ypInfo.Item1).Wait();
         return dao.AddYellowPageAsync("pcp", yellowPages.Name, "pcp://" + yellowPages.Url).Result;
     }
     return ypInfo.Item1;
 }
Ejemplo n.º 2
0
        public override Task<Tuple<string, int>> BroadcastAsync(YellowPages yellowPages, BroadcastParameter parameter)
        {
            return Task.Factory.StartNew(() =>
            {
                using (var dao = new PeercastStationDao(Address))
                {
                    var ypId = GetOrCreateYellowPagesIdAwait(dao, yellowPages);

                    var id = dao.BroadcastChannelAsync(ypId, parameter.StreamUrl,
                        parameter.StreamUrl.Contains("rtmp://") ? "RTMP Source" : "http",
                        parameter.Type == "WMV" ? "ASF(WMV or WMA)"
                        : parameter.Type == "FLV" ? "Flash Video (FLV)"
                        : "",
                        parameter.Name, parameter.ContactUrl, -1, "",
                        parameter.Genre, parameter.Description, parameter.Comment,
                        parameter.TrackTitle, parameter.TrackArtist, parameter.TrackGenre,
                        parameter.TrackAlbum, parameter.TrackContact).Result;
                    return Tuple.Create(id, -1);
                }
            });
        }
Ejemplo n.º 3
0
        public override Task<Tuple<string, int>> BroadcastAsync(YellowPages yellowPages, BroadcastParameter parameter)
        {
            return Task.Factory.StartNew(() =>
            {
                using (var dao = new PeercastDao(Address))
                {
                    SetYellowPagesAwait(dao, yellowPages.Url);

                    var status = new XmlStatus(dao.GetViewXmlAsync().Result);
                    if (status.Exists(parameter.Name))
                    {
                        throw new PeerCastException("同名のチャンネルが既にあります。");
                    }

                    dao.FetchAsync(parameter.StreamUrl, parameter.Name, parameter.Genre, parameter.Description,
                        parameter.ContactUrl, parameter.Type).Wait();
                    var tuple = Repeat(() =>
                    {
                        var afterStatus = new XmlStatus(dao.GetViewXmlAsync().Result);
                        return GetChannelInfo(afterStatus, parameter.Name);
                    });
                    if (NullId == tuple.Item1)
                    {
                        dao.StopAsync(tuple.Item1).Wait();
                        throw new PeerCastException("チャンネルの作成に失敗しました。" + Environment.NewLine
                            + "エンコードが開始されているか、またはストリームURLが正しいか確認してください。");
                    }

                    dao.SetMetaAsync(parameter.Name, parameter.Genre, parameter.Description,
                        parameter.ContactUrl, parameter.Comment,
                        parameter.TrackArtist, parameter.TrackTitle, parameter.TrackAlbum,
                        parameter.TrackGenre, parameter.TrackContact).Wait();
                    return tuple;
                }
            });
        }
Ejemplo n.º 4
0
 public abstract Task<Tuple<string, int>> BroadcastAsync(
     YellowPages yellowPages, BroadcastParameter parameter);