Beispiel #1
0
        public async void GetStatus(string objectIdentifier, int timeout, IReactPromise <string> promise)
        {
            if (!GetObject(objectIdentifier, out StarPrinter nativeObject))
            {
                promise.Reject(new ReactError());
                return;
            }

            nativeObject.GetStatusTimeout = timeout;

            try
            {
                StarPrinterStatus status = await nativeObject.GetStatusAsync();

                StarPrinterStatusWrapper.SetObject(status, out string statusIdentifier);
                promise.Resolve(statusIdentifier);
            }
            catch (StarIO10Exception e)
            {
                StarIO10ErrorWrapper.SetObject(e, out string exceptionIdentifier);
                promise.Reject(new ReactError()
                {
                    Code = exceptionIdentifier, Exception = e
                });
            }
        }
Beispiel #2
0
        public async void ActionShowImage(string objectIdentifier, string source, bool effectDiffusion, int threshold, IReactPromise <JSValue.Void> promise)
        {
            try
            {
                if (!GetObject(objectIdentifier, out DisplayBuilder nativeObject))
                {
                    promise.Reject(new ReactError());
                    return;
                }

                ImageParameter parameter = await StarIO10ValueConverter.ToDisplayImageParameterAsync(source, effectDiffusion, threshold);

                nativeObject.ActionShowImage(parameter);

                promise.Resolve();
            }
            catch (Exception)
            {
                StarIO10Exception exception = new StarIO10ArgumentException("Invalid source.");
                StarIO10ErrorWrapper.SetObject(exception, out string exceptionIdentifier);
                promise.Reject(new ReactError()
                {
                    Code = exceptionIdentifier, Exception = exception
                });
            }
        }
Beispiel #3
0
        public async void Open(string objectIdentifier, string interfaceType, string identifier, int timeout, bool autoSwitchInterface, IReactPromise <JSValue.Void> promise)
        {
            if (!GetObject(objectIdentifier, out StarPrinter nativeObject) ||
                !StarIO10ValueConverter.ToInterfaceType(interfaceType, out InterfaceType nativeInterfaceType))
            {
                promise.Reject(new ReactError());
                return;
            }

            nativeObject.ConnectionSettings.InterfaceType       = nativeInterfaceType;
            nativeObject.ConnectionSettings.Identifier          = identifier;
            nativeObject.ConnectionSettings.AutoSwitchInterface = autoSwitchInterface;
            nativeObject.OpenTimeout = timeout;

            try
            {
                await nativeObject.OpenAsync();

                promise.Resolve();
            }
            catch (StarIO10Exception e)
            {
                StarIO10ErrorWrapper.SetObject(e, out string exceptionIdentifier);
                promise.Reject(new ReactError()
                {
                    Code = exceptionIdentifier, Exception = e
                });
            }
        }
Beispiel #4
0
        public async void PrintRawData(string objectIdentifier, byte[] data, int timeout, IReactPromise <JSValue.Void> promise)
        {
            if (!GetObject(objectIdentifier, out StarPrinter nativeObject))
            {
                promise.Reject(new ReactError());
                return;
            }

            nativeObject.PrintTimeout = timeout;

            try
            {
                await nativeObject.PrintAsync(data);

                promise.Resolve();
            }
            catch (StarIO10Exception e)
            {
                StarIO10ErrorWrapper.SetObject(e, out string exceptionIdentifier);
                promise.Reject(new ReactError()
                {
                    Code = exceptionIdentifier, Exception = e
                });
            }
        }
Beispiel #5
0
        public async void ActionDriveOneTimeSound(string objectIdentifier, string source, int volume, IReactPromise <JSValue.Void> promise)
        {
            try
            {
                if (!GetObject(objectIdentifier, out MelodySpeakerBuilder nativeObject))
                {
                    promise.Reject(new ReactError());
                    return;
                }

                DriveOneTimeSoundParameter parameter = await StarIO10ValueConverter.ToMelodySpeakerDriveOneTimeSoundParameterAsync(source, volume);

                nativeObject.ActionDriveOneTimeSound(parameter);

                promise.Resolve();
            }
            catch (Exception)
            {
                StarIO10Exception exception = new StarIO10ArgumentException("Invalid source.");
                StarIO10ErrorWrapper.SetObject(exception, out string exceptionIdentifier);
                promise.Reject(new ReactError()
                {
                    Code = exceptionIdentifier, Exception = exception
                });
            }
        }
        public void Init(IReactPromise <string> promise)
        {
            StarPrinter nativeObject = new StarPrinter(new StarConnectionSettings());

            SetObject(nativeObject, out string objectIdentifier);

            nativeObject.PrinterDelegate.CommunicationError += (sender, e) =>
            {
                StarIO10ErrorWrapper.SetObject(e.Exception, out string exceptionIdentifier);
                PrinterCommunicationError(new CommunicationErrorEventParameter()
                {
                    identifier = objectIdentifier, errorIdentifier = exceptionIdentifier
                });
            };

            nativeObject.DrawerDelegate.CommunicationError += (sender, e) =>
            {
                StarIO10ErrorWrapper.SetObject(e.Exception, out string exceptionIdentifier);
                DrawerCommunicationError(new CommunicationErrorEventParameter()
                {
                    identifier = objectIdentifier, errorIdentifier = exceptionIdentifier
                });
            };

            nativeObject.InputDeviceDelegate.CommunicationError += (sender, e) =>
            {
                StarIO10ErrorWrapper.SetObject(e.Exception, out string exceptionIdentifier);
                InputDeviceCommunicationError(new CommunicationErrorEventParameter()
                {
                    identifier = objectIdentifier, errorIdentifier = exceptionIdentifier
                });
            };

            promise.Resolve(objectIdentifier);
        }
        public void Init(string[] interfaceTypes, IReactPromise <string> promise)
        {
            List <InterfaceType> nativeInterfaceTypes = new List <InterfaceType>();

            foreach (string interfaceType in interfaceTypes)
            {
                if (!StarIO10ValueConverter.ToInterfaceType(interfaceType, out InterfaceType nativeInterfaceType))
                {
                    promise.Reject(new ReactError());
                    return;
                }

                nativeInterfaceTypes.Add(nativeInterfaceType);
            }

            try
            {
                IStarDeviceDiscoveryManager nativeObject = StarDeviceDiscoveryManagerFactory.Create(nativeInterfaceTypes);

                SetObject(nativeObject, out string objectIdentifier);

                nativeObject.PrinterFound += (sender, e) =>
                {
                    if (!StarIO10ValueConverter.ToString(e.Printer.ConnectionSettings.InterfaceType, out string interfaceTypeString) ||
                        !StarIO10ValueConverter.ToString(e.Printer.Information.Model, out string modelString) ||
                        !StarIO10ValueConverter.ToString(e.Printer.Information.Emulation, out string emulationString))
                    {
                        return;
                    }

                    var parameter = new Dictionary <string, JSValue>();
                    parameter.Add(EventParameter.KeyIdentifier, objectIdentifier);
                    parameter.Add(EventParameter.KeyInterfaceType, interfaceTypeString);
                    parameter.Add(EventParameter.KeyConnectionIdentifier, e.Printer.ConnectionSettings.Identifier);
                    parameter.Add(EventParameter.KeyModel, modelString);
                    parameter.Add(EventParameter.KeyEmulation, emulationString);
                    parameter.Add(EventParameter.KeyReserved, StarIO10ValueConverter.ToJSValue(e.Printer.Information.Reserved));

                    PrinterFound(parameter);
                };
                nativeObject.DiscoveryFinished += (sender, e) =>
                {
                    var parameter = new Dictionary <string, JSValue>();
                    parameter.Add(EventParameter.KeyIdentifier, objectIdentifier);

                    DiscoveryFinished(parameter);
                };

                promise.Resolve(objectIdentifier);
            }
            catch (StarIO10Exception e)
            {
                StarIO10ErrorWrapper.SetObject(e, out string exceptionIdentifier);
                promise.Reject(new ReactError()
                {
                    Code = exceptionIdentifier, Exception = e
                });
            }
        }
Beispiel #8
0
        public void Init(IReactPromise <string> promise)
        {
            StarPrinter nativeObject = new StarPrinter(new StarConnectionSettings());

            SetObject(nativeObject, out string objectIdentifier);

            nativeObject.PrinterDelegate.CommunicationError += (sender, e) =>
            {
                StarIO10ErrorWrapper.SetObject(e.Exception, out string exceptionIdentifier);

                var parameter = new Dictionary <string, JSValue>();
                parameter.Add(EventParameter.KeyIdentifier, objectIdentifier);
                parameter.Add(EventParameter.KeyErrorIdentifier, exceptionIdentifier);

                PrinterCommunicationError(parameter);
            };

            nativeObject.DrawerDelegate.CommunicationError += (sender, e) =>
            {
                StarIO10ErrorWrapper.SetObject(e.Exception, out string exceptionIdentifier);

                var parameter = new Dictionary <string, JSValue>();
                parameter.Add(EventParameter.KeyIdentifier, objectIdentifier);
                parameter.Add(EventParameter.KeyErrorIdentifier, exceptionIdentifier);

                DrawerCommunicationError(parameter);
            };

            nativeObject.InputDeviceDelegate.CommunicationError += (sender, e) =>
            {
                StarIO10ErrorWrapper.SetObject(e.Exception, out string exceptionIdentifier);

                var parameter = new Dictionary <string, JSValue>();
                parameter.Add(EventParameter.KeyIdentifier, objectIdentifier);
                parameter.Add(EventParameter.KeyErrorIdentifier, exceptionIdentifier);

                InputDeviceCommunicationError(parameter);
            };

            nativeObject.DisplayDelegate.CommunicationError += (sender, e) =>
            {
                StarIO10ErrorWrapper.SetObject(e.Exception, out string exceptionIdentifier);

                var parameter = new Dictionary <string, JSValue>();
                parameter.Add(EventParameter.KeyIdentifier, objectIdentifier);
                parameter.Add(EventParameter.KeyErrorIdentifier, exceptionIdentifier);

                DisplayCommunicationError(parameter);
            };

            promise.Resolve(objectIdentifier);
        }
 public void Stop(IReactPromise <JSValue.Void> promise)
 {
     try
     {
         StarIO10Logger nativeObject = StarIO10Logger.Instance;
         nativeObject.Stop();
         promise.Resolve();
     }
     catch (StarIO10Exception e)
     {
         StarIO10ErrorWrapper.SetObject(e, out string exceptionIdentifier);
         promise.Reject(new ReactError()
         {
             Code = exceptionIdentifier, Exception = e
         });
     }
 }
        public void StopDiscovery(string objectIdentifier, IReactPromise <JSValue.Void> promise)
        {
            if (!GetObject(objectIdentifier, out IStarDeviceDiscoveryManager nativeObject))
            {
                promise.Reject(new ReactError());
                return;
            }

            try
            {
                nativeObject.StopDiscovery();
                promise.Resolve();
            }
            catch (StarIO10Exception e)
            {
                StarIO10ErrorWrapper.SetObject(e, out string exceptionIdentifier);
                promise.Reject(new ReactError()
                {
                    Code = exceptionIdentifier, Exception = e
                });
            }
        }
Beispiel #11
0
        public async void Close(string objectIdentifier, IReactPromise <JSValue.Void> promise)
        {
            if (!GetObject(objectIdentifier, out StarPrinter nativeObject))
            {
                promise.Reject(new ReactError());
                return;
            }

            try
            {
                await nativeObject.CloseAsync();

                promise.Resolve();
            }
            catch (StarIO10Exception e)
            {
                StarIO10ErrorWrapper.SetObject(e, out string exceptionIdentifier);
                promise.Reject(new ReactError()
                {
                    Code = exceptionIdentifier, Exception = e
                });
            }
        }