Example #1
0
        public void ShowTodayTimetable(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            MessageTransfer msg = new MessageTransfer()
            {
                ChatId = user.Id
            };

            DayTimetable timetable = new DayTimetable();

            switch (user.Role)
            {
            case Role.Student:
                timetable = CistApi.GetGroupTimetable((user as Student).GroupId, DateTime.Now);
                break;

            case Role.Teacher:
                timetable = CistApi.GetTeacherTimetable((user as Teacher).TeacherId, DateTime.Now);
                break;

            default:
                break;
            }

            msg.Message = timetable?.ToString() ?? "На сегодня пар нету!";
            result.SendResponse(msg.ToJson());
        }
Example #2
0
        public void ShowNextDayTimetable(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            MessageTransfer msg = new MessageTransfer()
            {
                ChatId = user.Id
            };

            var day = result.Entities.OfType <DateEntity>(Sys.Date);

            DayTimetable timetable = new DayTimetable();

            switch (user.Role)
            {
            case Role.Student:
                timetable = CistApi.GetGroupTimetable((user as Student).GroupId, day.DateTime);
                break;

            case Role.Teacher:
                timetable = CistApi.GetTeacherTimetable((user as Teacher).TeacherId, day.DateTime);
                break;

            default:
                break;
            }

            msg.Message = timetable?.ToString() ?? $"В расписании нету пар на {day.DateTime.ToShortDateString()}";
            result.SendResponse(msg.ToJson());
        }
Example #3
0
        public void ShowTeacherNearestTimetable(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            var msg = new MessageTransfer()
            {
                ChatId = user.Id
            };

            var teacher   = result.Entities.OfType("teacherName");
            var day       = DateTime.Now;
            int teacherId = -1;

            try
            {
                teacherId = CistApi.GetTeacherIdFromName(teacher.Value);
            }
            catch (Exception)
            {
                msg.Message = "Что-то я не нашел такого преподователя, попробуй ещё раз!";
                result.SendResponse(msg.ToJson());
                return;
            }

            var timetable = CistApi.GetTeacherNearestTimetable(teacherId, day);

            msg.Message = timetable != null
                ? $"Ближайшая пара у {teacher}:\n" + timetable?.ToString()
                : $"В расписании нету пар для {teacher}";

            result.SendResponse(msg.ToJson());
        }
Example #4
0
        public void ShowTeacherTimetable(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            MessageTransfer msg = new MessageTransfer()
            {
                ChatId = user.Id
            };

            var teacher   = result.Entities.OfType("teacherName");
            var day       = result.Entities.OfType <DateEntity>(Sys.Date);
            int teacherId = -1;

            try
            {
                teacherId = CistApi.GetTeacherIdFromName(teacher.Value);
            }
            catch (Exception)
            {
                msg.Message = "Что-то я не нашел такого преподователя, попробуй ещё раз!";
                result.SendResponse(msg.ToJson());
                return;
            }

            DayTimetable timetable = CistApi.GetTeacherTimetable(teacherId, day.DateTime);

            msg.Message = timetable?.ToString() ?? $"В расписании нету пар на {day.DateTime.ToShortDateString()}";
            result.SendResponse(msg.ToJson());
        }
Example #5
0
        private void startTLS()
        {
            transportStream = new System.Net.Security.SslStream(tcpClient.GetStream(), false
                                                                , new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate))
            {
                ReadTimeout  = IOTimeout,
                WriteTimeout = IOTimeout
            };

            // According to RFC 5425 we MUST support TLS 1.2, but this protocol version only implemented in framework 4.5 and Windows Vista+...
            ((System.Net.Security.SslStream)transportStream).AuthenticateAsClient(
                hostname,
                null,
                (System.Security.Authentication.SslProtocols)_sslProtocol,
                false
                );



            if (!((System.Net.Security.SslStream)transportStream).IsEncrypted)
            {
                throw new System.Security.SecurityException("Could not establish an encrypted connection");
            }

            messageTransfer = MessageTransfer.OctetCounting;
        }
Example #6
0
        public void ShowGroupTimetable(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            MessageTransfer msg = new MessageTransfer()
            {
                ChatId = user.Id
            };

            var group = result.Entities.OfType("groupName");
            var day   = result.Entities.OfType <DateEntity>(Sys.Date) ?? new DateEntity("", DateTime.Now);

            int groupId = -1;

            try
            {
                groupId = CistApi.GetGroupIdFromName(group.Value);
            }
            catch (Exception)
            {
                msg.Message = "Что-то я не нашел такой группы, попробуй ещё раз!";
                result.SendResponse(msg.ToJson());
                return;
            }

            DayTimetable timetable = CistApi.GetGroupTimetable(groupId, day.DateTime);

            msg.Message = timetable?.ToString() ?? $"В расписании нету пар на {day.DateTime.ToShortDateString()}";
            result.SendResponse(msg.ToJson());
        }
Example #7
0
        public SyslogTcpSender(string hostname, int port, MessageTransfer messageTransferMethod = MessageTransfer.OctetCounting)
        {
            this.hostname = hostname;
            this.port     = port;

            Connect();

            messageTransfer = messageTransferMethod;
            trailer         = 10;     // LF
        }
 //  --------------------------------------------
 //   Message methods
 // --------------------------------------------
 public override void MessageTransfer(Session session, MessageTransfer xfr)
 {
     if (((ClientSession)session).MessageListeners.ContainsKey(xfr.GetDestination()))
     {
         IMessageListener listener = ((ClientSession)session).MessageListeners[xfr.GetDestination()];
         listener.MessageTransfer(new Message(xfr));
     }
     else
     {
         _log.Warn("No listener set for: {0}", xfr);
     }
 }
 //  --------------------------------------------
 //   Message methods
 // --------------------------------------------
 public override void MessageTransfer(Session session, MessageTransfer xfr)
 {
     if (((ClientSession) session).MessageListeners.ContainsKey(xfr.GetDestination()))
     {
         IMessageListener listener = ((ClientSession)session).MessageListeners[xfr.GetDestination()];
         listener.MessageTransfer( new Message(xfr));
     }
     else
     {
         _log.Warn("No listener set for: {0}", xfr);
     }
 }
Example #10
0
        public void Default(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            MessageTransfer msg = new MessageTransfer
            {
                ChatId  = user.Id,
                Message = $"Ой, что-то я не разобрал что тут написано {Emoji.Confused} \nМожете повторить ввод?"
            };

            result.SendResponse(msg.ToJson());
        }
        public async void ShowTodayWeather(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            MessageTransfer msg = new MessageTransfer()
            {
                ChatId = user.Id
            };

            var openClient     = new OpenWeatherMapClient("22a6ae75fa60f187c896025ec05038ce");
            var currentWeather = await openClient.CurrentWeather.GetByCityId(706483, MetricSystem.Metric, OpenWeatherMapLanguage.RU);

            msg.Message = $"В Харькове сейчас {currentWeather.Temperature.Value}° {Emoji.Sunny}\n" +
                          $"На небе {currentWeather.Weather.Value}\n" +
                          $"Обновленно:{currentWeather.LastUpdate.Value}";
            result.SendResponse(msg.ToJson());
        }
		private void startTLS()
		{
			transportStream = new SslStream(tcpClient.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate))
			{
				ReadTimeout = IOTimeout,
				WriteTimeout = IOTimeout
			};

			// According to RFC 5425 we MUST support TLS 1.2, but this protocol version only implemented in framework 4.5 and Windows Vista+...
			((SslStream)transportStream).AuthenticateAsClient(
				hostname,
				null,
				System.Security.Authentication.SslProtocols.Tls,
				false
			);

			if (!((SslStream)transportStream).IsEncrypted)
				throw new SecurityException("Could not establish an encrypted connection");

			messageTransfer = MessageTransfer.OctetCounting;
		}
        public async void ShowWeather(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            var day = result.Entities.OfType <DateEntity>(Sys.Date);

            MessageTransfer msg = new MessageTransfer()
            {
                ChatId = user.Id
            };

            var openClient     = new OpenWeatherMapClient("22a6ae75fa60f187c896025ec05038ce");
            var currentWeather = await openClient.Forecast.GetByCityId(706483, true, MetricSystem.Metric, OpenWeatherMapLanguage.RU);

            var dayWeather = currentWeather.Forecast.SingleOrDefault(a => a.Day.ToShortDateString().Equals(day.DateTime.ToShortDateString()));

            msg.Message = dayWeather == null ? $"Извините, но у мен не вышло найти прогноз на {day.DateTime.ToShortDateString()}" : $"В Харькове будет от {dayWeather.Temperature.Min}° до {dayWeather.Temperature.Max}° {Emoji.Sunny}\n";

            result.SendResponse(msg.ToJson());
        }
Example #14
0
        public void ShowMap(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            var msg = new MessageTransfer()
            {
                ChatId = user.Id
            };

            msg.Message     = "Отправьте пожалуйста своё местоположение!";
            msg.ReplyMarkup = new ReplyKeyboardMarkup(new[]
            {
                new KeyboardButton($"{Emoji.Round_Pushpin} Моё местоположение")
                {
                    RequestLocation = true
                }
            }
                                                      );

            result.SendResponse(msg.ToJson());
        }
Example #15
0
        /// <summary>
        /// Read the command of SagaManager
        /// </summary>
        /// <param name="message"></param>
        public void Read(MessageTransfer message)
        {
            //Get the command of SagaManager
            var typeOfCommand = message.Type.FindCommand().FirstOrDefault();

            if (typeOfCommand != null)
            {
                Console.WriteLine($"Read Command Message ({DateTime.Now}): { message.Type } Time Stamp: {message.CreatedOn}");
                var commad = (Command)JsonConvert.DeserializeObject(message.DataJson, typeOfCommand);
                Console.WriteLine($"Send  Command Message ({DateTime.Now}): { commad.MessageType }");
                Task commandSend = Mediator.SendCommand(Guid.NewGuid(), commad);
                if (!commandSend.IsCompletedSuccessfully)
                {
                    throw new ArgumentException("Command not completed");
                }
            }
            else
            {
                Console.WriteLine("Command not found on Domain: " + message.Type);
                throw new CommandNotFoundException("Command not found on Domain");
            }
        }
Example #16
0
        public void ShowNureFeed(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            var msg = new MessageTransfer()
            {
                ChatId = user.Id
            };


            try
            {
                msg.Message = CistApi.GetNureFeed();
            }
            catch (Exception)
            {
                msg.Message = "К сожалению, сервер с новостями не работает!";
                result.SendResponse(msg.ToJson());
                return;
            }

            result.SendResponse(msg.ToJson());
        }
Example #17
0
 public Message()
 {
     _message        = new MessageTransfer();
     _message.Header = new Header(new MessageProperties(), new DeliveryProperties());
     ((MessageProperties)_message.Header.Structs[0]).SetApplicationHeaders(new Dictionary <string, object>());
 }
Example #18
0
 public Message(MessageTransfer m)
 {
     _message = m;
 }
Example #19
0
 public virtual void MessageTransfer(C context, MessageTransfer mystruct)
 {
 }
Example #20
0
        private void computarProbabilidadesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            tabControl1.SelectTab(0);
            try
            {
                if (CheckConsistency())
                {
                    //obtener la evidencia
                    if (flowChartViewer1.Charts.Count > 0 && Evidence.Count > 0)
                    {
                        GetEvidence();
                    }
                    //transformar el grafo del visor a un grafo de nodos bayesianos

                    var graph = new BayesianGraph();
                    //
                    var          dict = new Dictionary <BayesianNode, BayesianNodeChartElement>(flowChartViewer1.Charts.Count);
                    BayesianNode node;
                    var          dict2 = new Dictionary <BayesianNodeChartElement, BayesianNode>(flowChartViewer1.Charts.Count);

                    graph.Clear();

                    foreach (var item in flowChartViewer1.Charts.Cast <BayesianNodeChartElement>())
                    {
                        node = new BayesianNode(item.Parents.Count, item.Childs.Count(), item.States.Count,
                                                item.Parents.Select(x => x.States.Count).ToArray())
                        {
                            Probabilities = item.Condicional_Probabilities, Name = item.Name
                        };

                        dict.Add(node, item);
                        dict2.Add(item, node);
                        item.CreateConditionalProbabilities();


                        graph.AddVertex(node);
                    }
                    foreach (var bnodechart in flowChartViewer1.Charts.Cast <BayesianNodeChartElement>())
                    {
                        foreach (var child in bnodechart.Childs)
                        {
                            graph.AddEdge(dict2[bnodechart], dict2[child]);
                        }
                    }
                    //ejecutar el traspaso de mensajes en un poliarbol o en una red multiplemente conexa
                    progressBar1.Value = 5;
                    //if(MessageTransfer.ParalellStartNumber>graph.Count)
                    MessageTransfer.Increment += UpdateProgress;


                    if (graph.Arbol())
                    {
                        if (Evidence.Count > 0)
                        {
                            MessageTransfer.Message_Tranfer_Poliarbol(graph, Evidence[EvidenceIndex]);
                        }
                        else
                        {
                            MessageTransfer.Message_Tranfer_Poliarbol(graph);
                        }
                        foreach (var nodebayesian in graph)
                        {
                            dict[nodebayesian].SetConditionalProbabilities(nodebayesian.ConditionalProbability);
                        }
                    }
                    else
                    {
                        var markovnet = new MarkovNet(graph);
                        if (Evidence.Count > 0)
                        {
                            MessageTransfer.Message_Tranfer_Arbol_Union(markovnet, Evidence[EvidenceIndex]);
                        }
                        else
                        {
                            MessageTransfer.Message_Tranfer_Arbol_Union(markovnet);
                        }
                        foreach (var nodebayesian in markovnet.BayesianNet)
                        {
                            dict[nodebayesian].SetConditionalProbabilities(nodebayesian.ConditionalProbability);
                        }
                    }

                    timer1.Stop();
                    progressBar1.Value = 100;

                    Tests.Add(new BayesianTest()
                    {
                        Evidence      = Evidence[EvidenceIndex].Clone(),
                        Probabilities =
                            graph.Select(x => x.ConditionalProbability.Clone() as double[]).ToArray()
                    });
                    TestsIndex = Tests.Count - 1;
                    ShowConditionalProbabilities();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hubo algun problema al calcular las probabilidades condicionales. " + ex.Message);
            }
        }
Example #21
0
 public Message(MessageTransfer m)
 {
     _message = m;    
 }
Example #22
0
 public Message()
 {
     _message = new MessageTransfer();
     _message.Header = new Header( new MessageProperties(), new DeliveryProperties());
     ((MessageProperties) _message.Header.Structs[0]).SetApplicationHeaders(new Dictionary<string, object>());
 }