Ejemplo n.º 1
0
        /// <summary>
        /// 添加配置
        /// </summary>
        /// <param name="newConfiguration"></param>
        /// <returns></returns>
        public async Task <JsonDataMsg <string> > UserAddConfigurationToToolAsync(ToolConfigDto newConfiguration)
        {
            //参数为空检查
            if (null == newConfiguration)
            {
                NLogMgr.DebugLog(_programLog, "后台接收配置数据失败");
                return(new JsonDataMsg <string>(null, false, "后台接收数据失败"));
            }



            //使用mapper装换成聚合根
            MapperConfiguration cfg         = EntityAutoMapper.Instance.AutoMapperConfig(nameof(JobConfiguration));
            CheckConfig         checkConfig = EntityAutoMapper.Instance.GetMapperResult <CheckConfig>(cfg, newConfiguration);

            var success = await Repository.AddConfigDataAsync(checkConfig);

            if (!success)
            {
                NLogMgr.DebugLog(_programLog, "增添配置异常");
                return(new JsonDataMsg <string>(null, success, "增添配置异常"));
            }

            //异步IPC通知工具客户端配置已变化
            _client.InvokeAsync(p => p.ConfigWasModify());

            NLogMgr.DebugLog(_programLog, "已经为您加入该配置");
            return(new JsonDataMsg <string>(null, success, "已经为您加入该配置"));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            var simpleModules = await _client.InvokeAsync(host => host.GetSimpleModules(), cancellationToken)
                                .ConfigureAwait(false);

            if (simpleModules.Count == 0)
            {
                return;
            }

            var simpleModuleItems = await _client.InvokeAsync(
                host => host.GetSimpleModuleInfo(simpleModules.ToArray()),
                cancellationToken)
                                    .ConfigureAwait(false);

            if (simpleModuleItems.Count == 0)
            {
                return;
            }

            var maxLabelLength = simpleModuleItems.SelectMany(x => x.Value).Max(x => x.Key.Length);
            var formatString   = $"\t{{0,{-maxLabelLength}}} = {{1}}";

            foreach (var moduleName in simpleModules)
            {
                if (simpleModuleItems.TryGetValue(moduleName, out var items))
                {
                    Console.WriteLine($"{moduleName}:");
                    foreach (var(label, value) in items)
                    {
                        Console.WriteLine(formatString, label, value);
                    }
                }
            }
        }
 public void SendMethod()
 {
     if (!string.IsNullOrEmpty(ChatText))
     {
         client.InvokeAsync(x => x.SendChat(Username, ChatText));
     }
     ChatText = string.Empty;
 }
Ejemplo n.º 4
0
        public async Task <JsonDataMsg <string> > ImportingMachinesAsync(IFormCollection formCollection)
        {
            if (null == formCollection || null == formCollection.Files || !formCollection.Files.Any())
            {
                NLogMgr.ErrorExLog(_errorLog, "服务器接收不到文件文件", null);
                return(new JsonDataMsg <string>(null, false, "服务器接收不到文件"));
            }

            IFormFile file = formCollection.Files[0];

            if (!ExcelFile.ValidExcelFile(file))
            {
                NLogMgr.DebugLog(_programLog, "您上传的文件不是*.xlsx后缀的文件");
                return(new JsonDataMsg <string>(null, false, "您上传的文件不是*.xlsx后缀的文件"));
            }


            //导入前通知工具停止作业
            NLogMgr.DebugLog(_programLog, "通知工具停止作业");
            try
            {
                bool ipcResult = await _client.InvokeAsync(p => p.StopJob());

                NLogMgr.DebugLog(_programLog, "工具反馈结果:" + ipcResult);
            }
            catch (Exception ipcEx)
            {
                NLogMgr.ErrorExLog(_errorLog, "ipc通信失败", ipcEx);
            }

            List <EquipmentDto> list = await ExcelFileService.GetExcelDataAsync(file);

            bool success = await Repository.ReplaceTargetsAsync(list);

            JsonDataMsg <string> result = null;

            if (success)
            {
                NLogMgr.DebugLog(_programLog, "设备导入完毕");
                result = new JsonDataMsg <string>(null, success, "设备导入完毕");
            }
            else
            {
                NLogMgr.DebugLog(_programLog, "导入设备操作过程发生异常");
                result = new JsonDataMsg <string>(null, success, "导入设备操作过程发生异常");
            }

            //导入后重新开始作业
            NLogMgr.DebugLog(_programLog, "通知工具可以继续作业");
            _client.InvokeAsync(p => p.JobRestart());
            return(result);
        }
Ejemplo n.º 5
0
        public async Task <List <string> > GetProjectsId()
        {
            List <string> projectList;

            try
            {
                projectList = await _client.InvokeAsync(x => x.GetProjects());
            }
            catch (Exception e)
            {
                throw new Exception("An error occured while retrieving a new Task", e);
            }

            return(projectList);
        }
Ejemplo n.º 6
0
        public static async Task OrderAsync <TInterface>(
            this IpcServiceClient <TInterface> client,
            Expression <Func <TInterface, Order> > action) where TInterface : class
        {
            var result = await client.InvokeAsync(action);

            if (!result.Success)
            {
                throw new InvalidOperationException(result.UserErrorMessage);
            }
        }
        /// <inheritdoc />
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            var connections = await _client
                              .InvokeAsync(host => host.GetConnections(), cancellationToken)
                              .ConfigureAwait(false);

            Console.WriteLine("ID                                  \tIs alive?\tRemote IP");
            foreach (var connection in connections)
            {
                Console.WriteLine($"{connection.Id}\t{connection.IsAlive}\t{connection.RemoteIp}");
            }
        }
Ejemplo n.º 8
0
        public static async Task InvokeWithDelayAsync <TInterface>(this IpcServiceClient <TInterface> client,
                                                                   Expression <Func <TInterface, Task> > exp,
                                                                   TimeSpan delay,
                                                                   CancellationToken cancellationToken = default(CancellationToken))
            where TInterface : class
        {
            var task = client.InvokeAsync(exp, cancellationToken);

            if (await Task.WhenAny(task, Task.Delay(delay, cancellationToken)) != task)
            {
                throw new TimeoutException();
            }
        }
Ejemplo n.º 9
0
            /// <inheritdoc />
            public async Task ExecuteAsync(CancellationToken cancellationToken)
            {
                var info = await _client.InvokeAsync(host => host.GetExtendedModuleInfo(Name), cancellationToken)
                           .ConfigureAwait(false);

                if (!info.TryGetValue(Name, out var lines))
                {
                    return;
                }

                foreach (var line in lines)
                {
                    Console.WriteLine(line);
                }
            }
        public async void LoginMethod()
        {
            if (!string.IsNullOrEmpty(Username))
            {
                LoginVisibility    = Visibility.Collapsed;
                ChatViewVisibility = Visibility.Visible;

                client = new IpcServiceClientBuilder <IChatService>()
                         .UseTcp(IPAddress.Loopback, 8000)
                         .Build();

                await client.InvokeAsync(x => x.Join(Username));

                var dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
                dispatcherTimer.Tick    += new EventHandler(RefreshMethod);
                dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
                dispatcherTimer.Start();
            }
        }
Ejemplo n.º 11
0
        public async Task <TaskBox> GetNewTaskBoxAsync(string brief, string summary, string assignedUser, string reviewer, DateTime dueDate, TaskType taskType)
        {
            ITaskItem taskItem;

            try
            {
                taskItem = await _client.InvokeAsync(x => x.AddTask(brief, summary, assignedUser, reviewer, dueDate, taskType));
            }
            catch (Exception e)
            {
                throw new Exception("An error occured while retrieving a new Task", e);
            }

            return(AddTaskBox(taskItem));

            // return new ChatBox(10);
            // return AddChatBox(_chatboxManager.AddRoom());
        }
 /// <inheritdoc />
 public Task ExecuteAsync(CancellationToken cancellationToken)
 {
     return(_client.InvokeAsync(host => host.CloseConnectionAsync(Name), cancellationToken));
 }
Ejemplo n.º 13
0
 public void AddMessage(string roomID, string author, string message)
 {
     //            _chatboxManager.AddRoomMessage(roomID, author, message);
     _client.InvokeAsync(x => x.AddRoomMessage(roomID, author, message));
 }
Ejemplo n.º 14
0
 public Task <int> InvokeMethodAsync(string assemblyPath, string typeAndMethodName, string[] args, CancellationToken token = default)
 {
     return(m_client.InvokeAsync(s => s.InvokeMethod(assemblyPath, typeAndMethodName, args), token));
 }
Ejemplo n.º 15
0
 /// <inheritdoc />
 public Task ExecuteAsync(CancellationToken cancellationToken)
 {
     _status.Closed = true;
     return(_client.InvokeAsync(host => host.StopAsync(), cancellationToken));
 }
Ejemplo n.º 16
0
        public async Task TestConnection__OKAsync()
        {
            bool isConnected = await _client.InvokeAsync(x => x.IsConnected());

            Assert.IsTrue(isConnected);
        }
Ejemplo n.º 17
0
 static async Task GoAsync(IpcServiceClient <IBmsService> client)
 {
     var result = await client.InvokeAsync(x => x.AddFloat(1.23f, 4.56f));
 }
Ejemplo n.º 18
0
 public Guid?TryGetElementUnderCursor()
 {
     return(_client.InvokeAsync(x => x.TryGetElementUnderCursor()).GetAwaiter().GetResult());
 }
Ejemplo n.º 19
0
 /// <inheritdoc />
 public Task ExecuteAsync(CancellationToken cancellationToken)
 {
     return(_client.InvokeAsync(host => host.PauseAsync(), cancellationToken));
 }
Ejemplo n.º 20
0
 public async Task HighlightElement(Guid elementId)
 {
     await _ipcServiceClient.InvokeAsync(x => x.HighlightGuiElement(elementId), new CancellationTokenSource(5000).Token);
 }