/// <summary> /// Анализатор приходящих информационных пакетов /// </summary> /// <param name="currentDatagram">Принятый пакет</param> private void ParseInfoPackage(UDPDatagram currentDatagram) { //Преобразуем датаграмму в сообщение var currentMessage = new ModelMessage(currentDatagram.MessageBody); // Перебираем все параметры из списка обменика foreach (Parameter Item in Parameters) { // Если параметр входящий или двунаправленый if (Item.Direction == ParameterDirection.input || Item.Direction == ParameterDirection.inpout) { // Пробуем выделить параметр с таким именем из входящего пакета var paramValue = currentMessage.GetParameter(Item.Name); // Если такой параметр есть в пакете обновляем атрибуты параметра в обменнике if (paramValue != null) { lock (Item) { Item.Value = paramValue.ToString(); Item.LastUpdateTime = DateTime.Now; Item.UpdateCounter++; //Item.LastIPReceiving = remoteIP; //Item.LastPortReceiving = remoteReceivingPort; } } } } }
public ViewModelCreatePage(string name_category) { data_task = new ModelTask(); data_message = new ModelMessage(); data_message.name_category = name_category; SaveCommand = new Command(Save); }
public void Send(ModelMessage message) { Messages mess = new Messages { RecipientId = message.RecipientId, SenderId = message.SenderId, Text = message.Text, DateCreate = DateTime.Now }; if (!mess.IsValide()) { return; } var Sender = _context.UserProfile.FirstOrDefault(x => x.Id == mess.SenderId); if (Sender == null) { return; } if (Sender.Messages == null) { Sender.Messages = new List <Messages>(); } var Recip = _context.UserRecipient.FirstOrDefault(x => x.Id == mess.RecipientId); if (Recip == null) { var recProfile = _context.UserProfile.FirstOrDefault(x => x.Id == mess.RecipientId); if (recProfile == null) { return; } UserRecipient user = new UserRecipient { Id = recProfile.Id, Messages = new List <Messages>() }; Recip = user; _context.UserRecipient.Add(user); } var messages = _context.Messages; messages.Add(mess); _context.SaveChanges(); Clients.All.SendAsync(message.RecipientId, message); }
bool IWeChatSendMessage.modelMsg(ModelMessage msg) { if (_info == null) { throw new WeChatError("请先调用init初始化"); } var access_token = BaseClass.getAccessToken(_info); var url = $"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={access_token}"; var data = JsonHelper.modelToJson(msg).Replace("\"{", "{").Replace("}\"", "}").Replace(@"\", ""); var str = BaseClass.postFormWechatService(data, url); var message = JsonHelper.jsonToModel <ErrorMessage>(str); return(message.errcode == 0); }
/// <summary> /// Формирует пакет "готовность к приему" /// </summary> /// <returns>Пакет для отправки</returns> private UDPDatagram CreateReadyPackage() { UDPDatagram Result = new UDPDatagram(); ModelMessage Message = new ModelMessage(); Message.Header_T = "VHost"; Message.Header_S = DateTime.Now.ToString(); HybridDictionary ParametersSet = new HybridDictionary(); Result.PackageType = PackageTypes.Ready; Result.MessageBody = String.Empty; return(Result); }
public ActionResult <ChatIsSuccess> DeleteMessage([FromBody] ModelMessage message) { if (User.Claims.ToList().Count > 0) { if (User.Claims.ToList()[0].Value.ToString() != message.SenderId || User.Claims.ToList()[0].Value.ToString() != message.RecipientId) { return(BadRequest()); } } if (!ModelState.IsValid) { var errors = CustomValidator.GetErrorsByModel(ModelState); return(BadRequest(errors)); } try { var Message = _context.Messages.First(x => x.RecipientId == message.RecipientId && x.SenderId == message.SenderId && x.Text == message.Text && x.DateCreate == message.DateCreate); if (Message == null) { return(BadRequest()); } var Sender = Message.UserSender; var Recip = Message.UserRecipient; Recip.Messages.Remove(Message); Sender.Messages.Remove(Message); _context.Messages.Remove(Message); _context.SaveChanges(); } catch (Exception) { return(BadRequest()); } ChatIsSuccess isSuccess = new ChatIsSuccess { IsSuccess = true }; return(Ok(isSuccess)); }
/// <summary> /// Собирает пакет для отправки к моделирующему узлу /// </summary> /// <returns>Пакет для отправки</returns> private UDPDatagram CreateInfoPackage() { UDPDatagram Result = new UDPDatagram(); ModelMessage Message = new ModelMessage(); Message.Header_T = "VHost"; Message.Header_S = DateTime.Now.ToString(); HybridDictionary ParametersSet = new HybridDictionary(); //HybridDictionary Entry = (HybridDictionary)GadgetsMessageQueue.Dequeue(); uint PackageParameterCounter = 0; foreach (Parameter Item in Parameters) { if ((Item.Direction == ParameterDirection.output || Item.Direction == ParameterDirection.inpout) && Item.Value != null) { ParametersSet.Add(Item.Name, Item.Value); Message.Parameters = ParametersSet; // TO DO ??? Item.LastSendingTime = DateTime.Now; Item.SendingCounter++; //Item.LastIPSending = remoteIP; //Item.LastPortSending = remoteSendingPort; PackageParameterCounter++; } } Result.PackageType = PackageTypes.Info; Result.MessageBody = Message.ToString(); //else //{ //Если сообщений нет отправляем пустой пакет Ready // Result.PackageType = PackageTypes.Ready; // Result.MessageBody = String.Empty; //} return(Result); }
void LoadSQLite() { //#if UNITY_EDITOR || UNITY_STANDALONE_WIN // //string path = "URI=file:" + Application.dataPath + "/Plugins/Android/assets/38Database.db"; // // path = "Data Source=" + Application.dataPath + "/38DatabaseV1.0.db"; // // path = "Data Source=" + Application.dataPath + "/AllModelTest.db"; // // path = @"Data Source=E:\RevitProject\RevitGeometry2017-3-2\AllModelTest.db"; // path = "Data Source=" + LoadXMLGetModelPath(); // //string path = "Data Source =E:/UnityProject/20161118_v4/Assets/Plugins/Android/assets/38Database.db"; //#elif UNITY_ANDROID // path= "URI=file:"+LoadXMLGetModelPath(); // // //将第三方数据库拷贝至Android可找到的地方 // //path = Application.persistentDataPath + "/" + "AllModelTest.db"; // // //string appDBPath = "jar:file://" + Application.dataPath + "!/assets/" + "38Database.db"; // // string appDBPath = Application.streamingAssetsPath + "/AllModelTest.db"; // // if (!File.Exists(path)) // // { // // WWW loadDB = new WWW(appDBPath); // // while (!loadDB.isDone) {} // // File.WriteAllBytes(path, loadDB.bytes); // // } // // path= "URI=file:"+path; //#endif List <VerticesAndNormals> verticesAndNormalsList = new List <VerticesAndNormals>(); List <Triangles> trianglesList = new List <Triangles>(); List <ModelID> modelIdList = new List <ModelID>(); conn = Tools.Instance.SqlConnection(); //conn = new SqliteConnection(path); //try //{ // conn.Open(); // //MessageBox.Show("connection is ok","Normal"); //} //catch (Exception e) //{ // MessageBox.Show(e.Message, "Eroor"); //} SqliteCommand cmd1 = conn.CreateCommand(); cmd1.CommandText = @"SELECT * FROM [Model_Geometry]"; // where ProjectName = '"38#结构模型.0005'""; SqliteDataReader dr1 = cmd1.ExecuteReader(); //读取几何信息 if (dr1.HasRows) { int id = 0; //判断Id是否相同 string name = ""; //模型的名字 bool first = true; List <int> triList = new List <int>(); List <Vector3> verticesList = new List <Vector3>(); List <Vector3> normalsList = new List <Vector3>(); while (dr1.Read()) { name = dr1.GetString(2); if (first) { first = false; id = dr1.GetInt32(3); } Vector3 ver = new Vector3(); Vector3 nor = new Vector3(); ver.x = dr1.GetFloat(4); ver.y = dr1.GetFloat(5); ver.z = dr1.GetFloat(6); nor.x = dr1.GetFloat(7); nor.y = dr1.GetFloat(8); nor.z = dr1.GetFloat(9); if (id != dr1.GetInt32(3)) { ModelMessage mm = new ModelMessage(); mm.Name = dr1.GetString(2); mm.Id = id; mm.Vertices = verticesList.ToArray(); mm.Normals = normalsList.ToArray(); mm.Triangles = triList.ToArray(); mmList.Add(mm); verticesList.Clear(); normalsList.Clear(); triList.Clear(); } verticesList.Add(ver); normalsList.Add(nor); if (!dr1.IsDBNull(10) && !dr1.IsDBNull(11) && !dr1.IsDBNull(12)) { triList.Add(dr1.GetInt32(10)); triList.Add(dr1.GetInt32(11)); triList.Add(dr1.GetInt32(12)); } id = dr1.GetInt32(3); } ModelMessage mmLast = new ModelMessage(); mmLast.Name = name; mmLast.Id = id; mmLast.Vertices = verticesList.ToArray(); mmLast.Normals = normalsList.ToArray(); mmLast.Triangles = triList.ToArray(); mmList.Add(mmLast); verticesList.Clear(); normalsList.Clear(); triList.Clear(); } // SqliteReadWallParameters(conn);//读取墙的属性 // SqliteReadFloorsParameters(conn);//读取楼板属性 // SqliteReadFrameWorksParameters(conn);//读取结构框架(梁)属性 StartCoroutine(GenerateModel());//生成模型 }
public void Init(ModelMessage modelmessage) { modelMessage = modelmessage; DrawModel(); }
public static ModelMessage GetModel(String messageType) { ModelMessage mm = new ModelMessage() { Name = messageType, Version = "2.3", Items = new IElement[] { new ModelSegment() { Name = "MSH", IsRequired = true}, new ModelSegment() { Name = "PID", IsRequired = true}, new ModelSegment() { Name = "XXX", IsRequired = false}, new ModelSegment() { Name = "ORC", IsRequired = true}, new ModelSegmentGroup() { Name = "OBR_NTE", IsRequired = true, CanRepeat = true, Items = new IElement[]{ new ModelSegment() { Name = "OBR", IsRequired = true}, new ModelSegment() { Name = "NTE", IsRequired = false, CanRepeat = true}, new ModelSegmentGroup() { Name = "OBX_NTE", IsRequired = true, CanRepeat = true, Items = new IElement[]{ new ModelSegment() { Name = "OBX", IsRequired = true}, new ModelSegment { Name = "NTE", IsRequired = false, CanRepeat = true} } } } } } }; return mm; }
// TODO: // 1. Split into IHL7Message interface and a DelimitedMessageParser (or MessageParser) to give // flexiblity in type of message returned. // 2. Allow for parser to either use a model, which will validate that required segments // exist and create structure of repeating segments or to use no model and just make // an object that represents the raw message. // 3. Create a means to map callbacks/events to the iteration of message segments or groups. // These events can be called during parse or as a separate step afterwards. public DelimitedMessage(String rawText) { // Set the Raw Text this.RawText = rawText.Trim(); // Validate the the message begins with an MSH segment switch (this.RawText.IndexOf("MSH")) { case 0: break; case -1: throw new MessageException("Required segment MSH could not be found."); default: throw new MessageException("Message does not begin with the required segment MSH."); } // Set the encoding characters this.Context.SetEncodingCharacters( this.RawText[3], this.RawText.Substring(4, 4)); // Get an array of all the segments as raw strings String[] segmentStrings = this.RawText.Split( new[] { this.Context.SegmentSeparator }); // Get an array of all the segments as Segment objects, not // structured into groups Segment[] allSegments = ( from i in segmentStrings select new Segment(i.Trim(), this.Context)).ToArray(); // TODO: If we decide the enumerator is the way to go, ditch the ToArray and // just make the Enumerator the output of the above LINQ query IEnumerator <Segment> allSegmentsEnumerator = allSegments.ToList().GetEnumerator(); // Get a list of the IElemnts (Segments and SegmentGroups) // that will be structured after the model. List <IElement> itemList = new List <IElement>(segmentStrings.Length); // Get the Model for the Ihl7Message // TODO: Pre-parse the message at least far enough to know the type and event ModelMessage model = ModelFactory.GetModel("ORU"); // Prepare the segment enumerator (TryPopulate expects it to be at first element) allSegmentsEnumerator.MoveNext(); // Try to populate the top-level group (the message) TryPopulateGroup(this, model, allSegmentsEnumerator, new HashSet <String>()); /* * //// Iterate the raw segment strings * //while (segIt < segmentStrings.Length) * //{ * // // Windows-style line breaks may leave white space, * // // so trim it * // segmentStrings[segIt] = segmentStrings[segIt].Trim(); * * // // Build a segment and add it to the unstructured array * // Segment segment = new Segment(segmentStrings[segIt], this.Context); * // allSegments[segIt] = segment; * * // ModelElement modelElement = (ModelElement) model.Items[modIt]; * * // // If name of current message item matches current * // // model item, add message item to the structured list * // if (modelElement.Name == segment.Name) * // { * // itemList.Add((IElement)segment); * // // If ModelElement can't repeat, then iterate model i * // // and bring the saved value up to the current value. * // if (!modelElement.CanRepeat) * // { * // modBookmark = ++modIt; * // } * // } * * // // Finally, move the segment iterator forward * // segIt++; * //} */ //this.Items = itemList.ToArray(); this.AllSegments = allSegments; }