public Scheduler() { // Default the Handler ID to the UAC ad handler format. This could be changed to cause ads to be handled by a different plugin. HandlerId = AdHandler.PayloadFormat; AutoPlay = true; status = SchedulingStatus.Pending; StartPositionExcludeTheshold = TimeSpan.FromSeconds(.25); }
/// <summary> /// 枚举转文字 /// </summary> /// <param name="d"></param> /// <returns></returns> public static string Enum2String(SchedulingStatus d) { switch (d) { case SchedulingStatus.Full: return("满"); case SchedulingStatus.Nothing: return("无"); case SchedulingStatus.MoreThan: return("余"); case SchedulingStatus.NoNum: return("无号"); default: return("未知"); } }
private SchedulingInfo(SerializationInfo info, StreamingContext context) { _requestedTime = info.GetDateTime("_requestedTime"); _expectedStartTime = info.GetDateTime("_expectedStartTime"); _expectedEndTime = info.GetDateTime("_expectedEndTime"); _maxDeviationAfter = (TimeSpan)info.GetValue("_maxDeviationAfter", typeof(TimeSpan)); _maxDeviationBefore = (TimeSpan)info.GetValue("_maxDeviationBefore", typeof(TimeSpan)); _schedulingStatus = (SchedulingStatus)info.GetValue("_schedulingStatus", typeof(SchedulingStatus)); _schedulingScope = (SchedulingScope)info.GetValue("_schedulingScope", typeof(SchedulingScope)); if (info.GetBoolean("IsLocked")) { ((ILockable)this).Lock(); } }
internal static Task ToTask(dynamic dTask) { if (dTask == null) { return(null); } /* * { * "id": 752517863351, * "created_at": "2012-04-22T03:29:33.284Z", * "modified_at": "2012-05-05T14:54:17.789Z", * "name": "require a login", * "notes": "", * "assignee": { * "id": 752517793331, * "name": "Chris Barbara" * }, * "completed": false, * "assignee_status": "later", * "due_on": null, * "projects": [ * { * "id": 752517863337, * "name": "T-1000" * } * ], * "workspace": { * "id": 752517862999, * "name": "Xignite" * }, * "followers": [ * { * "id": 752517793331, * "name": "Chris Barbara" * } * ], * "completed_at": null * } */ Task t = new Task() { Id = long.Parse(dTask.id.ToString()), Name = dTask.name }; //if this is null, then we are just dealing with a list of Ids & names. if (dTask.created_at == null) { return(t); } t.CreatedAt = DateTime.Parse(dTask.created_at); if (dTask.modified_at != null) { t.ModifiedAt = DateTime.Parse(dTask.modified_at); } t.Notes = dTask.notes; t.Assignee = ToAssignee(dTask.assignee); t.Completed = dTask.completed; SchedulingStatus ss = SchedulingStatus.Inbox; if (Enum.TryParse <SchedulingStatus>(dTask.assignee_status, true, out ss)) { t.AssigneeStatus = ss; } if (dTask.due_on != null) { t.DueDate = DateTime.Parse(dTask.due_on); } t.Projects = ToProjects(dTask.projects); t.Workspace = ToWorkspace(dTask.workspace); t.Followers = ToAssignees(dTask.followers); if (dTask.completed_at != null) { t.CompletedAt = DateTime.Parse(dTask.completed_at); } return(t); }
private void ScheduleDownloadedHandler(Exception error, AdSchedule schedule) { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { if (error != null) { HandleManifestDownloadFailed(error); return; } if (IsLoaded) { this.adSchedule = schedule; if (AutoPlay || PlayWhenReady) { try { Status = SchedulingStatus.ScheduleReady; } catch (Exception ex) { Status = SchedulingStatus.Failed; if (SchedulingFailed != null) SchedulingFailed(this, new SchedulingFailedEventArgs(ex)); } finally { // release the player block ReleasePlayback(); } } else { Status = SchedulingStatus.Postponed; } } else { Status = SchedulingStatus.Disabled; } }); }
private void ScheduleAds() { if (Status == SchedulingStatus.ScheduleReady) { // schedule ads if (ReadManifest()) { Status = SchedulingStatus.Scheduled; PreparePostRolls(); } else { HandleManifestDownloadFailed(new System.Exception("No valid ads in schedule")); } } }
void player_ContentChanged(object sender, EventArgs e) { pendingMediaSource = null; PlayWhenReady = false; PostRoll = null; adSchedule = null; CleanupScheduledAds(); if (player.ActiveMediaPlugin != null) { Status = SchedulingStatus.Downloading; // block the player from starting. We need to get a video manifest first in case there is a preroll. BlockPlayback(); System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { object adData = null; // Disable warning on using freewheel and microsoft keys #pragma warning disable 618 if (player.ContentMetadata.ContainsKey(Key_FreeWheelUrl)) { adData = player.ContentMetadata[Key_FreeWheelUrl]; } if (player.ContentMetadata.ContainsKey(Key_MicrosoftUrl)) { adData = player.ContentMetadata[Key_MicrosoftUrl]; } #pragma warning restore 618 if (player.ContentMetadata.ContainsKey(Key_AdUrl)) { adData = player.ContentMetadata[Key_AdUrl]; } if (adData != null) { if (adData is String || adData is Stream) { try { if (adData is String) { string uri = adData as String; if (Uri.IsWellFormedUriString(uri, UriKind.RelativeOrAbsolute) == false) { uri = Uri.EscapeUriString(uri); } AdManager.GetSchedule(uri, ScheduleDownloadedHandler); } else if (adData is Stream) { AdManager.GetSchedule(adData as Stream, ScheduleDownloadedHandler); } } catch (Exception ex) { HandleManifestDownloadFailed(ex); } } else { SendLogEntry("UAC Metadata type is not supported", Microsoft.SilverlightMediaFramework.Plugins.Primitives.LogLevel.Information, "Skipping UAC ad scheduling"); } } else { if (AutoPlay || PlayWhenReady) ReleasePlayback(); Status = SchedulingStatus.Failed; SendLogEntry("UAC Metadata not found", Microsoft.SilverlightMediaFramework.Plugins.Primitives.LogLevel.Information, "Skipping UAC ad scheduling"); return; } }); } else { Status = SchedulingStatus.Disabled; } }
private void HandleManifestDownloadFailed(Exception ex) { adSchedule = null; if (AutoPlay || PlayWhenReady) ReleasePlayback(); Status = SchedulingStatus.Failed; if (SchedulingFailed != null) SchedulingFailed(this, new SchedulingFailedEventArgs(ex)); SendLogEntry("UAC VideoManifest.DownloadAsync Failed", Microsoft.SilverlightMediaFramework.Plugins.Primitives.LogLevel.Error, ex.Message); }
/// <summary> /// Manually force ads to get scheduled and start playing. Only use this if AutoPlay = false. /// </summary> public void Play() { try { switch (Status) { case SchedulingStatus.Postponed: // Schedule ads found in the video manifest Status = SchedulingStatus.ScheduleReady; ReleasePlayback(); break; case SchedulingStatus.Downloading: // we're still loading the manifest, play as soon as possible PlayWhenReady = true; break; case SchedulingStatus.Failed: // we failed, but at least we can release the player block ReleasePlayback(); break; case SchedulingStatus.Disabled: throw new Exception("Invalid request, Scheduler is disabled"); case SchedulingStatus.Pending: throw new Exception("Invalid request, Scheduler is pending and cannot be played until PlaylistItemChanged event finishes"); case SchedulingStatus.Scheduled: case SchedulingStatus.ScheduleReady: throw new Exception("Invalid request, Scheduler has already been scheduled"); } } catch { // release the player block ReleasePlayback(); throw; } }
protected void SetStatus(SchedulingStatus status) { this.Status = status; }