コード例 #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();
        }
コード例 #2
0
        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();
            }
        }