コード例 #1
0
ファイル: Bdd.cs プロジェクト: psymon75/WebradioManager
 /**
 // \fn public int AddWebradio(Webradio webradio)
 //
 // \brief Adds a webradio to db. Create server and calendar entries for this new webradio.
 //
 // \author Simon Menetrey
 // \date 26.05.2014
 //
 // \param webradio The webradio.
 //
 // \return Id of created webradio. or ERROR.
 **/
 public int AddWebradio(Webradio webradio)
 {
     //Webradio name must be unique !
     if (this.WebradioExist(webradio.Name))
         return ERROR;
     Dictionary<string, string> data = new Dictionary<string, string>();
     data.Add("name", webradio.Name);
     try
     {
         //Webradio
         this.Controls.Insert("twebradio", data);
         SQLiteDataReader reader = this.Controls.ExecuteDataReader("SELECT id FROM twebradio WHERE name = '" + webradio.Name + "'");
         reader.Read();
         int id = int.Parse(reader["id"].ToString());
         reader.Close();
         data.Clear();
         //Server creation
         data.Add("webradioid", id.ToString());
         data.Add("port", webradio.Server.Port.ToString());
         data.Add("logfilename", webradio.Server.LogFilename);
         data.Add("configfilename", webradio.Server.ConfigFilename);
         data.Add("password", webradio.Server.Password);
         data.Add("adminpassword", webradio.Server.AdminPassword);
         data.Add("maxlistener", webradio.Server.MaxListener.ToString());
         this.Controls.Insert("tserver", data);
         data.Clear();
         //----
         //Calendar creation
         data.Add("filename", webradio.Calendar.Filename);
         data.Add("webradioid", id.ToString());
         this.Controls.Insert("tcalendar", data);
         data.Clear();
         reader = this.Controls.ExecuteDataReader("SELECT id FROM tcalendar WHERE webradioid = " + id.ToString());
         reader.Read();
         webradio.Calendar.Id = int.Parse(reader["id"].ToString());
         reader.Close();
         //----
         return id;
     }
     catch
     {
         return ERROR;
     }
 }
コード例 #2
0
ファイル: WMModel.cs プロジェクト: psymon75/WebradioManager
 /**
 // \fn public bool CreateWebradio(string name)
 //
 // \brief Creates a webradio.
 //
 // \author Simon Menetrey
 // \date 26.05.2014
 //
 // \param name The name.
 //
 // \return true if it succeeds, false if it fails.
 **/
 public bool CreateWebradio(string name)
 {
     if (this.IsValidPath(name))
     {
         string webradioFilename = DEFAULT_WEBRADIOS_FOLDER + name + "/";
         Webradio wr = new Webradio(name);
         WebradioServer server = new WebradioServer(DEFAULT_SERVER_PORT,
             webradioFilename + DEFAULT_SERVER_FOLDER + DEFAULT_LOGFILENAME,
             webradioFilename + DEFAULT_SERVER_FOLDER + DEFAULT_CONFIGFILENAME, DEFAULT_SERVER_PASSWORD, WebradioServer.DEFAULT_ADMIN_LOGIN, DEFAULT_MAX_LISTENER);
         wr.Server = server;
         wr.Playlists = new List<Playlist>();
         wr.Calendar = new WebradioCalendar(webradioFilename + DEFAULT_CALENDAR_FILENAME);
         wr.Transcoders = new List<WebradioTranscoder>();
         try
         {
             wr.Id = this.Bdd.AddWebradio(wr);
             this.Webradios.Add(wr.Id, wr);
             //Directory creation
             Directory.CreateDirectory(webradioFilename);
             Directory.CreateDirectory(webradioFilename + DEFAULT_SERVER_FOLDER);
             Directory.CreateDirectory(webradioFilename + DEFAULT_PLAYLISTS_FOLDER);
             Directory.CreateDirectory(webradioFilename + DEFAULT_TRANSCODERS_FOLDER);
             Thread.Sleep(100);
             wr.GenerateConfigFiles();
         }
         catch
         {
             return false;
         }
         return true;
     }
     else
         return false;
 }
コード例 #3
0
ファイル: Bdd.cs プロジェクト: psymon75/WebradioManager
 /**
 // \fn public bool UpdateFilenames(string oldName, string newName, Webradio webradio)
 //
 // \brief Updates the filenames with new webradio's name.
 //
 // \author Simon Menetrey
 // \date 26.05.2014
 //
 // \param oldName  Webradio's old name.
 // \param newName  Webradio's new name.
 // \param webradio The webradio.
 //
 // \return true if it succeeds, false if it fails.
 **/
 public bool UpdateFilenames(string oldName, string newName, Webradio webradio)
 {
     try
     {
         Dictionary<string, string> data = new Dictionary<string, string>();
         foreach (WebradioTranscoder transcoder in webradio.Transcoders)
         {
             data.Clear();
             data.Add("configfilename", transcoder.ConfigFilename.Replace(oldName, newName));
             data.Add("logfilename", transcoder.LogFilename.Replace(oldName, newName));
             this.Controls.Update("ttranscoder", data, "webradioid = " + webradio.Id);
         }
         data.Clear();
         data.Add("configfilename", webradio.Server.ConfigFilename.Replace(oldName, newName));
         data.Add("logfilename", webradio.Server.LogFilename.Replace(oldName, newName));
         this.Controls.Update("tserver", data, "webradioid = " + webradio.Id);
         foreach (Playlist playlist in webradio.Playlists)
         {
             data.Clear();
             data.Add("filename", playlist.Filename.Replace(oldName, newName));
             this.Controls.Update("tplaylist", data, "webradioid = " + webradio.Id);
         }
         data.Clear();
         data.Add("filename", webradio.Calendar.Filename.Replace(oldName, newName));
         this.Controls.Update("tcalendar", data, "webradioid = " + webradio.Id);
         return true;
     }
     catch
     {
         return false;
     }
 }