Esempio n. 1
0
        public static TeamMentor_Article xmlDB_NewGuidanceItem(this TM_Xml_Database tmDatabase, Guid guidanceItemId,
                                                               string title, string images,
//															   DateTime lastUpdate,
                                                               string topic, string technology, string category,
                                                               string ruleType, string priority, string status,
                                                               string author, string phase, string htmlContent,
                                                               Guid libraryId)
        {
            var article = new TeamMentor_Article();

            article.Metadata = new TeamMentor_Article_Metadata()
            {
                Id = (guidanceItemId == Guid.Empty)
                                                                                                        ? Guid.NewGuid()
                                                                                                        : guidanceItemId,
                Library_Id = libraryId,
                Author     = author,
                Category   = category,
                Priority   = priority,
                Type       = ruleType,
                //.Source ;
                Status     = status,
                Technology = technology,
                Title      = title,
                Phase      = phase,
                //			.Type1;
                //			.type;
            };
            article.Content = new TeamMentor_Article_Content()
            {
                DataType = "html"
                           //Sanitized = false
            };
            article.Content.Data.Value = htmlContent;

            /*var guidanceItem  = new guidanceItem()
             *                                              {
             *                                                      id = (guidanceItemId == Guid.Empty)
             *                                                                              ? Guid.NewGuid().str()
             *                                                                              : guidanceItemId.str(),
             *                                                      Author = author,
             *                                                      Category = category,
             *                                                      content = htmlContent,
             *              //					Date = lastUpdate.str(),
             *                                                      Priority = priority,
             *                                                      Rule_Type = ruleType,
             *                                                      //.Source ;
             *                                                      Status = status,
             *                                                      Technology = technology,
             *                                                      title = title,
             *                                                      Topic = topic,
             *                                                      phase = phase,
             *                                                      libraryId = libraryId.str()
             *                              //			.Type1;
             *                              //			.type;
             *                                              };
             */
            article.xmlDB_Save_Article(libraryId, tmDatabase);
            return(article.htmlEncode());  //this was causing double encoding problems with some properties (like the Title)
        }
 public static Guid xmlDB_Create_Article(this TM_Xml_Database tmDatabase, TeamMentor_Article article)
 {
     article.Metadata.Id = Guid.NewGuid();
     if(article.xmlDB_Save_Article(tmDatabase))
         return article.Metadata.Id;
     return Guid.Empty;
 }
 public static bool titleMatch(TeamMentor_Article article, string title1, string title2)
 {
     var match = (article.Metadata.Title.notNull() && (article.Metadata.Title.lower() == title1) ||
                                                       article.Metadata.Title.lower() == title2);
     if (match)
     {
     }
     return match;
 }
Esempio n. 4
0
 public static Guid xmlDB_Create_Article(this TM_Xml_Database tmDatabase, TeamMentor_Article article)
 {
     article.Metadata.Id = Guid.NewGuid();
     if (article.xmlDB_Save_Article(tmDatabase))
     {
         return(article.Metadata.Id);
     }
     return(Guid.Empty);
 }
Esempio n. 5
0
        public static bool titleMatch(TeamMentor_Article article, string title1, string title2)
        {
            var match = (article.Metadata.Title.notNull() && (article.Metadata.Title.lower() == title1) ||
                         article.Metadata.Title.lower() == title2);

            if (match)
            {
            }
            return(match);
        }
Esempio n. 6
0
        [WebMethod(EnableSession = true)][EditArticles(SecurityAction.Demand)]   public Guid CreateArticle_Simple(Guid libraryId, string title, string dataType, string htmlCode)
        {
            this.resetCache();
            var article = new TeamMentor_Article();

            article.Metadata.Library_Id = libraryId;
            article.Metadata.Title      = title;
            article.Content.DataType    = dataType;
            article.Content.Data.Value  = htmlCode;
            return(javascriptProxy.CreateArticle(article));
        }
Esempio n. 7
0
        private bool handleAction_Create(string data)
        {
            var article = new TeamMentor_Article();

            article.Metadata.Title = data.urlDecode();
            var xmlContent = article.serialize(false)
                             .add_Xslt("Article_Edit.xslt");

            context.Response.ContentType = "application/xml";
            context.Response.Write(xmlContent);
            return(true);
        }
        public static TeamMentor_Article createArticle_from_ExternalServiceData(this string service, string serviceData)
        {
            try
            {
                Func <string, string, TeamMentor_Article> createArticleFromUrl =
                    (title, url) => {
                    var externalArticle = new TeamMentor_Article();
                    externalArticle.Metadata.Title = title;
                    System.Net.WebClient webClient = new System.Net.WebClient();
                    webClient.Headers.Add("User-Agent", "TeamMentor");
                    var htmlContent   = webClient.DownloadString(url);
                    var sanitizedHtml = Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(htmlContent);
                    externalArticle.Content.Data.Value = sanitizedHtml;
                    return(externalArticle);
                };

                //Web.Https.ignoreServerSslErrors();
                switch (service)
                {
                case "wikipedia":
                {
                    var url = "https://en.wikipedia.org/wiki/{0}?action=render".format(serviceData);
                    return(createArticleFromUrl("From Wikipedia.org: " + serviceData, url));
                }

                case "owasp":
                {
                    var title = "From owasp.org: " + serviceData;
                    var url   = "https://www.owasp.org/index.php/{0}?action=render".format(serviceData);
                    return(createArticleFromUrl(title, url));
                }

                case "msdn":
                {
                    var externalArticle = new TeamMentor_Article();
                    externalArticle.Metadata.Title = "From MSDN: " + service;
                    var msdnUrl = "http://msdn.microsoft.com/en-us/library/{0}.aspx".format(serviceData);

                    externalArticle.Content.Data.Value = @"<IFrame src='{0}'/ id='msdnContent' style='width:99%;height:500px' frameborder='0'></IFrame>
																	<script>$('#msdnContent').height(document.height-180)</script>"                                                                    .format(msdnUrl);

                    return(externalArticle);
                }
                }
            }
            catch (Exception ex)
            {
                ex.log("in createArticleFromExternalServiceData");
            }
            return(null);
        }
Esempio n. 9
0
        public static bool article_Save(this TM_FileStorage tmFileStorage, TeamMentor_Article article)
        {
            editArticles.demand();
            var libraryId = article.Metadata.Library_Id;

            var guidanceXmlPath = tmFileStorage.getXmlFilePathForGuidanceId(article.Metadata.Id, libraryId);

            if (guidanceXmlPath.valid())
            {
                "Saving GuidanceItem {0} to {1}".info(article.Metadata.Id, guidanceXmlPath);
                article.saveAs(guidanceXmlPath);
                return(guidanceXmlPath.fileExists());
            }
            return(true);
        }
Esempio n. 10
0
        public static bool article_Delete(this TM_FileStorage tmFileStorage, TeamMentor_Article article)
        {
            editArticles.demand();
            var guidanceItemId = article.Metadata.Id;

            var guidanceItemXmlPath = tmFileStorage.removeGuidanceItemFileMapping(guidanceItemId);

            "removing GuidanceItem with Id:{0} located at {1}".info(guidanceItemId, guidanceItemXmlPath);
            if (guidanceItemXmlPath.valid())
            {
                Files.deleteFile(guidanceItemXmlPath);
            }

            tmFileStorage.tmXmlDatabase().Events.Articles_Cache_Updated.raise(); //tmDatabase.queue_Save_GuidanceItemsCache();

            //TM_Xml_Database.mapGuidanceItemsViews();
            return(true);
        }
        public static TeamMentor_Article update_Cache_GuidanceItems(this TeamMentor_Article guidanceItem, TM_Xml_Database tmDatabase)
        {
            guidanceItem.htmlEncode(); // ensure MetaData is encoded

            var guidanceItemGuid = guidanceItem.Metadata.Id;

            if (TM_Xml_Database.Cached_GuidanceItems.hasKey(guidanceItemGuid))
            {
                TM_Xml_Database.Cached_GuidanceItems[guidanceItemGuid] = guidanceItem;
            }
            else
            {
                TM_Xml_Database.Cached_GuidanceItems.Add(guidanceItem.Metadata.Id, guidanceItem);
            }

            tmDatabase.queue_Save_GuidanceItemsCache();

            return(guidanceItem);
        }
Esempio n. 12
0
        public static bool xmlDB_Save_Article(this TeamMentor_Article article, Guid libraryId, TM_Xml_Database tmDatabase)
        {
            if (libraryId == Guid.Empty)
            {
                "[xmlDB_Save_GuidanceItem] no LibraryId was provided".error();
                return(false);
            }
            var xmlLibraries    = TM_Xml_Database.Path_XmlLibraries;
            var guidanceXmlPath = tmDatabase.getXmlFilePathForGuidanceId(article.Metadata.Id, libraryId);

            "Saving GuidanceItem {0} to {1}".info(article.Metadata.Id, guidanceXmlPath);

            //tidy the html
            if (article.Content.DataType.lower() == "html")
            {
                var cdataContent = article.Content.Data.Value.replace("]]>", "]] >"); // xmlserialization below will break if there is a ]]>  in the text
                //cdataContent = cdataContent.fixXmlDoubleEncodingIssue();
                var tidiedHtml = cdataContent.tidyHtml();

                article.Content.Data.Value = tidiedHtml;
                if (article.serialize(false).inValid())        //see if the tidied content can be serialized  and if not use the original data
                {
                    article.Content.Data.Value = cdataContent;
                }
            }
            article.Metadata.Library_Id = libraryId;        //ensure the LibraryID is correct

            if (article.serialize(false).valid())           // make sure the article can be serilialized  correctly
            {
                article.saveAs(guidanceXmlPath);
                //add it to in Memory cache
                article.update_Cache_GuidanceItems(tmDatabase);
                return(guidanceXmlPath.fileExists());
            }
            return(false);
        }
        public static TeamMentor_Article createArticle_from_ExternalServiceData(this string service, string serviceData)
        {
            try
            {
                Func<string, string, TeamMentor_Article> createArticleFromUrl =
                    (title, url) =>	{
                                        var externalArticle = new TeamMentor_Article();
                                        externalArticle.Metadata.Title = title;
                                        System.Net.WebClient webClient = new System.Net.WebClient();
                                        webClient.Headers.Add("User-Agent", "TeamMentor");
                                        var htmlContent = webClient.DownloadString(url);
                                        var sanitizedHtml = Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(htmlContent);
                                        externalArticle.Content.Data.Value = sanitizedHtml;
                                        return externalArticle;
                                    };

                //Web.Https.ignoreServerSslErrors();
                switch (service)
                {
                    case "wikipedia":
                        {
                            var url = "https://en.wikipedia.org/wiki/{0}?action=render".format(serviceData);
                            return createArticleFromUrl("From Wikipedia.org: " + serviceData, url);
                        }
                    case "owasp":
                        {

                            var title  = "From owasp.org: " + serviceData;
                            var url = "https://www.owasp.org/index.php/{0}?action=render".format(serviceData);
                            return createArticleFromUrl(title, url);
                        }
                    case "msdn":
                        {

                            var externalArticle = new TeamMentor_Article();
                            externalArticle.Metadata.Title = "From MSDN: " + service;
                            var msdnUrl = "http://msdn.microsoft.com/en-us/library/{0}.aspx".format(serviceData);

                            externalArticle.Content.Data.Value = @"<IFrame src='{0}'/ id='msdnContent' style='width:99%;height:500px' frameborder='0'></IFrame>
                                                                    <script>$('#msdnContent').height(document.height-180)</script>".format(msdnUrl);

                            return externalArticle;
                        }
                }
            }
            catch (Exception ex)
            {
                ex.log("in createArticleFromExternalServiceData");
            }
            return null;
        }
Esempio n. 14
0
 public static bool xmlDB_Save_Article(this TeamMentor_Article article, TM_Xml_Database tmDatabase)
 {
     return(article.xmlDB_Save_Article(article.Metadata.Library_Id, tmDatabase));
 }
Esempio n. 15
0
        [WebMethod(EnableSession = true)][EditArticles(SecurityAction.Demand)]   public bool UpdateGuidanceItem(TeamMentor_Article guidanceItem)
        {
            this.resetCache();
            var result = javascriptProxy.UpdateGuidanceItem(guidanceItem);

            return(result);
        }
 public Guid CreateArticle(TeamMentor_Article article)
 {
     return(tmXmlDatabase.xmlDB_Create_Article(article));
 }
Esempio n. 17
0
 [WebMethod(EnableSession = true)][EditArticles(SecurityAction.Demand)]   public Guid CreateArticle(TeamMentor_Article article)
 {
     this.resetCache(); return(javascriptProxy.CreateArticle(article));
 }
 public static IE_TeamMentor article(this IE_TeamMentor ieTeamMentor, TeamMentor_Article tmArticle)
 {
     return(ieTeamMentor.article(tmArticle.Metadata.Id));
 }
 private bool handleAction_Create(string data)
 {
     var article = new TeamMentor_Article();
     article.Metadata.Title = data.urlDecode();
     var xmlContent = article.serialize(false)
                             .add_Xslt("Article_Edit.xslt");
     context.Response.ContentType = "application/xml";
     context.Response.Write(xmlContent);
     return true;
 }
 public static IE_TeamMentor article_Html(this IE_TeamMentor ieTeamMentor, TeamMentor_Article tmArticle)
 {
     return((ieTeamMentor.notNull() && tmArticle.notNull())
         ? ieTeamMentor.article_Html(tmArticle.Metadata.Id)
         : ieTeamMentor);
 }
		public static TeamMentor_Article xmlDB_NewGuidanceItem(this TM_Xml_Database tmDatabase, Guid guidanceItemId, 
															   string title, string images,
//															   DateTime lastUpdate, 
															   string topic, string technology, string category, 
															   string ruleType, string priority, string status, 
															   string author,string phase,  string htmlContent, 
															   Guid libraryId)
		{			
				
		    var article = new TeamMentor_Article();
            article.Metadata = new TeamMentor_Article_Metadata()
                					{
										Id = (guidanceItemId == Guid.Empty) 
													? Guid.NewGuid()
													: guidanceItemId,
                                        Library_Id = libraryId,
										Author = author,
										Category = category,
										Priority = priority,
										Type = ruleType,
										//.Source ;
										Status = status,
										Technology = technology,
										Title = title,										
										Phase = phase, 										
							//			.Type1;
							//			.type;
									};
            article.Content = new TeamMentor_Article_Content()
                                    {     
                                        DataType  = "html"
                                        //Sanitized = false
                                    };
            article.Content.Data.Value  = htmlContent;
			/*var guidanceItem  = new guidanceItem()
									{
										id = (guidanceItemId == Guid.Empty) 
													? Guid.NewGuid().str()
													: guidanceItemId.str(),
										Author = author,
										Category = category,
										content = htmlContent,
					//					Date = lastUpdate.str(),	
										Priority = priority,
										Rule_Type = ruleType,
										//.Source ;
										Status = status,
										Technology = technology,
										title = title,
										Topic = topic,
										phase = phase, 
										libraryId = libraryId.str()
							//			.Type1;
							//			.type;
									};
             */ 
			article.xmlDB_Save_Article(libraryId, tmDatabase);			
			return article.htmlEncode();
		}
 public bool UpdateGuidanceItem(TeamMentor_Article article)
 {
     return(article.xmlDB_Save_Article(tmXmlDatabase));
 }
 public Guid CreateArticle   (TeamMentor_Article article)						    { return tmXmlDatabase.xmlDB_Create_Article(article); }  	
 public bool UpdateGuidanceItem(TeamMentor_Article article)                          { return article.xmlDB_Save_Article(tmXmlDatabase); }