Example #1
0
        public bool Register(RegisteredParameter registeredParameter)
        {
            bool result = false;

            MsgLogger.WriteFlow($"{GetType().Name} - Register", $"Register parameter source = '{registeredParameter.Key}', index = {registeredParameter.Parameter.Index:X4}, subindex = {(registeredParameter.Parameter as XddParameter).SubIndex:X4}");

            try
            {
                lock (RegisteredParametersLock)
                {
                    if (!_registeredParameters.ContainsKey(registeredParameter.Key))
                    {
                        result = AddToRegisteredParameters(registeredParameter);
                    }
                    else
                    {
                        result = UpdateParameterRefCount(registeredParameter);
                    }
                }
            }
            catch (Exception e)
            {
                MsgLogger.Exception($"{GetType().Name} - Register", e);
            }

            MsgLogger.WriteDebug($"{GetType().Name} - Register", $"Register Parameter '{registeredParameter.Key}' - OK");

            return(result);
        }
Example #2
0
        public bool RegisterParameter(string source, ushort index, byte subIndex, ParameterUpdatePriority priority)
        {
            bool result           = false;
            var  objectDictionary = _device?.ObjectDictionary;
            var  parameter        = objectDictionary?.SearchParameter(index, subIndex);

            if (parameter != null)
            {
                var registeredParameter = new RegisteredParameter {
                    Source = source, Parameter = parameter, Priority = priority
                };

                MsgLogger.WriteFlow($"{GetType().Name} - RegisterParameter", $"register parameter index = 0x{index:X4}, subindex = 0x{subIndex:X4}, add to queue ...");

                lock (RegisterParametersQueueLock)
                {
                    _registerParametersQueue.Add(registeredParameter);
                    result = true;
                }

                MsgLogger.WriteFlow($"{GetType().Name} - RegisterParameter", $"register parameter index = 0x{index:X4}, subindex = 0x{subIndex:X4}, added to queue");
            }
            else
            {
                MsgLogger.WriteError($"{GetType().Name} - RegisterParameter", $"parameter index = 0x{index:X4}, subindex = 0x{subIndex:X4}, not found");
            }

            return(result);
        }
        private Task SetMuteAsync(bool muteValue)
        {
            var result = Task.Run(() =>
            {
                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    try
                    {
                        string muteString = muteValue ? "mute" : "unmute";

                        string args = $"-D pulse sset Master {muteString}";

                        var startInfo = new ProcessStartInfo("amixer");

                        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        startInfo.Arguments   = args;

                        SetExecutionStatus(StatusWordEnums.PendingExecution);

                        var startResult = Process.Start(startInfo);

                        MsgLogger.WriteFlow($"{GetType().Name} - SetMuteAsync", $"Mute request: {muteString}, result = {startResult!=null}");

                        SetExecutionStatus(startResult != null ? StatusWordEnums.ExecutedSuccessfully : StatusWordEnums.ExecutionFailed);
                    }
                    catch (Exception e)
                    {
                        MsgLogger.Exception($"{GetType().Name} - SetMuteAsync", e);
                    }
                }
            });

            return(result);
        }
Example #4
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <MasterOptions>(args)
            .WithParsed(RunOptionsAndReturnExitCode)
            .WithNotParsed(HandleParseError);

            MsgLogger.WriteFlow("Exit");
        }
Example #5
0
        private bool PurgeToolFileSystem(DeviceTool deviceTool)
        {
            bool result = false;

            foreach (var payload in deviceTool.PayloadSet)
            {
                result = PurgeToolFileSystem(payload);

                if (result)
                {
                    MsgLogger.WriteFlow($"{GetType().Name} - CleanupToolStorage", $"payload file name {payload.FileName} deleted from file system");
                }
            }

            return(result);
        }
Example #6
0
        private void SourceChannelGoingOffline(string source)
        {
            var parameters = _parameterUpdater.GetParametersFromSource(source);

            MsgLogger.WriteFlow($"{GetType().Name} - SourceChannelGoingOffline", $"Source {source} is going offline ...");

            lock (UnregisterParametersQueueLock)
            {
                foreach (var parameter in parameters)
                {
                    _unregisterParametersQueue.Add(parameter);
                }
            }

            MsgLogger.WriteFlow($"{GetType().Name} - SourceChannelGoingOffline", $"Source {source} unregister queue ready!");
        }
Example #7
0
        private void OnParametersUpdated(object sender, ParameterUpdateEventArgs args)
        {
            var device = args.Device;

            MsgLogger.WriteFlow($"{GetType().Name} - OnParametersUpdated", $"Device = {device.Name}, parameters updated, result = {args.Result}");

            if (device != null)
            {
                if (device.DeviceDescription != null)
                {
                    device.Status = DeviceStatus.Registered;
                }
                else
                {
                    device.Status = DeviceStatus.Ready;
                }

                device.RunAsync();
            }
        }
Example #8
0
        public bool WriteParameter(Parameter parameter)
        {
            bool result        = false;
            var  communication = _device?.Communication;

            lock (this)
            {
                if (parameter != null)
                {
                    if (parameter.Flags.Access == AccessMode.WriteOnly ||
                        parameter.Flags.Access == AccessMode.ReadWrite)
                    {
                        if (parameter.GetValue(out byte[] data))
                        {
                            MsgLogger.WriteFlow($"Write parameter, parameter='{parameter.UniqueId}', {data}");

                            if (communication.SetObject(parameter.Index, parameter.SubIndex, data))
                            {
                                result = true;
                            }
                            else
                            {
                                MsgLogger.WriteError($"{GetType().Name} - WriteParameter", $"Set value failed, parameter='{parameter.UniqueId}'");
                            }
                        }
                        else
                        {
                            MsgLogger.WriteError($"{GetType().Name} - WriteParameter", $"Get value failed, parameter='{parameter.UniqueId}'");
                        }
                    }
                    else
                    {
                        MsgLogger.WriteError($"{GetType().Name} - WriteParameter", $"Write not possible, index={parameter.Index}, subindex={parameter.SubIndex}, access flag={parameter.Flags.Access}");

                        result = false;
                    }
                }
            }

            return(result);
        }
        private async Task <bool> DownloadTool(DeviceTool deviceTool)
        {
            bool result = false;

            foreach (var payload in deviceTool.PayloadSet)
            {
                var pluginCacheItem = FindPluginInCache(payload);

                if (pluginCacheItem != null)
                {
                    MsgLogger.WriteFlow($"{GetType().Name} - DownloadTool", $"payload file name {payload.FileName} found in cache");
                    result = true;
                }
                else
                {
                    pluginCacheItem = FindPluginInFileSystem(payload);

                    if (pluginCacheItem != null)
                    {
                        MsgLogger.WriteFlow($"{GetType().Name} - DownloadTool", $"payload file name {payload.FileName} found in file system");
                        result = true;
                    }
                    else
                    {
                        if (await DownloadTool(payload.Id, payload.HashCode, payload.Mode))
                        {
                            result = UpdatePluginCache(payload);
                        }
                        else
                        {
                            MsgLogger.WriteError($"{GetType().Name} - DownloadTool", $"payload file name {payload.FileName} download failed!");
                        }
                    }
                }
            }

            return(result);
        }
Example #10
0
        public List <RegisteredParameter> GetParametersFromSource(string source)
        {
            var result = new List <RegisteredParameter>();

            MsgLogger.WriteFlow($"{GetType().Name} - GetParametersFromSource", $"GetParametersFromSource enter ...");

            lock (RegisteredParametersLock)
            {
                if (_registeredParameters.Count > 0)
                {
                    foreach (var registeredParameter in _registeredParameters.Values)
                    {
                        if (registeredParameter.Source == source)
                        {
                            result.Add(registeredParameter);
                        }
                    }
                }
            }

            MsgLogger.WriteFlow($"{GetType().Name} - GetParametersFromSource", $"GetParametersFromSource leave");

            return(result);
        }
        private void CloseWebAppInstances()
        {
            try
            {
                bool gracefullClose = false;

                if (_stationsCountParameter.GetValue(out ushort maxCount))
                {
                    for (ushort i = 0; i < maxCount; i++)
                    {
                        if (_processIdParameters[i].GetValue(out int processId) && processId > 0)
                        {
                            try
                            {
                                var p = Process.GetProcessById(processId);

                                if (p != null)
                                {
                                    if (!p.HasExited)
                                    {
                                        const int MaxWaitTimeInMs = 10000;
                                        var       startInfo       = new ProcessStartInfo("kill");

                                        startInfo.WindowStyle = ProcessWindowStyle.Normal;
                                        startInfo.Arguments   = $"{processId}";

                                        Process.Start(startInfo);

                                        gracefullClose = p.WaitForExit(MaxWaitTimeInMs);
                                    }
                                    else
                                    {
                                        MsgLogger.WriteError($"{GetType().Name} - CloseWebAppInstances", $"process id exited - pid {processId}");
                                    }
                                }
                                else
                                {
                                    MsgLogger.WriteError($"{GetType().Name} - CloseWebAppInstances", $"process id not found - pid {processId}");
                                }
                            }
                            catch (Exception e)
                            {
                                MsgLogger.Exception($"{GetType().Name} - CloseWebAppInstances [1]", e);
                            }
                        }
                    }
                }

                if (!gracefullClose)
                {
                    MsgLogger.WriteFlow("close browser brute force");

                    foreach (var p in Process.GetProcessesByName(_settings.AppName))
                    {
                        p.Kill();
                    }

                    if (_settings.IsWebKitProcess)
                    {
                        foreach (var p in Process.GetProcessesByName("WebKitWebProcess"))
                        {
                            p.Kill();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MsgLogger.Exception($"{GetType().Name} - CloseWebAppInstances [2]", e);
            }
        }
        private Task SetActiveStationAsync(int activeStationValue)
        {
            var result = Task.Run(() =>
            {
                if (activeStationValue == 0)
                {
                    CloseWebAppInstances();
                }
                else if (_urlParameters.Count >= activeStationValue && activeStationValue > 0)
                {
                    var urlParam     = _urlParameters[activeStationValue - 1];
                    var processParam = _processIdParameters[activeStationValue - 1];

                    if (urlParam.GetValue(out string url))
                    {
                        CloseWebAppInstances();

                        try
                        {
                            var startInfo = new ProcessStartInfo(_settings.AppPath);

                            startInfo.WindowStyle = ProcessWindowStyle.Normal;

                            string playUrl = _settings.PlayUrl;
                            string fullUrl = $"{playUrl}{url}";

                            if (_settings.UseIFrameDelegation)
                            {
                                if (CreateDelegationFile(fullUrl, out var delegationUri))
                                {
                                    fullUrl = delegationUri;
                                }
                            }

                            startInfo.Arguments = _settings.AppArgs + $" {fullUrl}";

                            SetExecutionStatus(StatusWordEnums.PendingExecution);

                            var startResult = Process.Start(startInfo);

                            SetExecutionStatus(startResult != null ? StatusWordEnums.ExecutedSuccessfully : StatusWordEnums.ExecutionFailed);

                            if (startResult != null)
                            {
                                if (!processParam.SetValue(startResult.Id))
                                {
                                    MsgLogger.WriteError($"{GetType().Name} - SetActiveStationAsync", "process id cannot be set");
                                }
                            }

                            MsgLogger.WriteFlow($"{GetType().Name} - SetActiveStationAsync", $"Set Station request: {url}, result = {startResult != null}");
                        }
                        catch (Exception e)
                        {
                            MsgLogger.Exception($"{GetType().Name} - SetActiveStationAsync", e);
                        }
                    }
                }
            });

            return(result);
        }