public object Create(object item) { var proxy = _proxyFactory.Create((T)item, _session, EntityStatus.New); _session.Register(proxy); return(proxy); }
public IDeviceMediaRepo GetMediaRepo(DeviceRepository deviceRepo) { return(deviceRepo.RepositoryType.Value == RepositoryTypes.Local ? _proxyFactory.Create <IDeviceMediaRepo>( new ProxySettings { OrganizationId = deviceRepo.OwnerOrganization.Id, InstanceId = deviceRepo.Instance.Id }) : _defaultMediaRepo); }
public IDeviceManagementRepo GetRepo(DeviceRepository deviceRepo) { return((deviceRepo.RepositoryType.Value == RepositoryTypes.Local || deviceRepo.RepositoryType.Value == RepositoryTypes.ClusteredMongoDB) ? _proxyFactory.Create <IDeviceManagementRepo>( new ProxySettings { OrganizationId = deviceRepo.OwnerOrganization.Id, InstanceId = deviceRepo.Instance?.Id }) : _defaultRepo); }
/// <summary> /// Registers this instance. /// </summary> /// <exception cref="ProxyInitializationException"></exception> private void Register() { try { if (!ObjectHelper.IsNull(_instance)) { return; } _states = TypeFactory.CreateInstance <StateInterceptorCollection>(); var stateIntercepors = Callbacks.Keys.Select(key => TypeFactory.CreateInstanceWithParameters <StateInterceptor>(key, Callbacks[key])); stateIntercepors.ForEach(stateInterceptor => _states.Add(stateInterceptor)); _context = TypeFactory.CreateInstanceWithParameters <ContextInterceptor>(_states); _instance = _proxyFactory.Create(_target, _context, ImplementedTypes.ToArray()); Container.RegisterInstance(ServiceType, _instance, Tag); } catch (Exception exception) { throw new ProxyInitializationException( string.Format("Unable to create a proxy instance of a '{0}' type: {1}", ServiceType.Name, exception.Message), exception); } }
public void Connect() { try { using (var deviceClient = _proxyFactory.Create <Device, DeviceClient>(_camera.ServiceAddress)) { var timeTest = deviceClient.GetSystemDateAndTimeAsync().Result; } } catch (AggregateException aggregateException) { var endpointNotFoundException = aggregateException.InnerExceptions.FirstOrDefault(x => x.GetType() == typeof(EndpointNotFoundException)); if (endpointNotFoundException != null) { throw new CameraConnectionException("Can not connect to a camera with a defined address. Check the endpoint address.", endpointNotFoundException); } else { throw new CameraConnectionException("An unknown error occurred while connecting to the camera. Check the endpoint address and the user credential.", aggregateException); } } catch (EndpointNotFoundException endpointNotFoundException) { throw new CameraConnectionException("Can not connect to a camera with a defined address. Check the endpoint address.", endpointNotFoundException); } catch (Exception exception) { throw new CameraConnectionException("An unknown error occurred while connecting to the camera. Check the endpoint address and the user credential.", exception); } _camera.StateObject = new CameraConnectedState(_camera, _proxyFactory); }
/// <summary>Creates an instance of a certain type of item. It's good practice to create new items through this method so the item's dependencies can be injected by the engine.</summary> /// <param name="itemType">Type of item to create</param> /// <param name="parentItem">Parent of the item to create.</param> /// <param name="templateKey">The type of template the item is associated with.</param> /// <returns>A new instance of an item.</returns> public virtual ContentItem CreateInstance(Type itemType, ContentItem parentItem, string templateKey, bool asProxy = false) { if (itemType == null) { throw new ArgumentNullException("itemType"); } ContentItem item = null; ItemDefinition definition; if (asProxy) { item = (ContentItem)interceptor.Create(itemType.FullName, 0); } if (item == null) { if (contentBuilders.TryGetValue(itemType, out definition)) { item = definition.CreateInstance(parentItem); } else { item = Activator.CreateInstance(itemType, true) as ContentItem; } } if (templateKey != null) { item.TemplateKey = templateKey; } OnItemCreating(item, parentItem); return(item); }
private T CreateItem <T>(ItemDefinition definition, IProxyFactory proxies, MongoDatabaseProvider database) where T : ContentItem { var item = (T)(proxies.Create(typeof(T).FullName, 0) ?? definition.CreateInstance(null, applyDefaultValues: false)); services.Resolve <IDependencyInjector>().FulfilDependencies(item); return(item); }
public async Task <InvokeResult> RestartDeviceAsync(string deviceRepoId, string deviceUniqueId, EntityHeader org, EntityHeader user) { var repo = await _repoManager.GetDeviceRepositoryAsync(deviceRepoId, org, user); if (EntityHeader.IsNullOrEmpty(repo.Instance)) { return(InvokeResult.FromError("Instance not deployed, can not set property.")); } var propertyManager = _proxyFactory.Create <IRemotePropertyNamanager>(new ProxySettings() { InstanceId = repo.Instance.Id, OrganizationId = repo.OwnerOrganization.Id }); return(await propertyManager.RestartDeviceAsync(deviceUniqueId)); }
public async Task <ListResponse <UsageMetrics> > GetMetricsForInstanceAsync(string instanceId, ListRequest request, EntityHeader org, EntityHeader user) { var instance = await _deploymentInstanceRepo.GetInstanceAsync(instanceId); await AuthorizeOrgAccessAsync(user, org, typeof(UsageMetrics), Core.Validation.Actions.Read, "Instance"); if (instance.LogStorage.Value == LogStorage.Local) { var proxy = _proxyFactory.Create <IUsageMetricsRepo>(new ProxySettings { OrganizationId = org.Id, InstanceId = instanceId }); return(await proxy.GetMetricsForInstanceAsync(instanceId, request)); } else { return(await _metricsRepo.GetMetricsForInstanceAsync(instanceId, request)); } }
public override object Instantiate(string clazz, EntityMode entityMode, object id) { logger.Debug("Instantiate: " + clazz + " " + entityMode + " " + id); object instance = interceptor.Create(clazz, id); if (instance != null) { sessionFactory.GetClassMetadata(clazz).SetIdentifier(instance, id, entityMode); } return instance; }
/// <summary>Creates an instance of a certain type of item. It's good practice to create new items through this method so the item's dependencies can be injected by the engine.</summary> /// <returns>A new instance of an item.</returns> public virtual ContentItem CreateInstance(Type itemType, ContentItem parentItem) { object intercepted = interceptor.Create(itemType.FullName, 0); ContentItem item = (intercepted ?? Activator.CreateInstance(itemType, true)) as ContentItem; stateChanger.ChangeTo(item, ContentState.New); OnItemCreating(item, parentItem); return(item); }
/// <summary>Creates an instance of a certain type of item. It's good practice to create new items through this method so the item's dependencies can be injected by the engine.</summary> /// <param name="itemType">Type of item to create</param> /// <param name="parentItem">Parent of the item to create.</param> /// <param name="templateKey">The type of template the item is associated with.</param> /// <returns>A new instance of an item.</returns> public virtual ContentItem CreateInstance(Type itemType, ContentItem parentItem, string templateKey) { object intercepted = interceptor.Create(itemType.FullName, 0); ContentItem item = (intercepted ?? Activator.CreateInstance(itemType, true)) as ContentItem; if (templateKey != null) { item.TemplateKey = templateKey; } OnItemCreating(item, parentItem); return(item); }
public BlockingCollection <Bitmap> StartStreaming(Profile profile, int maxCollectionSize) { _frameQueue = new BlockingCollection <Bitmap>(new ConcurrentQueue <Bitmap>(), maxCollectionSize); MediaUri streamingUrl = null; string[] uriParts = null; var uri = string.Empty; using (var mediaClient = _proxyFactory.Create <Media, MediaClient>(_camera.ServiceAddress)) { StreamSetup streamSetup = new StreamSetup(); streamSetup.Stream = StreamType.RTPUnicast; streamSetup.Transport = new Transport(); streamSetup.Transport.Protocol = TransportProtocol.RTSP; streamingUrl = mediaClient.GetStreamUriAsync(streamSetup, profile.token).Result; uriParts = streamingUrl.Uri.Split(new string[] { "//" }, StringSplitOptions.RemoveEmptyEntries); } if (uriParts != null && uriParts.Count() == 2) { uri = $"{uriParts[0]}//{_camera.ConnectionUser.Login}:{_camera.ConnectionUser.Password}@{uriParts[1]}"; } else { throw new InvalidUriAddressException($"Stream URI address is incorrect ({streamingUrl.Uri})."); } Task.Factory.StartNew(() => FrameProducer(uri)); _camera.StateObject = new CameraStreamingState(_camera, _proxyFactory, _tokenSource); return(_frameQueue); }
public async Task <ListResponse <TelemetryReportData> > GetForDeviceAsync(DeviceRepository deviceRepo, string deviceId, string recordType, ListRequest request, EntityHeader org, EntityHeader user) { if (deviceRepo.Instance == null) { return(ListResponse <TelemetryReportData> .FromError("No associated instance.")); } await base.AuthorizeOrgAccessAsync(user, org, typeof(TelemetryReportData)); var instance = await _deploymentInstanceRepo.GetInstanceAsync(deviceRepo.Instance.Id); if (instance.LogStorage.Value == LogStorage.Local) { var proxy = _proxyFactory.Create <ITelemetryService>(new ProxySettings { OrganizationId = org.Id, InstanceId = deviceRepo.Instance.Id }); return(await proxy.GetForPemAsync(deviceId, recordType, request)); } else { return(await _telemetryService.GetForDeviceAsync(deviceId, recordType, request)); } }
static public void Initialize() { if (_initialized) { return; } _initialized = true; Logger = new AdminLogger(new ConsoleLogWriter(), HostId); AsyncCoupler = new AsyncCoupler <IMessage>(Logger, new UsageMetrics(HostId, InstanceId, PipelineModuleId)); TransceiverSettings.RpcClientReceiver.AccountId = System.Environment.GetEnvironmentVariable("RPC_TESTS_SERVICE_BUS", EnvironmentVariableTarget.User); Assert.IsNotNull(TransceiverSettings.RpcClientReceiver.AccountId, "Please add environment variable for [RPC_TESTS_RECEIVE_KEY] with read acess to service bus"); TransceiverSettings.RpcClientReceiver.UserName = "******"; TransceiverSettings.RpcClientReceiver.AccessKey = System.Environment.GetEnvironmentVariable("RPC_TESTS_RECEIVE_KEY", EnvironmentVariableTarget.User); Assert.IsNotNull(TransceiverSettings.RpcClientReceiver.AccessKey, "Please add environment variable for [RPC_TESTS_RECEIVE_KEY] with read acess to service bus"); TransceiverSettings.RpcClientReceiver.ResourceName = "rpc_test"; TransceiverSettings.RpcClientReceiver.Uri = "application"; TransceiverSettings.RpcClientTransmitter.AccountId = TransceiverSettings.RpcClientReceiver.AccountId; TransceiverSettings.RpcClientTransmitter.UserName = "******"; TransceiverSettings.RpcClientTransmitter.AccessKey = System.Environment.GetEnvironmentVariable("RPC_TESTS_SEND_KEY", EnvironmentVariableTarget.User); Assert.IsNotNull(TransceiverSettings.RpcClientReceiver.AccessKey, "Please add environment variable for [RPC_TESTS_RECEIVE_KEY] with read acess to service bus"); TransceiverSettings.RpcClientTransmitter.ResourceName = "rpc_test"; TransceiverSettings.RpcClientTransmitter.TimeoutInSeconds = 30; TransceiverSettings.RpcServerTransmitter.AccountId = TransceiverSettings.RpcClientReceiver.AccountId; TransceiverSettings.RpcServerTransmitter.UserName = "******"; TransceiverSettings.RpcServerTransmitter.AccessKey = System.Environment.GetEnvironmentVariable("RPC_TESTS_SEND_KEY", EnvironmentVariableTarget.User); Assert.IsNotNull(TransceiverSettings.RpcServerTransmitter.AccessKey, "Please add environment variable for [RPC_TESTS_RECEIVE_KEY] with read acess to service bus"); TransceiverSettings.RpcServerTransmitter.ResourceName = "rpc_test"; TransceiverSettings.RpcServerTransmitter.TimeoutInSeconds = 30; TransceiverSettings.RpcServerReceiver.AccountId = System.Environment.GetEnvironmentVariable("RPC_TESTS_SERVICE_BUS", EnvironmentVariableTarget.User); TransceiverSettings.RpcServerReceiver.UserName = "******"; TransceiverSettings.RpcServerReceiver.AccessKey = System.Environment.GetEnvironmentVariable("RPC_TESTS_RECEIVE_KEY", EnvironmentVariableTarget.User); TransceiverSettings.RpcServerReceiver.ResourceName = "rpc_test"; TransceiverSettings.RpcServerReceiver.Uri = "application"; RpcTransceiver = new ServiceBusProxyClient(AsyncCoupler, Logger); RpcTransceiver.StartAsync(TransceiverSettings).Wait(); ProxySettings = new ProxySettings { OrganizationId = OrganizationId, InstanceId = InstanceId }; ProxyFactory = new ProxyFactory(TransceiverSettings, RpcTransceiver, AsyncCoupler, Logger); DeviceManagementRepoProxy = ProxyFactory.Create <IDeviceManagementRepo>(ProxySettings); DeviceArchiveRepoProxy = ProxyFactory.Create <IDeviceArchiveRepo>(ProxySettings); DeviceLogRepo = ProxyFactory.Create <IDeviceLogRepo>(ProxySettings); DevicePEMRepo = ProxyFactory.Create <IDevicePEMRepo>(ProxySettings); DeviceGroupRepo = ProxyFactory.Create <IDeviceGroupRepo>(ProxySettings); DeviceMediaRepo = ProxyFactory.Create <IDeviceMediaRepo>(ProxySettings); DeviceMediaItemRepo = ProxyFactory.Create <IDeviceMediaItemRepo>(ProxySettings); DeviceMediaRepoRemote = ProxyFactory.Create <IDeviceMediaRepoRemote>(ProxySettings); DeviceMediaItemRepoRemote = ProxyFactory.Create <IDeviceMediaItemRepoRemote>(ProxySettings); }
public ProxyTests() { _proxySubect = _proxyFactory.Create <IProxySubject>(Constants.ProxySettings); }
public static T Create <T>(this IProxyFactory proxyFactory, object key = null) where T : class { return((T)proxyFactory.Create(typeof(T), key)); }