Exemple #1
0
        public async Task <bool> EndUpdateOrAddTag(List <SuperBTagBase> sussTags, List <SuperBTagBase> failedTags)
        {
            foreach (var tag in failedTags)
            {
                TagList.Remove(tag);
            }
            foreach (var tag in sussTags)
            {
                var map = new SqlTagMap()
                {
                    tagIsid = tag.Tag.tagIsid, objId = tag.OrgiData.ID
                };

                try
                {
                    if (tag.TagType == EnumType.AI)
                    {
                        await _db.taic.AddAsync((tag as SuperB_Taic).DbData);
                    }
                    else if (tag.TagType == EnumType.AO)
                    {
                        await _db.taoc.AddAsync((tag as SuperB_Taoc).DbData);
                    }
                    else if (tag.TagType == EnumType.DI)
                    {
                        await _db.tdic.AddAsync((tag as SuperB_Tdic).DbData);
                    }
                    else if (tag.TagType == EnumType.DO)
                    {
                        await _db.tdoc.AddAsync((tag as SuperB_Tdoc).DbData);
                    }
                    else if (tag.TagType == EnumType.STRIN)
                    {
                        await _db.tdsc.AddAsync((tag as SuperB_Tdsc).DbData);
                    }

                    if (!tagmap.Exists(d => d.objId == tag.OrgiData.ID && d.tagIsid == tag.Tag.tagIsid))
                    {
                        await _db.tagmap.AddAsync(map);

                        tagmap.Add(map);
                    }
                    await _db.SaveChangesAsync();

                    TagList.Add(tag);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
        public async Task <bool> BeginUpdateOrAddTag(BStruBase data, TagReqFunc reqFunc)
        {
            var dev = devicemap.Find(m => m.objId == data.ParentID);

            if (dev == null)
            {
                return(false);             //没有父节点,返回
            }
            var tag = TagList.Find(n => n.OrgiData.ID == data.ID);

            if (tag == null)    //新增设备,返回新增的设备,等web新增成功,插入数据库
            {
                if (data.Type == EnumType.AI)
                {
                    tag = new SuperB_Taic(data as TAIC, dev.devIsid, null);
                }
                else if (data.Type == EnumType.AO)
                {
                    tag = new SuperB_Taoc(data as TAOC, dev.devIsid, null);
                }
                else if (data.Type == EnumType.DI)
                {
                    tag = new SuperB_Tdic(data as TDIC, dev.devIsid, null);
                }
                else if (data.Type == EnumType.DO)
                {
                    tag = new SuperB_Tdoc(data as TDOC, dev.devIsid, null);
                }
                else if (data.Type == EnumType.STRIN)
                {
                    tag = new SuperB_Tdsc(data as TDSC, dev.devIsid, null);
                }

                var map = new SqlTagMap()
                {
                    tagIsid = tag.Tag.tagIsid, objId = data.ID
                };

                TagList.Add(tag);
                var req = await reqFunc(tag, dev.groupIsid, ChangeType.Add);

                if (!req)
                {
                    return(true);
                }

                try
                {
                    if (data.Type == EnumType.AI)
                    {
                        await _db.taic.AddAsync((tag as SuperB_Taic).DbData);
                    }
                    else if (data.Type == EnumType.AO)
                    {
                        await _db.taoc.AddAsync((tag as SuperB_Taoc).DbData);
                    }
                    else if (data.Type == EnumType.DI)
                    {
                        await _db.tdic.AddAsync((tag as SuperB_Tdic).DbData);
                    }
                    else if (data.Type == EnumType.DO)
                    {
                        await _db.tdoc.AddAsync((tag as SuperB_Tdoc).DbData);
                    }
                    else if (data.Type == EnumType.STRIN)
                    {
                        await _db.tdsc.AddAsync((tag as SuperB_Tdsc).DbData);
                    }

                    if (!tagmap.Exists(d => d.objId == tag.OrgiData.ID && d.tagIsid == tag.Tag.tagIsid))
                    {
                        await _db.tagmap.AddAsync(map);

                        tagmap.Add(map);
                    }
                    await _db.SaveChangesAsync();

                    TagList.Add(tag);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                    return(false);
                }
            }
            else
            {
                if (!tagmap.Exists(d => d.objId == tag.OrgiData.ID && d.tagIsid == tag.Tag.tagIsid))
                {
                    return(false);
                }
                var tmp = tag.OrgiData;
                if (tag.Update(data))
                {
                    var req = await reqFunc(tag, dev.groupIsid, ChangeType.Update);

                    if (!req)
                    {
                        tag.Update(tmp);
                        return(false);
                    }

                    try
                    {
                        if (data.Type == EnumType.AI)
                        {
                            _db.taic.Update((tag as SuperB_Taic).DbData);
                        }
                        else if (data.Type == EnumType.AO)
                        {
                            _db.taoc.Update((tag as SuperB_Taoc).DbData);
                        }
                        else if (data.Type == EnumType.DI)
                        {
                            _db.tdic.Update((tag as SuperB_Tdic).DbData);
                        }
                        else if (data.Type == EnumType.DO)
                        {
                            _db.tdoc.Update((tag as SuperB_Tdoc).DbData);
                        }
                        else if (data.Type == EnumType.STRIN)
                        {
                            _db.tdsc.Update((tag as SuperB_Tdsc).DbData);
                        }
                        await _db.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error(ex);
                        return(false);
                    }
                }
            }

            return(true);
        }