internal async Task <string> ProtectResource(SnapSession session) { try { ProtectionBody body = new ProtectionBody(); body.ProtectionGroup = new ProtectionGroup(); body.ProtectionGroup.ProtectionGroupType = "Backup"; ProtectionPolicy p = new ProtectionPolicy(); p.Name = session.Policy; body.ProtectionGroup.Policies = new System.Collections.Generic.List <ProtectionPolicy>(); body.ProtectionGroup.Policies.Add(p); PluginConfiguration pconf = new PluginConfiguration(); pconf.type = "SMCoreContracts.SmSCBackupConfiguration, SMCoreContracts"; pconf.FileSystemConsistentSnapshot = false; ProtectionConfiguration conf = new ProtectionConfiguration(); conf.type = "SMCoreContracts.SmSCBackupConfiguration, SMCoreContracts"; conf.Name = "rg_internal"; conf.ConfigurationType = "ProtectionGroup"; conf.PluginConfiguration = pconf; body.ProtectionGroup.Configuration = conf; var response = await this.SendRequestAsync <dynamic>(Method.POST, $"api/3.0/plugins/{session.Plugin}/resources/{session.DbKey}/protect", body, false); this.log.Info($"Protect Resource Response: {response.Response.Content.ToString()}"); return(response.Response.Content.ToString()); } catch (Exception ex) { this.log.Error($"Error while protecting resource with key {session.DbKey}: {ex}"); throw; } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary>Requests the retrieving of an advertisement. This function can only be used /// in 2-legged-mode (To use when the OAuth token hasn't been included in the construction of the client).</summary> /// <param name="adSpace">The adSpace of the Bluevia application.</param> /// <param name="country">Country where the target user is located. /// Must follow <a href="http://www.iso.org/iso/country_codes.htm)">ISO-3166</a>.</param> /// <param name="targetUserId">Optional: Identifier of the Target User.</param> /// <param name="adRequestId">Optional: an unique id for the request. /// (if it is not set, the SDK will generate it automatically).</param> /// <param name="adPresentation">Optional: The value is a code that represents the ad format type</param> /// <param name="keywords">Optional: If you wish to retrieve advertisings related to some keywords.</param> /// <param name="protectionPolicy">Optional: The adult control policy. It will be safe, low, high. /// It should be checked with the application SLA in the Bluevia endpoint</param> /// <param name="userAgent">Optional: The user agent of the client. ("none" by default).</param> /// <returns>The result returned by the server that contains the advertising meta-data</returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public Schemas.SimpleAdResponse GetAdvertising2L(string adSpace, string country , string targetUserId = null , string adRequestId = null, TypeId adPresentation = 0, string[] keywords = null , ProtectionPolicy protectionPolicy = 0, string userAgent = "none") { return GetAdvertising2L(adSpace, country, targetUserId, adRequestId, adPresentation, keywords, protectionPolicy, userAgent, null); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary>Creates a Full SimpleAdRequest from the single request's advertising fields.</summary> /// <param name="adSpace">Unique ID that identifies the ad-space, the place the ad is going to be placed within the /// channel. This parameter should be unique for partner_id.</param> /// <param name="country">The requester's country.</param> /// <param name="targetUserId">The user identification.</param> /// <param name="adRequestId">Advertisement page Request Id identification.</param> /// <param name="adPresentation">Format of the target advertising space.</param> /// <param name="keywords">Array of keywords the ads are related to.</param> /// <param name="protectionPolicy">The adult control policy. It will be safe, low, high.</param> /// <param name="userAgent">The user agent of the user's navigator.</param> /// <returns>A full builded SimpleAdRequest ready to be serialized.</returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public static Schemas.SimpleAdRequest CreateSimpleAdRequest(string adSpace, string country, string targetUserId, string adRequestId, TypeId adPresentation, string[] keywords, ProtectionPolicy protectionPolicy, string userAgent) { Schemas.SimpleAdRequest simpleAdRequest = new Schemas.SimpleAdRequest() { adSpace = adSpace, country = country, targetUserId = targetUserId, adRequestId = adRequestId, adPresentation = AdvertisingTools.TranslateTypeId(adPresentation), keywords = AdvertisingTools.ConvertKeywordsToString(keywords), protectionPolicy = Convert.ToString(protectionPolicy.GetHashCode()), userAgent = userAgent }; //To avoid sending protection policy, if the developer hasn't specified it if (simpleAdRequest.protectionPolicy.Equals("0")) { simpleAdRequest.protectionPolicy = null; } return simpleAdRequest; }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary>As this function can only be used in 2-legged-mode, this function checks that, /// and if needed, generates the apropiate identifier. Then calls <see cref="GetAdvertisingProcess"/> /// </summary> /// <param name="adSpace">The adSpace of the Bluevia application.</param> /// <param name="country">Country where the target user is located. /// Must follow <a href="http://www.iso.org/iso/country_codes.htm)">ISO-3166</a>.</param> /// <param name="targetUserId">Identifier of the Target User.</param> /// <param name="adRequestId">An unique id for the request. /// (if it is not set, the SDK will generate it automatically).</param> /// <param name="adPresentation">The value is a code that represents the ad format type</param> /// <param name="keywords">If you wish to retrieve advertisings related to some keywords.</param> /// <param name="protectionPolicy">The adult control policy. It will be <a href=""> safe, low, high.</a> /// It should be checked with the application SLA in the Bluevia endpoint</param> /// <param name="userAgent">The user agent of the client. ("none" by default).</param> /// <param name="xPhoneNumber">Will be used to convey the MSISDN to whom the advertising is targeted in trusted behavior.</param> /// <returns>The result returned by the server that contains the ad meta-data</returns> //////////////////////////////////////////////////////////////////////////////////////////////////// protected SimpleAdResponse GetAdvertising2L(string adSpace, string country ,string targetUserId , string adRequestId, TypeId adPresentation, string[] keywords , ProtectionPolicy protectionPolicy, string userAgent, string xPhoneNumber) { if(!connector.IsTwoLegged()) { throw new BlueviaException("GetAdvertising2L is only for requesting advertising by twolegged mode." , ExceptionCode.InvalidModeException); } if (string.IsNullOrEmpty(xPhoneNumber)) { if (string.IsNullOrEmpty(country)) { throw new BlueviaException("Null or empty \"country\" when calling GetAdvertising2L." , ExceptionCode.InvalidArgumentException); } } //RequestId is mandatory for the request, so if the developer hasn't specified it, a new one is created //without token if (string.IsNullOrEmpty(adRequestId)) { adRequestId = string.Concat( Guid.NewGuid().ToString().Replace("-", "_") , Convert.ToString(DateTime.UtcNow)); } return GetAdvertisingProcess(adSpace,country,targetUserId ,adRequestId,adPresentation,keywords ,protectionPolicy,userAgent,xPhoneNumber); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> This function creates and calls the advertising request, with the data received from /// <see cref="GetAdvertising2L"/> and <see cref="GetAdvertising3L"/>.</summary> /// <param name="adSpace">The adSpace of the Bluevia application.</param> /// <param name="country">Country where the target user is located. /// Must follow <a href="http://www.iso.org/iso/country_codes.htm)">ISO-3166</a>.</param> /// <param name="targetUserId">Identifier of the Target User.</param> /// <param name="adRequestId">An unique id for the request. /// (if it is not set, the SDK will generate it automatically).</param> /// <param name="adPresentation">The value is a code that represents the ad format type</param> /// <param name="keywords">If you wish to retrieve advertisings related to some keywords.</param> /// <param name="protectionPolicy">The adult control policy. It will be <a href=""> safe, low, high.</a> /// It should be checked with the application SLA in the Bluevia endpoint</param> /// <param name="userAgent">The user agent of the client. ("none" by default).</param> /// <param name="xPhoneNumber">Will be used to convey the MSISDN to whom the advertising is targeted in trusted behavior.</param> /// <returns>The result returned by the server that contains the ad meta-data</returns> //////////////////////////////////////////////////////////////////////////////////////////////////// private SimpleAdResponse GetAdvertisingProcess(string adSpace, string country, string targetUserId , string adRequestId, TypeId adPresentation, string[] keywords , ProtectionPolicy protectionPolicy, string userAgent, string xPhoneNumber) { if (string.IsNullOrEmpty(adSpace)) { throw new BlueviaException("Null or empty adSpace when getting Advertising." , ExceptionCode.InvalidArgumentException); } //Building the request object SimpleAdRequest simpleAdRequest = AdvertisingTools.CreateSimpleAdRequest(adSpace, country, targetUserId, adRequestId, adPresentation, keywords, protectionPolicy, userAgent); Dictionary<string,string> headers = CreateHeaders(HttpTools.ContetTypeFormUrl); if(!string.IsNullOrEmpty(xPhoneNumber)) { headers.Add(Constants.XPhoneKey,xPhoneNumber); } //Dont need to select the apropiate parser/serializer for the operation: //The Bluevia´s complex response object, as result of the call: SimpleAdResponseType simpleAdResponseType = BaseCreate<SimpleAdResponseType, Dictionary<string, string>>( string.Format(url, Constants.AdvertisingAdRequestSend) ,CreateParameters() ,simpleAdRequest.ToDictionary() , headers); return AdvertisingSimplifiers.SimplifyAdResponse(simpleAdResponseType); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary>As this function can only be used in 3-legged-mode, this function checks that, /// and if needed, generates the apropiate identifier. Then calls <see cref="GetAdvertisingProcess"/> /// </summary> /// <param name="adSpace">The adSpace of the Bluevia application.</param> /// <param name="country">Country where the target user is located. /// Must follow <a href="http://www.iso.org/iso/country_codes.htm)">ISO-3166</a>.</param> /// <param name="adRequestId">An unique id for the request. /// (if it is not set, the SDK will generate it automatically).</param> /// <param name="adPresentation">The value is a code that represents the ad format type</param> /// <param name="keywords">If you wish to retrieve advertisings related to some keywords.</param> /// <param name="protectionPolicy">The adult control policy. It will be <a href=""> safe, low, high.</a> /// It should be checked with the application SLA in the Bluevia endpoint</param> /// <param name="userAgent">The user agent of the client. ("none" by default).</param> /// <returns>The result returned by the server that contains the advertising meta-data</returns> //////////////////////////////////////////////////////////////////////////////////////////////////// protected SimpleAdResponse GetAdvertising3L(string adSpace, string country , string adRequestId, TypeId adPresentation, string[] keywords , ProtectionPolicy protectionPolicy, string userAgent) { if (connector.IsTwoLegged()) { throw new BlueviaException("GetAdvertising is only for requesting advertising by threelegged mode." , ExceptionCode.InvalidModeException); } //RequestId is mandatory for the request, so if the developer hasnt specified it, a new one is created //with token if (string.IsNullOrEmpty(adRequestId)) { adRequestId = string.Concat(connector.GetToken(), Convert.ToString(DateTime.UtcNow)); } return GetAdvertisingProcess(adSpace, country, null , adRequestId, adPresentation, keywords , protectionPolicy, userAgent, null); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary>Requests the retrieving of an advertisement. This function can only be used /// in 3-legged-mode (To use when the OAuth token has been included in the construction of the client).</summary> /// <param name="adSpace">The adSpace of the Bluevia application.</param> /// <param name="country">Optional: country where the target user is located. /// Must follow <a href="http://www.iso.org/iso/country_codes.htm)">ISO-3166</a>.</param> /// <param name="adRequestId">Optional: an unique id for the request. /// (if it is not set, the SDK will generate it automatically).</param> /// <param name="adPresentation">Optional: The value is a code that represents the ad format type</param> /// <param name="keywords">Optional: If you wish to retrieve advertisings related to some keywords.</param> /// <param name="protectionPolicy">Optional: The adult control policy. It will be safe, low, high. /// It should be checked with the application SLA in the Bluevia endpoint</param> /// <param name="userAgent">Optional: The user agent of the client. ("none" by default).</param> /// <returns>The result returned by the server that contains the advertising meta-data</returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public new Schemas.SimpleAdResponse GetAdvertising3L(string adSpace, string country = null , string adRequestId = null, TypeId adPresentation = 0, string[] keywords = null , ProtectionPolicy protectionPolicy = 0, string userAgent = "none") { return base.GetAdvertising3L(adSpace, country, adRequestId, adPresentation, keywords, protectionPolicy, userAgent); }