Exemplo n.º 1
0
        public override Task ExecuteAsync(dynamic p)
        {
            if (!CanExecute(p))
            {
                return(Task.FromResult(false));
            }

            // Create FavoriteEntity
            FavoriteEntity favoriteEntity = TableEntityFactory.CreateFavoriteEntity(p);

            if (favoriteEntity == null)
            {
                return(Task.FromResult(false));
            }
            p.Entity = favoriteEntity;

            // Copies
            var entities = new List <FavoriteEntity> {
                favoriteEntity
            };

            if (!_mediaType.Equals(LvConstants.MediaTypeOfAll))
            {
                var copyEntity = favoriteEntity.CloneByJson();
                copyEntity.RowKey = UriFactory.ReplaceMediaTypeOfRowKey(favoriteEntity.RowKey, MediaType.All);
                entities.Add(copyEntity);
            }

            p.Entities = entities.Cast <ITableEntity>().ToList();
            return(Task.FromResult(true));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <int> InsertAsync(FavoriteEntity entity)
        {
            if (entity.FavoriteID <= 0)
            {
                entity.FavoriteID = GetNewID();
            }
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into Favorite (" +
                            "FavoriteID," +
                            "UserID," +
                            "InfoID," +
                            "FavoriteTime) " +
                            "values(" +
                            "@FavoriteID," +
                            "@UserID," +
                            "@InfoID," +
                            "@FavoriteTime)";

            if (await Task.Run(() => _DB.ExeSQLResult(strSQL, dict)))
            {
                return(DataConverter.CLng(entity.FavoriteID));
            }
            return(-1);
        }
Exemplo n.º 3
0
        public static async Task <FavoriteItemEntity> ViewFavorite(int user_id)
        {
            FavoriteItemEntity favorite = new FavoriteItemEntity();

            favorite.total        = 0;
            favorite.FavoriteItem = new List <FavoriteEntity>();
            var query = "SELECT favorite_id,user_id,favorite_name,work_num FROM favorite WHERE user_id=@user_id";

            using var connection = DatabaseConnector.Connect();
            await connection.OpenAsync();

            using var command   = connection.CreateCommand();
            command.CommandText = query;
            command.Parameters.AddWithValue("@user_id", user_id);
            using var reader = await command.ExecuteReaderAsync();

            while (reader.Read())
            {
                FavoriteEntity temp = new FavoriteEntity();

                temp.favorite_id   = reader.GetInt32("favorite_id");
                temp.user_id       = reader.GetInt32("user_id");
                temp.favorite_name = reader.GetString("favorite_name");
                temp.work_num      = reader.GetInt32("work_num");

                favorite.total++;
                favorite.FavoriteItem.Add(temp);
            }
            return(favorite);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 把实体类转换成键/值对集合
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="dict"></param>
 private static void GetParameters(FavoriteEntity entity, Dictionary <string, object> dict)
 {
     dict.Add("FavoriteID", entity.FavoriteID);
     dict.Add("UserID", entity.UserID);
     dict.Add("InfoID", entity.InfoID);
     dict.Add("FavoriteTime", entity.FavoriteTime);
 }
Exemplo n.º 5
0
        public void Create(FavoriteEntity entity)
        {
            string sql = "insert into favorite(host, title, category_id) values (@Host, @Title, @CategoryId);";

            using (var sqliteConn = connectionProvider.GetConnection())
            {
                sqliteConn.Execute(sql, new { Host = entity.Host, Title = entity.Title, CategoryId = entity.CategoryId });
            }
        }
Exemplo n.º 6
0
        public void Update(FavoriteEntity entity)
        {
            string sql = "update favorite set host = @Host, title = @Title, category_id = @CategoryId where id = @Id;";

            using (var sqliteConn = connectionProvider.GetConnection())
            {
                sqliteConn.Execute(sql, new { id = entity.Id, Host = entity.Host, Title = entity.Title, CategoryId = entity.CategoryId });
            }
        }
        /// <summary>
        /// 将entity转换为vo。不包括来自元数据的属性
        /// </summary>
        private FavoriteVo toVo(FavoriteEntity entity)
        {
            FavoriteVo vo = new FavoriteVo();

            vo.Id    = entity.Id;
            vo.Host  = entity.Host;
            vo.Title = entity.Title;

            return(vo);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 通过数据读取器生成实体类
        /// </summary>
        /// <param name="rdr"></param>
        /// <returns></returns>
        private static FavoriteEntity GetEntityFromrdr(NullableDataReader rdr)
        {
            FavoriteEntity info = new FavoriteEntity();

            info.FavoriteID   = rdr.GetInt32("FavoriteID");
            info.UserID       = rdr.GetInt32("UserID");
            info.InfoID       = rdr.GetInt32("InfoID");
            info.FavoriteTime = rdr.GetNullableDateTime("FavoriteTime");
            return(info);
        }
        public FavoriteEntity toEntity(FavoriteCreateRequest request)
        {
            FavoriteEntity entity = new FavoriteEntity();

            entity.Host       = request.Host;
            entity.Title      = request.Title;
            entity.CategoryId = request.CategoryId != null ? request.CategoryId.Value : 0;

            return(entity);
        }
        public FavoriteVo toMoreVo(FavoriteEntity entity)
        {
            FavoriteVo vo = toVo(entity);

            List <TheCategoryEntity> theCategoryEntityList = theCategoryMeta.GetEntityList();

            vo.CategoryId = theCategoryConvertor.getMoreVoList(theCategoryEntityList, entity.CategoryId);

            return(vo);
        }
Exemplo n.º 11
0
 public static DalFavorite ToDalFavorite(this FavoriteEntity favoriteEntity)
 {
     return(new DalFavorite()
     {
         Id = favoriteEntity.Id,
         UserId = favoriteEntity.UserId,
         MovieId = favoriteEntity.MovieId,
         Target = favoriteEntity.Target,
         Movies = favoriteEntity.Movies
     });
 }
Exemplo n.º 12
0
 public FavoriteFile(string path, FavoriteEntity fav)
 {
     this.Name        = fav.friendlyName;
     this.FullPath    = path;
     this.GroupName   = fav.groupName;
     this.ProjectFile = fav.file;
     this.TargetSets  = new ObservableCollection <TargetSet>();
     foreach (TargetSet s in fav.TargetSet)
     {
         this.TargetSets.Add(s);
     }
 }
Exemplo n.º 13
0
 public FavoriteFile(string path, FavoriteEntity fav)
 {
     this.Name = fav.friendlyName;
     this.FullPath = path;
     this.GroupName = fav.groupName;
     this.ProjectFile = fav.file;
     this.TargetSets = new ObservableCollection<TargetSet>();
     foreach (TargetSet s in fav.TargetSet)
     {
         this.TargetSets.Add(s);
     }
 }
Exemplo n.º 14
0
        public FavoriteEntity Create(FavoriteEntity entity)
        {
            var r = this._favoriteRepository.Insert(entity);

            if (r != null)
            {
                //TODO:对用户账户操作
                this._userService.AddFover(entity.User_Id, 1, entity.CreatedUser);
            }

            return(r);
        }
Exemplo n.º 15
0
        public void Del(FavoriteEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            entity.Status = (int)DataStatus.Deleted;
            this._favoriteRepository.Delete(entity);

            //TODO: 账户减少一个fover
            this._userService.SubFover(entity.User_Id, 1, entity.User_Id);
        }
Exemplo n.º 16
0
        /// <summary>
        /// 获取实体(异步方式)
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual async Task <FavoriteEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null)
        {
            FavoriteEntity obj    = null;
            string         strSQL = "select top 1 * from Favorite where 1=1 " + strWhere;

            using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict)))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual bool Update(FavoriteEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);
            string strSQL = "Update Favorite SET " +
                            "UserID = @UserID," +
                            "InfoID = @InfoID," +
                            "FavoriteTime = @FavoriteTime" +
                            " WHERE " +

                            "FavoriteID = @FavoriteID";

            return(_DB.ExeSQLResult(strSQL, dict));
        }
Exemplo n.º 18
0
        /// <summary>
        /// 更新一条记录(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <bool> UpdateAsync(FavoriteEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);
            string strSQL = "Update Favorite SET " +
                            "UserID = @UserID," +
                            "InfoID = @InfoID," +
                            "FavoriteTime = @FavoriteTime" +
                            " WHERE " +

                            "FavoriteID = @FavoriteID";

            return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict)));
        }
Exemplo n.º 19
0
        public async Task CreateFavorite_Return_EquivalentOfTumblrEntity()
        {
            var          partitionKey = LvConstants.MediaTypeOfAll;
            const string mediaUri     = "TestMediaUri";
            const string thumbnailUri = "TestThumbnailUri";
            var          tumblrText   = new TumblrText
            {
                Text     = "TestText",
                Category = TumblrCategory.C1
            };

            dynamic p1 = new ExpandoObject();

            p1.PartitionKey = partitionKey;
            p1.MediaUri     = mediaUri;
            p1.ThumbnailUri = thumbnailUri;
            p1.TumblrText   = tumblrText;

            await _fixture.CreateTumblrCommand.ExecuteAsync(p1);

            TumblrEntity tumblr = p1.Entity;

            const string userId = "userid";
            dynamic      p2     = tumblr.ToExpandoObject();

            p2.RowKey = _fixture.UriFactory.GetInvertedTicksFromTumblrRowKey(tumblr.RowKey);
            p2.UserId = userId;
            await _fixture.CreateFavoriteCommand.ExecuteAsync(p2);

            FavoriteEntity favorite = p2.Entity;

            Assert.Equal(favorite.PartitionKey, userId);
            Assert.Equal(favorite.RowKey,
                         _fixture.UriFactory.CreateFavoriteRowKey(partitionKey,
                                                                  _fixture.UriFactory.GetInvertedTicksFromTumblrRowKey(tumblr.RowKey)));
            Assert.Equal(favorite.MediaUri, tumblr.MediaUri);
            Assert.Equal(favorite.MediaSmallUri, tumblr.MediaSmallUri);
            Assert.Equal(favorite.Text, tumblr.Text);
            Assert.Equal(favorite.CreateTime, tumblr.CreateTime);
            Assert.Equal(favorite.MediaType, tumblr.MediaType);
            Assert.Equal(favorite.TumblrCategory, tumblr.TumblrCategory);

            List <ITableEntity> ientities = p2.Entities;
            var entities = ientities.Cast <FavoriteEntity>().ToList();

            Assert.Equal(1, entities.Count());
        }
Exemplo n.º 20
0
        public static async Task <int> Create(FavoriteEntity favorite)
        {
            var query = "INSERT INTO favorite(user_id,favorite_name) VALUES(@user_id,@favorite_name)";

            using var connection = DatabaseConnector.Connect();
            await connection.OpenAsync();

            using var command   = connection.CreateCommand();
            command.CommandText = query;

            command.Parameters.AddWithValue("@user_id", favorite.user_id);
            command.Parameters.AddWithValue("@favorite_name", favorite.favorite_name);


            await command.ExecuteNonQueryAsync();

            return((int)command.LastInsertedId);
        }
Exemplo n.º 21
0
        public static async Task <int> Change(FavoriteEntity favorite)
        {
            var query = "UPDATE favorite SET favorite_name=@favorite_name where favorite_id=@favorite_id";

            using var connection = DatabaseConnector.Connect();
            await connection.OpenAsync();

            using var command   = connection.CreateCommand();
            command.CommandText = query;

            command.Parameters.AddWithValue("@favorite_id", favorite.favorite_id);
            command.Parameters.AddWithValue("@favorite_name", favorite.favorite_name);


            var row = await command.ExecuteNonQueryAsync();

            if (row > 0)
            {
                return(favorite.favorite_id);
            }
            return(0);
        }
Exemplo n.º 22
0
        public FavoriteUpdateResponse Update([FromBody] FavoriteUpdateRequest request)
        {
            FavoriteUpdateResponse response = new FavoriteUpdateResponse();

            if (request.Id == 0 || request.Id < 0)
            {
                response.Status = -1;
                return(response);
            }

            FavoriteEntity entity = favoriteRepository.GetById(request.Id);

            if (entity == null)
            {
                response.Status = 404;
                return(response);
            }

            favoriteRepository.Update(favoriteConvertor.toEntity(request, entity));

            response.Status = 1;
            return(response);
        }
Exemplo n.º 23
0
        /// <summary>
        /// 增加一条记录
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual bool Add(FavoriteEntity entity)
        {
            if (entity.FavoriteID <= 0)
            {
                entity.FavoriteID = GetNewID();
            }
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into Favorite (" +
                            "FavoriteID," +
                            "UserID," +
                            "InfoID," +
                            "FavoriteTime) " +
                            "values(" +
                            "@FavoriteID," +
                            "@UserID," +
                            "@InfoID," +
                            "@FavoriteTime)";

            return(_DB.ExeSQLResult(strSQL, dict));
        }
Exemplo n.º 24
0
        public FavoriteItemResponse Item([FromBody] FavoriteItemRequest request)
        {
            FavoriteItemResponse response = new FavoriteItemResponse();

            if (request.Id <= 0)
            {
                response.Status = -1;
                return(response);
            }

            FavoriteEntity entity = favoriteRepository.GetById(request.Id);

            if (entity == null)
            {
                response.Status = 404;
                return(response);
            }

            response.Item = favoriteConvertor.toLessVo(entity);

            response.Status = 1;
            return(response);
        }
Exemplo n.º 25
0
        public FavoriteVo toLessVo(FavoriteEntity entity)
        {
            FavoriteVo vo = toVo(entity);

            return(vo);
        }
Exemplo n.º 26
0
 /// <summary>
 /// 增加或更新一条记录
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual bool AddOrUpdate(FavoriteEntity entity, bool IsSave)
 {
     return(IsSave ? Add(entity) : Update(entity));
 }
Exemplo n.º 27
0
 /// <summary>
 /// 增加或更新一条记录(异步方式)
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual async Task <bool> AddOrUpdateAsync(FavoriteEntity entity, bool IsSave)
 {
     return(IsSave ? await AddAsync(entity) : await UpdateAsync(entity));
 }
Exemplo n.º 28
0
        private void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            TargetSet tset = new TargetSet {
                file = this.favFileName, Name = this.txtTargetSetName.Text, Parameters = this.favParameters, Strapper = this.favStrapper, Targets = this.favTargets
            };

            if (this.listBoxExistingFavorites.SelectedIndex >= 0)
            {
                FavoriteFile   f            = this.listBoxExistingFavorites.SelectedItem as FavoriteFile;
                XmlSerializer  deserializer = new XmlSerializer(typeof(FavoriteEntity));
                FavoriteEntity foundFavorite;
                using (FileStream favStream = new FileStream(f.FullPath, FileMode.Open, FileAccess.Read))
                {
                    foundFavorite = (FavoriteEntity)deserializer.Deserialize(favStream);
                }

                TargetSet[] temp = new TargetSet[foundFavorite.TargetSet.Length + 1];
                int         i    = 0;
                foreach (TargetSet t in foundFavorite.TargetSet)
                {
                    temp[i] = t;
                    i++;
                }

                temp[i] = tset;
                foundFavorite.TargetSet = temp;

                XmlSerializer serializer = new XmlSerializer(typeof(FavoriteEntity));
                using (FileStream fs = new FileStream(f.FullPath, FileMode.Create))
                {
                    TextWriter writer = new StreamWriter(fs, new UTF8Encoding());
                    serializer.Serialize(writer, foundFavorite);
                }

                this.Close();
                return;
            }

            SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog {
                DefaultExt = ".msbef", Filter = "MSBuild Explorer Favorite (.msbef)|*.msbef"
            };

            if (dlg.ShowDialog() == true)
            {
                FavoriteEntity fe = new FavoriteEntity();
                fe.groupName = this.txtFavoriteGroupName.Text;
                TargetSet[] tsetcol = new TargetSet[1];
                tsetcol[0]      = tset;
                fe.TargetSet    = tsetcol;
                fe.file         = this.favFileName;
                fe.friendlyName = this.txtFavoriteName.Text;

                XmlSerializer serializer = new XmlSerializer(typeof(FavoriteEntity));
                using (FileStream fs = new FileStream(dlg.FileName, FileMode.Create))
                {
                    TextWriter writer = new StreamWriter(fs, new UTF8Encoding());
                    serializer.Serialize(writer, fe);
                }

                StringCollection favs = new StringCollection();
                foreach (string s in from string s in Settings.Default.Favorites where !favs.Contains(s) select s)
                {
                    favs.Add(s);
                }

                if (!favs.Contains(dlg.FileName))
                {
                    favs.Add(dlg.FileName);
                }

                Settings.Default.Favorites = favs;

                Settings.Default.Save();

                this.Close();
            }
        }
Exemplo n.º 29
0
 public void DeleteFavorite(FavoriteEntity favorite)
 {
     favoriteRepository.Delete(favorite.ToDalFavorite());
 }
Exemplo n.º 30
0
 public void AddFavorite(FavoriteEntity favorite)
 {
     favoriteRepository.Create(favorite.ToDalFavorite());
 }
Exemplo n.º 31
0
 public async void CreateFavoriteAsync(FavoriteEntity favoriteItem)
 {
     await _dynamoDBcontext.SaveAsync(favoriteItem);
 }
Exemplo n.º 32
0
        private void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            TargetSet tset = new TargetSet { file = this.favFileName, Name = this.txtTargetSetName.Text, Parameters = this.favParameters, Strapper = this.favStrapper, Targets = this.favTargets };

            if (this.listBoxExistingFavorites.SelectedIndex >= 0)
            {
                FavoriteFile f = this.listBoxExistingFavorites.SelectedItem as FavoriteFile;
                XmlSerializer deserializer = new XmlSerializer(typeof(FavoriteEntity));
                FavoriteEntity foundFavorite;
                using (FileStream favStream = new FileStream(f.FullPath, FileMode.Open, FileAccess.Read))
                {
                    foundFavorite = (FavoriteEntity)deserializer.Deserialize(favStream);
                }

                TargetSet[] temp = new TargetSet[foundFavorite.TargetSet.Length + 1];
                int i = 0;
                foreach (TargetSet t in foundFavorite.TargetSet)
                {
                    temp[i] = t;
                    i++;
                }

                temp[i] = tset;
                foundFavorite.TargetSet = temp;

                XmlSerializer serializer = new XmlSerializer(typeof(FavoriteEntity));
                using (FileStream fs = new FileStream(f.FullPath, FileMode.Create))
                {
                    TextWriter writer = new StreamWriter(fs, new UTF8Encoding());
                    serializer.Serialize(writer, foundFavorite);
                }

                this.Close();
                return;
            }

            SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog { DefaultExt = ".msbef", Filter = "MSBuild Explorer Favorite (.msbef)|*.msbef" };
            if (dlg.ShowDialog() == true)
            {
                FavoriteEntity fe = new FavoriteEntity();
                fe.groupName = this.txtFavoriteGroupName.Text;
                TargetSet[] tsetcol = new TargetSet[1];
                tsetcol[0] = tset;
                fe.TargetSet = tsetcol;
                fe.file = this.favFileName;
                fe.friendlyName = this.txtFavoriteName.Text;

                XmlSerializer serializer = new XmlSerializer(typeof(FavoriteEntity));
                using (FileStream fs = new FileStream(dlg.FileName, FileMode.Create))
                {
                    TextWriter writer = new StreamWriter(fs, new UTF8Encoding());
                    serializer.Serialize(writer, fe);
                }

                StringCollection favs = new StringCollection();
                foreach (string s in from string s in Settings.Default.Favorites where !favs.Contains(s) select s)
                {
                    favs.Add(s);
                }

                if (!favs.Contains(dlg.FileName))
                {
                    favs.Add(dlg.FileName);
                }

                Settings.Default.Favorites = favs;

                Settings.Default.Save();

                this.Close();
            }
        }