public Task <List <string> > CreateTagsAsync(List <string> tagList)
        {
            return(Task.Run(() =>
            {
                List <Entities.Tag> newTags = new();

                foreach (var tagName in tagList)
                {
                    var tag = dbContext.Tags.FirstOrDefault(x => x.Name == tagName);

                    if (tag == null)
                    {
                        tag = new Entities.Tag
                        {
                            Slug = UtilityService.GenerateSlug(tagName),
                            Name = tagName
                        };

                        dbContext.Tags.Add(tag);
                    }

                    newTags.Add(tag);
                }

                dbContext.SaveChanges();

                return newTags.Select(x => x.Slug).ToList();
            }));
        }
Esempio n. 2
0
        internal static Tag ToDto(Entities.Tag tag, bool include_subjects = false)
        {
            if (tag == null)
            {
                return(null);
            }
            if (include_subjects)
            {
                return(new Tag
                {
                    Id = tag.Id,
                    Description = tag.Description,
                    Subjects = tag.Subjects.Select(s => SubjectRepository.ToDto(s.Subject, false, false)).ToList(),
                    Category = TagCategoryRepository.ToDto(tag.Category),

                    Parent = ToDto(tag.Parent),
                    Children = tag.Children.Select(t => ToDto(t)).ToList()
                });
            }
            else
            {
                return(new Tag
                {
                    Id = tag.Id,
                    Description = tag.Description,
                    Category = TagCategoryRepository.ToDto(tag.Category)
                });
            }
        }
Esempio n. 3
0
        public object CreateDataShapedObject(Entities.Tag tag, List <string> lstOfFields)
        {
            if (!lstOfFields.Any())
            {
                return(tag);
            }
            else
            {
                // create a new ExpandoObject & dynamically create the properties for this object

                ExpandoObject objectToReturn = new ExpandoObject();
                foreach (var field in lstOfFields)
                {
                    // need to include public and instance, b/c specifying a binding flag overwrites the
                    // already-existing binding flags.

                    var fieldValue = tag.GetType()
                                     .GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)
                                     .GetValue(tag, null);

                    // add the field to the ExpandoObject
                    ((IDictionary <String, Object>)objectToReturn).Add(field, fieldValue);
                }

                return(objectToReturn);
            }
        }
 public static Data.Entities.Tag MapTag(Logic.Objects.Tag logicTag)
 {
     Data.Entities.Tag contextTag = new Entities.Tag()
     {
         TagId   = logicTag.tagID,
         TagName = logicTag.tagName
     };
     return(contextTag);
 }
 public static Logic.Objects.Tag MapTag(Entities.Tag contextTag)
 {
     Logic.Objects.Tag logicTag = new Logic.Objects.Tag()
     {
         tagID        = contextTag.TagId,
         tagName      = contextTag.TagName,
         deletable    = contextTag.ClientTagXrefs.Count > 0 ? false : true,
         tagImmutable = contextTag.TagName == Constants.MASS_MAILER_TAG || contextTag.TagName == Constants.MASS_MAIL_RECIPIENT_TAG || contextTag.TagName == Constants.GRINCH_TAG ? true : false
     };
     return(logicTag);
 }
Esempio n. 6
0
        internal static async Task <Entities.Tag> ToEntity(Tag tag, MintPlayerContext mintplayer_context)
        {
            if (tag == null)
            {
                return(null);
            }
            var entity_tag = new Entities.Tag
            {
                Id          = tag.Id,
                Description = tag.Description,
                Category    = mintplayer_context.TagCategories.Find(tag.Category.Id)
            };

            if (tag.Parent != null)
            {
                entity_tag.Parent = await mintplayer_context.Tags.FindAsync(tag.Parent.Id);
            }
            return(entity_tag);
        }
Esempio n. 7
0
        public static TagDto Build(Entities.Tag tag)
        {
            List <string> imageUrls = new List <string>();

            if (tag.TagImages != null)
            {
                foreach (var tagImage in tag.TagImages)
                {
                    imageUrls.Add(tagImage.FilePath);
                }
            }

            return(new TagDto
            {
                Id = tag.Id,
                Name = tag.Name,
                Description = tag.Description,
                ImageUrls = imageUrls
            });
        }
Esempio n. 8
0
        private void DownloadTags()
        {
            Database   db = new Database();
            Repository repo;
            //List<Entities.Tag> tagList;
            //Entities.Tag tag;
            NotificationArgs notificationArgs;

            var directories = Directory.GetDirectories(downloadDirectory);

            //int counter = 0;
            //int groupSize = Convert.ToInt32(Math.Ceiling(directories.Count() / 3.0));
            //var result = directories.GroupBy(s => counter++ / groupSize).Select(g => g.ToArray()).ToList();
            //int threadCount = result.Count() + 1;


            string repoURL, archiveURL, tagDownloadLocation, tagArchive;

            foreach (var directory in directories)
            {
                string lastFolderName = Path.GetFileName(directory);
                long   appId          = db.GetAppByName(lastFolderName).Id;
                try
                {
                    repo = new Repository(directory);
                    List <Entities.Tag> tagList = new List <Entities.Tag>();
                    repoURL = repo.Config.GetValueOrDefault <string>("remote.origin.url");

                    int tagCount = repo.Tags.Count();

                    notificationArgs = new NotificationArgs(string.Format("Started - Tags for {0} - Total tags: {1}", lastFolderName, tagCount), DateTime.Now, NotificationType.INFORMATION);
                    OnMessageIssued(notificationArgs);

                    var xxx = repo.Tags.OrderBy(b => ((LibGit2Sharp.Commit)b.PeeledTarget).Author.When.LocalDateTime);

                    LibGit2Sharp.Commit tg;
                    foreach (var t in xxx)
                    {
                        tg = (LibGit2Sharp.Commit)t.PeeledTarget;
                        Entities.Tag tag = new Entities.Tag(t.FriendlyName, tg.MessageShort, tg.Author.Email, tg.Id.ToString(), tg.Author.When.LocalDateTime);
                        tagList.Add(tag);

                        using (var client = new WebClient())
                        {
                            if (repoURL.Substring(repoURL.Length - 4).Equals(".git", StringComparison.CurrentCultureIgnoreCase))
                            {
                                archiveURL = string.Format("{0}/archive/{1}.zip", repoURL.Substring(0, repoURL.Length - 4), t.FriendlyName);
                            }
                            else
                            {
                                archiveURL = string.Format("{0}/archive/{1}.zip", repoURL, t.FriendlyName);
                            }
                            tagDownloadLocation = string.Format(@"{0}\{1}\{2}", tagDownloadDirectory, lastFolderName, t.FriendlyName);
                            tagArchive          = string.Format(@"{0}\{1}\{2}.zip", tagDownloadDirectory, lastFolderName, t.FriendlyName);
                            Directory.CreateDirectory(tagDownloadLocation);

                            client.Credentials = CredentialCache.DefaultCredentials;
                            client.DownloadFile(archiveURL, tagArchive);

                            if (true)
                            {
                                lock (locker)
                                {
                                    ZipFile.ExtractToDirectory(tagArchive, tagDownloadLocation);
                                    File.Delete(tagArchive);
                                }
                            }
                        }
                    }

                    db.BatchInsertTag(tagList, appId);

                    notificationArgs = new NotificationArgs(string.Format("Completed - Tags for {0}", lastFolderName), DateTime.Now, NotificationType.SUCCESS);
                    OnMessageIssued(notificationArgs);
                }
                catch (Exception error)
                {
                    LogFailure(string.Format("Failed - Tags for {0} ; {1}", lastFolderName, error.Message));
                    notificationArgs = new NotificationArgs("Failed -  Tags for " + lastFolderName, DateTime.Now, NotificationType.FAILURE);
                    OnMessageIssued(notificationArgs);
                    continue;
                }
            }



            //Parallel.For(0, threadCount, i =>
            //{
            //    var dataSet = result.ElementAtOrDefault(i);
            //    if (dataSet != null)
            //    {
            //        Console.WriteLine("Processing dataset: " + i + "; Count: " + dataSet.Count());
            //        string repoURL, archiveURL, tagDownloadLocation, tagArchive;
            //        foreach (var directory in dataSet)
            //        {
            //            string lastFolderName = Path.GetFileName(directory);
            //            long appId = db.GetAppByName(lastFolderName).Id;
            //            try
            //            {
            //                repo = new Repository(directory);
            //                List<Entities.Tag> tagList = new List<Entities.Tag>();
            //                repoURL = repo.Config.GetValueOrDefault<string>("remote.origin.url");

            //                int tagCount = repo.Tags.Count();

            //                notificationArgs = new NotificationArgs(string.Format("Started - Tags for {0} - Total tags: {1}", lastFolderName, tagCount), DateTime.Now, NotificationType.INFORMATION);
            //                OnMessageIssued(notificationArgs);

            //                var xxx = repo.Tags.OrderBy(b => ((LibGit2Sharp.Commit)b.PeeledTarget).Author.When.LocalDateTime);

            //                LibGit2Sharp.Commit tg;
            //                foreach (var t in xxx)
            //                {
            //                    tg = (LibGit2Sharp.Commit)t.PeeledTarget;
            //                    Entities.Tag tag = new Entities.Tag(t.FriendlyName, tg.MessageShort, tg.Author.Email, tg.Id.ToString(), tg.Author.When.LocalDateTime);
            //                    tagList.Add(tag);

            //                    using (var client = new WebClient())
            //                    {
            //                        if (repoURL.Substring(repoURL.Length - 4).Equals(".git", StringComparison.CurrentCultureIgnoreCase))
            //                            archiveURL = string.Format("{0}/archive/{1}.zip", repoURL.Substring(0, repoURL.Length - 4), t.FriendlyName);
            //                        else
            //                            archiveURL = string.Format("{0}/archive/{1}.zip", repoURL, t.FriendlyName);
            //                        tagDownloadLocation = string.Format(@"{0}\{1}\{2}", tagDownloadDirectory, lastFolderName, t.FriendlyName);
            //                        tagArchive = string.Format(@"{0}\{1}\{2}.zip", tagDownloadDirectory, lastFolderName, t.FriendlyName);
            //                        Directory.CreateDirectory(tagDownloadLocation);

            //                        client.Credentials = CredentialCache.DefaultCredentials;
            //                        client.DownloadFile(archiveURL, tagArchive);

            //                        if (extractArchive)
            //                        {
            //                            ZipFile.ExtractToDirectory(tagArchive, tagDownloadLocation);
            //                            File.Delete(tagArchive);
            //                        }

            //                    }
            //                }

            //                db.BatchInsertTag(tagList, appId);

            //                notificationArgs = new NotificationArgs(string.Format("Completed - Tags for {0}", lastFolderName), DateTime.Now, NotificationType.SUCCESS);
            //                OnMessageIssued(notificationArgs);
            //            }
            //            catch (Exception error)
            //            {
            //                LogFailure(string.Format("Failed - Tags for {0} ; {1}", lastFolderName, error.Message));
            //                notificationArgs = new NotificationArgs("Failed -  Tags for " + lastFolderName, DateTime.Now, NotificationType.FAILURE);
            //                OnMessageIssued(notificationArgs);
            //                continue;
            //            }
            //        }
            //    }
            //});
        }