private bool SelectConvokeTargets(ActivationParameters parameters) { if (!Card.Has().Convoke) { return(true); } var spec = new IsValidTargetBuilder() .Card(c => c.CanBeTapped && c.Is().Creature&& c.Controller == Card.Controller) .On.Battlefield(); var tp = new TargetValidatorParameters( isValidTarget: spec.IsValidTarget, isValidZone: spec.IsValidZone) { MinCount = 0, MaxCount = null, Message = "Select creatures to tap for convoke.", MustBeTargetable = false }; var validator = new TargetValidator(tp); validator.Initialize(Game, Card.Controller); var dialog = ShowSelectorDialog(validator, null); if (dialog.WasCanceled) { return(false); } parameters.ConvokeTargets.AddRange(dialog.Selection.Cast <Card>()); return(true); }
protected override void ExecuteQuery() { var activationParameters = new ActivationParameters { PayManaCost = D._p.PayManaCost }; var spellPrerequisites = SelectSpell(); if (spellPrerequisites == null) { return; } UiHelpers.SelectX(spellPrerequisites, activationParameters, canCancel: false); UiHelpers.SelectTargets(spellPrerequisites, activationParameters, canCancel: false); var playable = new PlayableSpell { Card = D._p.Card, ActivationParameters = activationParameters, Index = spellPrerequisites.Index }; Result = new ChosenPlayable { Playable = playable }; }
private bool SelectDelveTargets(ActivationParameters parameters) { if (!Card.Has().Delve) { return(true); } var spec = new IsValidTargetBuilder().Is.Card().In.YourGraveyard(); var tp = new TargetValidatorParameters( isValidTarget: spec.IsValidTarget, isValidZone: spec.IsValidZone) { MinCount = 0, MaxCount = Card.HasXInCost ? int.MaxValue : Card.GenericCost, Message = "Select cards to exile for delve.", MustBeTargetable = false }; var validator = new TargetValidator(tp); validator.Initialize(Game, Card.Controller); var dialog = ShowSelectorDialog(validator, null); if (dialog.WasCanceled) { return(false); } parameters.DelveTargets.AddRange(dialog.Selection.Cast <Card>()); return(true); }
private void Activate() { if (!IsPlayable) { return; } var activation = SelectActivation(); if (activation == null) { return; } var activationParameters = new ActivationParameters(); var proceed = SelectX(activation.Prerequisites, activationParameters) && SelectTargets(activation.Prerequisites, activationParameters) && SelectConvokeTargets(activationParameters) && SelectDelveTargets(activationParameters); if (!proceed) { return; } var playable = activation.GetPlayable(activationParameters); Publisher.Publish(new PlayableSelected { Playable = playable }); }
private void Activate() { if (!IsPlayable) { return; } var activationParameters = new ActivationParameters(); var playableActivator = SelectAbility(); if (playableActivator == null) { return; } var proceed = SelectX(playableActivator, activationParameters) && SelectTargets(playableActivator, activationParameters); if (!proceed) { return; } var ability = playableActivator.GetPlayable(activationParameters); Publisher.Publish(new PlayableSelected { Playable = ability }); }
private FabricHostEntryPoint CreateStartAndInvokeActivate(ActivationParameters activationParams, bool validate = true) { var hep = this.CreateAndInvokeStartWithDefaults(); this.InvokeActivate(hep, activationParams, validate); return(hep); }
protected Playable(SerializationInfo info, StreamingContext context) { var ctx = (SerializationContext)context.Context; ActivationParameters = (ActivationParameters)info.GetValue("parameters", typeof(ActivationParameters)); Card = (Card)ctx.Recorder.GetObject(info.GetInt32("card")); Index = info.GetInt32("index"); }
protected Playable(SerializationInfo info, StreamingContext context) { var ctx = (SerializationContext) context.Context; ActivationParameters = (ActivationParameters) info.GetValue("parameters", typeof (ActivationParameters)); Card = (Card) ctx.Recorder.GetObject(info.GetInt32("card")); Index = info.GetInt32("index"); }
public async Task <ActionResult> Open() { ActivationParameters parameters = this.LoadActivationParameters(); string test = HttpContext.User.Identity.Name; await HttpContext.GetOwinContext().Authentication.AuthenticateAsync(OpenIdConnectAuthenticationDefaults.AuthenticationType); //load activation parameters and all the stuff you need to get a token var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; var userObjectId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value; var tenantId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value; String token = null; AuthenticationContext authContext = new AuthenticationContext(string.Format(AADAppSettings.AuthorizationUri, tenantId), new ADALTokenCache(signInUserId)); AuthenticationResult authResult = null; Session[AADAppSettings.SavedFormDataName] = parameters; try { //grab the token authResult = await authContext.AcquireTokenSilentAsync(parameters.ResourceId, new ClientCredential(AADAppSettings.ClientId, AADAppSettings.AppKey), new UserIdentifier(userObjectId, UserIdentifierType.UniqueId)); token = authResult.AccessToken; //assemble request to get the file HttpWebRequest request = (HttpWebRequest)WebRequest.Create(parameters.FileGet.Replace("''", "'")); request.Headers.Add("Authorization: bearer " + token); Stream responseStream = request.GetResponse().GetResponseStream(); //get the file & load it into a gpx file bool complete = gpxUtils.LoadGPXFromStream(responseStream); Session[DocumentKey] = gpxUtils; if (complete) { //set the name of the user, the different coordinates to map out, and the title of the track ViewBag.Name = ClaimsPrincipal.Current.FindFirst(ClaimTypes.GivenName).Value + " " + ClaimsPrincipal.Current.FindFirst(ClaimTypes.Surname).Value; ViewBag.Coordinates = gpxUtils.getPointsFromGPX(); ViewBag.Title = gpxUtils.getTitle(); return(View()); } } catch (AdalException exception) { //handle token acquisition failure if (exception.ErrorCode == AdalError.FailedToAcquireTokenSilently) { authContext.TokenCache.Clear(); return(Content(exception.Message)); } } catch (Exception exception) { authContext.TokenCache.Clear(); return(Content(exception.Message)); } return(Content("GPX file could not be loaded.<br/>Token: " + token + "<br/> FileGet URL: " + parameters.FileGet)); }
private bool SelectTargets(ActivationPrerequisites prerequisites, ActivationParameters parameters) { if (prerequisites.Selector.RequiresCostTargets) { var dialog = ShowSelectorDialog( prerequisites.Selector.Cost.FirstOrDefault(), parameters.X); if (dialog.WasCanceled) { return(false); } foreach (var target in dialog.Selection) { parameters.Targets.AddCost(target); } } if (prerequisites.Selector.RequiresEffectTargets) { foreach (var selector in prerequisites.Selector.Effect) { var dialog = ShowSelectorDialog(selector, parameters.X); if (dialog.WasCanceled) { return(false); } // this can occur when game is terminated if (dialog.Selection.Count == 0) { return(false); } foreach (var target in dialog.Selection) { parameters.Targets.AddEffect(target); } } } if (prerequisites.DistributeAmount > 0) { parameters.Targets.Distribution = DistributeAmount(parameters.Targets.Effect, prerequisites.DistributeAmount); } return(prerequisites.Selector.ValidateTargetDependencies( new ValidateTargetDependenciesParam { Cost = parameters.Targets.Cost, Effect = parameters.Targets.Effect } )); }
public override double Activate(double x, ActivationParameters Params) { double temp = 0; if (x >= 0) { temp = 1; } return(temp); }
// Adaptive Piecewise Linear public override double Activate(double x, ActivationParameters Params) { APLParams temp = (APLParams)Params; double total = (x < 0) ? 0 : x; for (int i = 1; i <= temp.S; i++) { total += temp.Alpha * ((-x + temp.Beta < 0) ? 0 : -x + temp.Beta); } return(total); }
public override double Derivate(double x, ActivationParameters Params) { APLParams temp = (APLParams)Params; double total = 0; for (int i = 1; i <= temp.S; i++) { total += temp.Alpha * HeavySideStep(-x + temp.Beta); } return(HeavySideStep(x) - total); }
private void InvokeActivate(FabricHostEntryPoint hep, ActivationParameters activationParams, bool validate = true) { if (validate) { activationParams.Validate(); } hep.ActivateCodePackageInternal( activationParams.ActivationContextId, activationParams.CodePackageName, activationParams.CodePackageActivationContext, activationParams.Stub); }
// S-shaped ReLU public override double Activate(double x, ActivationParameters Params) { SReLUParams temp = (SReLUParams)Params; if (x <= temp.TLeft) { return(temp.TLeft + temp.AlphaLeft * (x - temp.TLeft)); } if (x < temp.TRight) { return(x); } return(temp.TRight + temp.AlphaRight * (x - temp.TRight)); }
// Inverse Square Root Linear Unit public override double Activate(double x, ActivationParameters Params) { SoftExponentialParams temp = (SoftExponentialParams)Params; if (temp.Alpha < 0) { return(-(Math.Log(1 - temp.Alpha * (x + temp.Alpha))) / temp.Alpha); } if (temp.Alpha == 0) { return(x); } return((Math.Exp(temp.Alpha * x) - 1) / temp.Alpha + temp.Alpha); }
public static bool SelectTargets(ActivationPrerequisites prerequisites, ActivationParameters parameters, bool canCancel) { if (parameters.PayManaCost && prerequisites.Selector.RequiresCostTargets) { var dialog = ShowSelectTargetDialog( prerequisites.Selector.Cost.FirstOrDefault(), parameters.X, canCancel); if (dialog.WasCanceled) { return(false); } foreach (var target in dialog.Selection) { parameters.Targets.AddCost(target); } } if (prerequisites.Selector.RequiresEffectTargets) { foreach (var selector in prerequisites.Selector.Effect) { var dialog = ShowSelectTargetDialog(selector, parameters.X, canCancel); if (dialog.WasCanceled) { return(false); } foreach (var target in dialog.Selection) { parameters.Targets.AddEffect(target); } } } return(prerequisites.Selector.ValidateTargetDependencies( new ValidateTargetDependenciesParam { Cost = parameters.Targets.Cost, Effect = parameters.Targets.Effect } )); }
public static bool SelectX(ActivationPrerequisites prerequisites, ActivationParameters activation, bool canCancel) { if (prerequisites.HasXInCost) { var dialog = Ui.Dialogs.SelectXCost.Create(prerequisites.MaxX.Value, canCancel); Ui.Shell.ShowModalDialog(dialog, DialogType.Small, InteractionState.Disabled); if (dialog.WasCanceled) { return(false); } activation.X = dialog.ChosenX; } return(true); }
private bool SelectX(PlayableActivator playableActivator, ActivationParameters activationParameters) { if (playableActivator.Prerequisites.HasXInCost) { var dialog = ViewModels.SelectXCost.Create(playableActivator.Prerequisites.MaxX.Value.Value); Shell.ShowModalDialog(dialog, DialogType.Small, InteractionState.Disabled); if (dialog.WasCanceled) { return(false); } activationParameters.X = dialog.ChosenX; } return(true); }
private bool SelectTargets(PlayableActivator activator, ActivationParameters parameters) { if (activator.Prerequisites.Selector.RequiresCostTargets) { var dialog = ShowSelectorDialog( activator.Prerequisites.Selector.Cost.FirstOrDefault(), parameters.X); if (dialog.WasCanceled) { return(false); } foreach (var target in dialog.Selection) { parameters.Targets.AddCost(target); } } if (activator.Prerequisites.Selector.RequiresEffectTargets) { foreach (var selector in activator.Prerequisites.Selector.Effect) { var dialog = ShowSelectorDialog(selector, parameters.X); if (dialog.WasCanceled) { return(false); } foreach (var target in dialog.Selection) { parameters.Targets.AddEffect(target); } } } return(activator.Prerequisites.Selector.ValidateTargetDependencies( new ValidateTargetDependenciesParam { Cost = parameters.Targets.Cost, Effect = parameters.Targets.Effect } )); }
private void Activate() { if (!IsPlayable) { return; } var activationParameters = new ActivationParameters(); var playableActivator = SelectAbility(); if (playableActivator == null) { return; } var wasCanceled = UiHelpers.SelectX( playableActivator.Prerequisites, activationParameters, canCancel: true) && UiHelpers.SelectTargets( playableActivator.Prerequisites, activationParameters, canCancel: true); if (!wasCanceled) { return; } var ability = playableActivator.GetPlayable(activationParameters); Publisher.Publish(new PlayableSelected { Playable = ability }); }
public async Task <ActionResult> Index() { //get activation parameters off the request ActivationParameters parameters = ActivationParameters.LoadActivationParameters(System.Web.HttpContext.Current); //try to get access token using refresh token var token = await GetAccessToken(parameters.ResourceId); //get the image HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token.AccessToken); var imgBytes = await client.GetByteArrayAsync(parameters.FileGet); //return the image as a base64 string ViewData["img"] = "data:image/png;base64, " + Convert.ToBase64String(imgBytes); ViewData["resource"] = parameters.ResourceId; ViewData["refresh_token"] = token.RefreshToken; ViewData["file_put"] = parameters.FilePut; ViewData["return_url"] = parameters.FilePut.Substring(0, parameters.FilePut.IndexOf("_vti_bin")); return(View()); }
public async Task <ActionResult> Preview() { var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; var userObjectId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value; var tenantId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value; String token = null; AuthenticationContext authContext = new AuthenticationContext(string.Format(AADAppSettings.AuthorizationUri, tenantId), new ADALTokenCache(signInUserId)); AuthenticationResult authResult = null; try { ActivationParameters parameters = this.LoadActivationParameters(); authResult = await authContext.AcquireTokenSilentAsync(parameters.ResourceId, new ClientCredential(AADAppSettings.ClientId, AADAppSettings.AppKey), new UserIdentifier(userObjectId, UserIdentifierType.UniqueId)); token = authResult.AccessToken; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(parameters.FileGet); request.Headers.Add("Authorization: bearer " + token); Stream responseStream = request.GetResponse().GetResponseStream(); bool complete = gpxUtils.LoadGPXFromStream(responseStream); if (complete) { ViewBag.Coordinates = gpxUtils.getPointsFromGPX(); return(View()); } } catch (AdalException exception) { //handle token acquisition failure if (exception.ErrorCode == AdalError.FailedToAcquireTokenSilently) { authContext.TokenCache.Clear(); return(Content(exception.Message)); } } return(Content("GPX file could not be loaded.")); }
public async Task <ActionResult> Open() { var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; var userObjectId = ClaimsPrincipal.Current.FindFirst(SettingsHelper.ClaimTypeObjectIdentifier).Value; var clientCredential = new ClientCredential(SettingsHelper.ClientId, SettingsHelper.ClientSecret); var userIdentifier = new UserIdentifier(userObjectId, UserIdentifierType.UniqueId); string token = null; AuthenticationContext authContext = new AuthenticationContext(SettingsHelper.AzureADAuthority, new EFADALTokenCache(signInUserId)); // get the activation parameters submitted from SharePoint ActivationParameters parameters = this.LoadActivationParameters(); // get access token for unified api var authResult = await authContext.AcquireTokenSilentAsync(parameters.ResourceId, clientCredential, userIdentifier); token = authResult.AccessToken; // get contents of the file in SharePoint HttpWebRequest request = (HttpWebRequest)WebRequest.Create(parameters.FileGet); request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + token); Stream responseStream = request.GetResponse().GetResponseStream(); StreamReader srReader = new StreamReader(responseStream); var fileContents = srReader.ReadToEnd(); // read XML feed XmlReader xmlReader = XmlReader.Create(fileContents); SyndicationFeed feed = SyndicationFeed.Load(xmlReader); xmlReader.Close(); ViewBag.FeedTitle = feed.Title.Text; ViewBag.Posts = feed.Items; return(View()); }
private ActivationParameters LoadActivationParameters() { ActivationParameters parameters; FormDataCookie cookie = new FormDataCookie(AADAppSettings.SavedFormDataName); if (Request.Form != null && Request.Form.AllKeys.Count <string>() != 0) { // get from current request's form data parameters = new ActivationParameters(Request.Form); } else if (cookie.Load() && cookie.IsLoaded && cookie.FormData.AllKeys.Count <string>() > 0) { // if form data does not exist, it must be because of the sign in redirection, at the time form data is saved in the cookie parameters = new ActivationParameters(cookie.FormData); // clear the cookie after using it cookie.Clear(); } else { parameters = (ActivationParameters)Session[AADAppSettings.SavedFormDataName]; } return(parameters); }
public override double Activate(double x, ActivationParameters Params) { return((2 / (1 + Math.Exp(-2 * x))) - 1); }
public override double Derivate(double x, ActivationParameters Params) { return(1 - Math.Pow(Activate(x, Params), 2)); }
// Exponential Linear Unit public override double Activate(double x, ActivationParameters Params) { ELUParams temp = (ELUParams)Params; return((x < 0) ? temp.Alpha * (Math.Exp(x) - 1) : x); }
public override double Derivate(double x, ActivationParameters Params) { ELUParams temp = (ELUParams)Params; return((x < 0) ? Activate(x, Params) + temp.Alpha : 1); }
// Inverse Square Root Unit public override double Activate(double x, ActivationParameters Params) { ISRUParams temp = (ISRUParams)Params; return(x / Math.Sqrt(1 + temp.Alpha * Math.Pow(x, 2))); }
public override double Activate(double x, ActivationParameters Params) { return((Math.Sqrt(Math.Pow(x, 2) + 1) - 1) / 2 + x); }