Ejemplo n.º 1
0
        public AppParamSourceService()
        {
            var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AppParamInfo.xml");

            _appParamInfo = File.Exists(filePath) ? filePath.ToObjectFromXmlFile <AppParamInfo>() : new AppParamInfo();
        }
Ejemplo n.º 2
0
        public async Task <bool> StartApp
        (
            string appKey,
            string filePath,
            string startArgs,
            IEnumerable <BoardNotificationInfo> inputBoardInfos,
            IEnumerable <BoardNotificationInfo> outputBoardInfos,
            IEnumerable <string> musicInfos)
        {
            var result = await SendCommand(async() =>
            {
                var appParamInfo = new AppParamInfo();
                foreach (var inputBoardParamInfo in inputBoardInfos)
                {
                    appParamInfo.InputBoardParamInfos.Add(new AppBoardParamInfo
                    {
                        DeviceNumber   = inputBoardParamInfo.DeviceNumber,
                        Number         = inputBoardParamInfo.Number,
                        ServiceAddress = inputBoardParamInfo.ServiceAddress,
                        PortName       = inputBoardParamInfo.PortName
                    });
                }
                foreach (var outputBoardParamInfo in outputBoardInfos)
                {
                    appParamInfo.OutputBoardParamInfos.Add(new AppBoardParamInfo
                    {
                        DeviceNumber   = outputBoardParamInfo.DeviceNumber,
                        Number         = outputBoardParamInfo.Number,
                        ServiceAddress = outputBoardParamInfo.ServiceAddress,
                        PortName       = outputBoardParamInfo.PortName
                    });
                }
                foreach (var musicParamInfo in musicInfos)
                {
                    appParamInfo.MusicServiceAddressList.Add(musicParamInfo);
                }
                try
                {
                    appParamInfo.ToXmlFile(Path.Combine(Path.GetDirectoryName(filePath), "AppParamInfo.xml"));
                    Messenger.Default.Send(new NotificationMessage(string.Format("{0} 正在启动 {0} App。", appKey)));
                    Process.Start(filePath, startArgs);
                    var isStartApp = false;
                    await Task.Factory.StartNew(() =>
                    {
                        var fileName   = Path.GetFileNameWithoutExtension(filePath);
                        var checkIndex = 5;
                        while (checkIndex != 0)
                        {
                            var processList = Process.GetProcessesByName(fileName).ToList();
                            if (processList.Count > 0)
                            {
                                isStartApp = true;
                                break;
                            }
                            Task.Delay(1000);
                            checkIndex--;
                        }
                    });
                    return(isStartApp);
                }
                catch (Exception ex)
                {
                    Messenger.Default.Send(new NotificationMessage(string.Format("{0} 启动APP出现异常,原因:{1}", appKey, ex.Message)));
                    return(false);
                }
                return(false);
            });

            return(result);
        }