Example #1
0
        //内部调用的,根据ID查询返回MessageForShow类型的函数
        static public async Task <MessageForShow> InnerQuery(int message_id)
        {
            return(await Wrapper.wrap(async (OracleConnection conn) =>
            {
                //function FUNC_SHOW_MESSAGE_BY_ID(message_id in INTEGER, result out sys_refcursor)
                //return INTEGER
                string procedurename = "FUNC_SHOW_MESSAGE_BY_ID";
                OracleCommand cmd = new OracleCommand(procedurename, conn);
                cmd.CommandType = CommandType.StoredProcedure;

                //Add return value
                OracleParameter p1 = new OracleParameter();
                p1 = cmd.Parameters.Add("state", OracleDbType.Int32);
                p1.Direction = ParameterDirection.ReturnValue;

                //Add first parameter message_id
                OracleParameter p2 = new OracleParameter();
                p2 = cmd.Parameters.Add("message_id", OracleDbType.Int32);
                p2.Direction = ParameterDirection.Input;
                p2.Value = message_id;

                //Add second parameter search_result
                OracleParameter p3 = new OracleParameter();
                p3 = cmd.Parameters.Add("result", OracleDbType.RefCursor);
                p3.Direction = ParameterDirection.Output;

                //Get the result table
                OracleDataAdapter DataAdapter = new OracleDataAdapter(cmd);
                DataTable dt = new DataTable();
                await Task.FromResult(DataAdapter.Fill(dt));

                if (int.Parse(p1.Value.ToString()) == 0)
                {
                    throw new Exception("failed");
                }
                MessageForShow infos = new MessageForShow();
                infos.message_id = int.Parse(dt.Rows[0][0].ToString());
                infos.message_content = dt.Rows[0][1].ToString();
                infos.message_create_time = dt.Rows[0][2].ToString();
                infos.message_like_num = int.Parse(dt.Rows[0][3].ToString());
                infos.message_transpond_num = int.Parse(dt.Rows[0][4].ToString());
                infos.message_comment_num = int.Parse(dt.Rows[0][5].ToString());
                infos.message_view_num = int.Parse(dt.Rows[0][6].ToString());
                infos.message_has_image = int.Parse(dt.Rows[0][7].ToString());
                infos.message_sender_user_id = int.Parse(dt.Rows[0][8].ToString());
                infos.message_heat = int.Parse(dt.Rows[0][9].ToString());
                infos.message_image_count = int.Parse(dt.Rows[0][10].ToString() == "" ? "0" : dt.Rows[0][10].ToString());
                infos.message_transpond_message_id = int.Parse(dt.Rows[0][11].ToString() == "" ? "0" : dt.Rows[0][11].ToString());

                infos.message_topics = await TopicController.SearchTopicsInTwitter(infos.message_content);
                infos.message_ats = await AtController.SearchAtsInTwitter(infos.message_content);
                infos.message_image_urls = new string[infos.message_image_count];
                for (int i = 0; i < infos.message_image_count; i++)
                {
                    infos.message_image_urls = getMessageImageUrls(infos.message_id, infos.message_image_count);
                }

                return infos;
            }));
        }
Example #2
0
        public async Task <IActionResult> QueryFollowMessage([Required][FromBody] Range range)
        {
            int userId;

            if (HttpContext.User.Identity.IsAuthenticated)
            {
                userId = int.Parse(HttpContext.User.Claims.First().Value);
            }
            else
            {
                RestfulResult.RestfulData rr = new RestfulResult.RestfulData();
                rr.Code    = 200;
                rr.Message = "Need Authentication";
                return(new JsonResult(rr));
            }

            return(await Wrapper.wrap(async (OracleConnection conn) =>
            {
                //function FUNC_SHOW_FOLLOW_MESSAGE(startFrom in INTEGER, limitation in INTEGER, userid in INTEGER, search_result out sys_refcursor)
                //return INTEGER
                string procedurename = "FUNC_SHOW_FOLLOW_MESSAGE";
                OracleCommand cmd = new OracleCommand(procedurename, conn);
                cmd.CommandType = CommandType.StoredProcedure;

                //Add return value
                OracleParameter p1 = new OracleParameter();
                p1 = cmd.Parameters.Add("state", OracleDbType.Int32);
                p1.Direction = ParameterDirection.ReturnValue;

                //Add first parameter startFrom
                OracleParameter p2 = new OracleParameter();
                p2 = cmd.Parameters.Add("startFrom", OracleDbType.Int32);
                p2.Direction = ParameterDirection.Input;
                p2.Value = range.startFrom;

                //Add second parameter limitation
                OracleParameter p3 = new OracleParameter();
                p3 = cmd.Parameters.Add("limitation", OracleDbType.Int32);
                p3.Direction = ParameterDirection.Input;
                p3.Value = range.limitation;

                OracleParameter p4 = new OracleParameter();
                p4 = cmd.Parameters.Add("userid", OracleDbType.Int32);
                p4.Direction = ParameterDirection.Input;
                p4.Value = userId;

                //Add third parameter search_result
                OracleParameter p5 = new OracleParameter();
                p5 = cmd.Parameters.Add("search_result", OracleDbType.RefCursor);
                p5.Direction = ParameterDirection.Output;

                //Get the result table
                OracleDataAdapter DataAdapter = new OracleDataAdapter(cmd);
                DataTable dt = new DataTable();
                await Task.FromResult(DataAdapter.Fill(dt));

                if (int.Parse(p1.Value.ToString()) == 0)
                {
                    throw new Exception("failed");
                }
                MessageForShow[] receivedTwitters = new MessageForShow[dt.Rows.Count];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    receivedTwitters[i] = new MessageForShow();
                    receivedTwitters[i].message_id = int.Parse(dt.Rows[i][0].ToString());
                    receivedTwitters[i].message_content = dt.Rows[i][1].ToString();
                    receivedTwitters[i].message_create_time = dt.Rows[i][2].ToString();
                    receivedTwitters[i].message_like_num = int.Parse(dt.Rows[i][3].ToString());
                    receivedTwitters[i].message_transpond_num = int.Parse(dt.Rows[i][4].ToString());
                    receivedTwitters[i].message_comment_num = int.Parse(dt.Rows[i][5].ToString());
                    receivedTwitters[i].message_view_num = int.Parse(dt.Rows[i][6].ToString());
                    receivedTwitters[i].message_has_image = int.Parse(dt.Rows[i][7].ToString());
                    receivedTwitters[i].message_sender_user_id = int.Parse(dt.Rows[i][8].ToString());
                    receivedTwitters[i].message_heat = int.Parse(dt.Rows[i][9].ToString());
                    receivedTwitters[i].message_image_count = int.Parse(dt.Rows[i][10].ToString() == "" ? "0" : dt.Rows[i][10].ToString());
                    receivedTwitters[i].message_transpond_message_id = int.Parse(dt.Rows[i][11].ToString() == "" ? "0" : dt.Rows[i][11].ToString());

                    receivedTwitters[i].message_topics = await TopicController.SearchTopicsInTwitter(receivedTwitters[i].message_content);
                    receivedTwitters[i].message_ats = await AtController.SearchAtsInTwitter(receivedTwitters[i].message_content);
                }
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (receivedTwitters[i].message_has_image == 1)
                    {
                        string path = @"wwwroot\Messages\" + receivedTwitters[i].message_id.ToString() + @"\";
                        receivedTwitters[i].message_image_urls =
                            getMessageImageUrls(receivedTwitters[i].message_id, receivedTwitters[i].message_image_count);
                    }
                }

                RestfulResult.RestfulArray <MessageForShow> rr = new RestfulResult.RestfulArray <MessageForShow>();
                rr.Code = 200;
                rr.Message = "success";
                rr.Data = receivedTwitters;
                return new JsonResult(rr);
            }));
        }
Example #3
0
        public async Task <IActionResult> Query([Required] int message_id)
        {
            //获得推特的详细信息
            //无需验证登录态
            //除了基本的推特信息以外,我们需要根据这条推特是否含有图,来把MessageForShow的图片url列表填好

            return(await Wrapper.wrap(async (OracleConnection conn) =>
            {
                //function FUNC_SHOW_MESSAGE_BY_ID(message_id in INTEGER, result out sys_refcursor)
                //return INTEGER
                string procedurename = "FUNC_SHOW_MESSAGE_BY_ID";
                OracleCommand cmd = new OracleCommand(procedurename, conn);
                cmd.CommandType = CommandType.StoredProcedure;

                //Add return value
                OracleParameter p1 = new OracleParameter();
                p1 = cmd.Parameters.Add("state", OracleDbType.Int32);
                p1.Direction = ParameterDirection.ReturnValue;

                //Add first parameter message_id
                OracleParameter p2 = new OracleParameter();
                p2 = cmd.Parameters.Add("message_id", OracleDbType.Int32);
                p2.Direction = ParameterDirection.Input;
                p2.Value = message_id;

                //Add second parameter search_result
                OracleParameter p3 = new OracleParameter();
                p3 = cmd.Parameters.Add("result", OracleDbType.RefCursor);
                p3.Direction = ParameterDirection.Output;

                //Get the result table
                OracleDataAdapter DataAdapter = new OracleDataAdapter(cmd);
                DataTable dt = new DataTable();
                await Task.FromResult(DataAdapter.Fill(dt));

                if (int.Parse(p1.Value.ToString()) == 0)
                {
                    throw new Exception("failed");
                }
                MessageForShow infos = new MessageForShow();
                infos.message_id = int.Parse(dt.Rows[0][0].ToString());
                infos.message_content = dt.Rows[0][1].ToString();
                infos.message_create_time = dt.Rows[0][2].ToString();
                infos.message_like_num = int.Parse(dt.Rows[0][3].ToString());
                infos.message_transpond_num = int.Parse(dt.Rows[0][4].ToString());
                infos.message_comment_num = int.Parse(dt.Rows[0][5].ToString());
                infos.message_view_num = int.Parse(dt.Rows[0][6].ToString());
                infos.message_has_image = int.Parse(dt.Rows[0][7].ToString());
                infos.message_sender_user_id = int.Parse(dt.Rows[0][8].ToString());
                infos.message_heat = int.Parse(dt.Rows[0][9].ToString());
                infos.message_image_count = int.Parse(dt.Rows[0][10].ToString() == "" ? "0" : dt.Rows[0][10].ToString());
                infos.message_transpond_message_id = int.Parse(dt.Rows[0][11].ToString() == "" ? "0" : dt.Rows[0][11].ToString());

                infos.message_topics = await TopicController.SearchTopicsInTwitter(infos.message_content);
                infos.message_ats = await AtController.SearchAtsInTwitter(infos.message_content);

                if (infos.message_has_image == 1)
                {
                    string path = @"wwwroot\Messages\" + infos.message_id.ToString() + @"\";
                    infos.message_image_urls = getMessageImageUrls(infos.message_id, infos.message_image_count);
                }

                RestfulResult.RestfulData <MessageForShow> rr = new RestfulResult.RestfulData <MessageForShow>();
                rr.Code = 200;
                rr.Message = "success";
                rr.Data = infos;
                return new JsonResult(rr);
            }));
        }