public B1Session LoginServer(string usrName = "manager", string pwd = @"L4nd3$", string db = @"SBOLANDE") { B1Session session = null; try { //Discard last login information sessionGuid = string.Empty; Uri login = new Uri(urlSl + "Login"); //Use : UriOperationParameter for querying options. //Use : BodyOperationParameter for sending JSON body. BodyOperationParameter[] body = new BodyOperationParameter[3]; body[0] = new BodyOperationParameter("UserName", usrName); body[1] = new BodyOperationParameter("Password", pwd); body[2] = new BodyOperationParameter("CompanyDB", db); //Both HTTP & HTTPs protocols are supported. session = (B1Session)serviceContainer.Execute <B1Session>(login, "POST", true, body).SingleOrDefault(); if (null != session) { sessionGuid = session.SessionId; } } catch (Exception ex) { sessionGuid = string.Empty; //clear the last time's session id throw ex; } return(session); }
private static Job initiateRunbookJob(OrchestratorApi sma, String runbookName, List <NameValuePair> runbookParameters) { ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback( delegate { return(true); }); List <string> parameterNames = new List <string>(); var runbook = (from rb in sma.Runbooks where rb.RunbookName == runbookName select rb).AsEnumerable().FirstOrDefault(); if (runbook == null) { var msg = string.Format(CultureInfo.InvariantCulture, "{0}: {1}", refStrings.RunbookNotFound, runbookName); throw new Exception(msg); } OperationParameter operationParameters = new BodyOperationParameter(refStrings.JobParameterName, runbookParameters); string uri = string.Concat(sma.Runbooks, string.Format("(guid'{0}')/{1}", runbook.RunbookID, refStrings.StartRunbookActionName)); Uri uriSMA = new Uri(uri, UriKind.Absolute); // Create the job var jobIdValue = sma.Execute <Guid>(uriSMA, refStrings.HttpPost, true, operationParameters) as QueryOperationResponse <Guid>; var jobId = jobIdValue.Single(); var job = sma.Jobs.Where(j => j.JobID == jobId).AsEnumerable().FirstOrDefault(); if (job == null) { throw new Exception(refStrings.JobNotStarted); } return(job); }
public BodyOperationParameter[] GetBodyOperationParametersFromObject(object input) { var operationParameters = new List <BodyOperationParameter>(); if (null == input) { return(operationParameters.ToArray()); } const BindingFlags BINDING_FLAGS = BindingFlags.Public | BindingFlags.Instance; var properties = input.GetType().GetProperties(BINDING_FLAGS); foreach (var property in properties) { var operationParameter = new BodyOperationParameter(property.Name, property.GetValue(input)); operationParameters.Add(operationParameter); } var fields = input.GetType().GetFields(BINDING_FLAGS); foreach (var field in fields) { var operationParameter = new BodyOperationParameter(field.Name, field.GetValue(input)); operationParameters.Add(operationParameter); } return(operationParameters.ToArray()); }
/// <summary> /// Scales the streaming endpoint. /// </summary> /// <param name="scaleUnits">New scale units.</param> /// <returns>Task to wait on for operation completion.</returns> public Task ScaleAsync(int scaleUnits) { var uri = new Uri(string.Format(CultureInfo.InvariantCulture, "/StreamingEndpoints('{0}')/Scale", Id), UriKind.Relative); var ruParameter = new BodyOperationParameter("scaleUnits", scaleUnits); return(ExecuteActionAsync(uri, StreamingConstants.ScaleStreamingEndpointPollInterval, ruParameter)); }
/// <summary> /// Sends scale operation to the service and returns. Use Operations collection to get operation's status. /// </summary> /// <returns>Operation info that can be used to track the operation.</returns> public IOperation SendScaleOperation(int scaleUnits) { var uri = new Uri(string.Format(CultureInfo.InvariantCulture, "/StreamingEndpoints('{0}')/Scale", Id), UriKind.Relative); var ruParameter = new BodyOperationParameter("scaleUnits", scaleUnits); return(SendOperation(uri, ruParameter)); }
/// <summary> /// Sends end advertisement operation to the service and returns. Use Operations collection to get operation's status. /// </summary> /// <param name="cueId">The cue id of the ad marker to end.</param> /// <returns>Operation info that can be used to track the operation.</returns> public IOperation SendEndAdvertisementOperation(int cueId) { var uri = new Uri( string.Format(CultureInfo.InvariantCulture, StreamingConstants.ChannelEndAdUriFormat, Id), UriKind.Relative); var cueIdParameter = new BodyOperationParameter(StreamingConstants.StartAdCueIdParameter, cueId); return(SendOperation(uri, cueIdParameter)); }
/// <summary> /// Ends the ad marker on the channel asynchronously. /// </summary> /// <param name="cueId">The cue id of the ad marker to end.</param> /// <returns>Task to wait on for operation completion.</returns> public Task EndAdvertisementAsync(int cueId) { var uri = new Uri( string.Format(CultureInfo.InvariantCulture, StreamingConstants.ChannelEndAdUriFormat, Id), UriKind.Relative); var cueIdParameter = new BodyOperationParameter(StreamingConstants.StartAdCueIdParameter, cueId); return(ExecuteActionAsync(uri, StreamingConstants.EndAdvertisementPollInterval, cueIdParameter)); }
/// <summary> /// Sends show slate operation to the service and returns. Use Operations collection to get operation's status. /// </summary> /// <param name="duration">The duration of time to display the slate</param> /// <param name="assetId">Optional asset id to be used for the slate.</param> /// <returns>Operation info that can be used to track the operation.</returns> public IOperation SendShowSlateOperation(TimeSpan duration, string assetId) { var uri = new Uri( string.Format(CultureInfo.InvariantCulture, StreamingConstants.ChannelShowSlateUriFormat, Id), UriKind.Relative); var durationParameter = new BodyOperationParameter(StreamingConstants.ShowSlateDurationParameter, duration); var assetIdParameter = new BodyOperationParameter(StreamingConstants.ShowSlateAssetIdParameter, assetId); return(SendOperation(uri, durationParameter, assetIdParameter)); }
/// <summary> /// Show a slate on the channel asynchronously. /// </summary> /// <param name="duration">The duration of time to display the slate</param> /// <param name="assetId">Optional asset id to be used for the slate.</param> /// <returns>Task to wait on for operation completion.</returns> public Task ShowSlateAsync(TimeSpan duration, string assetId) { var uri = new Uri( string.Format(CultureInfo.InvariantCulture, StreamingConstants.ChannelShowSlateUriFormat, Id), UriKind.Relative); var durationParameter = new BodyOperationParameter(StreamingConstants.ShowSlateDurationParameter, duration); var assetIdParameter = new BodyOperationParameter(StreamingConstants.ShowSlateAssetIdParameter, assetId); return(ExecuteActionAsync(uri, StreamingConstants.ShowSlatePollInterval, durationParameter, assetIdParameter)); }
/// <summary> /// Sends start advertisement operation to the service and returns. Use Operations collection to get operation's status. /// </summary> /// <param name="duration">The duration of the ad marker.</param> /// <param name="cueId">optional cue id to use for the ad marker.</param> /// <param name="showSlate">Indicates whether to show slate for the duration of the ad.</param> /// <returns>Operation info that can be used to track the operation.</returns> public IOperation SendStartAdvertisementOperation(TimeSpan duration, int cueId, bool showSlate = true) { var uri = new Uri( string.Format(CultureInfo.InvariantCulture, StreamingConstants.ChannelStartAdUriFormat, Id), UriKind.Relative); var durationParameter = new BodyOperationParameter(StreamingConstants.StartAdDurationParameter, duration); var cueIdParameter = new BodyOperationParameter(StreamingConstants.StartAdCueIdParameter, cueId); var showSlateParameter = new BodyOperationParameter(StreamingConstants.StartAdShowSlateParameter, showSlate); return(SendOperation(uri, durationParameter, cueIdParameter, showSlateParameter)); }
/// <summary> /// Start an Ad marker on the channel asynchronously. /// </summary> /// <param name="duration">The duration of the ad marker.</param> /// <param name="cueId">optional cue id to use for the ad marker.</param> /// <param name="showSlate">Indicates whether to show slate for the duration of the ad.</param> /// <returns>Task to wait on for operation completion.</returns> public Task StartAdvertisementAsync(TimeSpan duration, int cueId, bool showSlate = true) { var uri = new Uri( string.Format(CultureInfo.InvariantCulture, StreamingConstants.ChannelStartAdUriFormat, Id), UriKind.Relative); var durationParameter = new BodyOperationParameter(StreamingConstants.StartAdDurationParameter, duration); var cueIdParameter = new BodyOperationParameter(StreamingConstants.StartAdCueIdParameter, cueId); var showSlateParameter = new BodyOperationParameter(StreamingConstants.StartAdShowSlateParameter, showSlate); return(ExecuteActionAsync(uri, StreamingConstants.StartAdvertisementPollInterval, durationParameter, cueIdParameter, showSlateParameter)); }
/// <summary> /// Start Runbook with the the given Runbook and list of NameValuepair parameters /// </summary> /// <param name="runbook"></param> /// <param name="parameters"></param> /// <returns></returns> private RunbookJob StartRunBook(Runbook runbook, List <NameValuePair> parameters) { //try //{ IgnoreCertificate(); #region Setting up parameters for runbook OperationParameter operationParameters = new BodyOperationParameter(JobParameterName, parameters); #endregion Setting up parameters for runbook ValidateParameters(runbook, parameters); #region Create runbook job // Format the uri var uri = string.Concat(api.Runbooks, string.Format("(guid'{0}')/{1}", runbook.RunbookID, StartRunbookActionName)); var uriSMA = new Uri(uri, UriKind.Absolute); var jobIdValue = api.Execute <Guid>(uriSMA, HttpPost, true, operationParameters) as QueryOperationResponse <Guid>; var jobId = jobIdValue.Single(); var job = api.Jobs.Where(j => j.JobID == jobId).First(); if (job == null) { return(new RunbookJob { OutputMessage = "Job not started!" }); } else { return(new RunbookJob { Id = jobId, OutputMessage = String.Format("Job Started. JobID: {0}, JobStatus: {1}", jobId, job.JobStatus) }); } #endregion Create runbook job // } //catch (DataServiceQueryException ex) //{ // throw new ApplicationException("Error starting runbook.", ex); //} }
public BodyOperationParameter[] GetBodyOperationParametersFromDictionary(Dictionary <string, object> input) { var operationParameters = new List <BodyOperationParameter>(); if (null == input) { return(operationParameters.ToArray()); } foreach (var entry in input) { var operationParameter = new BodyOperationParameter(entry.Key, entry.Value); operationParameters.Add(operationParameter); } return(operationParameters.ToArray()); }
public BodyOperationParameter[] GetBodyOperationParametersFromHashtable(Hashtable input) { var operationParameters = new List <BodyOperationParameter>(); if (null == input) { return(operationParameters.ToArray()); } foreach (DictionaryEntry entry in input) { var operationParameter = new BodyOperationParameter(entry.Key.ToString(), entry.Value); operationParameters.Add(operationParameter); } return(operationParameters.ToArray()); }
/// <summary> /// Gets the Key Delivery Uri Asynchronously /// </summary> public Task <Uri> GetKeyDeliveryUrlAsync(ContentKeyDeliveryType contentKeyDeliveryType) { return(Task.Factory.StartNew <Uri>(() => { Uri returnValue = null; if (this.GetMediaContext() != null) { IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext(); MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetQueryRetryPolicy(dataContext as IRetryPolicyAdapter); Uri uriGetKeyDeliveryUrl = new Uri(string.Format(CultureInfo.InvariantCulture, "/ContentKeys('{0}')/GetKeyDeliveryUrl", this.Id), UriKind.Relative); BodyOperationParameter keyDeliveryTypeParameter = new BodyOperationParameter("keyDeliveryType", (int)contentKeyDeliveryType); try { IEnumerable <string> results = retryPolicy.ExecuteAction <IEnumerable <string> >(() => dataContext.ExecuteAsync(uriGetKeyDeliveryUrl, "POST", true, keyDeliveryTypeParameter).Result); if (results != null) { // We specified only one result above so take the first result string uriString = results.FirstOrDefault(); if (uriString != null) { returnValue = new Uri(uriString); } } } catch (AggregateException exception) { throw exception.Flatten().InnerException; } } return returnValue; })); }
public void ExecuteRunbook(string subscriptionId, OpsLogix.WAP.RunPowerShell.ApiClient.DataContracts.RunbookParameter rbParameter) { System.Configuration.ConnectionStringSettings url = System.Configuration.ConfigurationManager.ConnectionStrings["SMAUrl"]; /* * var api = new OrchestratorApi(new Uri("https://sma.lab.local/00000000-0000-0000-0000-000000000000"));*/ //var api = new OrchestratorApi(new Uri(url.ConnectionString)); var api = new OrchestratorApi(new Uri(url.ConnectionString)); ((DataServiceContext)api).Credentials = CredentialCache.DefaultCredentials; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); }); var runbook = api.Runbooks.Where(r => r.RunbookName == rbParameter.RunbookName).AsEnumerable().FirstOrDefault(); if (runbook == null) { return; } var runbookParams = new List <NameValuePair> { new NameValuePair() { Name = "Upn", Value = rbParameter.Upn }, new NameValuePair() { Name = "RunbookName", Value = rbParameter.RunbookName }, new NameValuePair() { Name = "SubscriptionId", Value = rbParameter.SubscriptionId }, new NameValuePair() { Name = "SelectedVmId", Value = rbParameter.SelectedVmId }, new NameValuePair() { Name = "ParamBool", Value = rbParameter.ParamBool }, new NameValuePair() { Name = "ParamString", Value = rbParameter.ParamString }, new NameValuePair() { Name = "ParamInt", Value = rbParameter.ParamInt }, new NameValuePair() { Name = "ParamDate", Value = rbParameter.ParamDate }, new NameValuePair() { Name = "ParamStringArray", Value = rbParameter.ParamStringArray } }; OperationParameter operationParameters = new BodyOperationParameter("parameters", runbookParams); var uriSma = new Uri(string.Concat(api.Runbooks, string.Format("(guid'{0}')/{1}", runbook.RunbookID, "Start")), UriKind.Absolute); var jobIdValue = api.Execute <Guid>(uriSma, "POST", true, operationParameters) as QueryOperationResponse <Guid>; if (jobIdValue == null) { return; } var jobId = jobIdValue.Single(); Task.Factory.StartNew(() => QueryJobCompletion(jobId)); }
/// <summary> /// Writes collection value in body operation parameter. /// </summary> /// <param name="parameterWriter">The odata parameter writer.</param> /// <param name="operationParameter">The operation parameter.</param> /// <param name="edmCollectionType">The edm collection type.</param> private void WriteCollectionValueInBodyOperationParameter(ODataParameterWriter parameterWriter, BodyOperationParameter operationParameter, IEdmCollectionType edmCollectionType) { ClientEdmModel model = this.requestInfo.Model; var elementTypeKind = edmCollectionType.ElementType.TypeKind(); if (elementTypeKind == EdmTypeKind.Entity || elementTypeKind == EdmTypeKind.Complex) { ODataWriter feedWriter = parameterWriter.CreateResourceSetWriter(operationParameter.Name); feedWriter.WriteStart(new ODataResourceSet()); IEnumerator enumerator = ((ICollection)operationParameter.Value).GetEnumerator(); while (enumerator.MoveNext()) { Object collectionItem = enumerator.Current; if (collectionItem == null) { if (elementTypeKind == EdmTypeKind.Complex) { feedWriter.WriteStart((ODataResource)null); feedWriter.WriteEnd(); continue; } else { throw new NotSupportedException(Strings.Serializer_NullCollectionParameterItemValue(operationParameter.Name)); } } IEdmType edmItemType = model.GetOrCreateEdmType(collectionItem.GetType()); Debug.Assert(edmItemType != null, "edmItemType != null"); if (edmItemType.TypeKind != EdmTypeKind.Entity && edmItemType.TypeKind != EdmTypeKind.Complex) { throw new NotSupportedException(Strings.Serializer_InvalidCollectionParameterItemType(operationParameter.Name, edmItemType.TypeKind)); } Debug.Assert(model.GetClientTypeAnnotation(edmItemType).ElementType != null, "edmItemType.GetClientTypeAnnotation().ElementType != null"); ODataResourceWrapper entry = this.CreateODataResourceFromEntityOperationParameter(model.GetClientTypeAnnotation(edmItemType), collectionItem); Debug.Assert(entry != null, "entry != null"); ODataWriterHelper.WriteResource(feedWriter, entry); } feedWriter.WriteEnd(); feedWriter.Flush(); } else { ODataCollectionWriter collectionWriter = parameterWriter.CreateCollectionWriter(operationParameter.Name); ODataCollectionStart odataCollectionStart = new ODataCollectionStart(); collectionWriter.WriteStart(odataCollectionStart); IEnumerator enumerator = ((ICollection)operationParameter.Value).GetEnumerator(); while (enumerator.MoveNext()) { Object collectionItem = enumerator.Current; if (collectionItem == null) { collectionWriter.WriteItem(null); continue; } IEdmType edmItemType = model.GetOrCreateEdmType(collectionItem.GetType()); Debug.Assert(edmItemType != null, "edmItemType != null"); switch (edmItemType.TypeKind) { case EdmTypeKind.Primitive: { object primitiveItemValue = ODataPropertyConverter.ConvertPrimitiveValueToRecognizedODataType(collectionItem, collectionItem.GetType()); collectionWriter.WriteItem(primitiveItemValue); break; } case EdmTypeKind.Enum: { ODataEnumValue enumTmp = this.propertyConverter.CreateODataEnumValue(model.GetClientTypeAnnotation(edmItemType).ElementType, collectionItem, false); collectionWriter.WriteItem(enumTmp); break; } default: // EdmTypeKind.Entity // EdmTypeKind.Row // EdmTypeKind.EntityReference throw new NotSupportedException(Strings.Serializer_InvalidCollectionParameterItemType(operationParameter.Name, edmItemType.TypeKind)); } } collectionWriter.WriteEnd(); collectionWriter.Flush(); } }