Exemple #1
0
        /// <summary>
        ///  EA Execution
        /// </summary>
        protected override void Execute()
        {
            IEXGateway._IEXResult res;
            string   EventName            = "";
            EpgEvent eventToBeModified    = new EpgEvent(EPG.Utils);
            String   EPGDate              = "";
            String   EPGEventdate         = "";
            String   PCATEventDate        = "";
            String   EPGDateFormat        = "";
            String   PCATDateFormat       = "";
            String   milestoneDateFormat  = "";
            bool     Current              = true;
            string   EventSource          = "ManualFuture";
            string   Frequency            = "";
            int      Occurences           = 0;
            long     newDuration          = 0;
            String   tuneToService        = "";
            string   TodayDateInEPGFormat = "";

            tuneToService       = EPG.Utils.GetValueFromProject("MANUAL_RECORDING", "TUNE_TO_SERVICE_BEFORE_RECORD");
            milestoneDateFormat = EPG.Utils.GetValueFromProject("EPG", "MILESTONE_DATE_FORMAT");
            try
            {
                string recordNameChangeSupportedVal = EPG.Utils.GetValueFromProject("MANUAL_RECORDING", "RECORD_NAME_CHANGE_SUPPORTED");
                if (recordNameChangeSupportedVal != null)
                {
                    recordNameChangeSupported = Convert.ToBoolean(recordNameChangeSupportedVal);
                }
            }
            catch
            {
                recordNameChangeSupported = true;
            }
            PCATDateFormat = EPG.Utils.GetDateFormatForEventDictionary();
            EPGDateFormat  = EPG.Utils.GetEpgDateFormat();
            if (string.IsNullOrEmpty(this._EventKeyName))
            {
                ExceptionUtils.ThrowEx(new EAException(ExitCodes.NoValidParameters, "Param EventKeyName Is Empty"));
            }
            else
            {
                try
                {
                    eventToBeModified = EPG.Events[_EventKeyName];
                    EventName         = eventToBeModified.Name;
                }
                catch
                {
                    ExceptionUtils.ThrowEx(new EAException(ExitCodes.EventNotExistsFailure, "Event With Key Name - " + this._EventKeyName + " Does Not Exists On Collection"));
                }
            }

            EPGEventdate = eventToBeModified.ConvertedDate;
            Occurences   = eventToBeModified.Occurrences;

            if (!string.IsNullOrEmpty(_StartTime) && _StartTime.Contains(":") == false)
            {
                ExceptionUtils.ThrowEx(new EAException(ExitCodes.NoValidParameters, "Start Time Should Be Entered With Format : HH:MM"));
            }

            if (!string.IsNullOrEmpty(_EndTime) && _EndTime.Contains(":") == false)
            {
                ExceptionUtils.ThrowEx(new EAException(ExitCodes.NoValidParameters, "End Time Should Be Entered With Format : HH:MM"));
            }

            Current = false;

            switch (_Frequency)
            {
            case EnumFrequency.ONE_TIME:
                Frequency = EPG.Utils.GetValueFromDictionary("DIC_ONE_TIME");
                break;

            case EnumFrequency.DAILY:
                Frequency = EPG.Utils.GetValueFromDictionary("DIC_DAILY");
                break;

            case EnumFrequency.WEEKLY:
                Frequency = EPG.Utils.GetValueFromDictionary("DIC_WEEKLY");
                break;

            case EnumFrequency.WEEKDAY:
                Frequency = EPG.Utils.GetValueFromDictionary("DIC_WEEKDAY");
                break;

            case EnumFrequency.WEEKEND:
                Frequency = EPG.Utils.GetValueFromDictionary("DIC_WEEKEND");
                break;

            case EnumFrequency.NO_CHANGE:
                Frequency = eventToBeModified.Frequency;
                break;

            default:
                ExceptionUtils.ThrowEx(new EAException(ExitCodes.NoValidParameters, "No Valid Frequency Has Been Entered"));
                break;
            }

            EPG.Live.GetEpgDate(ref EPGDate);
            TodayDateInEPGFormat = DateTime.ParseExact(EPGDate, milestoneDateFormat, CultureInfo.InvariantCulture).ToString(EPGDateFormat);

            if (_Days > 0)
            {
                EPGEventdate  = DateTime.ParseExact(EPGEventdate, EPGDateFormat, CultureInfo.InvariantCulture).AddDays(_Days).ToString(EPGDateFormat);
                PCATEventDate = DateTime.ParseExact(EPGEventdate, EPGDateFormat, CultureInfo.InvariantCulture).AddDays(_Days).ToString(PCATDateFormat);
            }

            // Calculate the days delay
            if (EPGEventdate != TodayDateInEPGFormat)
            {
                _Days = (DateTime.ParseExact(EPGEventdate, EPGDateFormat, CultureInfo.InvariantCulture) - DateTime.ParseExact(TodayDateInEPGFormat, EPGDateFormat, CultureInfo.InvariantCulture)).Days;
            }


            EPG.ManualRecording.GetOccurences(Frequency, _Days, ref Occurences);

            if (!string.IsNullOrEmpty(_StartTime) && !string.IsNullOrEmpty(_EndTime))
            {
                newDuration = EPG.Utils._DateTime.SubtractInSec(DateTime.Parse(_EndTime), DateTime.Parse(_StartTime));
            }

            // Tune to service if required
            int    channelNum  = -1;
            String channelName = "";

            if (!string.IsNullOrEmpty(_ChannelName) && _ChannelName != eventToBeModified.Channel)
            {
                if (tuneToService.ToUpper() == "TRUE")
                {
                    try
                    {
                        channelNum = int.Parse(_manager.GetServiceFromContentXML("Name=" + _ChannelName).LCN);
                    }
                    catch (Exception ex)
                    {
                        ExceptionUtils.ThrowEx(new EAException(ExitCodes.GetChannelFailure, ex.Message));
                    }
                    res = _manager.ChannelSurf(EnumSurfIn.Live, channelNum.ToString());
                    if (!res.CommandSucceeded)
                    {
                        ExceptionUtils.ThrowEx(new EAException(ExitCodes.TuneToChannelFailure, res.FailureReason));
                    }
                }
                else
                {
                    channelName = _ChannelName;
                }

                // Event name should be changed to channel name
                EventName = _ChannelName;
            }
            else
            {
                // For Event based to Time based, fetch channel name from the channel number in event collection
                try
                {
                    if (recordNameChangeSupported)
                    {
                        EventName = _manager.GetServiceFromContentXML("LCN=" + eventToBeModified.Channel).Name;
                    }
                }
                catch
                {
                    EPG.Utils.LogCommentInfo("Event channel from collection:" + eventToBeModified.Channel);
                }
            }

            res = _manager.PVR.VerifyEventInPlanner(_EventKeyName);
            if (res.CommandSucceeded == false)
            {
                ExceptionUtils.ThrowEx(new EAException(ExitCodes.FindEventFailure, res.FailureReason));
            }

            EPG.FutureRecordings.SelectEvent(eventToBeModified.Name);

            EPG.FutureRecordings.ModifyEvent();

            //Checking if there are no changes required in setting date and Frequency
            if (EPGEventdate == eventToBeModified.ConvertedDate)
            {
                EPGEventdate = "";
            }

            if (_IsFirstTime)
            {
                if (Frequency == eventToBeModified.Frequency)
                {
                    Frequency = "";
                }
            }

            EPG.ManualRecording.SetManualRecordingParams(EPGEventdate, _StartTime, channelName, channelNum, _EndTime, Frequency, true, _IsFirstTime);

            EPG.ManualRecording.SaveAndEnd(Current, true);

            try
            {
                EPG.ManualRecording.VerifySaveAndEndFinished(Current);
            }
            catch (EAException ex)
            {
                EPG.Events.Remove(_EventKeyName);
                ExceptionUtils.ThrowEx(new EAException(ExitCodes.VerificationFailure, ex.Message));
            }

            EPG.Utils.InsertEventToCollection(this._EventKeyName, EventName, EventSource, _StartTime, _EndTime, _ChannelName, newDuration, 0, PCATEventDate, Frequency,
                                              Occurences, EPGEventdate, true);

            EPG.Utils.ReturnToLiveViewing();
        }
        protected override void Execute()
        {
            IEXGateway._IEXResult res  = default(IEXGateway._IEXResult);
            string EventName           = "";
            string StartTime           = "";
            string EndTime             = "";
            int    OriginalDuration    = 0;
            int    Duration            = 0;
            string milestoneDateFormat = "";
            string EventDate           = "";
            int    TimeLeft            = 0;

            milestoneDateFormat = EPG.Utils.GetValueFromProject("EPG", "MILESTONE_DATE_FORMAT");
            if (string.IsNullOrEmpty(_EventKeyName))
            {
                ExceptionUtils.ThrowEx(new EAException(ExitCodes.NoValidParameters, "EventKeyName Is Empty"));
            }

            if (Convert.ToInt32(_ChannelNumber) <= 0)
            {
                ExceptionUtils.ThrowEx(new EAException(ExitCodes.NoValidParameters, "ChannelNumber Can't Be Equal Or Less Than 0"));
            }

            res = _manager.ChannelSurf(EnumSurfIn.Live, _ChannelNumber);

            if (this._MinTimeBeforeEvEnd > 0)
            {
                EPG.Banner.GetEventTimeLeft(ref TimeLeft);

                if (TimeLeft <= _MinTimeBeforeEvEnd * 60)
                {
                    EPG.Utils.LogCommentImportant("Current Event Time Left Was Less Than " + Convert.ToString(_MinTimeBeforeEvEnd) + " Minutes Waiting " + (TimeLeft + 5).ToString() + " Seconds");
                    EPG.Utils.ReturnToLiveViewing();
                    _iex.Wait(TimeLeft + 5);

                    EPG.Utils.EPG_Milestones_NavigateByName("STATE:LIVE");
                }
            }


            switch (_RecordIn)
            {
            case EnumRecordIn.Guide:
            {
                EPG.Guide.Navigate();
                EPG.Guide.NavigateToChannel(_ChannelNumber, true);
                if (!(_IsCurrent))
                {
                    EPG.Guide.NextEvent();
                }
                break;
            }

            case EnumRecordIn.ChannelBar:
            {
                if (_IsCurrent)
                {
                    EPG.ChannelBar.Navigate();
                }

                else
                {
                    EPG.ChannelBar.NextEvent(false);
                }
                break;
            }

            case EnumRecordIn.ActionBar:
            {
                EPG.Banner.Navigate();
                break;
            }

            case EnumRecordIn.Live:
            {
                EPG.Utils.ReturnToLiveViewing(true);
                break;
            }
            }

            EPG.Banner.GetEventName(ref EventName);

            if (string.IsNullOrEmpty(EventName) | EventName == "null")
            {
                SetWarning("Event Name Is Empty Will Fail Test If Tryied To Use");
            }

            EPG.Banner.GetEventStartTime(ref StartTime);

            EPG.Banner.GetEventEndTime(ref EndTime);
            EPG.Live.GetEpgDate(ref EventDate);
            EventDate = DateTime.ParseExact(EventDate, milestoneDateFormat, CultureInfo.InvariantCulture).ToString(EPG.Utils.GetEpgDateFormat());

            OriginalDuration = EPG.Utils._DateTime.SubtractInSec(Convert.ToDateTime(EndTime), Convert.ToDateTime(StartTime));

            EPG.Banner.GetEventTimeLeft(ref Duration);

            EPG.Utils.InsertEventToCollection(_EventKeyName, EventName, "GuideCurrent", StartTime, EndTime, Convert.ToString(_ChannelNumber), Duration, OriginalDuration, "", "",
                                              0, EventDate);

            if (_IsConflict)
            {
                try
                {
                    EPG.Menu.SelectToConflict();
                }
                catch
                {
                    EPG.Events.Remove(_EventKeyName);
                    ExceptionUtils.ThrowEx(new EAException(ExitCodes.SelectEventFailure, "Failed to select event " + _EventKeyName + "'"));
                }
            }
            else
            {
                try
                {
                    EPG.Utils.PreRecordRECkey(_IsCurrent, _IsConflict, _IsSeries);
                    _iex.Wait(2);
                    EPG.Banner.RecordEvent(_IsCurrent, false, _IsConflict, false, _IsSeries);
                }
                catch
                {
                    EPG.Events.Remove(_EventKeyName);
                    ExceptionUtils.ThrowEx(new EAException(ExitCodes.RecordEventFailure, "Failed to Record event " + _EventKeyName + "'"));
                }
                if (_IsCurrent)
                {
                    if (this._VerifyBookingInPCAT)
                    {
                        res = this._manager.PCAT.VerifyEventBooked(this._EventKeyName);
                        if (!res.CommandSucceeded)
                        {
                            EPG.Events.Remove(_EventKeyName);
                            ExceptionUtils.ThrowEx(new EAException(ExitCodes.PCATFailure, res.FailureReason));
                        }
                    }
                }
                else
                {
                    if (this._VerifyBookingInPCAT)
                    {
                        res = this._manager.PCAT.VerifyEventBooked(this._EventKeyName);
                        if (!res.CommandSucceeded)
                        {
                            EPG.Events.Remove(_EventKeyName);
                            ExceptionUtils.ThrowEx(new EAException(ExitCodes.PCATFailure, res.FailureReason));
                        }
                        res = this._manager.PCAT.VerifyEventStatus(this._EventKeyName, EnumPCATtables.FromBookings, "BOOKING_TYPE", "RECORD", false);
                        if (!res.CommandSucceeded)
                        {
                            EPG.Events.Remove(_EventKeyName);
                            ExceptionUtils.ThrowEx(new EAException(ExitCodes.PCATFailure, res.FailureReason));
                        }
                    }
                }

                if (this._ReturnToLive)
                {
                    EPG.Utils.ReturnToLiveViewing();
                }
            }
        }
        protected override void Execute()
        {
            String  frequency           = "";
            int     occurences          = -1;
            String  EPGTime             = "";
            String  EPGDate             = "";
            String  startTimeToSet      = "";
            String  endTimeToSet        = "";
            String  EPGEventdate        = "";
            String  PCATEventDate       = "";
            String  EPGDateFormat       = "";
            String  PCATDateFormat      = "";
            String  tuneToService       = "";
            String  milestoneDateFormat = "";
            Boolean isCurrentRecording  = false;
            String  EventSource         = "";
            String  EventName           = "";

            IEXGateway._IEXResult res;

            tuneToService       = EPG.Utils.GetValueFromProject("MANUAL_RECORDING", "TUNE_TO_SERVICE_BEFORE_RECORD");
            milestoneDateFormat = EPG.Utils.GetValueFromProject("EPG", "MILESTONE_DATE_FORMAT");
            EPGDateFormat       = EPG.Utils.GetEpgDateFormat();
            PCATDateFormat      = EPG.Utils.GetDateFormatForEventDictionary();

            // Validate input parameters
            if (String.IsNullOrEmpty(_EventKeyName))
            {
                ExceptionUtils.ThrowEx(new EAException(ExitCodes.NoValidParameters, "EventKeyName Is Empty"));
            }

            if (String.IsNullOrEmpty(_ChannelName) && _ChannelNumber == -1)
            {
                ExceptionUtils.ThrowEx(new EAException(ExitCodes.NoValidParameters, "Channel Argument Can't Be Empty"));
            }

            if (_DurationInMin <= 0)
            {
                ExceptionUtils.ThrowEx(new EAException(ExitCodes.NoValidParameters, "DurationInMin Can't Be Equal Or Less Than 0"));
            }

            if (_StartTime != "" && _DaysDelay < 1)
            {
                ExceptionUtils.ThrowEx(new EAException(ExitCodes.NoValidParameters, "DaysDelay Can't Be Less Then 1 In Case StartTime Entered"));
            }

            // Set validation params for frequency and occurences accordingly
            switch (_Frequency)
            {
            case EnumFrequency.ONE_TIME:
                frequency = EPG.Utils.GetValueFromDictionary("DIC_ONE_TIME");
                break;

            case EnumFrequency.DAILY:
                frequency = EPG.Utils.GetValueFromDictionary("DIC_DAILY");
                break;

            case EnumFrequency.WEEKLY:
                frequency = EPG.Utils.GetValueFromDictionary("DIC_WEEKLY");
                break;

            case EnumFrequency.WEEKDAY:
                frequency = EPG.Utils.GetValueFromDictionary("DIC_WEEKDAY");
                break;

            case EnumFrequency.WEEKEND:
                frequency = EPG.Utils.GetValueFromDictionary("DIC_WEEKEND");
                break;

            default:
                ExceptionUtils.ThrowEx(new EAException(ExitCodes.NoValidParameters, "No Valid Frequency Has Been Entered"));
                break;
            }

            // In case from Planner, keep 2 min buffer for delay until beginning to account for time taken up for scheduling the recording
            if (!_IsCurrent)
            {
                if (_MinutesDelayUntilBegining < 0)
                {
                    _MinutesDelayUntilBegining = 2;
                }
                else
                {
                    _MinutesDelayUntilBegining += 2;
                }
            }
            else
            {
                _MinutesDelayUntilBegining = 0;
            }

            // Tune to service if required
            String channelName = "";
            int    channelNum  = -1;

            if (_IsCurrent || tuneToService.ToUpper() == "TRUE")
            {
                if (_ChannelNumber == -1)
                {
                    try
                    {
                        _ChannelNumber = int.Parse(_manager.GetServiceFromContentXML("Name=" + _ChannelName).LCN);
                    }
                    catch (Exception ex)
                    {
                        ExceptionUtils.ThrowEx(new EAException(ExitCodes.GetChannelFailure, ex.Message));
                    }
                }
                res = _manager.ChannelSurf(EnumSurfIn.Live, _ChannelNumber.ToString());
                if (!res.CommandSucceeded)
                {
                    ExceptionUtils.ThrowEx(new EAException(ExitCodes.TuneToChannelFailure, res.FailureReason));
                }
            }
            else
            {
                channelName = _ChannelName;
                channelNum  = _ChannelNumber;
            }

            // Set the event Name
            EventName = _ChannelName;
            if (_ChannelName == "")
            {
                EventName   = _manager.GetServiceFromContentXML("LCN=" + _ChannelNumber).Name;
                channelName = EventName;
            }

            // Calculate start Time to be set
            EPG.Live.GetEpgTime(ref EPGTime);
            if (_StartTime == "")
            {
                // Handle the case if Minutes delay passed is more than a day
                if (_MinutesDelayUntilBegining > ((24 * 60) - ((DateTime.Parse(EPGTime).Hour * 60) + DateTime.Parse(EPGTime).Minute)))
                {
                    if (_DaysDelay == -1)
                    {
                        _DaysDelay = 0;
                        _DaysDelay = _DaysDelay + _MinutesDelayUntilBegining / (24 * 60) + 1;
                    }
                    else
                    {
                        _DaysDelay = _DaysDelay + _MinutesDelayUntilBegining / (24 * 60);
                    }

                    _MinutesDelayUntilBegining = _MinutesDelayUntilBegining % (24 * 60);
                }

                startTimeToSet = DateTime.Parse(EPGTime).AddMinutes(_MinutesDelayUntilBegining).ToString("HH:mm");
            }
            else
            {
                startTimeToSet = _StartTime;
            }

            // Set Event Source
            if (_IsCurrent)
            {
                isCurrentRecording = true;
                EventSource        = "ManualCurrent";
            }
            else
            {
                EventSource = "ManualFuture";
            }

            // Calculate end time to be set
            endTimeToSet = (DateTime.Parse(startTimeToSet).AddMinutes(_DurationInMin)).ToString("HH:mm");

            // Set proper days delay param
            if (_DaysDelay < 0)
            {
                _DaysDelay = 0;
            }

            // Calculate the date to be set
            EPG.Live.GetEpgDate(ref EPGDate);

            EPGEventdate  = DateTime.ParseExact(EPGDate, milestoneDateFormat, CultureInfo.InvariantCulture).AddDays(_DaysDelay).ToString(EPGDateFormat);
            PCATEventDate = DateTime.ParseExact(EPGDate, milestoneDateFormat, CultureInfo.InvariantCulture).AddDays(_DaysDelay).ToString(PCATDateFormat);

            // Get the expected number of occurences
            EPG.ManualRecording.GetOccurences(frequency, _DaysDelay, ref occurences);

            // Navigate to Manual Recording screen from Planner
            EPG.ManualRecording.Navigate(_IsCurrent, _NoEIT);

            // Set params for manual recording
            if (_IsCurrent)
            {
                EPG.ManualRecording.SetManualRecordingParams("", "", "", -1, endTimeToSet, frequency);
            }
            else
            {
                EPG.ManualRecording.SetManualRecordingParams(EPGEventdate, startTimeToSet, channelName, channelNum, endTimeToSet, frequency);
            }

            // Save and verify
            if (_IsConflict)
            {
                EPG.Utils.InsertEventToCollection(_EventKeyName, EventName, EventSource, startTimeToSet, endTimeToSet, _ChannelName, _DurationInMin * 60, _DurationInMin * 60, PCATEventDate, frequency, occurences, EPGEventdate, false);
                try
                {
                    EPG.ManualRecording.NavigateToRecord(false);
                    EPG.Menu.SelectToConflict();
                }
                catch (Exception ex)
                {
                    EPG.Events.Remove(_EventKeyName);
                    ExceptionUtils.ThrowEx(new EAException(ExitCodes.ConflictFailure, "Failed To Create Conflict By Recording Event From Planner:" + ex.Message));
                }
            }
            else
            {
                EPG.ManualRecording.SaveAndEnd(isCurrentRecording);

                try
                {
                    EPG.ManualRecording.VerifySaveAndEndFinished(isCurrentRecording);
                }
                catch (Exception ex)
                {
                    EPG.Events.Remove(_EventKeyName);
                    ExceptionUtils.ThrowEx(new EAException(ExitCodes.DeleteEventFailure, ex.Message));
                }

                EPG.Utils.InsertEventToCollection(_EventKeyName, EventName, EventSource, startTimeToSet, endTimeToSet, _ChannelName, _DurationInMin * 60, _DurationInMin * 60, PCATEventDate, frequency, occurences, EPGEventdate, false);

                if (_VerifyBookingInPCAT)
                {
                    res = _manager.PCAT.VerifyEventBooked(_EventKeyName);
                    if (!res.CommandSucceeded)
                    {
                        EPG.Events.Remove(_EventKeyName);
                        ExceptionUtils.ThrowEx(new EAException(ExitCodes.VerificationFailure, res.FailureReason));
                    }
                }

                EPG.Utils.ReturnToLiveViewing();
            }
        }