protected ProjectBase(string location, string title) { Location = location; Title = title; Id = UniqueIdentifierHelper.GetUniqueIdentifier(GetType()); }
public void LoadConnectables() { var savePathDir = Path.Combine(Main.GetSavePathDir(), "Connectables"); if (Directory.Exists(savePathDir)) { var files = new DirectoryInfo(savePathDir).GetFiles(); foreach (var file in files) { var id = Path.GetFileNameWithoutExtension(file.Name); var connectedToId = File.ReadAllText(file.FullName); var main = UniqueIdentifierHelper.GetByName(id); var connectedTo = UniqueIdentifierHelper.GetByName(connectedToId); if (main && connectedTo) { main.GetComponent <Connectable>().OnConnectEnd(connectedTo.GetComponent <Connectable>()); } else { Console.WriteLine("Nullll!"); } } } }
public Notification() { Id = UniqueIdentifierHelper.GetUniqueIdentifier <Notification>(); ShowTime = TimeSpan.FromSeconds(5); IsClosable = true; Priority = NotificationPriority.Normal; Level = NotificationLevel.Normal; }
/// <summary> /// Initializes a new instance of the <see cref="LogicBase"/> class. /// </summary> /// <param name="targetControl">The target control.</param> /// <param name="viewModelType">Type of the view model.</param> /// <param name="viewModel">The view model.</param> /// <exception cref="ArgumentNullException">The <paramref name="targetControl"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="viewModelType"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="viewModelType"/> does not implement interface <see cref="IViewModel"/>.</exception> protected LogicBase(FrameworkElement targetControl, Type viewModelType, IViewModel viewModel = null) { Argument.IsNotNull("targetControl", targetControl); Argument.IsNotNull("viewModelType", viewModelType); Argument.ImplementsInterface("viewModelType", viewModelType, typeof(IViewModel)); UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <LogicBase>(); Log.Debug("Constructing behavior '{0}' for '{1}' with unique id '{2}'", GetType().Name, targetControl.GetType().Name, UniqueIdentifier); TargetControl = targetControl; ViewModelType = viewModelType; ViewModel = viewModel; #if SL4 || SL5 TargetControl.FixUILanguageBug(); #endif ViewModelBehavior = (viewModel != null) ? LogicViewModelBehavior.Injected : LogicViewModelBehavior.Dynamic; if (ViewModel != null) { SetDataContext(ViewModel); } // Very impoortant to exit here in design mode if (Catel.Environment.IsInDesignMode) { return; } #if NET TargetControl.Loaded += OnTargetControlLoadedInternal; #else // Note: in non-WPF, use LayoutUpdated instead of Loaded because the order is down => top instead of top => down _frameworkElementLoadedManager.AddElement(TargetControl, () => OnTargetControlLoadedInternal(null, new RoutedEventArgs())); #endif TargetControl.Unloaded += OnTargetControlUnloadedInternal; #if WIN81 // TODO: make the same for WIN80. There is no DataContextChanged event in WIN80. TargetControl.DataContextChanged += (sender, args) => OnTargetControlDataContextChanged(sender, new DependencyPropertyValueChangedEventArgs("DataContext", FrameworkElement.DataContextProperty, null, args.NewValue)); #endif // This also subscribes to DataContextChanged, don't double subscribe var dependencyPropertiesToSubscribe = DetermineInterestingDependencyProperties(); foreach (var dependencyPropertyToSubscribe in dependencyPropertiesToSubscribe) { TargetControl.SubscribeToDependencyProperty(dependencyPropertyToSubscribe.PropertyName, OnTargetControlPropertyChangedInternal); } #if NET IsTargetControlLoaded = TargetControl.IsLoaded; #endif Log.Debug("Constructed behavior '{0}' for '{1}'", GetType().Name, TargetControl.GetType().Name); }
public SnapshotManager(ISnapshotStorageService snapshotStorageService, IServiceLocator serviceLocator) { Argument.IsNotNull(() => snapshotStorageService); Argument.IsNotNull(() => serviceLocator); _snapshotStorageService = snapshotStorageService; _serviceLocator = serviceLocator; UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <SnapshotManager>(); }
/// <summary> /// Initializes a new instance of the <see cref="UnitOfWork" /> class. /// </summary> /// <param name="context">The context.</param> /// <param name="tag">The tag to uniquely identify this unit of work. If <c>null</c>, a unique id will be generated.</param> /// <exception cref="ArgumentNullException">The <paramref name="context" /> is <c>null</c>.</exception> public UnitOfWork(DbContext context, string tag = null) { Argument.IsNotNull("context", context); _serviceLocator = ServiceLocator.Default; _typeFactory = _serviceLocator.ResolveType <ITypeFactory>(); DbContext = context; Tag = tag ?? UniqueIdentifierHelper.GetUniqueIdentifier <UnitOfWork>().ToString(CultureInfo.InvariantCulture); }
/// <summary> /// Initializes a new instance of the <see cref="WarningAndErrorValidator"/> class. /// </summary> public WarningAndErrorValidator() { UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <WarningAndErrorValidator>(); #if NET Focusable = false; #endif Loaded += OnLoaded; Unloaded += OnUnloaded; }
/// <summary> /// Initializes a new instance of the <see cref="MediaElementThreadInfo"/> class. /// </summary> /// <param name="hostVisual">The host visual.</param> /// <param name="createVisual">The function responsible fro creating the visual that will run on the separate UI thread.</param> /// <param name="thread">The thread.</param> public MediaElementThreadInfo(HostVisual hostVisual, Func <Visual> createVisual, Thread thread) { Argument.IsNotNull(nameof(hostVisual), hostVisual); Argument.IsNotNull(nameof(createVisual), createVisual); Argument.IsNotNull(nameof(thread), thread); Id = UniqueIdentifierHelper.GetUniqueIdentifier(typeof(MediaElementThreadInfo)); HostVisual = hostVisual; CreateVisual = createVisual; Thread = thread; thread.Name = $"Media Element Thread: {Id}"; }
/// <summary> /// Initializes a new instance of the <see cref="WarningAndErrorValidator"/> class. /// </summary> public WarningAndErrorValidator() { UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <WarningAndErrorValidator>(); #if NET || NETCORE Focusable = false; #endif Loaded += OnLoaded; Unloaded += OnUnloaded; this.HideValidationAdorner(); }
/// <summary> /// Initializes the view model. /// </summary> protected ViewModelBase() { if (CatelEnvironment.IsInDesignMode) { return; } UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier(GetType()); ViewModelConstructionTime = DateTime.Now; AuditingHelper.RegisterViewModel(this); _viewModelCommandManager = ViewModelCommandManager.Create(this); _viewModelCommandManager.AddHandler((viewModel, propertyName, command, commandParameter) => _catelCommandExecuted.SafeInvoke(this, new CommandExecutedEventArgs((ICatelCommand)command, commandParameter, propertyName))); ViewModelManager.RegisterViewModelInstance(this); }
public IRepository GetSerializableRepository(string name, string source, PackageOperationType operationType, Func <IPackageRepository> packageRepositoryFactory, bool renew = false) { Argument.IsNotNullOrEmpty(() => name); Argument.IsNotNull(() => packageRepositoryFactory); var key = GetKey(operationType, name); if (_keyIdDictionary.TryGetValue(key, out var id)) { return(!renew ? _idTupleDictionary[id].Item1 : CreateSerializableRepository(id, name, source, operationType, packageRepositoryFactory)); } id = UniqueIdentifierHelper.GetUniqueIdentifier <RepositoryCacheService>(); _keyIdDictionary.Add(key, id); return(CreateSerializableRepository(id, name, source, operationType, packageRepositoryFactory)); }
/// <summary> /// Initializes the view model. /// </summary> protected ViewModelBase() { if (Catel.Environment.IsInDesignMode) { return; } UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier(GetType()); ViewModelConstructionTime = DateTime.Now; AuditingHelper.RegisterViewModel(this); _viewModelCommandManager = ViewModelCommandManager.Create(this); _viewModelCommandManager.AddHandler((viewModel, propertyName, command, commandParameter) => _catelCommandExecuted.SafeInvoke(this, new CommandExecutedEventArgs((ICatelCommand)command, commandParameter, propertyName))); ServiceLocator = IoCConfiguration.DefaultServiceLocator; DependencyResolver = ServiceLocator.ResolveType <IDependencyResolver>(); RegisterViewModelServices(ServiceLocator); ViewModelManager.RegisterViewModelInstance(this); }
public B() { Id = UniqueIdentifierHelper.GetUniqueIdentifier <B>(); }
/// <summary> /// Initializes a new instance of the <see cref="LogicBase"/> class. /// </summary> /// <param name="targetView">The target control.</param> /// <param name="viewModelType">Type of the view model.</param> /// <param name="viewModel">The view model.</param> /// <exception cref="ArgumentNullException">The <paramref name="targetView"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="viewModelType"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="viewModelType"/> does not implement interface <see cref="IViewModel"/>.</exception> protected LogicBase(IView targetView, Type viewModelType = null, IViewModel viewModel = null) { Argument.IsNotNull("targetView", targetView); if (viewModelType == null) { viewModelType = (viewModel != null) ? viewModel.GetType() : _viewModelLocator.ResolveViewModel(targetView.GetType()); if (viewModelType == null) { var error = string.Format("The view model of the view '{0}' could not be resolved. Make sure to customize the IViewModelLocator or register the view and view model manually", targetView.GetType().GetSafeFullName()); Log.Error(error); throw new NotSupportedException(error); } } UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <LogicBase>(); Log.Debug("Constructing behavior '{0}' for '{1}' with unique id '{2}'", GetType().Name, targetView.GetType().Name, UniqueIdentifier); TargetView = targetView; ViewModelType = viewModelType; ViewModel = viewModel; #if SL5 Catel.Windows.FrameworkElementExtensions.FixUILanguageBug((System.Windows.FrameworkElement)TargetView); #endif ViewModelBehavior = (viewModel != null) ? LogicViewModelBehavior.Injected : LogicViewModelBehavior.Dynamic; if (ViewModel != null) { SetDataContext(ViewModel); } // Very impoortant to exit here in design mode if (CatelEnvironment.IsInDesignMode) { return; } Log.Debug("Subscribing to view events"); ViewLoadManager.AddView(this); this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, "ViewLoading", OnViewLoadedManagerLoading); this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, "ViewLoaded", OnViewLoadedManagerLoaded); this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, "ViewUnloading", OnViewLoadedManagerUnloading); this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, "ViewUnloaded", OnViewLoadedManagerUnloaded); // Required so the ViewLoadManager can handle the rest targetView.Loaded += (sender, e) => Loaded.SafeInvoke(this); targetView.Unloaded += (sender, e) => Unloaded.SafeInvoke(this); TargetView.DataContextChanged += OnTargetViewDataContextChanged; Log.Debug("Subscribing to view properties"); // This also subscribes to DataContextChanged, don't double subscribe var viewPropertiesToSubscribe = DetermineInterestingViewProperties(); foreach (var viewPropertyToSubscribe in viewPropertiesToSubscribe) { TargetView.SubscribeToPropertyChanged(viewPropertyToSubscribe, OnTargetViewPropertyChanged); } Log.Debug("Constructed behavior '{0}' for '{1}'", GetType().Name, TargetView.GetType().Name); }
public MacroModel GetMacro(string fileName, string path) { var scriptRegex = new Regex(Constants.MacroScriptPattern); var model = new MacroModel(); model.FileName = fileName; model.DirectoryName = path; using (var sr = new StringReader(System.IO.File.ReadAllText($"{path}/{fileName}"))) { string line; var foundSubmethod = false; while ((line = sr.ReadLine()) != null) { if (!foundSubmethod) { var scriptMatch = scriptRegex.Match(line); if (scriptMatch.Success && scriptMatch.Groups.Count > 1 && !string.IsNullOrWhiteSpace(scriptMatch.Groups[1].Value)) { var parameters = scriptMatch.Groups[1].Value.Split(','); foreach (var parameter in parameters) { var temporaryParameter = parameter.Trim(); var parameterDesc = temporaryParameter.Split(' '); var parameterModel = new ParameterModel { ParameterName = parameterDesc[0], Type = parameterDesc[2] }; model.ParameterList.Add(parameterModel); foundSubmethod = true; } } } if (line.StartsWith("'")) { if (line.StartsWith(Constants.ParameterNames.Description)) { model.Description = line.Substring(Constants.ParameterNames.Description.Length); } else if (line.StartsWith(Constants.ParameterNames.Image)) { var splittedLine = line.Split(';'); model.Images.AddOrReplace(splittedLine[1], splittedLine[2]); } else { foreach (var parameter in model.ParameterList) { if (line.StartsWith($"'{parameter.ParameterName}:")) { var parameterInfo = line.Substring(parameter.ParameterName.Length + 2).Split(';'); if (parameterInfo.Length > 0) { parameter.DisplayName = parameterInfo[0]; if (parameterInfo.Length > 1) { parameter.DefaultValue = parameterInfo[1]; } } } } } } } } model.UniqueID = UniqueIdentifierHelper.GenerateUniqueID(); return(model); }
/// <summary> /// Initializes a new instance of the <see cref="Batch"/> class. /// </summary> public Batch() { UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <Batch>(); }
public Notification() { Id = UniqueIdentifierHelper.GetUniqueIdentifier <Notification>(); ShowTime = TimeSpan.FromSeconds(5); IsClosable = true; }
/// <summary> /// Initializes a new instance of the <see cref="LogicBase"/> class. /// </summary> /// <param name="targetView">The target control.</param> /// <param name="viewModelType">Type of the view model.</param> /// <param name="viewModel">The view model.</param> /// <exception cref="ArgumentNullException">The <paramref name="targetView"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="viewModelType"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="viewModelType"/> does not implement interface <see cref="IViewModel"/>.</exception> protected LogicBase(IView targetView, Type viewModelType = null, IViewModel viewModel = null) { if (CatelEnvironment.IsInDesignMode) { return; } Argument.IsNotNull("targetView", targetView); var targetViewType = targetView.GetType(); if (viewModelType is null) { viewModelType = (viewModel != null) ? viewModel.GetType() : _viewModelLocator.ResolveViewModel(targetViewType); if (viewModelType is null) { throw Log.ErrorAndCreateException <NotSupportedException>($"The view model of the view '{targetViewType.Name}' could not be resolved. Make sure to customize the IViewModelLocator or register the view and view model manually"); } } UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <LogicBase>(); Log.Debug($"Constructing behavior '{GetType().Name}' for '{targetView.GetType().Name}' with unique id '{UniqueIdentifier}'"); TargetView = targetView; ViewModelType = viewModelType; ViewModel = viewModel; ViewModelBehavior = (viewModel != null) ? LogicViewModelBehavior.Injected : LogicViewModelBehavior.Dynamic; if (ViewModel != null) { SetDataContext(ViewModel); } Log.Debug("Subscribing to view events"); ViewLoadManager.AddView(this); if (this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, nameof(IViewLoadManager.ViewLoading), OnViewLoadedManagerLoadingInternal, false) is null) { Log.Debug("Failed to use weak events to subscribe to 'ViewLoadManager.ViewLoading', going to subscribe without weak events"); ViewLoadManager.ViewLoading += OnViewLoadedManagerLoadingInternal; } if (this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, nameof(IViewLoadManager.ViewLoaded), OnViewLoadedManagerLoadedInternal, false) is null) { Log.Debug("Failed to use weak events to subscribe to 'ViewLoadManager.ViewLoaded', going to subscribe without weak events"); ViewLoadManager.ViewLoaded += OnViewLoadedManagerLoadedInternal; } if (this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, nameof(IViewLoadManager.ViewUnloading), OnViewLoadedManagerUnloadingInternal, false) is null) { Log.Debug("Failed to use weak events to subscribe to 'ViewLoadManager.ViewUnloading', going to subscribe without weak events"); ViewLoadManager.ViewUnloading += OnViewLoadedManagerUnloadingInternal; } if (this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, nameof(IViewLoadManager.ViewUnloaded), OnViewLoadedManagerUnloadedInternal, false) is null) { Log.Debug("Failed to use weak events to subscribe to 'ViewLoadManager.ViewUnloaded', going to subscribe without weak events"); ViewLoadManager.ViewUnloaded += OnViewLoadedManagerUnloadedInternal; } // Required so the ViewLoadManager can handle the rest targetView.Loaded += (sender, e) => Loaded?.Invoke(this, EventArgs.Empty); targetView.Unloaded += (sender, e) => Unloaded?.Invoke(this, EventArgs.Empty); TargetView.DataContextChanged += OnTargetViewDataContextChanged; Log.Debug("Subscribing to view properties"); // This also subscribes to DataContextChanged, don't double subscribe var viewPropertiesToSubscribe = DetermineInterestingViewProperties(); foreach (var viewPropertyToSubscribe in viewPropertiesToSubscribe) { TargetView.SubscribeToPropertyChanged(viewPropertyToSubscribe, OnTargetViewPropertyChanged); } Log.Debug($"Constructed behavior '{GetType().Name}' for '{TargetViewType?.Name}'"); }
/// <summary> /// Initializes a new instance of the <see cref="PoolableBase"/> class. /// </summary> protected PoolableBase() { var type = GetType(); UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier(type); }
public PackageOperationContext() { UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <PackageOperationContext>(); Exceptions = new List <Exception>(); }
/// <summary> /// Initializes a new instance of the <see cref="BindingContext"/> class. /// </summary> public BindingContext() { UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <BindingContext>(); Log.Debug("Initialized binding context"); }
public A() { Id = UniqueIdentifierHelper.GetUniqueIdentifier <A>(); SubClass = new B(); }
public CircularTestModel() { Name = UniqueIdentifierHelper.GetUniqueIdentifier <CircularTestModel>().ToString(); }
public static Optional <GameObject> GetObjectFrom(String guid) { GameObject gameObject = UniqueIdentifierHelper.GetByName(guid); return(Optional <GameObject> .OfNullable(gameObject)); }