public void CustomScope() { var kernel = new StandardKernel(); kernel.Bind <ScopeObject>().ToSelf().InScope(context => ProcessingScope.Current); var scopeA = new ScopeObject(); var scopeB = new ScopeObject(); ProcessingScope.Current = scopeA; var testA1 = kernel.Get <ScopeObject>(); var testA2 = kernel.Get <ScopeObject>(); Assert.AreSame(testA1, testA2); ProcessingScope.Current = scopeB; var testB = kernel.Get <ScopeObject>(); Assert.AreNotSame(testB, testA1); ProcessingScope.Current = scopeA; var testA3 = kernel.Get <ScopeObject>(); Assert.AreSame(testA3, testA1); }
public static void Test() { var kernel = new StandardKernel(); kernel.Bind <TestService>().ToSelf().InScope(x => ProcessingScope.Current); var ScopeA = new ScopeObject(); var ScopeB = new ScopeObject(); ProcessingScope.Current = ScopeA; var testA1 = kernel.Get <TestService>(); var testA2 = kernel.Get <TestService>(); Assert.Same(testA1, testA2); ProcessingScope.Current = ScopeB; var testB = kernel.Get <TestService>(); Assert.NotSame(testB, testA1); ProcessingScope.Current = ScopeA; var testA3 = kernel.Get <TestService>(); Assert.Same(testA1, testA3); }
/// <summary> /// Deletes the variable from the scope. /// </summary> /// <param name="variableName"> The name of the variable. </param> public bool Delete(string variableName) { if (variableName == null) { throw new ArgumentNullException(nameof(variableName)); } if (values != null && values.TryGetValue(variableName, out var localValue)) { if (localValue.Flags.HasFlag(LocalFlags.Deletable)) { values.Remove(variableName); return(true); } return(false); } if (ScopeObject != null) { return(ScopeObject.Delete(variableName, false)); } if (Parent != null) { return(Parent.Delete(variableName)); } return(false); }
public bool Equals(ScopeObject other) { if (this.Name == other.Name && this.Kind == other.Kind) { if (this.Next == null && other.Next == null) { return(true); } else if (this.Next == null && other.Next != null) { return(false); } else if (this.Next != null && other.Next == null) { return(false); } else { return(this.Next.Equals(other.Next)); } } else { return(false); } }
public void WeCanEvenDefineOurOwnScope() { var kernel = new StandardKernel(); var scopeObject = new ScopeObject(); kernel.Bind<ITool>().To<Hammer>().InScope(ctx=>scopeObject); var tool1 = kernel.Get<ITool>(); var tool2 = kernel.Get<ITool>(); scopeObject.Dispose(); GC.Collect(); GC.WaitForPendingFinalizers(); scopeObject = new ScopeObject(); var tool3 = kernel.Get<ITool>(); Assert.That(tool1, Is.EqualTo(tool2)); Assert.That(tool1, Is.Not.EqualTo(tool3)); }
static void Main(string[] args) { Console.WriteLine("Programa de consola. Inicio"); Setup(); try { var ScopeA = new ScopeObject(); ProcessingScope.Current = ScopeA; //indicamos el scope personalizado para cada servicio, antes de crearlo con ninject var svr = kernel.Get <IClientesServicio>(); var resultado = svr.ObtenerCliente(1); Console.WriteLine("Datos recuperados servicio 1"); Console.WriteLine("Firma"); Console.WriteLine(resultado.Firma); var ScopeB = new ScopeObject(); ProcessingScope.Current = ScopeB; //distinto scope var svr2 = kernel.Get <IClientesServicio>(); var resultado2 = svr2.ObtenerCliente(1); Console.WriteLine("Datos recuperados servicio 2"); Console.WriteLine("Firma"); Console.WriteLine(resultado2.Firma); } catch (Exception ex) { Console.WriteLine("ERROR"); Console.WriteLine(ex.Message); } //traemos el cliente, usando el servicio Console.WriteLine("Fin. pulse una tecla para cerrar"); Console.ReadKey(); }
public override void Execute(object parameter) { if (ScopeIsSelectedComponent && AcceptedSelectedComponentType != null && Current.ActiveDiagramView.IsSelectedComponentOfType(AcceptedSelectedComponentType)) { ScopeObject = Current.ActiveDiagramView.GetSelectedComponents().First(); } CommandDialogWindow w = null; dialogOpened = false; controls = new List <Control>(); #region substitute scope with diagram if (ScopeObject == null && Diagram != null) { CommandDescriptor commandDescriptor = PublicCommandsHelper.GetCommandDescriptor(ControllerCommandType); if (string.IsNullOrEmpty(ControllerCommandDescription)) { ControllerCommandDescription = commandDescriptor.CommandDescription; } commandDescriptor.ClearParameterValues(); OperationParametersControlCreator.ReadParameterValues(commandDescriptor, controls); foreach (ParameterDescriptor parameterDescriptor in commandDescriptor.Parameters) { if (parameterDescriptor.ParameterPropertyInfo == commandDescriptor.ScopeProperty) { if (parameterDescriptor.ComponentType != null && typeof(Diagram).IsAssignableFrom(parameterDescriptor.ComponentType)) { ScopeObject = Diagram; } if (parameterDescriptor.ComponentType == typeof(PSMSchema) && Diagram is PSMDiagram) { ScopeObject = Diagram.Schema; } } } } #endregion if (OpenDialog) { w = new CommandDialogWindow(); MenuHelper.CreateDialogControlsForCommand(ControllerCommandType, (ExolutioObject)ScopeObject, ProjectVersion, w.spParameters, out controls); if (Diagram != null) { foreach (Control control in controls) { ParameterControls.GuidLookup guidLookup = control as ParameterControls.GuidLookup; if (guidLookup != null) { if (guidLookup.LookedUpType == typeof(PSMSchema) && Diagram is PSMDiagram) { guidLookup.SetSuggestedValue(Diagram.Schema); guidLookup.Tag = "valueSuggested"; break; } } } } w.lTitle.Content = ControllerCommandDescription; if (NoScope) { w.lTarget.Content = " (global command) "; } else { w.lTarget.Content = ScopeObject.ToString(); } } bool dialogOk = !OpenDialog; if (!dialogOk) { #if SILVERLIGHT //Current.MainWindow.FloatingWindowHost.Add(w); w.Closed += new EventHandler(w_Closed); w.Show(); #else w.WindowStartupLocation = WindowStartupLocation.CenterScreen; //w.ShowDialog(); w.WindowStyle = WindowStyle.ToolWindow; w.Topmost = true; w.ShowInTaskbar = false; w.ShowActivated = true; Current.MainWindow.DisableCommands(); w.Show(); w.Closed += w_Closed; #endif dialogOpened = true; } else { DoExecute(); } //if (!OpenDialog || dialogOk) //{ // DoExecute(); //} }
public Task ReceiveFault(ReceiveContext context, Exception exception) { Current = null; return(Task.FromResult(0)); }
public Task ConsumeFault <T>(ConsumeContext <T> context, TimeSpan duration, string consumerType, Exception exception) where T : class { Current = null; return(Task.FromResult(0)); }
public Task PostConsume <T>(ConsumeContext <T> context, TimeSpan duration, string consumerType) where T : class { Current = null; return(Task.FromResult(0)); }
public Task PostReceive(ReceiveContext context) { Current = null; return(Task.FromResult(0)); }
public Task PreReceive(ReceiveContext context) { Current = new ScopeObject(); return(Task.FromResult(0)); }
public EntryPoint(ScopeObject scopeObject, IInstance instance, IFactory factory) { _factory = factory; Instance = instance; ScopeObject = scopeObject; }
public static bool FetchBaseAccessRights_ByUserID( IBDatabaseServiceInterface _DatabaseService, IBMemoryServiceInterface _MemoryService, string _UserID, out List <AccessScope> _AccessScopes, out BWebServiceResponse _FailureResponse, Action <string> _ErrorMessageAction = null) { _AccessScopes = null; _FailureResponse = new BWebServiceResponse(); var InMemoryResult = _MemoryService.GetKeyValue(CommonData.MemoryQueryParameters, UserBaseAccessMEntry.M_KEY_NAME_USER_ID + _UserID, _ErrorMessageAction); if (InMemoryResult != null) { try { _AccessScopes = JsonConvert.DeserializeObject <UserBaseAccessMEntry>(InMemoryResult.AsString).BaseAccessScope; return(true); } catch (Exception) { } } if (!_DatabaseService.GetItem( UserDBEntry.DBSERVICE_USERS_TABLE(), UserDBEntry.KEY_NAME_USER_ID, new BPrimitiveType(_UserID), UserDBEntry.Properties, out JObject UserObject, _ErrorMessageAction)) { _FailureResponse = BWebResponse.InternalError("Database fetch-user-info operation has failed."); return(false); } if (UserObject == null) { _FailureResponse = BWebResponse.NotFound("User does not exist."); return(false); } _AccessScopes = new List <AccessScope>(); if (UserObject.ContainsKey(UserDBEntry.BASE_ACCESS_SCOPE_PROPERTY)) { var BaseAccessScopeAsArray = (JArray)UserObject[UserDBEntry.BASE_ACCESS_SCOPE_PROPERTY]; foreach (JObject ScopeObject in BaseAccessScopeAsArray) { _AccessScopes.Add(JsonConvert.DeserializeObject <AccessScope>(ScopeObject.ToString())); } } _MemoryService.SetKeyValue(CommonData.MemoryQueryParameters, new Tuple <string, BPrimitiveType>[] { new Tuple <string, BPrimitiveType>( UserBaseAccessMEntry.M_KEY_NAME_USER_ID + _UserID, new BPrimitiveType(JsonConvert.SerializeObject(new UserBaseAccessMEntry() { BaseAccessScope = _AccessScopes }))) }, _ErrorMessageAction); return(true); }