Пример #1
0
 public override Task UpdateAsync(UpdateParameter parameter)
 {
     var dao = new PeercastDao(Address);
     return dao.SetMetaAsync(parameter.Name, parameter.Genre, parameter.Description,
             parameter.ContactUrl, parameter.Comment,
             parameter.TrackArtist, parameter.TrackTitle, parameter.TrackAlbum,
             parameter.TrackGenre, parameter.TrackContact)
         .ContinueWith(t => dao.Dispose());
 }
Пример #2
0
 private Task<XmlStatus> GetXmlStatusAsync()
 {
     var dao = new PeercastDao(Address);
     return dao.GetViewXmlAsync().ContinueWith(t =>
     {
         dao.Dispose();
         return new XmlStatus(t.Result);
     });
 }
Пример #3
0
        private void SetYellowPagesAwait(PeercastDao dao, string yellowPagesAddress)
        {
            var nvc = GetSettingsAwait(dao);
            var ypParam = nvc.Single(x => x.Key == "yp");
            if (yellowPagesAddress == ypParam.Value)
                return;

            nvc.Remove(ypParam);
            nvc.Add(new KeyValuePair<string, string>("yp", yellowPagesAddress));
            dao.ApplyAsync(nvc).Wait();
        }
Пример #4
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;
                }
            });
        }
Пример #5
0
 private IList<KeyValuePair<string, string>> GetSettingsAwait(PeercastDao dao)
 {
     return new SettingsHtmlParser().Parse(dao.GetSettingsHtmlAsync().Result);
 }
Пример #6
0
 public override Task StopAsync(string id)
 {
     var dao = new PeercastDao(Address);
     return dao.StopAsync(id).ContinueWith(t => dao.Dispose());
 }