public static string ArticleSearch(string ArticleTitle, int startIndex, int maximumRows, string sortExpressions)
        {
            ArticleCollection           ArticleListSearch = new ArticleCollection();
            Dictionary <string, object> dic = new Dictionary <string, object>();

            ArticleList = ArticleCollection.GetArticleBySearch(ArticleTitle);
            Guid subId = SessionHelper.GetSession(SessionKey.SubDomain) == string.Empty ? Guid.Empty : new Guid(SessionHelper.GetSession(SessionKey.SubDomain));

            if (subId == Guid.Empty)
            {
                ArticleListSearch = ArticleList;
            }
            else
            {
                PSCPortal.Engine.SubDomain subDomain = new PSCPortal.Engine.SubDomain {
                    Id = subId
                };
                PSCPortal.Engine.PageCollection listPage = subDomain.GetPagesBelongTo();
                foreach (var item in listPage)
                {
                    foreach (var article in ArticleList.Where(ar => ar.PageId == item.Id))
                    {
                        ArticleListSearch.Add(article);
                    }
                }
            }
            dic.Add("Data", ArticleListSearch.GetSegment(startIndex, maximumRows, sortExpressions));
            dic.Add("Count", ArticleListSearch.Count);
            System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
            return(js.Serialize(dic));
        }
Beispiel #2
0
        public void InheritedListSerialize()
        {
            var a1 = new Article("a1");
            var a2 = new Article("a2");

            var articles1 = new ArticleCollection();

            articles1.Add(a1);
            articles1.Add(a2);

            string jsonText = JavaScriptConvert.SerializeObject(articles1);

            var articles2 = JavaScriptConvert.DeserializeObject <ArticleCollection>(jsonText);

            Assert.AreEqual(articles1.Count, articles2.Count);
            Assert.AreEqual(articles1[0].Name, articles2[0].Name);
        }
Beispiel #3
0
        public ArticleCollection GetArticlesBelongTo()
        {
            PSCPortal.Framework.Database database = new PSCPortal.Framework.Database("PSCPortalConnectionString");
            ArticleCollection            result   = new ArticleCollection();

            using (DbConnection connection = database.GetConnection())
            {
                DbCommand command = database.GetCommand(connection);
                #region SubDomainId
                DbParameter prId = database.GetParameter(System.Data.DbType.Guid, "@SubDomainId", _id);
                command.Parameters.Add(prId);
                #endregion

                command.CommandText = @"SELECT 
	                                    a.[ArticleId],
	                                    [ArticleName],
	                                    [ArticleTitle],
                                        b.[IsCheck],
                                        s.[Name] as SubDomainFromName 
                                    FROM 
	                                    dbo.[Article] a 
	                                    inner join SubDomainInArticle b on a.ArticleId = b.ArticleNewId 
                                        inner join SubDomain s on b.SubDomainFromId = s.Id 
                                    WHERE 
	                                    b.SubDomainToId = @SubDomainId AND b.IsCheck = 'false'"    ;
                command.CommandType = System.Data.CommandType.Text;
                connection.Open();
                DbDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    Article item = new Article();
                    if (!reader.IsDBNull(reader.GetOrdinal("ArticleId")))
                    {
                        item.Id = new Guid(reader["ArticleId"].ToString());
                    }
                    if (!reader.IsDBNull(reader.GetOrdinal("ArticleName")))
                    {
                        item.Name = (string)reader["ArticleName"].ToString();
                    }
                    if (!reader.IsDBNull(reader.GetOrdinal("ArticleTitle")))
                    {
                        item.Title = (string)reader["ArticleTitle"].ToString();
                    }
                    if (!reader.IsDBNull(reader.GetOrdinal("SubDomainFromName")))
                    {
                        item.SubDomainFromName = (string)reader["SubDomainFromName"];
                    }
                    if (!reader.IsDBNull(reader.GetOrdinal("IsCheck")))
                    {
                        item.IsCheck = (bool)reader["IsCheck"];
                    }
                    result.Add(item);
                }
            }
            return(result);
        }
Beispiel #4
0
        public ArticleCollection Process(ClassRepository rep)
        {

            ArticleCollection artc = new ArticleCollection();

            
            List<Feature> features = new List<Feature>();
            foreach (KeyValuePair<string, Feature> kv in rep)
                features.Add(kv.Value);
            // Sort so classes are processed first
            features.Sort(delegate(Feature a, Feature b)
            {
                if ((a is SubSystem) && !(b is SubSystem)) return -1;
                else if ((b is SubSystem) && !(a is SubSystem)) return 1;
                else if ((a is Class) && !(b is Class)) return 1;
                else if ((b is Class) && !(a is Class)) return -1;
                else return a.GetType().Name.CompareTo(b.GetType().Name);
            });

            //var vocabArticle = new MohawkCollege.EHR.gpmr.Pipeline.Renderer.Deki.Article.Article()
            //{
            //    Title = "Vocabulary",
            //    Children = new ArticleCollection()
            //};
            //vocabArticle.Children.Add(new Article.Article() { Title = "Code Systems" });
            //vocabArticle.Children.Add(new Article.Article() { Title = "Concept Domains" });
            //vocabArticle.Children.Add(new Article.Article() { Title = "Value Sets" });

            //artc.Add(vocabArticle);
            WaitThreadPool wtp = new WaitThreadPool();

            // A thread that does the doohickey thing
            Thread doohickeyThread = new Thread((ThreadStart)delegate()
            {
                string[] hickeythings = { "|", "/", "-", "\\" };
                int hickeyThingCount = 0;
                try
                {
                    while (true)
                    {
                        int cPosX = Console.CursorLeft, cPosY = Console.CursorTop;
                        Console.SetCursorPosition(1, cPosY);
                        Console.Write(hickeythings[hickeyThingCount++ % hickeythings.Length]);
                        Console.SetCursorPosition(cPosX, cPosY);
                        Thread.Sleep(1000);
                    }
                }
                catch { }
            });
            doohickeyThread.Start();

            // Loop through each feature
            foreach (Feature f in features)
            {
                // Find the feature template
                FeatureTemplate ftpl = NonParameterizedTemplate.Spawn(FindTemplate(f.GetType().FullName, f) as NonParameterizedTemplate, this, f) as FeatureTemplate;

                if (ftpl == null) System.Diagnostics.Trace.WriteLine(string.Format("Feature '{0}' won't be published as no feature template could be located", f.Name), "warn");
                else if(f.Annotations.Find(o=>o is SuppressBrowseAnnotation) != null) System.Diagnostics.Trace.WriteLine(String.Format("Feature '{0}' won't be published as a SuppressBrowse annotation was found", f.Name), "warn");
                else if(ftpl.NewPage)
                {
                    System.Diagnostics.Trace.WriteLine(string.Format("Queueing ({1}) '{0}'...", f.Name, f.GetType().Name), "debug");

                    // Create a new worker
                    Worker w = new Worker();
                    w.ArticleCollection = artc;
                    w.FeatureTemplate = ftpl;
                    w.OnComplete += delegate(object sender, EventArgs e)
                    {
                        Worker wrkr = sender as Worker;
                        System.Diagnostics.Trace.WriteLine(String.Format("Rendered ({1}) '{0}'...", (wrkr.FeatureTemplate.Context as Feature).Name, wrkr.FeatureTemplate.Context.GetType().Name), "debug");
                    };
                    wtp.QueueUserWorkItem(w.Start);
                }
            }

            System.Diagnostics.Trace.WriteLine("Waiting for work items to complete...", "debug");
            wtp.WaitOne();
            doohickeyThread.Abort();

            ArticleCollection retVal = new ArticleCollection();
            Article.Article MasterTOC = new MohawkCollege.EHR.gpmr.Pipeline.Renderer.Deki.Article.Article();
            MasterTOC.Children = artc;
            System.Diagnostics.Trace.WriteLine("Creating Table of Contents...", "information");
            PrepareTOC(MasterTOC);
            MasterTOC.Children = null;
            artc.Add(MasterTOC);


            return artc;
        }
Beispiel #5
0
        /// <summary>
        /// Downloads up to maxHeaders article headers from the given group.  The latest ones are chosen.
        /// Currently, only some of the header fields are downloaded: id, from, date, subject, lines.  
        /// The body is not downloaded.  Use GetArticle to download an article's body text.
        /// </summary>
        /// <param name="group">Newsgroup whose articles headers will be downloaded.</param>
        /// <param name="maxHeaders">Maximum number of article headers to download.  The latest ones are chosen.</param>
        /// <returns>A collection of Article objects contained in the given newsgroup.  The articles' body
        /// text is not downloaded.  Use GetArticle to download an article's body text.</returns>
        public ArticleCollection GetArticleHeaders(Newsgroup group, int maxHeaders)
        {
            string message;
            string response;
            ArticleCollection articles = null;

            // Get the article numbers of the first and last articles in the group, and an
            // estimate of the number of articles on file in the group.

            try
            {
                message = "GROUP " + group.Name + "\r\n";
                Write(message);
                response = Response();
                if (response.Substring(0, 3) != "211")
                {
                    throw new NntpException(response);
                }

                char[] seps = { ' ' };
                string[] values = response.Split(seps);

                int start = Int32.Parse(values[2]);
                int end = Int32.Parse(values[3]);
                int estimatedArticleCount = end - start;
                if (estimatedArticleCount < 0) estimatedArticleCount = 100;

                // Was a maximum specified?
                if (maxHeaders != -1 && start + maxHeaders < end)
                {
                    start = end - maxHeaders;
                }

                articles = new ArticleCollection(estimatedArticleCount);

                // Create a collection of Article objects, storing just the heading information
                // into them.

                DateTime date;
                string from, subject, id;
                int numLines;
                bool allFieldsObtained;

                int sequenceNum;
                for (sequenceNum = start; sequenceNum < end; ++sequenceNum)
                {
                    message = "HEAD " + sequenceNum + "\r\n";
                    Write(message);
                    response = Response();
                    if (response.Substring(0, 3) == "423")
                    {
                        // 423 - No such article number in this group.
                        continue;
                    }

                    // 221 means article retrieved, head follows.
                    if (response.Substring(0, 3) != "221")
                    {
                        throw new NntpException(response);
                    }

                    date = DateTime.MinValue;
                    from = subject = id = "";
                    numLines = -1;
                    allFieldsObtained = false;

                    response = Response();
                    while (response != ".\r\n" && response != ".\n" && !allFieldsObtained)
                    {
                        // Find the delimiter--usually a colon but seems to be equals sign sometimes.
                        // If neither is found then move on.
                        int delimiterIdx;
                        delimiterIdx = response.IndexOf(':');
                        if (delimiterIdx == -1) delimiterIdx = response.IndexOf('=');
                        if (delimiterIdx == -1)
                        {
                            response = Response();
                            continue;
                        }

                        string headerFieldName = response.Substring(0, delimiterIdx).ToLower();
                        string headerFieldValue = response.Substring(delimiterIdx + 2);

                        headerFieldValue = headerFieldValue.Replace("\r\n", "");

                        switch (headerFieldName)
                        {
                            case "message-id":
                                id = headerFieldValue;
                                break;
                            case "from":
                                from = headerFieldValue;
                                break;
                            case "date":
                                DateTime.TryParse(headerFieldValue, out date);
                                break;
                            case "subject":
                                subject = headerFieldValue;
                                break;
                            case "lines":
                                int.TryParse(headerFieldValue, out numLines);
                                break;
                            default:
                                break;
                        }

                        allFieldsObtained = (id != "" && from != "" && date != DateTime.MinValue && subject != "" && numLines != -1);
                        if (allFieldsObtained)
                        {
                            // Finish getting rest of header but don't go through the switch.
                            response = Response();
                            while (response != ".\r\n" && response != ".\n")
                            {
                                response = Response();
                            }
                        }
                        else
                        {
                            response = Response();
                        }
                    }

                    Article newArticle;
                    newArticle = new Article(id, sequenceNum, from, date, subject, numLines);
                    articles.Add(newArticle);
                }
            }
            catch
            {
                // Ideally, I want to let this exception raise to the UI but we don't covered
                // exception handling until later, so just swallow it for now.
            }

            return articles;
        }
Beispiel #6
0
        public ArticleCollection Process(ClassRepository rep)
        {
            ArticleCollection artc = new ArticleCollection();


            List <Feature> features = new List <Feature>();

            foreach (KeyValuePair <string, Feature> kv in rep)
            {
                features.Add(kv.Value);
            }
            // Sort so classes are processed first
            features.Sort(delegate(Feature a, Feature b)
            {
                if ((a is SubSystem) && !(b is SubSystem))
                {
                    return(-1);
                }
                else if ((b is SubSystem) && !(a is SubSystem))
                {
                    return(1);
                }
                else if ((a is Class) && !(b is Class))
                {
                    return(1);
                }
                else if ((b is Class) && !(a is Class))
                {
                    return(-1);
                }
                else
                {
                    return(a.GetType().Name.CompareTo(b.GetType().Name));
                }
            });

            //var vocabArticle = new MohawkCollege.EHR.gpmr.Pipeline.Renderer.Deki.Article.Article()
            //{
            //    Title = "Vocabulary",
            //    Children = new ArticleCollection()
            //};
            //vocabArticle.Children.Add(new Article.Article() { Title = "Code Systems" });
            //vocabArticle.Children.Add(new Article.Article() { Title = "Concept Domains" });
            //vocabArticle.Children.Add(new Article.Article() { Title = "Value Sets" });

            //artc.Add(vocabArticle);
            WaitThreadPool wtp = new WaitThreadPool();

            // A thread that does the doohickey thing
            Thread doohickeyThread = new Thread((ThreadStart) delegate()
            {
                string[] hickeythings = { "|", "/", "-", "\\" };
                int hickeyThingCount  = 0;
                try
                {
                    while (true)
                    {
                        int cPosX = Console.CursorLeft, cPosY = Console.CursorTop;
                        Console.SetCursorPosition(1, cPosY);
                        Console.Write(hickeythings[hickeyThingCount++ % hickeythings.Length]);
                        Console.SetCursorPosition(cPosX, cPosY);
                        Thread.Sleep(1000);
                    }
                }
                catch { }
            });

            doohickeyThread.Start();

            // Loop through each feature
            foreach (Feature f in features)
            {
                // Find the feature template
                FeatureTemplate ftpl = NonParameterizedTemplate.Spawn(FindTemplate(f.GetType().FullName, f) as NonParameterizedTemplate, this, f) as FeatureTemplate;

                if (ftpl == null)
                {
                    System.Diagnostics.Trace.WriteLine(string.Format("Feature '{0}' won't be published as no feature template could be located", f.Name), "warn");
                }
                else if (f.Annotations.Find(o => o is SuppressBrowseAnnotation) != null)
                {
                    System.Diagnostics.Trace.WriteLine(String.Format("Feature '{0}' won't be published as a SuppressBrowse annotation was found", f.Name), "warn");
                }
                else if (ftpl.NewPage)
                {
                    System.Diagnostics.Trace.WriteLine(string.Format("Queueing ({1}) '{0}'...", f.Name, f.GetType().Name), "debug");

                    // Create a new worker
                    Worker w = new Worker();
                    w.ArticleCollection = artc;
                    w.FeatureTemplate   = ftpl;
                    w.OnComplete       += delegate(object sender, EventArgs e)
                    {
                        Worker wrkr = sender as Worker;
                        System.Diagnostics.Trace.WriteLine(String.Format("Rendered ({1}) '{0}'...", (wrkr.FeatureTemplate.Context as Feature).Name, wrkr.FeatureTemplate.Context.GetType().Name), "debug");
                    };
                    wtp.QueueUserWorkItem(w.Start);
                }
            }

            System.Diagnostics.Trace.WriteLine("Waiting for work items to complete...", "debug");
            wtp.WaitOne();
            doohickeyThread.Abort();

            ArticleCollection retVal = new ArticleCollection();

            Article.Article MasterTOC = new MohawkCollege.EHR.gpmr.Pipeline.Renderer.Deki.Article.Article();
            MasterTOC.Children = artc;
            System.Diagnostics.Trace.WriteLine("Creating Table of Contents...", "information");
            PrepareTOC(MasterTOC);
            MasterTOC.Children = null;
            artc.Add(MasterTOC);


            return(artc);
        }
Beispiel #7
0
        /// <summary>
        /// query article, all data
        /// </summary>
        /// <param name="ac_id"></param>
        /// <param name="startRowIndex"></param>
        /// <param name="maximumRows"></param>
        /// <param name="orderBy"></param>
        /// <returns>ArticleCollection include all data</returns>
        public static ArticleCollection GetList(int ac_id, int startRowIndex, int maximumRows)
        {
            int iStartRowIndex = -1;
            int iMaximumRows = -1;

            if (startRowIndex > 0 && maximumRows > 0)
            {
                iStartRowIndex = startRowIndex;
                iMaximumRows = maximumRows;
            }

            ArticleCollection tempList = new ArticleCollection();
            string sql = @"SELECT
                            *
                            FROM
                            (
                                select
                                   *, (select ifnull(sum(1) + 1, 1)
                                        from t_article
                                        where (?ac_id=0 or ac_id=?ac_id) and art_id > a.art_id) as row_rank
                                from t_article a
                                where
                                ?ac_id=0
                                or
                                ac_id in (select ac_id from (select ac_id from t_articleclass where ac_id=?ac_id
                                                         union all
                                                         select p.ac_id
                                                         from t_articleclass p
                                                         inner join
                                                         (select ac_id
                                                         from t_articleclass
                                                         where ac_id=?ac_id) t on p.parent_id = t.ac_id) as temp)
                                order by art_id desc
                            )
                            as ArticleWithRowNumbers
                            where
                            ((row_rank between ?start_row_index AND ?start_row_index + ?maximum_rows - 1)
                                        OR ?start_row_index = -1 OR ?maximum_rows = -1)";

            MySqlParameter[] parms = {
                                         new MySqlParameter("?ac_id",MySqlDbType.Int32),
                                         new MySqlParameter("?start_row_index",MySqlDbType.Int32),
                                         new MySqlParameter("?maximum_rows",MySqlDbType.Int32)
                                     };
            parms[0].Value = ac_id;
            parms[1].Value = iStartRowIndex;
            parms[2].Value = iMaximumRows;

            MySqlDataReader myReader = DbHelper.ExecuteDataReader(sql, parms);

            if (myReader.HasRows)
            {
                tempList = new ArticleCollection();
                while(myReader.Read())
                {
                    tempList.Add(FillDataRecord(myReader));
                }
            }

             myReader.Close();

            return tempList;
        }
Beispiel #8
0
        public static ArticleCollection GetTop()
        {
            ArticleCollection list = new ArticleCollection();
            string sql = @"SELECT * FROM t_article ORDER BY art_id DESC LIMIT 3;";

            MySqlDataReader reader = DbHelper.ExecuteDataReader(sql);

            if (reader.HasRows)
            {
                while(reader.Read())
                {
                    list.Add(FillDataRecord(reader));
                }
            }
            reader.Close();

            return list;
        }
Beispiel #9
0
        /// <summary>
        /// query article with condition.
        /// </summary>
        /// <param name="istop"></param>
        /// <param name="iscommand"></param>
        /// <returns></returns>
        public static ArticleCollection GetList(bool istop, bool iscommend)
        {
            bool bIsTop = false;
            bool bIsCommend = false;

            if (istop)
            {
                bIsTop = istop;
            }
            if (iscommend)
            {
                bIsCommend = iscommend;
            }

            ArticleCollection tempList = new ArticleCollection();

            string sql = "select * from T_Article where IsTop=?IsTop and IsCommend=?IsCommend";

            MySqlParameter[] parms = {
                                        new MySqlParameter("?IsTop", MySqlDbType.Bit),
                                        new MySqlParameter("?IsCommend", MySqlDbType.Bit)
                                     };

            parms[0].Value = bIsTop;
            parms[0].Value = bIsCommend;

            MySqlDataReader reader = DbHelper.ExecuteDataReader(sql, parms);

            if (reader.HasRows)
            {
                tempList = new ArticleCollection();
                while (reader.Read())
                {
                    tempList.Add(FillDataRecord(reader));
                }
            }

            reader.Close();

            return tempList;
        }