Example #1
0
        internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value)
        {
            if (instance == null)
            {
                value = this;
                return(true);
            }

            IProxyObject proxy = instance as IProxyObject;

            if (proxy == null)
            {
                throw PythonOps.TypeError("descriptor for {0} object doesn't apply to {1} object",
                                          PythonOps.Repr(context, _type.Name),
                                          PythonOps.Repr(context, PythonTypeOps.GetName(instance)));
            }

            if (!DynamicHelpers.GetPythonType(proxy.Target).TryGetBoundMember(context, proxy.Target, _name, out value))
            {
                return(false);
            }

            value = new GenericMethodWrapper(_name, proxy);
            return(true);
        }
Example #2
0
        public override Task Invoke(IProxyObject command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            var proxiedObject = (CreateVolumeDto)command;

            if (proxiedObject.VhdName != null && proxiedObject.Packages.Length < 2)
            {
                return(this.SelfElevationAwareObject.CreateVolume(
                           proxiedObject.Packages.First(),
                           Path.Combine(proxiedObject.VhdDirectory, proxiedObject.VhdName),
                           proxiedObject.SizeInMegaBytes,
                           proxiedObject.Type,
                           proxiedObject.ExtractCertificate,
                           proxiedObject.GenerateScripts,
                           cancellationToken,
                           progress));
            }

            return(this.SelfElevationAwareObject.CreateVolumes(
                       proxiedObject.Packages,
                       proxiedObject.VhdDirectory,
                       proxiedObject.Type,
                       proxiedObject.ExtractCertificate,
                       proxiedObject.GenerateScripts,
                       cancellationToken,
                       progress));
        }
Example #3
0
        public override Task Invoke(IProxyObject command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            if (command is MovePackageToVolumeDto movePackageToVolumeDto)
            {
                return(this.SelfElevationAwareObject.MovePackageToVolume(movePackageToVolumeDto.VolumePackagePath, movePackageToVolumeDto.PackageFullName, cancellationToken, progress));
            }

            if (command is DeleteDto deleteDto)
            {
                return(this.SelfElevationAwareObject.Delete(deleteDto.Name, cancellationToken, progress));
            }

            if (command is DismountDto dismountDto)
            {
                return(this.SelfElevationAwareObject.Dismount(dismountDto.Name, cancellationToken, progress));
            }

            if (command is MountDto mountDto)
            {
                return(this.SelfElevationAwareObject.Mount(mountDto.Name, cancellationToken, progress));
            }

            if (command is SetDefaultDto setDefaultDto)
            {
                return(this.SelfElevationAwareObject.SetDefault(setDefaultDto.DrivePath, cancellationToken, progress));
            }

            throw new NotSupportedException();
        }
Example #4
0
        /// <summary>
        /// Get only the underlying ID from a proxy. This avoids going to the database when an object is not loaded yet.
        /// </summary>
        /// <param name="proxy"></param>
        /// <returns></returns>
        public int GetIdFromProxy(IProxyObject proxy)
        {
            if (proxy == null)
            {
                throw new ArgumentNullException("proxy");
            }

            // existing object
            if (proxy.ID > Zetbox.API.Helper.INVALIDID)
            {
                return(proxy.ID);
            }

            // new object
            var implType = GetImplType(proxy);
            var ift      = GetImplementationType(implType).ToInterfaceType();
            var item     = (NHibernatePersistenceObject)_attachedObjectsByProxy.Lookup(ift, proxy);

            if (item == null)
            {
                // ... without wrapper
                item = (NHibernatePersistenceObject)Activator.CreateInstance(proxy.ZetboxWrapper, lazyCtx, proxy);
                AttachAsNew(item);
            }
            return(item.ID);
        }
Example #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="property"></param>
 /// <param name="value"></param>
 /// <param name="oldValue"></param>
 public SetProperty(IProxyObject proxy, Object obj, String property, Object value, Object oldValue)
 {
     mProxy    = proxy;
     mProperty = property;
     mObject   = obj;
     mNewValue = value;
     mOldValue = oldValue;
 }
Example #6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="property"></param>
 /// <param name="value"></param>
 /// <param name="oldValue"></param>
 public SetProperty(IProxyObject proxy, Object obj, String property, Object value, Object oldValue)
 {
     mProxy = proxy;
     mProperty = property;
     mObject = obj;
     mNewValue = value;
     mOldValue = oldValue;
 }
Example #7
0
        private void InitializeProxyObject()
        {
            proxy = factory.CreateObject(address);

            proxy.Closed  += BaseProxy_Closed;
            proxy.Closing += BaseProxy_Closing;
            proxy.Faulted += BaseProxy_Faulted;
            proxy.Opened  += BaseProxy_Opened;
            proxy.Opening += BaseProxy_Opening;
        }
Example #8
0
        public async Task Invoke(IProxyObject command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = default)
        {
            // ReSharper disable once StringLiteralTypo
            using (var pipeClient = await this.ipcManager.GetCommunicationChannel(cancellationToken).ConfigureAwait(false))
            {
                await pipeClient.ConnectAsync(4000, cancellationToken).ConfigureAwait(false);

                var stream = pipeClient;

                var binaryProcessor = new BinaryStreamProcessor(stream);
                // ReSharper disable once RedundantCast
                await binaryProcessor.Write((IProxyObject)command, cancellationToken).ConfigureAwait(false);

                await stream.FlushAsync(cancellationToken).ConfigureAwait(false);

                while (true)
                {
                    var response = (ResponseType)await binaryProcessor.ReadInt32(cancellationToken).ConfigureAwait(false);

                    switch (response)
                    {
                    case ResponseType.Exception:
                        var msg = await binaryProcessor.ReadString(cancellationToken).ConfigureAwait(false);

                        // ReSharper disable once UnusedVariable
                        var stack = await binaryProcessor.ReadString(cancellationToken).ConfigureAwait(false);

                        await stream.FlushAsync(cancellationToken).ConfigureAwait(false);

                        throw new ForwardedException(msg);

                    case ResponseType.Progress:
                        var deserializedProgress = await binaryProcessor.Read <ProgressData>(cancellationToken).ConfigureAwait(false);

                        if (progress != null)
                        {
                            progress.Report(deserializedProgress);
                        }

                        break;

                    case ResponseType.Result:
                        if (progress != null)
                        {
                            progress.Report(new ProgressData(100, null));
                        }

                        return;

                    default:
                        throw new NotSupportedException();
                    }
                }
            }
        }
Example #9
0
        public override async Task Invoke(IProxyObject command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            if (command is OpenEventViewerDto openEventViewerDto)
            {
                await this.SelfElevationAwareObject.OpenEventViewer(openEventViewerDto.Type, cancellationToken, progress).ConfigureAwait(false);

                return;
            }

            throw new NotSupportedException();
        }
Example #10
0
        private static Type GetImplType(IProxyObject proxy)
        {
            // search for "our" implementation
            var t = proxy.GetType();

            while (!t.IsNested && t != typeof(object))
            {
                t = t.BaseType;
            }
            var implType = t.DeclaringType;

            return(implType);
        }
Example #11
0
        public override Task Invoke(IProxyObject command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            if (command is InstallCertificateDto installCertificateDto)
            {
                return(this.SelfElevationAwareObject.InstallCertificate(installCertificateDto.FilePath, cancellationToken, progress));
            }

            if (command is TrustDto trustDto)
            {
                return(this.SelfElevationAwareObject.Trust(trustDto.FilePath, cancellationToken));
            }

            throw new NotSupportedException();
        }
        public override Task Invoke(IProxyObject command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            if (command is DismountRegistryDto dismountRegistryDto)
            {
                return(this.SelfElevationAwareObject.DismountRegistry(dismountRegistryDto.PackageName, cancellationToken, progress));
            }

            if (command is MountRegistryDto mountRegistryDto)
            {
                return(this.SelfElevationAwareObject.MountRegistry(mountRegistryDto.PackageName, mountRegistryDto.InstallLocation, mountRegistryDto.StartRegedit, cancellationToken, progress));
            }

            throw new NotSupportedException();
        }
        /// <summary>
        /// Retrieves the instance of a proxy. If an instance has been cached it is returned,
        /// otherwise a new one is resolved using the Unity container.
        /// </summary>
        /// <param name="proxy">the proxy to get the instance for</param>
        /// <returns>the current instance of the proxy</returns>
        public static object GetInstance(IProxyObject proxy)
        {
            var    instances = Instances.Value;
            object instance;

            if (!instances.TryGetValue(proxy, out instance))
            {
                Tuple <Type, string> key;
                if (Proxies.TryGetValue(proxy, out key))
                {
                    instance         = Containers[key].Resolve(key.Item1, key.Item2);
                    instances[proxy] = instance;
                }
            }
            return(instance);
        }
        public override Task Invoke(IProxyObject command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            switch (command)
            {
            case AddDto addDto:
            {
                AddAppxPackageOptions addDtoOptions = 0;

                if (addDto.AllUsers)
                {
                    addDtoOptions |= AddAppxPackageOptions.AllUsers;
                }

                if (addDto.AllowDowngrade)
                {
                    addDtoOptions |= AddAppxPackageOptions.AllowDowngrade;
                }

                if (addDto.KillRunningApps)
                {
                    addDtoOptions |= AddAppxPackageOptions.KillRunningApps;
                }

                return(this.SelfElevationAwareObject.Add(addDto.FilePath, addDtoOptions, cancellationToken, progress));
            }

            case DeprovisionDto deprovisionDto:
            {
                return(this.SelfElevationAwareObject.Deprovision(deprovisionDto.PackageFamilyName, cancellationToken, progress));
            }

            case RemoveDto removeDto:
            {
                return(this.SelfElevationAwareObject.Remove(removeDto.Packages, removeDto.Context == PackageContext.AllUsers, !removeDto.RemoveAppData, cancellationToken, progress));
            }

            case RemoveCurrentUserDto removeCurrentUserDto:
            {
                return(this.SelfElevationAwareObject.Remove(removeCurrentUserDto.PackageFullNames, !removeCurrentUserDto.RemoveAppData, cancellationToken, progress));
            }

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
        public static T ResolveRealRemoteObject <T>(T remoteObject)
        {
            IProxyObject proxyObject = remoteObject as IProxyObject;

            if (proxyObject == null)
            {
                return(remoteObject);
            }
            try
            {
                return((T)proxyObject.GetRemoteObject());
            }
            catch (Exception)
            {
                return(remoteObject);
            }
        }
Example #16
0
 /// <summary>
 /// Конструктор создает действие изменение свойства
 /// </summary>
 /// <param name="obj">Объект-владелец свойства</param>
 /// <param name="property">Имя свойства</param>
 /// <param name="value">Новое значение свойства</param>
 public SetProperty(IProxyObject proxy, Object obj, String property, Object value)
 {
     mProxy    = proxy;
     mProperty = property;
     mObject   = obj;
     mNewValue = value;
     mOldValue = mObject.GetType().InvokeMember(
         mProperty,
         BindingFlags.Public |
         BindingFlags.NonPublic |
         BindingFlags.Instance |
         BindingFlags.GetProperty,
         null,
         mObject,
         null
         );
 }
Example #17
0
 /// <summary>
 /// Конструктор создает действие изменение свойства
 /// </summary>
 /// <param name="obj">Объект-владелец свойства</param>
 /// <param name="property">Имя свойства</param>
 /// <param name="value">Новое значение свойства</param>
 public SetProperty(IProxyObject proxy, Object obj, String property, Object value)
 {
     mProxy = proxy;
     mProperty = property;
     mObject = obj;
     mNewValue = value;
     mOldValue = mObject.GetType().InvokeMember(
         mProperty,
         BindingFlags.Public |
         BindingFlags.NonPublic |
         BindingFlags.Instance |
         BindingFlags.GetProperty,
         null,
         mObject,
         null
     );
 }
        /// <summary>
        /// Retrieves the instance of a proxy. If an instance has been cached it is returned,
        /// otherwise a new one is resolved using the Unity container.
        /// </summary>
        /// <param name="proxy">the proxy to get the instance for</param>
        /// <returns>the current instance of the proxy</returns>
        public static object GetInstance(IProxyObject proxy)
        {
            var    instances = Instances.Value;
            object instance;

            if (!instances.TryGetValue(proxy, out instance))
            {
                Tuple <Type, string> key;
                if (Proxies.TryGetValue(proxy, out key))
                {
                    instance         = Containers[key].Resolve(key.Item1, key.Item2);
                    instances[proxy] = instance;
                    // Registering the destruction callback for the instance
                    RegisterDestructionCallback(key, instance);
                }
            }
            return(instance);
        }
Example #19
0
        public override Task Invoke(IProxyObject command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            switch (command)
            {
            case CheckUpdateAvailabilityDto checkUpdatesDto:
            {
                return(this.SelfElevationAwareObject.CheckForUpdates(checkUpdatesDto.PackageFullName, cancellationToken, progress));
            }

            case StopDto stopDto:
            {
                return(this.SelfElevationAwareObject.Stop(stopDto.PackageFullName, cancellationToken));
            }

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
Example #20
0
        public override Task Invoke(IProxyObject command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            switch (command)
            {
            case RunDto runPackageDto:
            {
                return(this.SelfElevationAwareObject.Run(runPackageDto.ManifestPath, runPackageDto.ApplicationId, cancellationToken, progress));
            }

            case RunToolInContextDto runToolInContextDto:
            {
                return(this.SelfElevationAwareObject.RunToolInContext(runToolInContextDto.PackageFamilyName, runToolInContextDto.AppId, runToolInContextDto.ToolPath, runToolInContextDto.Arguments, cancellationToken, progress));
            }

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
Example #21
0
        /// <summary>
        /// Given an NH-proxy, load a full Impl-object. This may force going to the database to find the concrete type.
        /// </summary>
        public IPersistenceObject AttachAndWrap(IProxyObject proxy)
        {
            if (proxy == null)
            {
                return(null);
            }

            var implType = GetImplType(proxy);
            var ift      = GetImplementationType(implType).ToInterfaceType();
            var item     = (NHibernatePersistenceObject)_attachedObjectsByProxy.Lookup(ift, proxy);

            if (item == null)
            {
                // re-load proxy to avoid aliasing issues from unloaded proxies, but only if there is the possibility, that this might be a _different_ sub-class

                if (proxy.ID > Zetbox.API.Helper.INVALIDID)
                {
                    var objClass = metaDataResolver.GetObjectClass(ift);
                    if (objClass != null && metaDataResolver.GetObjectClass(ift).SubClasses.Count > 0)
                    {
                        proxy = (IProxyObject)_nhSession.Load(proxy.ZetboxProxy, proxy.ID);
                        item  = (NHibernatePersistenceObject)ContainsObject(ift, proxy.ID);
                    }
                }

                if (item == null)
                {
                    item = (NHibernatePersistenceObject)Activator.CreateInstance(proxy.ZetboxWrapper, lazyCtx, proxy);

                    if (proxy.ID == Zetbox.API.Helper.INVALIDID)
                    {
                        AttachAsNew(item);
                    }
                    else
                    {
                        item = (NHibernatePersistenceObject)Attach(item);
                    }
                }
            }
            return(item);
        }
Example #22
0
        public override Task Invoke(IProxyObject command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            if (command is AddDto addDto)
            {
                AddAppxPackageOptions addDtoOptions = 0;

                if (addDto.AllUsers)
                {
                    addDtoOptions |= AddAppxPackageOptions.AllUsers;
                }

                if (addDto.AllowDowngrade)
                {
                    addDtoOptions |= AddAppxPackageOptions.AllowDowngrade;
                }

                if (addDto.KillRunningApps)
                {
                    addDtoOptions |= AddAppxPackageOptions.KillRunningApps;
                }

                return(this.SelfElevationAwareObject.Add(addDto.FilePath, addDtoOptions, cancellationToken, progress));
            }

            if (command is DeprovisionDto deprovisionDto)
            {
                return(this.SelfElevationAwareObject.Deprovision(deprovisionDto.PackageFamilyName, cancellationToken, progress));
            }

            if (command is CheckUpdateAvailabilityDto checkUpdatesDto)
            {
                return(this.SelfElevationAwareObject.CheckForUpdates(checkUpdatesDto.PackageFullName, cancellationToken, progress));
            }

            if (command is StopDto stopDto)
            {
                return(this.SelfElevationAwareObject.Stop(stopDto.PackageFullName, cancellationToken));
            }

            if (command is RemoveDto removeDto)
            {
                return(this.SelfElevationAwareObject.Remove(removeDto.Packages, removeDto.Context == PackageContext.AllUsers, !removeDto.RemoveAppData, cancellationToken, progress));
            }

            if (command is RemoveCurrentUserDto removeCurrentUserDto)
            {
                return(this.SelfElevationAwareObject.Remove(removeCurrentUserDto.PackageFullNames, !removeCurrentUserDto.RemoveAppData, cancellationToken, progress));
            }

            if (command is RunDto runPackageDto)
            {
                return(this.SelfElevationAwareObject.Run(runPackageDto.ManifestPath, runPackageDto.ApplicationId, cancellationToken, progress));
            }

            if (command is RunToolInContextDto runToolInContextDto)
            {
                return(this.SelfElevationAwareObject.RunToolInContext(runToolInContextDto.PackageFamilyName, runToolInContextDto.AppId, runToolInContextDto.ToolPath, runToolInContextDto.Arguments, cancellationToken, progress));
            }

            throw new NotSupportedException();
        }
 /// <summary>
 /// Retrieves the instance of a proxy. If an instance has been cached it is returned,
 /// otherwise a new one is resolved using the Unity container.
 /// </summary>
 /// <param name="proxy">the proxy to get the instance for</param>
 /// <returns>the current instance of the proxy</returns>
 public static object GetInstance(IProxyObject proxy)
 {
     var instances = Instances.Value;
     object instance;
     if (!instances.TryGetValue(proxy, out instance))
     {
         Tuple<Type, string> key;
         if (Proxies.TryGetValue(proxy, out key))
         {
             instance = Containers[key].Resolve(key.Item1, key.Item2);
             instances[proxy] = instance;
         }
     }
     return instance;
 }
 /// <summary>
 /// Retrieves the instance of a proxy. If an instance has been cached it is returned,
 /// otherwise a new one is resolved using the Unity container.
 /// </summary>
 /// <param name="proxy">the proxy to get the instance for</param>
 /// <returns>the current instance of the proxy</returns>
 public static object GetInstance(IProxyObject proxy)
 {
     var instances = Instances.Value;
     object instance;
     if (!instances.TryGetValue(proxy, out instance))
     {
         Tuple<Type, string> key;
         if (Proxies.TryGetValue(proxy, out key))
         {
             instance = Containers[key].Resolve(key.Item1, key.Item2);
             instances[proxy] = instance;
             // Registering the destruction callback for the instance
             RegisterDestructionCallback(key, instance);
         }
     }
     return instance;
 }
Example #25
0
        public override Task Invoke(IProxyObject command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            var proxiedObject = (CreateVolumeDto)command;

            return(this.SelfElevationAwareObject.CreateVolume(proxiedObject.PackagePath, proxiedObject.VhdPath, proxiedObject.SizeInMegaBytes, proxiedObject.ExtractCertificate, proxiedObject.GenerateScripts, cancellationToken, progress));
        }
Example #26
0
 public GenericMethodWrapper(string methodName, IProxyObject proxyTarget)
 {
     name   = methodName;
     target = proxyTarget;
 }
 /// <summary>
 /// Adds a new proxy for a dependency in the step scope.
 /// </summary>
 /// <param name="type">the type of the dependency</param>
 /// <param name="name">the name of the dependency, or null if it has no name</param>
 /// <param name="proxy">the new proxy</param>
 public static void AddProxy(Type type, string name, IProxyObject proxy)
 {
     Proxies[proxy] = new Tuple<Type, string>(type, name);
 }
Example #28
0
 public override Task Invoke(IProxyObject command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
 {
     throw new NotSupportedException();
 }
Example #29
0
 public GenericMethodWrapper(SymbolId methodName, IProxyObject proxyTarget) {
     name = methodName;
     target = proxyTarget;
 }
 public abstract Task Invoke(IProxyObject command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null);
 /// <summary>
 /// Adds a new proxy for a dependency in the step scope.
 /// </summary>
 /// <param name="type">the type of the dependency</param>
 /// <param name="name">the name of the dependency, or null if it has no name</param>
 /// <param name="proxy">the new proxy</param>
 public static void AddProxy(Type type, string name, IProxyObject proxy)
 {
     Proxies[proxy] = new Tuple <Type, string>(type, name);
 }
Example #32
0
 public GenericMethodWrapper(string methodName, IProxyObject proxyTarget) {
     name = methodName;
     target = proxyTarget;
 }