Beispiel #1
0
 public override ServiceMessage SendMessage(ServiceMessage message)
 {
     var msgType = DbSubsystemMessages.Undefined;
     try
     {
         msgType = (DbSubsystemMessages)Convert.ChangeType(message.Type, typeof(DbSubsystemMessages));
     }
     catch (Exception)
     {
         Logger.Log.Write(LogLevels.Emerg,
                          String.Format("Неправильный тип сообщения: {0} для подсистемы {1}",
                                         message.Type, this.Type()));
     }
     switch (msgType)
     {
         case DbSubsystemMessages.GetContext:
             return new ServiceMessage(KernelTypes.ServiceKernel, SubsystemType.DataBase, message.From, DbSubsystemMessages.GetContext, new object[] { context });
         case DbSubsystemMessages.SaveContext:
             {
                 context.SaveChanges();
                 return new ServiceMessage(KernelTypes.ServiceKernel, SubsystemType.DataBase, message.From, DbSubsystemMessages.SaveContext, new object[] { });
             }
         default:
             throw new SubsystemWorkingException("Неопознанный тип сообщения.");
     }
 }
Beispiel #2
0
 private static byte[] SerializeData(ServiceMessage msg)
 {
     var serializer = new DataContractSerializer(typeof(ServiceMessage));
     var writer = new MemoryStream();
     serializer.WriteObject(writer, msg);
     return writer.ToArray();
 }
Beispiel #3
0
        public override ServiceMessage SendMessage(ServiceMessage message)
        {
            var msgType = AccessMessages.Undefined;
            try
            {
                msgType = (AccessMessages)Convert.ChangeType(message.Type, typeof(AccessMessages));
            }
            catch (Exception)
            {
                Logger.Log.Write(LogLevels.Emerg,
                                 String.Format("Неправильный тип сообщения: {0} для подсистемы {1}",
                                                message.Type, this.Type()));
            }
            switch (msgType)
            {
                case AccessMessages.CheckLogin:
                    return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Access, SubsystemType.Access, AccessMessages.CheckLogin,
                                              new object[] { _acessModule.CheckLogin((string)message.Message[0]).ToString() });
                case AccessMessages.GetInfo:
                    {
                        throw new NotImplementedException();
                    }
                case AccessMessages.Login:
                    {
                        var login = (string)message.Message[0];
                        var passwd = (string)message.Message[1];
                        object result = _acessModule.Login(login, passwd);
                        return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Access, SubsystemType.Access, AccessMessages.Login,
                                                    new object[] { result });
                    }
                case AccessMessages.Register:
                    {
                        var u = new User
                                    {

                                        Login = message.Message[3].ToString(),
                                        Password = message.Message[4].ToString(),
                                        Email = message.Message[0].ToString(),
                                        Name = message.Message[1].ToString(),
                                        Sname = message.Message[2].ToString(),
                                        LastAccess = DateTime.Now,
                                        Registred = DateTime.Now,
                                    };

                        return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Access, SubsystemType.Access, AccessMessages.Register,
                                                    new object[] {_acessModule.Register(u)});
                    }
                case AccessMessages.Logout:
                    {
                        _acessModule.Logout(((UserCache)(message.Message[0])).Client);
                        return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Access, message.From, AccessMessages.Logout,
                            new object[] {  });
                    }
                default:
                    throw new SubsystemWorkingException("Неопознанный тип сообщения.");
            }
        }
Beispiel #4
0
 public ServiceMessage SendMessage(ServiceMessage message)
 {
     var msgType = (ReportMessages) message.Type;
     switch(msgType)
     {
         case ReportMessages.GetLastUserLog:
             logControl.SendMessage(message);
             return null;
     }
     return null;
 }
Beispiel #5
0
 public ServiceMessage SendMessage(ServiceMessage message)
 {
     var type = (AccessMessages) message.Type;
     if (type == AccessMessages.Register || type == AccessMessages.CheckLogin)
         RegControl.SendMessage(message);
     if(type == AccessMessages.Login)
         AccControl.SendMessage(message);
     if (type == AccessMessages.Logout)
         AccControl.SendMessage(message);
     return null;
 }
Beispiel #6
0
 public ServiceMessage SendMessage(ServiceMessage message)
 {
     switch ((ProjectMessages)message.Type)
     {
         case  ProjectMessages.GetProjectList:
             control.SendMessage(message);
             return null;
         case ProjectMessages.GetStructure:
             control.SendMessage(message);
             return null;
     }
     return null;
 }
Beispiel #7
0
 public override ServiceMessage SendMessage(ServiceMessage message)
 {
     switch ((ReportMessages)message.Type)
     {
         case ReportMessages.GetLastUserLog:
             return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Report, SubsystemType.Report,
                                       ReportMessages.GetLastUserLog, new object[]
                                                                      {
                                                                          _module.GetUserlog(
                                                                              ((UserCache) message.Message[0]).
                                                                                  Client)
                                                                      });
         default:
             throw new NotImplementedException();
     }
 }
Beispiel #8
0
 public void SendMessage(ServiceMessage msg)
 {
     if (!Dispatcher.CheckAccess())
     {
         Dispatcher.BeginInvoke(new IncomingMessage(SendMessage), msg);
         return;
     }
     if((ReportMessages)msg.Type == ReportMessages.GetLastUserLog)
     {
         var res = (List<UserlogDto>)msg.Message[0];
         foreach(var log in res)
         {
             _logs.Add(log);
         }
     }
 }
Beispiel #9
0
 public override ServiceMessage SendMessage(ServiceMessage message)
 {
     switch ((NetworkMessages) message.Type)
     {
         case NetworkMessages.Decode:
             return new ServiceMessage(KernelTypes.ServiceKernel, SubsystemType.Network,
                                       SubsystemType.Network, NetworkMessages.Decode,
                                       new object[] {_module.Decode((byte[]) message.Message[0])});
         case NetworkMessages.Encode:
             return new ServiceMessage(KernelTypes.ServiceKernel, SubsystemType.Network,
                                       SubsystemType.Network, NetworkMessages.Decode,
                                       new object[] {_module.Encode((ServiceMessage) message.Message[0])});
         default:
             throw new SubsystemWorkingException("Неопознанный тип сообщения.");
     }
 }
 public void SendMessage(ServiceMessage msg)
 {
     if (!Dispatcher.CheckAccess())
     {
         Dispatcher.BeginInvoke(new IncomingMessage(SendMessage), msg);
         return;
     }
     if ((AccessMessages)msg.Type == AccessMessages.Register)
         infoLabel.Text = (bool)msg.Message[0] ?
             "Пользователь успешно зарегистрирован" :
             "Пользователь c таким логином уже существует";
     if((AccessMessages)msg.Type == AccessMessages.CheckLogin)
         infoLabel.Text = msg.Message[0].ToString() != "Free" ?
             "Пользователь c таким логином уже существует" :
             "Логин свободен";
 }
Beispiel #11
0
        public ServiceMessage SendMessage(ServiceMessage message)
        {
            var msgType = (NetworkMessages) message.Type;
            switch(msgType)
            {
                case NetworkMessages.Encode:
                    return new ServiceMessage(KernelTypes.ClientKernel,SubsystemType.Network,
                                              SubsystemType.Network,NetworkMessages.Decode,
                                              new object[] { Encode((ServiceMessage) message.Message[0])});
                case NetworkMessages.Decode:
                    return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Network,
                                              SubsystemType.Network, NetworkMessages.Decode,
                                              new object[] {Decode((byte[]) message.Message[0])});

            }
            throw new Exception("неверный тип сообщения");
        }
Beispiel #12
0
        public override ServiceMessage SendMessage(ServiceMessage message)
        {
            /*var msgType = ChatMessages.Undefined;
            try
            {
                msgType = (ChatMessages)Convert.ChangeType(message.Type, typeof(ChatMessages));
            }
            catch (Exception)
            {
                Logger.Log.Write(LogLevels.Emerg,
                                 String.Format("Неправильный тип сообщения: {0} для подсистемы {1}",
                                                message.Type, this.Type()));
            }
            switch (msgType)
            {

            }
            */
            return message;
        }
Beispiel #13
0
 public void SendMessage(ServiceMessage message)
 {
     if(!Dispatcher.CheckAccess())
     {
         Dispatcher.BeginInvoke(new IncomingMessage(SendMessage), message);
         return;
     }
     switch ((AccessMessages) message.Type)
     {
         case AccessMessages.CheckLogin:
             return;
         case AccessMessages.GetInfo:
             return;
         case AccessMessages.Login:
             {
                 if (message.Message[0].ToString() == "0")
                     infoLabel.Text = "Пользователя с таким логином и/или паролем не существует";
                 else
                 {
                     Kernel.GetKernel.UID = int.Parse(message.Message[0].ToString());
                     Kernel.GetKernel.LoginAccess();
                 }
                 return;
             }
         case AccessMessages.Register:
             return;
         case AccessMessages.Logout:
             {
                 Kernel.GetKernel.UID = 0;
                 Kernel.GetKernel.Logout();
                 return;
             }
         default:
             throw new Exception("Неопознанный тип сообщения.");
     }
 }
Beispiel #14
0
 /// <summary>
 /// Отправка сообщения сервису для обработки
 /// </summary>
 /// <param name="msg"></param>
 public ServiceMessage SendMessage(ServiceMessage msg)
 {
     Logger.Log.Write(LogLevels.Debug, "Пришло сообщение: " + msg.ToString());
     ISubsystem targetSubsystem = null;
     foreach (var subsystem in Subsystems)
     {
         if (subsystem.Type() == msg.To)//Ищем целевую подсистему
             targetSubsystem = subsystem;
     }
     if (targetSubsystem == null)
     {
         Logger.Log.Write(LogLevels.Emerg, string.Format("Целевая подсистема {0} не зарегистрирвана", msg.To));
         return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Undefined, SubsystemType.Undefined, null, null);
     }
     var info = targetSubsystem.GetInfo();                              //Сбор информации
     var startTime = DateTime.Now;                                      //О работе подсистемы
     var answer = targetSubsystem.SendMessage(msg);                     //
     var endTime = DateTime.Now;                                        //
     info.ProcessTime += (endTime - startTime).TotalMilliseconds;
     info.RecievedMessages++;
     info.MeanTimeToMessage = info.ProcessTime / info.RecievedMessages;
     return answer;
 }
Beispiel #15
0
 /// <summary>
 /// Шифрование сообщения
 /// </summary>
 /// <param name="msg">Сервисное сообщение</param>
 /// <returns>Зашированный поток байт</returns>
 public byte[] Encode(ServiceMessage msg)
 {
     var toDecode = SerializeData(msg);
     var result =  AESCrypto.AES.Encrypt(toDecode, aesPasswd, aesSalt);
     return result;
 }
Beispiel #16
0
 public abstract ServiceMessage SendMessage(ServiceMessage message);
Beispiel #17
0
 /// <summary>
 /// Шифрование сообщения
 /// </summary>
 /// <param name="msg">Сервисное сообщение</param>
 /// <returns>Зашированный поток байт</returns>
 public byte[] Encode(ServiceMessage msg)
 {
     var toDecode = SerializeData(msg);
     Logger.Log.Write(LogLevels.Debug, "отправляем клиенту: " + Encoding.UTF8.GetString(toDecode));
     return AESCrypto.AES.Encrypt(toDecode, aesPasswd, aesSalt);
 }
 public override ServiceMessage SendMessage(ServiceMessage message)
 {
     throw new NotImplementedException();
 }
Beispiel #19
0
 public override ServiceMessage SendMessage(ServiceMessage message)
 {
     var cache = (UserCache)message.Message[0];
     var msgType =  ProjectMessages.Undefined;
     try
     {
         msgType = (IDEService.Core.ProjectMessages)Convert.ChangeType(message.Type, typeof(ProjectMessages));
     }
     catch (Exception)
     {
         Logger.Log.Write(LogLevels.Emerg,
                          String.Format("Неправильный тип сообщения: {0} для подсистемы {1}",
                                         message.Type, this.Type()));
     }
     switch (msgType)
     {
         case ProjectMessages.CreateProject:
             {
                 try
                 {
                     Module.AddProject(((UserCache)message.Message[0]), (string)message.Message[1]);
                     var answer = new  ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Project, SubsystemType.Project, ProjectMessages.Undefined, new object[] { true });
                     ((UserCache)message.Message[0]).LogMessages.Add((new UserlogDto() { Date = DateTime.Now, Message = "Создан проект " + (string)message.Message[1] }));
                     return answer;
                 }
                 catch(Exception ex)
                 {
                     return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Project,SubsystemType.Project,ProjectMessages.Undefined,new object[]{ex.Message});
                 }
             }
         case ProjectMessages.GetProjectList:
             {
                 var lst = Module.GetProjectList(((UserCache)message.Message[0]).Client);
                 return new ServiceMessage(KernelTypes.ClientKernel,SubsystemType.Project,SubsystemType.Project,ProjectMessages.GetProjectList, new object[]{ lst});
             }
         case  ProjectMessages.GetStructure:
             {
                 var structure = Module.GetStructure(((UserCache) message.Message[0]),
                                                     (string) message.Message[1]);
                 return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Project, SubsystemType.Project, ProjectMessages.GetStructure, new object[] { structure });
             }
         case ProjectMessages.AddFile:
             {
                 var userCache = (UserCache) message.Message[0];
                 var parenFolder = (FolderDto) message.Message[1];
                 var file = (FileDto) message.Message[2];
                 try
                 {
                     Module.AddFile(userCache,parenFolder, file);
                 }
                 catch (Exception ex)
                 {
                     return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Project, SubsystemType.Project, ProjectMessages.AddFile, new object[] { false,ex.ToString() });
                 }
                 return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Project, SubsystemType.Project, ProjectMessages.AddFile, new object[] { true, "Файл успешно добавлен" });
             }
         case ProjectMessages.AddFolder:
             {
                 var userCache = (UserCache)message.Message[0];
                 var parenFolder = (FolderDto)message.Message[1];
                 var folder = (FolderDto)message.Message[2];
                 try
                 {
                     Module.AddFolder(userCache, parenFolder, folder);
                 }
                 catch (Exception ex)
                 {
                     return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Project, SubsystemType.Project, ProjectMessages.AddFolder, new object[] { false, ex.ToString() });
                 }
                 return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Project, SubsystemType.Project, ProjectMessages.AddFolder, new object[] { true, "Папка успешно добавлена" });
             }
         case ProjectMessages.RemoveFile:
             {
                 var userCache = (UserCache)message.Message[0];
                 var file = (FileDto)message.Message[1];
                 try
                 {
                     Module.RemoveFile(userCache,file);
                 }
                 catch(Exception ex)
                 {
                     return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Project, SubsystemType.Project, ProjectMessages.RemoveFile, new object[] { false, ex.ToString() });
                 }
                 return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Project, SubsystemType.Project, ProjectMessages.RemoveFile, new object[] { true, "Файл успешно удален" });
            }
         case ProjectMessages.RemoveFolder:
             {
                 var userCache = (UserCache)message.Message[0];
                 var folder = (FolderDto)message.Message[1];
                 try
                 {
                     Module.RemoveFolder(userCache, folder);
                 }
                 catch (Exception ex)
                 {
                     return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Project, SubsystemType.Project, ProjectMessages.RemoveFolder, new object[] { false, ex.ToString() });
                 }
                 return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Project, SubsystemType.Project, ProjectMessages.RemoveFolder, new object[] { true, "Папка успешно удалена" });
             }
     }
     throw new Exception();
 }
 private void NextStep(object sender, RoutedEventArgs e)
 {
     if (CheckLogin() && CheckPasswd() && CheckMail())
     {
         var msg = new ServiceMessage(KernelTypes.ServiceKernel, SubsystemType.Access, SubsystemType.Access,
                                      AccessMessages.Register,
                                      new object[] { mailBox.Text , nameBox.Text, snameBox.Text,
                                          loginBox.Text, passwordBox1.Password});
         Kernel.GetKernel.SendToServer(msg);
     }
 }
Beispiel #21
0
 /// <summary>
 /// Оправляет сообщение серверу
 /// </summary>
 /// <param name="msg"></param>
 public void SendToServer(ServiceMessage msg)
 {
     while (msgsend)
     {
         Thread.Sleep(50);
     }
     msgsend = true;
     var network = Subsystems.Where(x => x.Type() == SubsystemType.Network).First();
     if(UID != 0)
     {
         var newMsg = new object[msg.Message.Length + 1];
         for (int i = 0; i < msg.Message.Length;++i )
             newMsg[i + 1] = msg.Message[i];
         newMsg[0] = UID;
         msg.Message = newMsg;
     }
     var answer =
             (byte[])network.SendMessage(new ServiceMessage(KernelTypes.ServiceKernel, SubsystemType.Undefined,
                                                             SubsystemType.Network, NetworkMessages.Encode,
                                                             new object[] { msg })).Message[0];
     Client.SendAsync(answer);
 }
Beispiel #22
0
 /// <summary>
 /// Отправка сообщения ядру для обработки
 /// </summary>
 /// <param name="msg"></param>
 public ServiceMessage SendMessage(ServiceMessage msg)
 {
     ISubsystem targetSubsystem = null;
     foreach (var subsystem in Subsystems)
     {
         if (subsystem.Type() == msg.To)//Ищем целевую подсистему
             targetSubsystem = subsystem;
     }
     if (targetSubsystem == null)
     {
         throw new Exception("target subsystem is null");
         //return new ServiceMessage(KernelTypes.ClientKernel, SubsystemType.Undefined, SubsystemType.Undefined, null, null);
     }
     var answer = targetSubsystem.SendMessage(msg);
     return answer;
 }
Beispiel #23
0
        public void SendMessage(ServiceMessage msg)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.BeginInvoke(new IncomingMessage(SendMessage), msg);
                return;
            }
            switch((ProjectMessages)msg.Type)
            {
                case ProjectMessages.GetProjectList:
                    {
                        foreach (var pInfo in (List<ProjectInfo>) msg.Message[0])
                        {
                            prjList.Items.Add(pInfo.Name);
                        }
                        break;
                    }
                case ProjectMessages.GetStructure:
                    {
                        var structure = (ProjectStructure)msg.Message[0];
                        var elem = Elem.Build(structure);
                        Structure = elem;
                        project.ItemsSource = new List<Elem>() {elem};
                        return;

                    }
            }
            return;
        }