예제 #1
0
 /**
 // \fn public bool DeleteEvent(CalendarEvent aEvent, int webradioId)
 //
 // \brief Deletes the event.
 //
 // \author Simon Menetrey
 // \date 26.05.2014
 //
 // \param aEvent     The event.
 // \param webradioId Identifier for the webradio.
 //
 // \return true if it succeeds, false if it fails.
 **/
 public bool DeleteEvent(CalendarEvent aEvent, int webradioId)
 {
     if (this.Bdd.DeleteEvent(aEvent))
     {
         this.Webradios[webradioId].Calendar.Events.Remove(aEvent);
         this.Webradios[webradioId].Calendar.GenerateConfigFile();
         this.UpdateObservers(webradioId);
         return true;
     }
     else
         return false;
 }
예제 #2
0
 /**
 // \fn public bool DuplicateWebradio(int id)
 //
 // \brief Duplicate webradio.
 //
 // \author Simon Menetrey
 // \date 26.05.2014
 //
 // \param id The identifier.
 //
 // \return true if it succeeds, false if it fails.
 **/
 public bool DuplicateWebradio(int id)
 {
     Webradio webradio = this.Webradios[id];
     string name = "Copy of " + webradio.Name;
     if (this.IsValidPath(name))
     {
         try
         {
             this.CreateWebradio(name);
             Webradio newWebradio = this.GetWebradioByName(name);
             //SERVER CONFIGURATION - Put server config to the clone
             this.UpdateServer(true, webradio.Server.Port, webradio.Server.Password, webradio.Server.AdminPassword, webradio.Server.MaxListener, newWebradio.Id);
             //PLAYLIST CONFIGURATION
             foreach (Playlist playlist in webradio.Playlists)
             {
                 Playlist newPlaylist;
                 if (this.CreatePlaylist(playlist.Name, newWebradio.Name, newWebradio.Id, playlist.Type, out newPlaylist))
                 {
                     newPlaylist.AudioFileList = new List<string>(playlist.AudioFileList);
                 }
             }
             //CALENDAR CONFIGURATION
             foreach (CalendarEvent ev in webradio.Calendar.Events)
             {
                 Playlist newPlaylistEvent = this.GetPlaylistByName(ev.Playlist.Name, newWebradio.Id);
                 if (newPlaylistEvent != null)
                 {
                     CalendarEvent newEvent = new CalendarEvent(ev.Name, ev.StartTime, ev.Duration, ev.Repeat, ev.Priority, ev.Shuffle, ev.Loopatend, newPlaylistEvent);
                     this.CreateEvent(newEvent, newWebradio.Id);
                 }
             }
             //TRANSCODER CONFIGURATION
             foreach (WebradioTranscoder transcoder in webradio.Transcoders)
             {
                 this.CreateTranscoder(transcoder.Name, transcoder.StreamType, transcoder.SampleRate, transcoder.Birate, transcoder.Url, transcoder.Ip, transcoder.Port, transcoder.AdminPort, transcoder.Password, newWebradio.Id);
             }
             this.UpdateObservers();
             return true;
         }
         catch
         {
             return false;
         }
     }
     else
         return false;
 }
예제 #3
0
 /**
 // \fn public bool UpdateEvent(CalendarEvent aEvent, int webradioId)
 //
 // \brief Updates the event with param one's values.
 //
 // \author Simon Menetrey
 // \date 26.05.2014
 //
 // \param aEvent     The event.
 // \param webradioId Identifier for the webradio.
 //
 // \return true if it succeeds, false if it fails.
 **/
 public bool UpdateEvent(CalendarEvent aEvent, int webradioId)
 {
     if (this.Bdd.UpdateEvent(aEvent))
     {
         foreach (CalendarEvent ce in this.Webradios[webradioId].Calendar.Events)
         {
             CalendarEvent tmp = ce;
             if (ce.Id == aEvent.Id)
             {
                 tmp.StartTime = aEvent.StartTime;
                 tmp.Duration = aEvent.Duration;
                 break;
             }
         }
         this.Webradios[webradioId].Calendar.GenerateConfigFile();
         this.UpdateObservers(webradioId);
         return true;
     }
     else
         return false;
 }
예제 #4
0
        /**
        // \fn public bool CreateEvent(CalendarEvent newEvent, int webradioId)
        //
        // \brief Creates an event.
        //
        // \author Simon Menetrey
        // \date 26.05.2014
        //
        // \param newEvent   The new event.
        // \param webradioId Identifier for the webradio.
        //
        // \return true if it succeeds, false if it fails.
        **/
        public bool CreateEvent(CalendarEvent newEvent, int webradioId)
        {
            if (this.Bdd.EventExist(newEvent, this.Webradios[webradioId].Calendar.Id))
                return false;

            int id = this.Bdd.AddEvent(newEvent, this.Webradios[webradioId].Calendar.Id, newEvent.Playlist.Id);
            newEvent.Id = id;
            this.Webradios[webradioId].Calendar.Events.Add(newEvent);
            this.Webradios[webradioId].Calendar.GenerateConfigFile();
            this.UpdateObservers(webradioId);
            return true;
        }
예제 #5
0
 /**
 // \fn public bool CreateEvent(CalendarEvent newEvent, int webradioId)
 //
 // \brief Creates an event.
 //
 // \author Simon Menetrey
 // \date 23.05.2014
 //
 // \param newEvent   The new event.
 // \param webradioId Identifier of the webradio.
 //
 // \return true if it succeeds, false if it fails.
 **/
 public bool CreateEvent(CalendarEvent newEvent, int webradioId)
 {
     return this.Model.CreateEvent(newEvent, webradioId);
 }
예제 #6
0
 /**
 // \fn public bool UpdateEvent(CalendarEvent aEvent, int webradioId)
 //
 // \brief Updates the event.
 //
 // \author Simon Menetrey
 // \date 23.05.2014
 //
 // \param aEvent     The event.
 // \param webradioId Identifier of the webradio.
 //
 // \return true if it succeeds, false if it fails.
 **/
 public bool UpdateEvent(CalendarEvent aEvent, int webradioId)
 {
     return this.Model.UpdateEvent(aEvent,webradioId);
 }
예제 #7
0
 /**
 // \fn public bool UpdateEvent(CalendarEvent aEvent)
 //
 // \brief Updates the event's value.
 //
 // \author Simon Menetrey
 // \date 26.05.2014
 //
 // \param aEvent The event.
 //
 // \return true if it succeeds, false if it fails.
 **/
 public bool UpdateEvent(CalendarEvent aEvent)
 {
     Dictionary<string,string> data = new Dictionary<string,string>();
     //Only change starttime and duration for the moment
     data.Add("starttime", aEvent.StartTime.ToString());
     data.Add("duration", aEvent.Duration.ToString());
     data.Add("repeat", aEvent.Repeat.ToString());
     try
     {
         this.Controls.Update("tcalendarevent", data, "id = " + aEvent.Id);
         return true;
     }
     catch
     {
         return false;
     }
 }
예제 #8
0
 /**
 // \fn public bool EventExist(CalendarEvent aEvent, int calendarId)
 //
 // \brief Event exists in the db.
 //
 // \author Simon Menetrey
 // \date 26.05.2014
 //
 // \param aEvent     The event.
 // \param calendarId Identifier for the calendar.
 //
 // \return true if it exists, false if it doesn't exists.
 **/
 public bool EventExist(CalendarEvent aEvent, int calendarId)
 {
     SQLiteDataReader reader = this.Controls.ExecuteDataReader("SELECT COUNT(*) AS Count FROM tcalendarevent WHERE name = '" + aEvent.Name + "' AND calendarid = " + calendarId.ToString());
     reader.Read();
     bool result = (reader["Count"].ToString() == "0")?false:true;
     reader.Close();
     return result;
 }
예제 #9
0
 /**
 // \fn public bool DeleteEvent(CalendarEvent aEvent)
 //
 // \brief Deletes the event described by aEvent.
 //
 // \author Simon Menetrey
 // \date 26.05.2014
 //
 // \param aEvent The event.
 //
 // \return true if it succeeds, false if it fails.
 **/
 public bool DeleteEvent(CalendarEvent aEvent)
 {
     try
     {
         this.Controls.Delete("tcalendarevent", "id = " + aEvent.Id.ToString());
         return true;
     }
     catch
     {
         return false;
     }
 }
예제 #10
0
        /**
        // \fn public int AddEvent(CalendarEvent newEvent, int calendarId, int playlistId)
        //
        // \brief Adds an event to a calendar.
        //
        // \author Simon Menetrey
        // \date 26.05.2014
        //
        // \param newEvent   The new event.
        // \param calendarId Identifier for the calendar.
        // \param playlistId Identifier for the playlist.
        //
        // \return The new event's id.
        **/
        public int AddEvent(CalendarEvent newEvent, int calendarId, int playlistId)
        {
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("name", newEvent.Name);
            data.Add("starttime", newEvent.StartTime.ToString());
            data.Add("duration", newEvent.Duration.ToString());
            data.Add("repeat", newEvent.Repeat.ToString());
            data.Add("priority", newEvent.Priority.ToString());
            data.Add("shuffle", (newEvent.Shuffle) ? "TRUE" : "FALSE");
            data.Add("loopatend", "TRUE");
            data.Add("calendarid", calendarId.ToString());
            data.Add("playlistid", playlistId.ToString());

            this.Controls.Insert("tcalendarevent", data);

            SQLiteDataReader reader = this.Controls.ExecuteDataReader("SELECT id FROM tcalendarevent WHERE name = '"+ newEvent.Name +"' AND calendarid = " + calendarId.ToString());
            reader.Read();
            int id = int.Parse(reader["id"].ToString());
            reader.Close();
            return id;
        }
예제 #11
0
        /**
        // \fn private void btnCreateEvent_Click(object sender, EventArgs e)
        //
        // \brief Event handler. Called by btnCreateEvent for click events.
        //
        // \author Simon Menetrey
        // \date 23.05.2014
        //
        // \param sender Source of the event.
        // \param e      Event information.
        **/
        private void btnCreateEvent_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txbEventName.Text.Trim()) && txbEventName.Text.Length <= MAX_NAME_LENGTH)
            {
                TimeSpan start = new TimeSpan();
                if (!TimeSpan.TryParse(mtbStartTime.Text, out start))
                {
                    MessageBox.Show("Start time format is not correct.", "Error");
                    return;
                }
                TimeSpan duration = new TimeSpan();
                if (!TimeSpan.TryParse(mtbDuration.Text, out duration))
                {
                    MessageBox.Show("Duration time format is not correct.", "Error");
                    return;
                }
                TimeSpan minimumDuration = new TimeSpan(0, 1, 0);
                if (duration >= minimumDuration)
                {
                    int repeat = this.GetRepeatValue();
                    if (repeat > 0)
                    {
                        CalendarEvent newEvent = new CalendarEvent(txbEventName.Text, start, duration, repeat, (int)nudPriority.Value, ckbShuffle.Checked, true, (Playlist)cmbPlaylistEvent.SelectedItem);
                        if (!this.Controller.CreateEvent(newEvent, this.IdWebradio))
                            MessageBox.Show("Event already exists (with this name)", "Error");
                    }
                    else
                        MessageBox.Show("Please select a day", "Error");

                }
                else
                    MessageBox.Show("Duration must be longer or equal to " + minimumDuration.ToString());
            }
            else
                MessageBox.Show("Please enter a valid event's name. (1-" + MAX_NAME_LENGTH + " characters)", "Error");
        }