Пример #1
0
        public static Topics GetSingle(int Id)
        {
            Topics topic = null;
            // 1) Create the connection
            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString;

            // 2) Open the connection
            connection.Open();

            // 3) Execute query
            SqlCommand command = new SqlCommand();

            command.Connection  = connection;
            command.CommandText = string.Format("select * from topics where id = '{0}'", Id);

            SqlDataReader dataReader = command.ExecuteReader();

            if (dataReader.Read())
            {
                topic = new Topics();

                topic.Id        = Convert.ToInt32(dataReader["Id"]);
                topic.Name      = Convert.ToString(dataReader["Name"]);
                topic.SubjectId = Convert.ToInt32(dataReader["SubjectId"]);
                topic.BranchId  = Convert.ToInt32(dataReader["BranchId"]);
                if (dataReader["ParentId"] != DBNull.Value)
                {
                    topic.ParentId = Convert.ToInt32(dataReader["ParentId"]);
                }

                topic.Subjects     = SubjectsDA.GetSingle(topic.SubjectId);
                topic.ParentTopics = TopicsDA.GetSingle(topic.ParentId);
            }

            // 4) Close the connection
            connection.Close();

            return(topic);
        }
Пример #2
0
        public async Task AddTopic(WebSocketTopic topic, CancellationToken cancellationToken = default)
        {
            var type      = topic.GetType();
            var fieldInfo = type.GetField(topic.ToString());

            var attribute =
                fieldInfo.GetCustomAttribute(typeof(WebSocketTopicStringValueAttribute), false) as WebSocketTopicStringValueAttribute;

            Topics.Add(attribute.Value);

            var addTopicObject = new
            {
                command = WebSocketCommands.AddTopics,
                topics  = new List <object>()
                {
                    new { topic = attribute.Value }
                }
            };

            await Send(JsonConvert.SerializeObject(addTopicObject), cancellationToken);
        }
Пример #3
0
        public void SaveATopic()
        {
            _topicTestName = Guid.NewGuid().ToString().Substring(0, 20);

            var newTopic = new Topics()
            {
                Created_On = DateTime.Now,
                TopicName  = _topicTestName
            };

            using (var svc = new TopicServices())
            {
                svc.SaveTopic(newTopic);
            }

            using (var db = new TraqnoteEntities())
            {
                Assert.AreEqual(_topicTestName,
                                db.topics.FirstOrDefault(x => x.topic_name == _topicTestName).topic_name);
            }
        }
Пример #4
0
        /// <summary>
        /// 获取主题信息列表
        /// </summary>
        /// <param name="pageSize">页面大小</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="startNumber">置顶帖数量</param>
        /// <returns></returns>
        public List <TopicInfo> GetTopicInfoList(int pageSize, int pageIndex, int startNumber)
        {
            List <TopicInfo> topicList = new List <TopicInfo>();

            if (orderStr == "" && direct == 1)
            {
                topicList = Topics.GetTopicList(forumid, pageSize, pageIndex, startNumber, 600, config.Hottopic, forum.Autoclose,
                                                forum.Topictypeprefix, condition);
            }
            else
            {
                if (direct == 0 && orderStr == string.Empty)
                {
                    orderStr = "lastpostid";
                }

                topicList = Topics.GetTopicList(forumid, pageSize, pageIndex, startNumber, 600, config.Hottopic, forum.Autoclose,
                                                forum.Topictypeprefix, condition, orderStr, direct);
            }
            return(topicList);
        }
        /// <summary>
        /// Trata de suscribir a un topic que recibe como parámetro
        /// </summary>
        /// <param name="topic"></param>
        public static void Suscribir(Topic topic)
        {
            try
            {
                client.SubscribeAsync(topic.Nombre, (MQTTnet.Protocol.MqttQualityOfServiceLevel)topic.QOS);
                //client.Subscribe(new string[] { topic.Nombre }, new byte[] { topic.QOS });

                //Desuscribir(topic);
                if (Topics.FirstOrDefault(x => x.Nombre == topic.Nombre && x.IdHandler == topic.IdHandler) != null)
                {
                }
                else
                {
                    Topics.Add(topic);
                }
            }
            catch (Exception ex)
            {
                new Log().Escribir(ex);
            }
        }
Пример #6
0
        //get random tweet with topic
        public virtual Tweet getTweet(Topics topic)
        {
            List <Tweet> temp = new List <Tweet>();

            foreach (Tweet tweet in this.Tweets)
            {
                if (tweet.Topic == topic)
                {
                    temp.Add(tweet);
                }
            }

            if (temp.Count == 0)
            {
                return(null);
            }
            else
            {
                return(temp[rand.Next(temp.Count - 1)]);
            }
        }
Пример #7
0
        //get tweets with topic XY
        public virtual List <Tweet> getTweetsWithTopic(Topics topic)
        {
            List <Tweet> temp = new List <Tweet>();

            foreach (Tweet tweet in this.Tweets)
            {
                if (tweet.Topic == topic)
                {
                    temp.Add(tweet);
                }
            }

            if (temp.Count == 0)
            {
                return(null);
            }
            else
            {
                return(temp);
            }
        }
Пример #8
0
        public async Task <IActionResult> OnGetAsync()
        {
            var topicsTask = LoadTopics();
            var groupsTask = LoadGroups();

            // load all in parallel
            await Task.WhenAll(
                topicsTask,
                groupsTask
                );

            Topics    = topicsTask.Result;
            Sequences = groupsTask.Result;

            var title = Topics.Select(t => t.Title).ToDelimitedString("; ");

            // shared layout title
            ViewData["TopicTitle"] = $" - {title}";

            return(Page());
        }
Пример #9
0
        public async Task <ActionResult <Topics> > PostTopics(Topics topics)
        {
            _context.Topics.Add(topics);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (TopicsExists(topics.TopicId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetTopics", new { id = topics.TopicId }, topics));
        }
Пример #10
0
        /// <summary>
        /// Add a new internal topic.
        /// </summary>
        /// <param name="name">Topic Name</param>
        /// <param name="topicCreationConfig"></param>
        public KafkaStreamOptions AddTopic(string name, TopicCreationConfig topicCreationConfig = null)
        {
            var config = new TopicConfig {
                IsExternal = false, Name = name
            };

            if (topicCreationConfig != null)
            {
                config.AutoCreate        = topicCreationConfig.AutoCreate;
                config.Partitions        = topicCreationConfig.Partitions;
                config.ReplicationFactor = topicCreationConfig.ReplicationFactor;
                if (topicCreationConfig.RetentionPeriodInMs.HasValue)
                {
                    config.RetentionPeriodInMs = topicCreationConfig.RetentionPeriodInMs;
                }
            }

            Topics.Add(config);

            return(this);
        }
        private void AllDelete_Click(object sender, EventArgs e)
        {
            #region 全部删除

            if (this.CheckCookie())
            {
                string    topiclist = "";
                DataTable dt        = Topics.GetAuditTopicList(ViewState["condition"].ToString());
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        topiclist += dr["tid"].ToString() + ",";
                    }
                    TopicAdmins.DeleteTopics(topiclist.TrimEnd(','), false);
                }
                this.RegisterStartupScript("", "<script>alert('提交成功');window.location.href='forum_auditingtopic.aspx';</script>");
            }

            #endregion
        }
Пример #12
0
        /// <summary>
        /// Add a new external topic.
        /// </summary>
        /// <param name="type">The data type that this contract will use.</param>
        /// <param name="name">Topic Name</param>
        /// <param name="topicCreationConfig"></param>
        public KafkaStreamOptions AddExternalTopic(
            Type type,
            string name,
            TopicCreationConfig topicCreationConfig = null
            )
        {
            var config = new TopicConfig {
                IsExternal = true, Name = name, ExternalContractType = type
            };

            if (topicCreationConfig != null)
            {
                config.AutoCreate        = topicCreationConfig.AutoCreate;
                config.Partitions        = topicCreationConfig.Partitions;
                config.ReplicationFactor = topicCreationConfig.ReplicationFactor;
            }

            Topics.Add(config);

            return(this);
        }
Пример #13
0
        /// <summary>
        /// Publishes a new message to the specified event on the bus.
        /// </summary>
        /// <param name="message">The message to publish.</param>
        public virtual Task Publish(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            Topic topic;

            if (Topics.TryGetValue(message.Key, out topic))
            {
                topic.Store.Add(message);
                ScheduleTopic(topic);
            }

            Counters.MessageBusMessagesPublishedTotal.Increment();
            Counters.MessageBusMessagesPublishedPerSec.Increment();


            return(TaskAsyncHelper.Empty);
        }
Пример #14
0
        private void SelectPass_Click(object sender, EventArgs e)
        {
            #region 对选中的主题设置为通过审核

            if (this.CheckCookie())
            {
                string tidlist = DNTRequest.GetString("tid");
                if (tidlist != "")
                {
                    //UpdateUserCredits(tidlist);
                    Topics.PassAuditNewTopic(tidlist);
                    base.RegisterStartupScript("", "<script>window.location='forum_auditnewtopic.aspx';</script>");
                }
                else
                {
                    base.RegisterStartupScript("", "<script>alert('您未选中任何选项');window.location='forum_auditnewtopic.aspx';</script>");
                }
            }

            #endregion
        }
Пример #15
0
        /// <summary>
        /// 新增
        /// </summary>
        public void AddTopics()
        {
            string author  = Request["author"];
            string title   = Request["title"];
            string content = Request["content"];

            if (string.IsNullOrEmpty(author))
            {
                author = "匿名";
            }
            Topics one = new Topics();

            one.Title           = title.Trim();
            one.Author          = author.Trim();
            one.Content         = content.Trim();
            one.UserHostAddress = System.Web.HttpContext.Current.Request.UserHostAddress;
            one.AddDate         = DateTime.Now;
            one.LastModifyDate  = DateTime.Now;
            one.UserName        = System.Web.HttpContext.Current.User.Identity.Name;
            topicsService.AddEntity(one);
        }
Пример #16
0
 private void LoadTopics()
 {
     if (TopicsInitialize())
     {
         string          query       = "SELECT * FROM `Topics`;";
         var             reader_temp = SQL.ExecuteQuery(query);
         MySqlDataReader reader;
         if (reader_temp.Item2)
         {
             reader = reader_temp.Item1;
             DataTable dt = new DataTable();
             dt.Load(reader);
             string topic;
             foreach (DataRow row in dt.Rows)
             {
                 topic = row["Topic"].ToString();
                 Topics.Add(topic);
             }
         }
     }
 }
Пример #17
0
        public static IQueryable <dynamic> GetTopics(Topics searchCrit)
        {
            BDIIDataContext dc  = new BDIIDataContext();
            var             res = from el in dc.Topics
                                  join ol in dc.Teachers on el.TeacherID equals ol.ID
                                  join il in dc.Users on ol.UserID equals il.ID
                                  where
                                  ((el.ID == searchCrit.ID) || (searchCrit.ID == 0))
                                  &&
                                  (el.Title.StartsWith(searchCrit.Title) || string.IsNullOrEmpty(searchCrit.Title))
                                  select new
            {
                el.ID,
                el.Title,
                el.Status,
                il.Name,
                il.Surname
            };

            return(res);
        }
Пример #18
0
        protected void TopicViewItemCommand(object sender, FormViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "prev":
                _topic = Topics.GetNextPrevTopic(_topic.Id, "prev");
                if (Session["TOPIC"].ToString() != _topic.Id.ToString())
                {
                    Response.Redirect("~/Content/Forums/topic.aspx?TOPIC=" + _topic.Id, true);
                }
                break;

            case "next":
                _topic = Topics.GetNextPrevTopic(_topic.Id, "next");
                if (Session["TOPIC"].ToString() != _topic.Id.ToString())
                {
                    Response.Redirect("~/Content/Forums/topic.aspx?TOPIC=" + _topic.Id, true);
                }
                break;
            }
        }
Пример #19
0
        public void DeletePost(string topicid, string replyid, string jsonform)
        {
            var form = HttpUtility.UrlDecode(jsonform);

            System.Collections.Specialized.NameValueCollection formresult = HttpUtility.ParseQueryString(form);
            string reason     = formresult["ctl00$txtReason"];
            int    adminmodid = Convert.ToInt32(formresult["ctl00$hdnModerator"]);

            if (!String.IsNullOrEmpty(topicid))
            {
                Topics.Delete(Convert.ToInt32(topicid));
            }
            if (!String.IsNullOrEmpty(replyid))
            {
                Replies.DeleteReply(Convert.ToInt32(replyid));
            }
            if (!string.IsNullOrEmpty(reason) && Config.UseEmail)
            {
                ProcessModeration(1, Convert.ToInt32(topicid), Convert.ToInt32(replyid), adminmodid, reason);
            }
        }
Пример #20
0
        public static bool Add(Topics topic)
        {
            // 1) Create the connection
            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString;

            // 2) Open the connection
            connection.Open();

            // 3) Execute query
            SqlCommand command = new SqlCommand();

            command.Connection = connection;
            if (topic.ParentId == 0)
            {
                command.CommandText = string.Format("insert into topics(name,subjectid,branchId,parentid) values('{0}','{1}','{2}',NULL)", topic.Name, topic.SubjectId, topic.BranchId);
            }

            if (topic.ParentId != 0)
            {
                command.CommandText = string.Format("insert into topics(name,subjectid,parentid,branchId) values('{0}','{1}','{2}','{3}')", topic.Name, topic.SubjectId, topic.ParentId, topic.BranchId);
            }



            int rowsAffected = command.ExecuteNonQuery();

            // 4) Close the connection
            connection.Close();

            if (rowsAffected == 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #21
0
        internal Topic GetTopic(string key)
        {
            Topic topic;
            int   oldState;

            do
            {
                if (BeforeTopicCreated != null)
                {
                    BeforeTopicCreated(key);
                }

                topic = Topics.GetOrAdd(key, _createTopic);

                if (BeforeTopicMarked != null)
                {
                    BeforeTopicMarked(key, topic);
                }

                // If the topic was dying revive it to the NoSubscriptions state.  This is used to ensure
                // that in the scaleout case that even if we're publishing to a topic with no subscriptions
                // that we keep it around in case a user hops nodes.
                oldState = Interlocked.CompareExchange(ref topic.State, TopicState.NoSubscriptions, TopicState.Dying);

                if (AfterTopicMarked != null)
                {
                    AfterTopicMarked(key, topic, topic.State);
                }

                // If the topic is currently dead then we're racing with the DestroyTopicCore function, therefore
                // loop around until we're able to create a new topic
            } while (oldState == TopicState.Dead);

            if (AfterTopicMarkedSuccessfully != null)
            {
                AfterTopicMarkedSuccessfully(key, topic);
            }

            return(topic);
        }
Пример #22
0
        public ActionResult EliminarTop(string name)
        {
            Session["UserIDG"] = Session["UserIDG"];
            Session["UserID"]  = Session["UserID"];
            Session["User"]    = Session["User"];
            string            texto    = "Estas seguro de Eliminar el topic?";
            string            titulo   = "Eliminar Topic";
            MessageBoxButtons button   = MessageBoxButtons.YesNoCancel;
            MessageBoxIcon    icon     = MessageBoxIcon.Question;
            DialogResult      result   = MessageBox.Show(texto, titulo, button, icon);
            Comments          comments = new Comments();
            Topics            topic    = new Topics();

            topic = topic.getTopicsByName(name);
            if (result.Equals(System.Windows.Forms.DialogResult.Yes))
            {
                if (!comments.DeleteCommentsByIDTopic(topic.id_topic))
                {
                    MessageBox.Show("Comentario de " + topic.id_topic + "no eliminado");
                    return(Redirect("GeneralCat"));
                }
                String sql     = "Delete from Topic where nameTopic = '" + name + "'";
                int    retorno = 0;
                using (SqlConnection connection = BD.getConnection())
                {
                    SqlCommand Comando = new SqlCommand(string.Format(sql), connection);
                    retorno = Comando.ExecuteNonQuery();
                    connection.Close();
                }
                if (retorno > 0)
                {
                    MessageBox.Show("Topic Borrado Con Exito!!", "Eliminado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("No se pudo borrar el Topic", "Fallo!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            return(RedirectToAction("GeneralCat", new { name = Session["CatName"] }));
        }
Пример #23
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing && _gcRunning != GCState.Disposed)
            {
                // Stop the broker from doing any work
                _broker.Dispose();

                // Spin while we wait for the timer to finish if it's currently running
                while (Interlocked.CompareExchange(ref _gcRunning, GCState.Disposed, GCState.Idle) == GCState.Running)
                {
                    Thread.Sleep(250);
                }

                // Remove all topics
                Topics.Clear();

                if (_gcTimer != null)
                {
                    _gcTimer.Dispose();
                }
            }
        }
Пример #24
0
        private async void StartStudy()
        {
            if (CurrentStudy == null || (CurrentStudy.CurrentState != TwitterStudyStates.Pending &&
                                         CurrentStudy.CurrentState != TwitterStudyStates.Revision))
            {
                MessageBox.Show("Only can start a service when it is pending or in a revision");
                return;
            }

            StartOperation("Starting Study");
            try
            {
                await
                _service.StartStudyAsync(new StartStudyRequest(CurrentStudy.Id, Topics.Split(','), Time, EmployeeId));
                await LoadEmployeeData();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            StopOperation();
        }
Пример #25
0
        // POST: api/Topics
        public IHttpActionResult Post(Topics topic)
        {
            // using (var conn = new NpgsqlConnection("Host = localhost; Port = 5432; Username = postgres; Database = invokeTest; "))
            using (var conn = new NpgsqlConnection("Host = localhost; Port = 5555; Username = db_201617z_va_proekt_invoke_mk_owner; Password = invoke_finki; Database = db_201617z_va_proekt_invoke_mk"))
            {
                conn.Open();
                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection = conn;

                    // Insert some data

                    cmd.CommandText = "INSERT INTO invoke.topics " +
                                      "(topicsname,topicsdescription,topicsdatewithtime,usersid,forumsid) " +
                                      $"VALUES('{topic.TopicName}','{topic.TopicDescription}','NOW()',{topic.UserID},{topic.ForumID});";

                    cmd.ExecuteNonQuery();
                }

                return(Ok("Added topic"));
            }
        }
Пример #26
0
        /// <summary>
        /// 更新主题相关信息
        /// </summary>
        /// <param name="postmessage"></param>
        private void UpdateTopicInfo(string postmessage)
        {
            int hide = (ForumUtils.IsHidePost(postmessage) && usergroupinfo.Allowhidecode == 1) ? 1 : 0;

            if (hide == 1 && topic.Hide != 1)
            {
                topic.Hide = hide;
                Topics.UpdateTopicHide(topicid);
            }

            //更新topic的attention为0
            if (Moderators.IsModer(useradminid, userid, topic.Fid) && topic.Attention == 1)
            {
                Topics.UpdateTopicAttentionByTidList(topicid.ToString(), 0);
            }
            else if (topic.Posterid != -1 && userid == topic.Posterid)
            {
                Topics.UpdateTopicAttentionByTidList(topicid.ToString(), 1);
            }

            Topics.UpdateTopicReplyCount(topicid);
        }
Пример #27
0
        public ActionResult GeneralCat(string name)
        {
            Session["UserIDG"] = Session["UserIDG"];
            Session["UserID"]  = Session["UserID"];
            Session["User"]    = Session["User"];
            Session["CatName"] = name;
            Categorias    cat    = new Categorias();
            int           id     = cat.getIDCatName(name);
            List <Topics> topics = new List <Topics>();
            Topics        top    = new Topics();
            List <string> items  = new List <string>();

            topics = top.getAllTopicsByCatID(id);

            for (int i = 0; i < topics.Count; i++)
            {
                items.Add(topics[i].name);
            }
            ViewBag.Items      = items;
            ViewData["TCount"] = topics.Count;
            return(View());
        }
Пример #28
0
    private void AddTopics(Topics topic, TreeNodeCollection nodes)
    {
        TreeNode node = new TreeNode();

        node.Text = topic.Name;
        int TopicId = topic.Id;

        node.NavigateUrl = string.Format("~/User/Download.aspx?Id={0}&branch={1}", TopicId, branchId);

        nodes.Add(node);

        // Get current topic's children
        List <Topics> children = TopicsBL.GetAllByTopics(topic.Id);

        if (children.Count > 1)
        {
            foreach (Topics childTopic in children)
            {
                AddTopics(childTopic, node.ChildNodes);
            }
        }
    }
Пример #29
0
        /// <summary>
        /// 设置查询条件
        /// </summary>
        private void SetCondition()
        {
            #region 对搜索条件进行检索

            condition = Topics.GetTopicCountCondition(out type, DNTRequest.GetString("type", true), newtopic);

            if (forumid > 0)
            {
                condition += " AND fid =" + forumid;
            }
            else
            {
                //验证重新生成的版块id列表是否合法(需要放入sql语句查询)
                if (!Utils.IsNumericList(forums))
                {
                    AddErrLine("版块ID不合法或没有该版块访问权限");
                }

                condition += " AND fid IN(" + forums + ")";
            }
            #endregion
        }
Пример #30
0
 public async Task <IActionResult> Create([Bind("TopicName,Description,StartDate,EndDate, isFeatured, Rules")] TopicViewModel model, string returnUrl = null)
 {
     ViewData["ReturnUrl"] = returnUrl;
     if (ModelState.IsValid)
     {
         var rules   = model.Rules;
         var request = new SearchRequest
         {
             Query = ElasticsearchQueryBuilder.QueryBuilder(JObject.Parse(rules)),
             Size  = 50
         };
         var topic = new Topics
         {
             TopicName   = model.TopicName,
             Description = model.Description,
             DateCreated = DateTime.Now,
             StartDate   = model.StartDate,
             EndDate     = model.EndDate,
             Rules       = model.Rules,
             ESRequest   = _client.RequestResponseSerializer.SerializeToString(request),
             isFeatured  = model.isFeatured
         };
         try
         {
             _context.Add(topic);
             var result = await _context.SaveChangesAsync();
         }
         catch (DbUpdateException /* ex */)
         {
             //Log the error (uncomment ex variable name and write a log.)
             ModelState.AddModelError("", "Unable to save changes. " +
                                      "Try again, and if the problem persists, " +
                                      "see your system administrator.");
         }
     }
     StatusMessage = "Thêm mới chủ đề thành công!";
     return(RedirectToAction(nameof(Index)));
     //return View("Index", model);
 }