public IEnumerable <ArticleReference> ListShortArticle() { List <ArticleReference> articles = new List <ArticleReference>(); string sqlExpression = "SELECT Id, Name FROM Articles"; using (SqlConnection connection = new SqlConnection(_connectionString)) { TryOpenConnection(connection); SqlCommand command = new SqlCommand(sqlExpression, connection); using (SqlDataReader reader = command.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { ArticleReference article = new ArticleReference { Id = (int)reader["Id"], Name = (string)reader["Name"] }; articles.Add(article); } } } } return(articles); }
/// <summary> /// Returns the PropertyValue if not empty /// </summary> /// <param name="articleReference">Function</param> /// <param name="identName">Identifing name</param> /// <returns>PropertyValue</returns> public static PropertyValue GetArticleReferencePropertyValueAndCheckIfEmpty(ArticleReference articleReference, string identName) { PropertyValue propertyValue = GetArticleReferencePropertyValue(articleReference, identName); if (propertyValue.IsEmpty) { return(null); } return(propertyValue); }
public EplanArticleReferenceViewModel(ArticleReference articleReference) { if (articleReference == null) { throw new ArgumentNullException(nameof(articleReference)); } this._articleReference = articleReference; SetPublicProperties(); }
public void DeleteReferenceArticle(int id) { Article referenceArticle = GetArticleById(id); List <ArticleCategory> articleCategories = GetArticleCategoriesByArticleId(id); ArticleReference articleReference = GetArticleReferenceByReferenceArticleId(id); if (articleCategories != null) { _context.ArticleCategory.RemoveRange(articleCategories); } _context.ArticleReference.Remove(articleReference); _context.Article.Remove(referenceArticle); _context.SaveChanges(); }
/// <summary> /// Returns the PropertyValue /// </summary> /// <param name="articleReference">Function</param> /// <param name="identName">Identifing name</param> /// <returns>PropertyValue</returns> public static PropertyValue GetArticleReferencePropertyValue(ArticleReference articleReference, string identName) { UserDefinedPropertyDefinition userDefProp = articleReference.Properties.ExistingIds .Select(anyPropertyId => anyPropertyId.Definition) .OfType <UserDefinedPropertyDefinition>() .FirstOrDefault(obj => obj.IdentifyingName.Equals(identName)); if (userDefProp != null) { AnyPropertyId anyPropertyId = userDefProp.Id; PropertyValue propertyValue = articleReference.Properties[anyPropertyId]; return(propertyValue); } return(null); }
public static MDPart CreatePart(ArticleReference articleReference) { // Need to lock project var project = articleReference.Project; project.SmartLock(); if (articleReference.ParentObject != null) { articleReference.ParentObject.SmartLock(); } articleReference.SmartLock(); // Init var partsDatabase = new MDPartsManagement().OpenDatabase(); articleReference.SmartLock(); var partNr = articleReference.PartNr; var partVariant = articleReference.VariantNr; MDPart part = partsDatabase.GetPart(partNr, partVariant); // Create new part if (part == null) { articleReference.SmartLock(); // ReSharper disable once RedundantAssignment part = partsDatabase.AddPart(partNr, partVariant); using (new LockingUtility.SeplaLockingVector()) { new EplApplication().ShowPartSelectionDialog(ref partNr, ref partVariant); } partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part part = partsDatabase.GetPart(partNr, partVariant); } // Load data var article = project.Articles .FirstOrDefault(obj => obj.PartNr.Equals(partNr) && obj.VariantNr.Equals(partVariant) ); if (article != null) { article.SmartLock(); article.LoadFromMasterdata(); } return(part); }
public static MDPart CreatePart(ArticleReference articleReference) { // Need to lock project var project = articleReference.Project; project.SmartLock(); if (articleReference.ParentObject != null) { articleReference.ParentObject.SmartLock(); } articleReference.SmartLock(); // Init var partsDatabase = new MDPartsManagement().OpenDatabase(); //var articleReference = function.ArticleReferences.First(); articleReference.SmartLock(); var partNr = articleReference.PartNr; var partVariant = articleReference.VariantNr; MDPart part = partsDatabase.GetPart(partNr, partVariant); // Create new part if (part == null) { part = partsDatabase.AddPart(partNr, partVariant); // PartSelection to edit data new EplApplication().ShowPartSelectionDialog(ref partNr, ref partVariant); //partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part //part = partsDatabase.GetPart(partNr, partVariant); } // Load data var article = project.Articles .FirstOrDefault(obj => obj.PartNr.Equals(partNr) && obj.VariantNr.Equals(partVariant) ); if (article != null) { article.SmartLock(); article.LoadFromMasterdata(); } return(part); }
/// <summary> /// Sets a value to PropertyValue /// </summary> /// <param name="articleReference">Function</param> /// <param name="identName">Identifing name</param> /// <param name="value">New value</param> public static void SetArticleReferencePropertyValue(ArticleReference articleReference, string identName, object value) { PropertyValue propertyValue = GetArticleReferencePropertyValue(articleReference, identName); if (propertyValue != null) { if (value is bool) { propertyValue.Set((bool)value); return; } if (value is double) { propertyValue.Set((double)value); return; } if (value is MultiLangString) { propertyValue.Set((MultiLangString)value); return; } if (value is PointD) { propertyValue.Set((PointD)value); return; } if (value is int) { propertyValue.Set((int)value); return; } if (value is string) { propertyValue.Set((string)value); return; } if (value is DateTime) { propertyValue.Set((DateTime)value); return; } throw new Exception("Type not supported"); } throw new Exception("Property not found"); }
public ArticleReferences GetById(int id) { string sqlExpressionReference = "SELECT ReferenceId, Name FROM ReferenceToArticle WHERE ArticleId = @id"; ArticleReferences articlesRefs = new ArticleReferences() { Id = id, Refs = new List <ArticleReference>() }; using (SqlConnection connection = new SqlConnection(_connectionString)) { TryOpenConnection(connection); SqlCommand commandRef = new SqlCommand(sqlExpressionReference, connection); commandRef.Parameters.Add("@id", SqlDbType.Int); commandRef.Parameters["@id"].Value = id; using (SqlDataReader readerRef = commandRef.ExecuteReader()) { if (readerRef.HasRows) { while (readerRef.Read()) { ArticleReference articleRef = new ArticleReference { Id = (int)readerRef["ReferenceId"], Name = (string)readerRef["Name"] }; articlesRefs.Refs.Add(articleRef); } } } } return(articlesRefs); }
public static MDPart CreateOrUpdatePart(ArticleReference articleReference, bool updateFunctionTemplate) { // Need to lock project var project = articleReference.Project; project.SmartLock(); //if (articleReference.ParentObject != null) articleReference.ParentObject.SmartLock(); articleReference.SmartLock(); // Init var partsDatabase = new MDPartsManagement().OpenDatabase(); //var articleReference = function.ArticleReferences.First(); articleReference.SmartLock(); var partNr = articleReference.PartNr; var partVariant = articleReference.VariantNr; MDPart part = partsDatabase.GetPart(partNr, partVariant); // Check if article is in project and remove, because the eplan action to create is not possible var existingArticle = project.Articles .FirstOrDefault(obj => obj.PartNr.Equals(partNr) && obj.VariantNr.Equals(partVariant) ); if (existingArticle != null) { existingArticle.SmartLock(); existingArticle.Remove(); } // Need to focus again if its lost if (articleReference.ParentObject is Placement placementToBringInFront) { new Edit().BringToFront(placementToBringInFront); } // Create new part if (part == null) { // LockingVector is needed because of locking exception from EPLAN action (no catch possible) using (new LockingUtility.SeplaLockingVector()) { new CommandLineInterpreter().Execute("XPameCreateType"); } partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part part = partsDatabase.GetPart(partNr, partVariant); } // Existing part else { // Check if pro panel, because there is no update possible bool isProPanel = articleReference.ParentObject is Component; string partNrTemp = partNr; if (!isProPanel) { // Rename part string suffix = "_temp"; partNrTemp = part.PartNr + suffix; try { articleReference.PartNr = partNrTemp; articleReference.ParentObject.SmartLock(); articleReference.StoreToObject(); // Quiet create temp part var application = new EplApplication(); var quiteMode = application.QuietMode; application.QuietMode = EplApplication.QuietModes.ShowNoDialogs; using (new LockingUtility.SeplaLockingVector()) { new CommandLineInterpreter().Execute("XPameCreateType"); } application.QuietMode = quiteMode; } finally { // Rename back articleReference.PartNr = partNr; articleReference.StoreToObject(); } // Copy FunctionTemplate if (updateFunctionTemplate) { partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part MDPart partDuplicate = partsDatabase.GetPart(partNrTemp, partVariant); foreach (var partFunctionTemplatePosition in part.FunctionTemplatePositions) { part.RemoveFunctionTemplatePosition(partFunctionTemplatePosition); } foreach (var partDuplicateFunctionTemplatePosition in partDuplicate.FunctionTemplatePositions) { part.AddFunctionTemplatePosition(partDuplicateFunctionTemplatePosition); } partsDatabase.RemovePart(partDuplicate); } } // Check if article is in project var existingTempArticle = project.Articles .FirstOrDefault(obj => obj.PartNr.Equals(partNrTemp) && obj.VariantNr.Equals(partVariant) ); if (existingTempArticle != null) { existingTempArticle.SmartLock(); existingTempArticle.Remove(); } } // Load data var article = project.Articles .FirstOrDefault(obj => obj.PartNr.Equals(partNr) && obj.VariantNr.Equals(partVariant) ); if (article != null) { article.SmartLock(); article.LoadFromMasterdata(); } return(part); }
// Add sample data private void AddSampleData() { var user1 = new UserProfile() { DisplayName = "jlaw21", FirstName = "Cindy", LastName = "Stone", Email = "*****@*****.**", CreateDateTime = DateTime.Now - TimeSpan.FromDays(150), FirebaseUserId = "TEST_FIREBASE_UID_2", ImageLocation = null, }; var user2 = new UserProfile() { DisplayName = "jlaw21", FirstName = "Jonny", LastName = "Law", Email = "*****@*****.**", CreateDateTime = DateTime.Now - TimeSpan.FromDays(400), FirebaseUserId = "TEST_FIREBASE_UID_2", ImageLocation = null, }; var article1 = new Article() { UserProfileId = 1, Author = "@rogervincent", Publisher = "latimes", CurrentsId = "553abec9-6f64-4787-8244-46788b4d195c", Title = "Motels are having a moment. It's a coronavirus thing", Description = "Motels, long the orphans of the hospitality industry, stand to gain popularity as people hit the road again and seek to avoid interior spaces....", Url = "https://www.latimes.com/business/story/2020-07-24/motels-coronavirus-design", UserTitle = "Dune Ipsum", Content = "Beneath hostility proverb creates about Paul, whenever tends. Wife grasps legendary around sand. Purpose seeks the imperium stops the unique Rautha. Over native so Harah, beside Lisan al-Gaib and the reflection. For thinking where assassination above the trained Ichwan Bedwine. Self-control reaches the deep-sand Tleilax.", CreateDateTime = DateTime.Now - TimeSpan.FromDays(10), Image = "https://ca-times.brightspotcdn.com/dims4/default/8eb9564/2147483647/strip/true/crop/5760x3240+0+300/resize/1200x675!/quality/90/?url=https%3A%2F%2Fcalifornia-times-brightspot.s3.amazonaws.com%2F1d%2F58%2F6cab4fd8479d94bb8f1892ca19fe%2Fap18290829832389.jpg", Language = "en", Published = Convert.ToDateTime("2020-07-24 18:03:42 +0000"), Objectivity = 0.50, Sentimentality = 0.50 }; var article2 = new Article() { UserProfileId = 2, Author = "The Bon Appétit Staff", Publisher = "bonappetit", CurrentsId = "f624f638-ac4a-4577-a312-a647e36f3b7d", Title = "93 Grilling Recipes So You Don’t Have to Cook Anything Inside", Description = "From ribs to shrimp, chicken to veggies, fish to ... so much more, get grilling with these recipes!...", Url = "https://www.bonappetit.com/recipes/slideshow/60-favorite-grilling-recipes-almost-everything", UserTitle = "Dune Ipsum User 2", Content = "The breeding program passes for question, against spannungsbogen yet enemy threatens instinctual. The water burden stops near exploitation. Nothing sinks superior out Water of Life. Awakening uses for the kiswa ridge beside the Jamis chooses extreme. The Leto manipulates, the Wellington clouds. Spacing Guild disobeys the superior the Way. Between the prompt guilt disturbs the scorched conditioning yet the weirding homeworld nor terrifies Hasimir.", CreateDateTime = DateTime.Now - TimeSpan.FromDays(20), Image = "https://assets.bonappetit.com/photos/5cdf092b56f182a9a3eb2e97/16:9/w_1600,c_limit/grilled-scallops-with-nori-ginger-lime.jpg", Language = "en", Published = Convert.ToDateTime("2020-07-24 13:00:00 +0000"), Objectivity = 0.50, Sentimentality = 0.50 }; var referenceArticle1 = new Article() { UserProfileId = 1, Author = "The Associated Press", Publisher = "seattletimes", CurrentsId = "774bc577-f284-41a8-ad58-cd99e252332c", Title = "FAA orders emergency engine checks of parked Boeing 737s", Description = "Airlines parked hundreds of planes when the coronavirus pandemic triggered a collapse in air travel and are slowly bringing some of those planes....", Url = "https://www.seattletimes.com/business/faa-orders-emergency-engine-checks-of-parked-boeing-737s/", CreateDateTime = DateTime.Now - TimeSpan.FromDays(1), Language = "en", Published = Convert.ToDateTime("2020-07-24 16:25:16 +0000"), Objectivity = 0.50, Sentimentality = 0.50 }; var referenceArticle2 = new Article() { UserProfileId = 2, Author = "Tyler Durden", Publisher = "google", CurrentsId = "a9fa3cca-e0e7-4ce2-95d3-12ffd7e9d97b", Title = "Some Optimism From Goldman: The Number Of New COVID Cases Is Starting To Flatten", Description = "Some Optimism From Goldman: The Number Of New COVID Cases Is Starting To Flatten \n\nTyler Durden\n\nFri, 07/24/2020 - 12:05\nAs the US reports more than 1k deaths for the third straight day, reporters are mostly focusing on this milestone, along with the US surmounting the 4 million-case mark, as the bi...", Url = "http://feedproxy.google.com/~r/zerohedge/feed/~3/97bxxwviQ-Q/some-optimism-goldman-number-new-covid-cases-starting-flatten", CreateDateTime = DateTime.Now - TimeSpan.FromDays(1), Language = "en", Published = Convert.ToDateTime("2020-07-24 16:05:00 +0000"), Objectivity = 0.50, Sentimentality = 0.50 }; var articleCategory1 = new ArticleCategory() { ArticleId = 1, CategoryId = 4 }; var articleCategory2 = new ArticleCategory() { ArticleId = 2, CategoryId = 18 }; var articleCategory3 = new ArticleCategory() { ArticleId = 3, CategoryId = 4 }; var articleCategory4 = new ArticleCategory() { ArticleId = 4, CategoryId = 18 }; var articleReference1 = new ArticleReference() { ArticleId = 1, ReferenceArticleId = 3 }; var articleReference2 = new ArticleReference() { ArticleId = 2, ReferenceArticleId = 4 }; _context.Add(user1); _context.Add(user2); _context.Add(article1); _context.Add(article2); _context.Add(referenceArticle1); _context.Add(referenceArticle2); _context.Add(articleCategory1); _context.Add(articleCategory2); _context.Add(articleCategory3); _context.Add(articleCategory4); _context.Add(articleReference1); _context.Add(articleReference2); _context.SaveChanges(); }
public async Task <List <ArticleReference> > GetAll(int page = 1) { if (page < 1) { throw new ArgumentOutOfRangeException(); } // container for the post request's response var resultObject = new ApiResponse(); using (var client = new HttpClient()) { // Create form data content var formData = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>( "action", "td_ajax_loop"), new KeyValuePair <string, string>( "loopState[moduleId]", "5"), new KeyValuePair <string, string>( "loopState[currentPage]", page.ToString()), new KeyValuePair <string, string>( "loopState[atts][category_id]", "4") // National news category }; var formContent = new FormUrlEncodedContent(formData); // Submit post request to api using (var response = await client.PostAsync(apiUrl, formContent)) { response.EnsureSuccessStatusCode(); var responseContent = await response.Content.ReadAsStringAsync(); resultObject = JsonConvert.DeserializeObject <ApiResponse>(responseContent); } } // Parse the resulting html var html = new HtmlDocument(); html.LoadHtml(resultObject.HtmlData); var newsNodes = html.DocumentNode.SelectNodes("//*[contains(@class, 'td_module_wrap')]"); var result = new List <ArticleReference>(); foreach (var news in newsNodes) { // breakdown html content into object property var article = new ArticleReference { ArticleUrl = new Uri( news.SelectSingleNode(".//h3[contains(@class, 'td-module-title')]/a") .Attributes["href"].Value).AbsolutePath, Title = news.SelectSingleNode(".//h3[contains(@class, 'td-module-title')]/a").InnerText, Excerpt = news.SelectSingleNode(".//div[contains(@class, 'td-excerpt')]").InnerText.Trim(), ThumbnailUrl = new Uri( news.SelectSingleNode(".//div[contains(@class, 'td-module-thumb')]/a/img") .Attributes["src"].Value), PublishedDate = DateTime.Parse( news.SelectSingleNode(".//time").Attributes["datetime"].Value) }; result.Add(article); } return(result); }
public IActionResult Post(ArticleReference snippetReferrence) { _snippetRepository.AddArticleReference(snippetReferrence); return(CreatedAtAction("Get", new { id = snippetReferrence.Id }, snippetReferrence)); }
//Beginning of ArticleReference methods. public void AddArticleReference(ArticleReference articleReferrence) { _context.Add(articleReferrence); _context.SaveChanges(); }