예제 #1
0
        public void Copy(IIdObject src)
        {
            UseVertex srcUV = src as UseVertex;

            Id   = srcUV.Id;
            HEId = srcUV.HEId;
            VId  = srcUV.VId;
        }
예제 #2
0
        public void Copy(IIdObject src)
        {
            UseLoop srcUL = src as UseLoop;

            Id         = srcUL.Id;
            LId        = srcUL.LId;
            HEId       = srcUL.HEId;
            ChildULId  = srcUL.ChildULId;
            ParentULId = srcUL.ParentULId;
        }
예제 #3
0
        public void Copy(IIdObject src)
        {
            HalfEdge srcHE = src as HalfEdge;

            Id        = srcHE.Id;
            UVId      = srcHE.UVId;
            FHEId     = srcHE.FHEId;
            BHEId     = srcHE.BHEId;
            OHEId     = srcHE.OHEId;
            ULId      = srcHE.ULId;
            EId       = srcHE.EId;
            IsSameDir = srcHE.IsSameDir;
        }
예제 #4
0
        public static TagCloser RABeginDataGridSelectableRow(
            this IHtmlHelper htmlHelper,
            IIdObject idObject,
            bool canSelect    = true,
            string idOverride = null)
        {
            var id = !String.IsNullOrEmpty(idOverride) ? idOverride : idObject.Id.ToString();

            var content = new HtmlContentBuilder();

            content.AppendFormat("<tr class='{0}' data-row-id='{1}' data-row-name='{2}' onmouseup='{3}'",
                                 canSelect ? "ra-datagrid-row-selectable" : "", id, idObject.ToString(),
                                 canSelect ? "selectDataGridRow(this);" : "");
            content.AppendHtml(">");
            htmlHelper.ViewContext.Writer.Write(content);
            return(new TagCloser(htmlHelper, "</tr>"));
        }
예제 #5
0
        private void Bind(IdObject modelItem, IIdObject dbItem)
        {
            cache = cache.Add(modelItem, dbItem);
            int?isSavePending = null;

            foreach (var property in modelItem.GetType().GetProperties().Where(x => typeof(IRxListObservables).IsAssignableFrom(x.PropertyType)))
            {
                var list = (IRxListObservables)property.GetValue(modelItem, null);
                if (list == null)
                {
                    list = (IRxListObservables)Activator.CreateInstance(property.PropertyType);
                    property.SetValue(modelItem, list);
                }
                var dbListProperty = dbItem.GetType().GetProperty(property.Name);
                var dbList         = (IList)dbListProperty.GetValue(dbItem, null);
                if (dbList == null)
                {
                    dbList = (IList)Activator.CreateInstance(dbListProperty.PropertyType);
                    dbListProperty.SetValue(dbItem, dbList);
                }
                list.Changed
                .Do(_ =>
                {
                    using (locker.Lock())
                    {
                        isSavePending = isSavePending ?? ++this.isSavePending;
                    }
                })
                .Select(async changes =>
                {
                    foreach (var added in changes.Added)
                    {
                        var childDbType    = dbListProperty.PropertyType.GetGenericArguments()[0];
                        var childDbItem    = (IIdObject)Activator.CreateInstance(childDbType);
                        var childModelItem = (IdObject)added.Value;
                        Bind(childModelItem, childDbItem);
                        MapScalarsToDb(childModelItem, childDbItem);
                        dbList.Add(childDbItem);

                        if (childDbItem is DbApiItem dbApiItem)
                        {
                            dbApiItem.ObservePropertyChange(x => x.Id).SubscribeOnce(x => childModelItem.Id = x);
                        }
                    }
                    foreach (var removed in changes.Removed)
                    {
                        var childModelItem = (IdObject)removed.Value;
                        var childDbItem    = cache[childModelItem];
                        dbList.Remove(childDbItem);
                    }
                    using (await locker.LockAsync())
                    {
                        await db.SaveChangesAsync();
                        this.isSavePending--;
                        isSavePending = null;
                        if (this.isSavePending == 0)
                        {
                            idle.Set();
                        }
                    }
                })
                .Subscribe();
            }
            modelItem.Changed
            .Where(x => x.Property.Name != nameof(IIdObject.Id) && !typeof(IRxListObservables).IsAssignableFrom(x.Property.PropertyType))
            .Do(x =>
            {
                using (locker.Lock())
                {
                    isSavePending = isSavePending ?? ++this.isSavePending;
                }
            })
            .Throttle(TimeSpan.FromSeconds(1))
            .Select(async x =>
            {
                MapScalarsToDb(modelItem, dbItem);
                using (await locker.LockAsync())
                {
                    await db.SaveChangesAsync();
                    this.isSavePending--;
                    isSavePending = null;
                    if (this.isSavePending == 0)
                    {
                        idle.Set();
                    }
                }
            })
            .Subscribe();
        }
예제 #6
0
        private async void Client_MessageReceived(MessageWebSocket sender, MessageWebSocketMessageReceivedEventArgs args)
        {
            using (DataReader reader = args.GetDataReader())
                try
                {
                    string str = reader.ReadString(reader.UnconsumedBufferLength).Trim('\0');
                    if (!string.IsNullOrEmpty(str))
                    {
                        JObject json = JObject.Parse(str);
                        switch (json["event"].ToString())
                        {
                        case "auth":
                            if ((bool)json["needsAuth"])
                            {
                                string login = string.Format("{{\"username\":\"{0}\",\"password\":\"{1}\"}}", AuthenticationCredentials.UserName.Replace("\"", "\\\""), AuthenticationCredentials.Password.Replace("\"", "\\\""));
                                clientWriter.WriteString(login);
                                await clientWriter.FlushAsync();
                            }
                            break;

                        case "update":
                            EventType  eventType  = (EventType)Enum.Parse(typeof(EventType), json["eventType"].ToString());
                            ObjectType objectType = (ObjectType)Enum.Parse(typeof(ObjectType), json["objectType"].ToString());
                            IIdObject  obj        = JsonToObject(objectType, (JObject)json["obj"]);
                            switch (eventType)
                            {
                            case EventType.Add:
                                switch (objectType)
                                {
                                case ObjectType.Recipient:
                                    recipients.Add(obj.Id, obj as Recipient);
                                    break;

                                case ObjectType.Conversation:
                                    conversations.Add(obj.Id, obj as Conversation);
                                    break;

                                case ObjectType.Message:
                                    messages.Add(obj.Id, obj as Message);
                                    break;

                                case ObjectType.Attachment:
                                    attachments.Add(obj.Id, obj as Attachment);
                                    break;
                                }
                                break;

                            case EventType.Update:
                                switch (objectType)
                                {
                                case ObjectType.Recipient:
                                    UpdateObject(recipients[obj.Id], obj);
                                    break;

                                case ObjectType.Conversation:
                                    UpdateObject(conversations[obj.Id], obj);
                                    break;

                                case ObjectType.Message:
                                    UpdateObject(messages[obj.Id], obj);
                                    break;

                                case ObjectType.Attachment:
                                    UpdateObject(attachments[obj.Id], obj);
                                    break;
                                }
                                break;

                            case EventType.Remove:
                                switch (objectType)
                                {
                                case ObjectType.Recipient:
                                    recipients.Remove(obj.Id);
                                    break;

                                case ObjectType.Conversation:
                                    conversations.Remove(obj.Id);
                                    break;

                                case ObjectType.Message:
                                    messages.Remove(obj.Id);
                                    break;

                                case ObjectType.Attachment:
                                    attachments.Remove(obj.Id);
                                    break;
                                }
                                break;
                            }
                            StreamUpdate?.Invoke(this, new StreamUpdateEventArgs()
                            {
                                ObjectType = objectType,
                                EventType  = eventType,
                                Object     = obj
                            });
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    StopStream();
                    StreamUpdate?.Invoke(this, new StreamUpdateEventArgs()
                    {
                        Error = ex
                    });
                }
        }
예제 #7
0
 static void InvokeStoreUpdate(ObjectType updateObjectType, EventType updateEventType, IIdObject obj)
 {
     StoreUpdate?.Invoke(updateObjectType, updateEventType, obj);
 }
예제 #8
0
        async void StreamClientThread()
        {
            try
            {
                while (running)
                {
                    var buffer  = new byte[1024];
                    var segment = new ArraySegment <byte>(buffer);
                    var result  = await client.ReceiveAsync(segment, cancelToken.Token);

                    string str = Encoding.UTF8.GetString(buffer).Trim('\0');
                    if (!string.IsNullOrEmpty(str))
                    {
                        JObject json = JObject.Parse(str);
                        switch (json["event"].ToString())
                        {
                        case "auth":
                            if ((bool)json["needsAuth"])
                            {
                                string login = string.Format("{{\"username\":\"{0}\",\"password\":\"{1}\"}}", AuthenticationCredentials.UserName.Replace("\"", "\\\""), AuthenticationCredentials.Password.Replace("\"", "\\\""));
                                await client.SendAsync(new ArraySegment <byte>(Encoding.UTF8.GetBytes(login)), WebSocketMessageType.Text, true, cancelToken.Token);
                            }
                            break;

                        case "update":
                            EventType  eventType  = (EventType)Enum.Parse(typeof(EventType), json["eventType"].ToString());
                            ObjectType objectType = (ObjectType)Enum.Parse(typeof(ObjectType), json["objectType"].ToString());
                            IIdObject  obj        = JsonToObject(objectType, (JObject)json["obj"]);
                            switch (eventType)
                            {
                            case EventType.Add:
                                switch (objectType)
                                {
                                case ObjectType.Recipient:
                                    recipients.Add(obj.Id, obj as Recipient);
                                    break;

                                case ObjectType.Conversation:
                                    conversations.Add(obj.Id, obj as Conversation);
                                    break;

                                case ObjectType.Message:
                                    messages.Add(obj.Id, obj as Message);
                                    break;

                                case ObjectType.Attachment:
                                    attachments.Add(obj.Id, obj as Attachment);
                                    break;
                                }
                                break;

                            case EventType.Update:
                                switch (objectType)
                                {
                                case ObjectType.Recipient:
                                    UpdateObject(recipients[obj.Id], obj);
                                    break;

                                case ObjectType.Conversation:
                                    UpdateObject(conversations[obj.Id], obj);
                                    break;

                                case ObjectType.Message:
                                    UpdateObject(messages[obj.Id], obj);
                                    break;

                                case ObjectType.Attachment:
                                    UpdateObject(attachments[obj.Id], obj);
                                    break;
                                }
                                break;

                            case EventType.Remove:
                                switch (objectType)
                                {
                                case ObjectType.Recipient:
                                    recipients.Remove(obj.Id);
                                    break;

                                case ObjectType.Conversation:
                                    conversations.Remove(obj.Id);
                                    break;

                                case ObjectType.Message:
                                    messages.Remove(obj.Id);
                                    break;

                                case ObjectType.Attachment:
                                    attachments.Remove(obj.Id);
                                    break;
                                }
                                break;
                            }
                            StreamUpdate?.Invoke(this, new StreamUpdateEventArgs()
                            {
                                ObjectType = objectType,
                                EventType  = eventType,
                                Object     = obj
                            });
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                StopStream();
                StreamUpdate?.Invoke(this, new StreamUpdateEventArgs()
                {
                    Error = ex
                });
            }
        }
예제 #9
0
 private static void DatabaseStore_StoreUpdate(ObjectType updateObjectType, EventType updateEventType, IIdObject obj)
 {
     foreach (WebSocket ws in webSockets)
     {
         if (ws.IsConnected)
         {
             ws.WriteString(string.Format("{{\"event\":\"update\",\"objectType\":\"{0}\",\"eventType\":\"{1}\",\"obj\":{2}}}", updateObjectType, updateEventType, JSON.FormatJSONObject(obj, false)));
         }
     }
     webSockets.RemoveAll((ws) => !ws.IsConnected);
 }