Exemplo n.º 1
0
        private void TagImage(ITagManager tagManager)
        {
            foreach (var tagName in TagNames)
            {
                var tag = TagFacade.FindByTagName(tagName);

                if (tag == null)
                {
                    tag = new TagViewModel(Guid.NewGuid(), tagName);
                    TagFacade.Insert(tag);
                    tagManager.Tags.Add(tag);
                }

                _images = new List <ImageViewModel>();

                var pages = PageFacade.FindByBookId(_BookID);
                for (int i = 0; i < pages.Count(); ++i)
                {
                    var page = pages.ElementAt(i);
                    PageFacade.GetProperty(ref page);
                    _images.Add(page.Image);
                }

                ImageTagFacade.BatchInsert(tag, _images);

                foreach (var imageTag in _images.Select(i => new ImageTagViewModel(i.ID, tag)))
                {
                    tagManager.Chains.Add(imageTag);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// gets the home of challenge module
        /// </summary>
        /// <param name="mod">identifier of module</param>
        /// <param name="sectionId">identifier of section</param>
        /// <returns>returns the result to action</returns>
        public ActionResult Index(int mod, int?sectionId)
        {
            ContentManagement  objcontentman = new ContentManagement(this.SessionCustom, HttpContext);
            SectionRepository  objsection    = new SectionRepository(this.SessionCustom);
            TemplateRepository objtemplate   = new TemplateRepository(this.SessionCustom);
            ContentRepository  objcontent    = new ContentRepository(SessionCustom);
            TagFacade          tagFacade     = new TagFacade();

            objtemplate.Entity.Type = 0;

            return(this.View(new ChallengeModel()
            {
                UserPrincipal = this.CustomUser,
                Module = this.Module,
                ColModul = CustomMemberShipProvider.GetModuls(this.CustomUser.UserId, this.SessionCustom, HttpContext),
                Templates = objtemplate.GetAll().Select(t => t.TemplateId),
                DeepFollower = sectionId != null ? Business.Utils.GetDeepFollower(objsection.GetAll(), sectionId.Value) : null,
                IContent = new Domain.Entities.Content()
                {
                    ModulId = mod,
                    SectionId = sectionId
                },
                CurrentLanguage = this.CurrentLanguage,
                Categories = objcontent.Categories(),
                Tags = tagFacade.GetAll().Select(t => new SelectListItem {
                    Text = t.Name, Value = t.TagId.ToString()
                })
            }));
        }
Exemplo n.º 3
0
        public ActionResult Detail(int id, int?mod, int?sectionId)
        {
            SuccessStoryPostulateFacade successStoryPostulateFacade = new SuccessStoryPostulateFacade();
            TagFacade       tagFacade = new TagFacade();
            ModulRepository modul     = new ModulRepository(SessionCustom);

            modul.Entity.ModulId    = mod;
            modul.Entity.LanguageId = this.CurrentLanguage.LanguageId;
            modul.Load();
            this.ViewBag.SectionId = sectionId;

            SuccessStoryPostulate successStoryPostulate = successStoryPostulateFacade.GetById(id, (int)this.CurrentLanguage.LanguageId);

            successStoryPostulate.State = (byte)SuccessStoryPostulateStateEnum.Pending;
            successStoryPostulateFacade.Update(successStoryPostulate);

            return(this.View(new DetailModel
            {
                SuccessStoryPostulate = successStoryPostulate,
                TagsText = string.Join(", ", tagFacade.GetBySuccessStoryPostulate(id).Select(t => t.Name)),
                UserPrincipal = this.CustomUser,
                ColModul = CustomMemberShipProvider.GetModuls(this.CustomUser.UserId, this.SessionCustom, HttpContext),
                Module = modul.Entity,
                CurrentLanguage = this.CurrentLanguage,
            }));
        }
Exemplo n.º 4
0
        public override void ConfigureTaskImplementation(AsyncTaskSequence sequence)
        {
            foreach (var tagName in TagNames)
            {
                var itTargets = (from it in TagManager.Value.Chains
                                 join t in TagNames on it.Tag.Name equals t
                                 select it).ToList();

                foreach (var target in itTargets)
                {
                    sequence.Add(new Task(() =>
                    {
                        TagManager.Value.Chains.Remove(target);
                    }));
                }

                var tTargets = (from t in TagManager.Value.Tags
                                join i in TagNames on t.Name equals i
                                select t).ToList();

                foreach (var target in tTargets)
                {
                    sequence.Add(new Task(() =>
                    {
                        TagManager.Value.Tags.Remove(target);
                    }));
                }

                sequence.Add(new Task(() => ImageTagFacade.DeleteByTagName(tagName)));
                sequence.Add(new Task(() => TagFacade.DeleteByTagName(tagName)));
            }
        }
Exemplo n.º 5
0
        public void LookingForTagAmongTagsWithDifferentPopularity_GetSortedResultList()
        {
            //Arrange
            var tagRepository = new InMemoryTagRepository();

            tagRepository.Add("Tag1");
            tagRepository.Add("Tag2");
            tagRepository.Add("Tag3");
            var tagFacade = new TagFacade(tagRepository);

            tagFacade.UseTag("Tag1");

            tagFacade.UseTag("Tag2");
            tagFacade.UseTag("Tag2");
            tagFacade.UseTag("Tag2");

            tagFacade.UseTag("Tag3");
            tagFacade.UseTag("Tag3");

            //Act
            var expectedTags = new List <string> {
                "Tag2", "Tag3", "Tag1"
            };
            var actualTags = tagFacade.FindTag("Tag").ToList();

            //Assert
            Assert.AreEqual(expectedTags[0], actualTags[0]);
            Assert.AreEqual(expectedTags[1], actualTags[1]);
            Assert.AreEqual(expectedTags[2], actualTags[2]);
            Assert.AreEqual(expectedTags.Count, actualTags.Count);
        }
Exemplo n.º 6
0
        //UnFlag Export Data - Tags dropdown. [Task] MP-360
        public static List <TagsEntity> GetExportedDataTags(string ConnectionString)
        {
            // Get Exported tags from the database for un-flag as exported
            TagFacade         fac     = new TagFacade(ConnectionString);
            List <TagsEntity> lstTags = fac.GetExportedDataTags(Helper.oUser != null ? (Helper.oUser.LOBTag != null ? Helper.oUser.LOBTag : "") : "", Helper.oUser != null ? (Helper.oUser.Tags != null ? Helper.oUser.Tags : "") : "", Helper.oUser.UserId);

            return(lstTags);
        }
Exemplo n.º 7
0
        private static TagViewModel CreateTag(ITagManager tagMng, string tagName)
        {
            var newTag = new TagViewModel(Guid.NewGuid(), tagName);

            TagFacade.Insert(newTag);
            tagMng.Tags.Add(newTag);
            return(newTag);
        }
Exemplo n.º 8
0
        public static List <TagsEntity> GetExportDataTags(string ConnectionString)
        {
            // Get All tags from the database and fill the dropdown
            List <TagsEntity> model = new List <TagsEntity>();
            TagFacade         fac   = new TagFacade(ConnectionString);

            model = fac.GetExportDataTags(Helper.oUser != null ? (Helper.oUser.LOBTag != null ? Helper.oUser.LOBTag : "") : "", Helper.oUser != null ? (Helper.oUser.Tags != null ? Helper.oUser.Tags : "") : "", Helper.oUser.UserId);
            return(model);
        }
Exemplo n.º 9
0
        public static List <TagsEntity> GetAllTags(string ConnectionString /*,string LOBTag*/)
        {
            // Get All tags from the database and fill the dropdown
            List <TagsEntity> model = new List <TagsEntity>();
            TagFacade         fac   = new TagFacade(ConnectionString);

            model = fac.GetAllTags(Helper.oUser.LOBTag);
            return(model);
        }
Exemplo n.º 10
0
        //Session Filter - Tags [Task] MP-361
        //GetAllTags - Remove LOB Tags (MP-376)
        public static List <TagsEntity> GetAllTagsForUser(string ConnectionString, bool FilterNoTag)
        {
            // Get All tags from the database and fill the dropdown
            List <TagsEntity> model = new List <TagsEntity>();
            TagFacade         fac   = new TagFacade(ConnectionString);

            model = fac.GetAllTagsForUser(Helper.oUser.LOBTag, Helper.oUser.UserId, FilterNoTag);
            return(model);
        }
Exemplo n.º 11
0
        /// <summary>
        /// obtains the challenge detail
        /// </summary>
        /// <param name="mod">identifier of module</param>
        /// <param name="id">identifier of section</param>
        /// <param name="sectionId">seccion del molulo</param>
        /// <returns>returns the result to action</returns>
        public ActionResult Detail(int mod, int id, int?sectionId)
        {
            ContentManagement      objcontentman   = new ContentManagement(SessionCustom, HttpContext);
            ContentRepository      objcontent      = new ContentRepository(SessionCustom);
            SuccessStoryRepository objSuccessStory = new SuccessStoryRepository(SessionCustom);
            FileattachRepository   objfiles        = new FileattachRepository(SessionCustom);
            TagRepository          objtag          = new TagRepository(SessionCustom);
            SectionRepository      objsection      = new SectionRepository(SessionCustom);
            TemplateRepository     objtemplate     = new TemplateRepository(SessionCustom);
            CommentRepository      objcomment      = new CommentRepository(SessionCustom);
            TagFacade tagFacade = new TagFacade();

            objtemplate.Entity.Type = 0;

            objSuccessStory.Entity.ContentId        =
                objfiles.Entity.ContentId           =
                    objcomment.Entity.ContentId     =
                        objcontent.Entity.ContentId = id;

            objSuccessStory.LoadByKey();
            objcontent.LoadByKey();

            int totalComments = 0;
            List <CommentsPaging> comments = objcomment.CommentsPagingContent(0, 50, out totalComments, id);

            ViewBag.TotalComments = totalComments;

            IEnumerable <Tag> SelectedTags = objtag.GetTagbycontent(id);

            this.ViewBag.SelectedTags = string.Join("|", SelectedTags.Select(t => t.TagId));
            this.ViewBag.NewsTags     = string.Empty;

            return(this.View(
                       "Index",
                       new SuccessStoryModel()
            {
                UserPrincipal = this.CustomUser,
                ColModul = CustomMemberShipProvider.GetModuls(this.CustomUser.UserId, this.SessionCustom, HttpContext),
                Module = this.Module,
                ListFiles = objfiles.GetAllReadOnly(),
                SuccessStory = objSuccessStory.Entity,
                IContent = objcontent.Entity,
                Templates = objtemplate.GetAll().Select(t => t.TemplateId),
                ListContent = objcontent.GetContentRelation(CurrentLanguage.LanguageId.Value),
                ListTags = SelectedTags,
                DeepFollower = Business.Utils.GetDeepFollower(objsection.GetAll(), objcontent.Entity.SectionId.Value),
                CurrentLanguage = this.CurrentLanguage,
                ListComments = comments,
                Tags = tagFacade.GetAll().Select(t => new SelectListItem {
                    Text = t.Name, Value = t.TagId.ToString()
                })
            }));
        }
Exemplo n.º 12
0
        private void TagBook(ITagManager tagMng)
        {
            foreach (var tagName in TagNames)
            {
                var tag = TagFacade.FindByTagName(tagName);
                Debug.Assert(tag != null);
                var newBookTag = new BookTagViewModel(_book, tag);

                BookTagFacade.Insert(newBookTag);
                tagMng.BookTagChains.Add(newBookTag);
            }
        }
Exemplo n.º 13
0
        public void UseNewTag_GetAddedNewTag()
        {
            //Arrange
            var tagRepository = new InMemoryTagRepository();
            var tagFacade     = new TagFacade(tagRepository);

            //Act
            tagFacade.UseTag("Tag");

            //Assert
            Assert.AreEqual(1, tagFacade.FindTag("Tag").Count());
        }
Exemplo n.º 14
0
        public bool IsTasExists(string tagValue)
        {
            // Validate tag is already exists or not
            bool      IsExists = false;
            TagFacade fac      = new TagFacade(this.CurrentClient.ApplicationDBConnectionString);
            int       TagId    = fac.GetAllTags("").Where(x => x.Tag.ToLower() == tagValue.ToLower()).Select(x => x.TagId).FirstOrDefault();

            if (TagId > 0)
            {
                IsExists = true;
            }
            return(IsExists);
        }
Exemplo n.º 15
0
        public static void Create(ITagManager tagMng, ImageViewModel targetImage, string tagName)
        {
            bool tagExists = TagFacade.Exists(tagName);

            if (tagExists)
            {
                var tag = TagFacade.FindByTagName(tagName);
                CreateImageTag(tagMng, targetImage, tag);
            }
            else
            {
                var newTag = CreateTag(tagMng, tagName);
                CreateImageTag(tagMng, targetImage, newTag);
            }
        }
Exemplo n.º 16
0
        public void TryToFindNotExistingTags_GetEmptyList()
        {
            //Arrange
            var tagRepository = new InMemoryTagRepository();

            tagRepository.Add("Tag1");
            tagRepository.Add("Tag2");
            tagRepository.Add("Teg3");
            var tagFacade = new TagFacade(tagRepository);

            //Act
            var actualTags = tagFacade.FindTag("Teg1").ToList();

            //Assert
            Assert.AreEqual(0, actualTags.Count);
        }
Exemplo n.º 17
0
        public static SelectList GetTagTypeCode(string ConnectionString)
        {
            // Get All tags type code from the database and fill the dropdown
            List <SelectListItem> lstAllFilter = new List <SelectListItem>();
            TagFacade             fac          = new TagFacade(ConnectionString);
            DataTable             dt           = fac.GetTagTypeCode();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                lstAllFilter.Add(new SelectListItem {
                    Value = dt.Rows[i]["TagTypeCode"].ToString() + "@#$" + dt.Rows[i]["Value"].ToString(), Text = dt.Rows[i]["Description"].ToString()
                });
            }

            return(new SelectList(lstAllFilter, "Value", "Text"));
        }
Exemplo n.º 18
0
        private void LoadTag()
        {
            Stopwatch sw = new Stopwatch();

            s_logger.Info("Loading Tag list...");
            sw.Start();
            try
            {
                Tags = new ObservableCollection <TagViewModel>(TagFacade.FindAll());
                Tags.CollectionChanged += Tags_CollectionChanged;
            }
            finally
            {
                s_logger.Info($"Completed to load Tag list. {sw.ElapsedMilliseconds}ms");
            }
        }
Exemplo n.º 19
0
        public static void Remove(ITagManager tagMng, ImageViewModel targetImage, string tagName)
        {
            bool tagExists = TagFacade.Exists(tagName);

            if (tagExists)
            {
                var tag = TagFacade.FindByTagName(tagName);
                ImageTagFacade.DeleteWhereIDIs(targetImage.ID, tag.ID);
                var willRemoves = tagMng.Chains.Where(a => a.ImageID == targetImage.ID && a.Tag.ID == tag.ID);
                if (willRemoves.Count() == 1)
                {
                    var willRemove = willRemoves.Single();
                    tagMng.Chains.Remove(willRemove);
                }
                s_logger.Info($"Removed ImageTag:{tag}");
            }
        }
Exemplo n.º 20
0
        public JsonResult AddTags(TagsEntity objTags)
        {
            string Parameters = string.Empty;
            string strOption  = "";

            if (objTags.TagId > 0 || (!string.IsNullOrEmpty(objTags.Tag?.Trim()) && !string.IsNullOrEmpty(objTags.TagTypeCode?.Trim())))
            {
                if (objTags.TagId > 0 || CommonMethod.isValidTagName(objTags.Tag) == true)
                {
                    TagFacade fac = new TagFacade(this.CurrentClient.ApplicationDBConnectionString);
                    if (objTags.TagId > 0)
                    {
                        TagsEntity newObjTags = fac.GetTagByTagId(objTags.TagId);
                        newObjTags.LOBTag = objTags.LOBTag;
                        fac.UpdateTags(newObjTags);
                        return(Json(new { result = true, message = CommonMessagesLang.msgCommanUpdateMessage, tagValue = objTags.Tag }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        string[] separatingStrings = { "@#$" };
                        string[] tagCode           = objTags.TagTypeCode.Split(separatingStrings, System.StringSplitOptions.RemoveEmptyEntries);
                        objTags.TagValue      = objTags.Tag;
                        objTags.Tag           = "[" + tagCode[1] + "::" + objTags.Tag + "]";
                        objTags.TagTypeCode   = tagCode[0];
                        objTags.CreatedUserId = Convert.ToInt32(User.Identity.GetUserId());

                        if (!IsTasExists(objTags.Tag))// Validate tag is already exists or not
                        {
                            // Insert Tag into database.
                            fac.InsertTags(objTags, Helper.oUser.UserId);
                            return(Json(new { result = true, message = CommonMessagesLang.msgCommanInsertMessage, tagValue = objTags.Tag }, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            return(Json(new { result = false, message = TagLang.msgTagAlreadyExists, tagValue = objTags.Tag }, JsonRequestBehavior.AllowGet));
                        }
                    }
                }
                else
                {
                    return(Json(new { result = false, message = CommonMessagesLang.msgValidCharacters, tagValue = "" }, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(new { result = false, message = CommonMessagesLang.msgCommanErrorMessage, tagValue = "" }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 21
0
        public void Load()
        {
            var id         = Guid.Parse("00000000-0000-0000-0000-000000000000");
            var appDao     = DataAccessManager.AppDao.Build <StatisticsDao>();
            var statistics = appDao.FindBy(new Dictionary <string, object>()
            {
                { "ID", id }
            }).First();

            NumberOfBoots.Value = statistics.NumberOfBoots;

            NumberOfBooks.Value = BookFacade.FindAll().Count();

            TotalFileSize.Value = ImageFacade.SumTotalFileSize();

            NumberOfPages.Value = PageFacade.CountAll();

            NumberOfAuthors.Value = AuthorFacade.CountAll();

            NumberOfTags.Value = TagFacade.CountAll();

            NumberOfBookTags.Value = BookTagFacade.CountAll();

            NumberOfImageTags.Value = ImageTagFacade.CountAll();

            NumberOfBooks5.Value = StarFacade.FindBookByStar(5).Count();

            NumberOfBooks4.Value = StarFacade.FindBookByStar(4).Count();

            NumberOfBooks3.Value = StarFacade.FindBookByStar(3).Count();

            NumberOfBooks2.Value = StarFacade.FindBookByStar(2).Count();

            NumberOfBooks1.Value = StarFacade.FindBookByStar(1).Count();

            NumberOfBooksN.Value = StarFacade.FindBookByStar(null).Count();

            NumberOfDuplicateBooks.Value = BookFacade.FindDuplicateFingerPrint().Count();

            TotalDuplicateBooksSize.Value = BookFacade.FindDuplicateFingerPrint().Where(x => x.ByteSize != null).Select(x => x.ByteSize.Value).Sum();
        }
Exemplo n.º 22
0
        public void TryToFindExistingTags_GetListOfFoundTags()
        {
            //Arrange
            var tagRepository = new InMemoryTagRepository();

            tagRepository.Add("Tag1");
            tagRepository.Add("Tag2");
            tagRepository.Add("Teg3");
            var tagFacade = new TagFacade(tagRepository);

            //Act
            var expectedTags = new List <string> {
                "Tag1", "Tag2"
            };
            var actualTags = tagFacade.FindTag("Tag").ToList();

            //Assert
            Assert.AreEqual(expectedTags[0], actualTags[0]);
            Assert.AreEqual(expectedTags[1], actualTags[1]);
            Assert.AreEqual(expectedTags.Count, actualTags.Count);
        }
Exemplo n.º 23
0
        public void UseExistingTag_GetUpdatedPopularity()
        {
            //Arrange
            var tagRepository = new InMemoryTagRepository();

            tagRepository.Add("Tag1");
            tagRepository.Add("Tag2");
            var tagFacade = new TagFacade(tagRepository);

            //Act
            tagFacade.UseTag("Tag2");

            //Assert
            var expectedTags = new List <string> {
                "Tag2", "Tag1"
            };
            var actualTags = tagFacade.FindTag("Tag").ToList();

            Assert.AreEqual(expectedTags[0], actualTags[0]);
            Assert.AreEqual(expectedTags[1], actualTags[1]);
            Assert.AreEqual(expectedTags.Count, actualTags.Count);
        }
Exemplo n.º 24
0
        private void OpenTagManagementDialog()
        {
            EntityManagementDialog <TagViewModel>          dialog          = new EntityManagementDialog <TagViewModel>();
            EntityManagementDialogViewModel <TagViewModel> dialogViewModel = new EntityManagementDialogViewModel <TagViewModel>(dialog, LibraryVM, "タグの管理",
                                                                                                                                new Func <string, TagViewModel>((name) =>
            {
                var tag           = new TagViewModel();
                tag.ID            = Guid.NewGuid();
                tag.UnescapedName = name;
                TagFacade.Insert(tag);
                return(tag);
            }),
                                                                                                                                new Func <IEnumerable <TagViewModel> >(() =>
            {
                return(TagFacade.OrderByNaturalString());
            }),
                                                                                                                                new Func <Guid, TagViewModel>((id) =>
            {
                return(TagFacade.FindBy(id));
            }),
                                                                                                                                null,
                                                                                                                                new Action <Guid>((id) =>
            {
                TagFacade.Delete(id);
                var willDelete = TagManager.Chains.Where(t => t.TagID == id).ToList();
                foreach (var del in willDelete)
                {
                    TagManager.Chains.Remove(del);
                }
            }),
                                                                                                                                null);

            dialog.EntityMngVM = dialogViewModel;
            dialogViewModel.Initialize();
            dialog.Show();
        }
Exemplo n.º 25
0
        public static List <Task> GenerateRemoveTagTasks(ITagManager tagManager, string[] tagNames)
        {
            List <Task> tasks = new List <Task>();

            foreach (var tagName in tagNames)
            {
                var itTargets = (from it in tagManager.Chains
                                 join t in tagNames on it.Tag.Name equals t
                                 select it).ToList();

                foreach (var target in itTargets)
                {
                    tasks.Add(new Task(() =>
                    {
                        tagManager.Chains.Remove(target);
                    }));
                }

                var tTargets = (from t in tagManager.Tags
                                join i in tagNames on t.Name equals i
                                select t).ToList();

                foreach (var target in tTargets)
                {
                    tasks.Add(new Task(() =>
                    {
                        tagManager.Tags.Remove(target);
                    }));
                }

                tasks.Add(new Task(() => ImageTagFacade.DeleteByTagName(tagName)));
                tasks.Add(new Task(() => TagFacade.DeleteByTagName(tagName)));
            }

            return(tasks);
        }
Exemplo n.º 26
0
        public static List <TagsEntity> GetTagByTypeCode(string ConnectionString)
        {
            TagFacade fac = new TagFacade(ConnectionString);

            return(fac.GetTagByTypeCode(ConstantValues.LOBTagCode));
        }
Exemplo n.º 27
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            StartLoggly();

            services.AddWebSocketManager();

            IFileRepository     fileRepository;
            IGroupRepository    groupRepository;
            IKeysRepository     keysRepository;
            ITagRepository      tagRepository;
            IUserRepository     userRepository;
            ISanctionRepository sanctionRepository;
            IEventRepository    eventRepository;

            if (bool.Parse(Configuration.GetValue <string>("UseDB")))
            {
                var dbContext = Configuration.GetValue <string>("MysqlConnectionString");
                using (var context = new EduhubContext(dbContext))
                {
                    if (bool.Parse(Configuration.GetValue <string>("DeleteDB")))
                    {
                        context.Database.EnsureDeleted();
                    }
                    if (context.Database.EnsureCreated())
                    {
                        var dbName = dbContext.Split("database=")[1].Split(";")[0];
                        context.Database.ExecuteSqlCommand(
                            "ALTER DATABASE " + dbName + " CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;");
                        var modelNames = context.Model.GetEntityTypes();
                        foreach (var modelname in modelNames)
                        {
                            var mapping   = context.Model.FindEntityType(modelname.Name).Relational();
                            var tableName = mapping.TableName;
                            context.Database.ExecuteSqlCommand(
                                "alter table " + tableName.ToLower()
                                + " convert to character set utf8mb4 collate utf8mb4_bin;");
                        }
                    }

                    context.Database.Migrate();
                }

                fileRepository     = new InMysqlFileRepository(dbContext);
                groupRepository    = new InMysqlGroupRepository(dbContext);
                keysRepository     = new InMysqlKeyRepository(dbContext);
                tagRepository      = new InMysqlTagRepository(dbContext);
                userRepository     = new InMysqlUserRepository(dbContext);
                sanctionRepository = new InMysqlSanctionRepository(dbContext);
                eventRepository    = new InMemoryEventRepository();
            }
            else
            {
                fileRepository     = new InMemoryFileRepository();
                groupRepository    = new InMemoryGroupRepository();
                keysRepository     = new InMemoryKeysRepository();
                tagRepository      = new InMemoryTagRepository();
                sanctionRepository = new InMemorySanctionRepository();
                userRepository     = new InMemoryUserRepository();
                eventRepository    = new InMemoryEventRepository();
            }

            var emailSettings = new EmailSettings(Configuration.GetValue <string>("EmailLogin"),
                                                  Configuration.GetValue <string>("Email"),
                                                  Configuration.GetValue <string>("EmailPassword"),
                                                  Configuration.GetValue <string>("SmtpAddress"),
                                                  Configuration.GetValue <string>("ConfirmAddress"),
                                                  int.Parse(Configuration.GetValue <string>("SmtpPort")));


            var defaultAvatarFilename    = Configuration.GetValue <string>("DefaultAvatarFilename");
            var defaultAvatarContentType = Configuration.GetValue <string>("DefaultAvatarContentType");
            var userSettings             = new UserSettings(defaultAvatarFilename);

            if (!fileRepository.DoesFileExists(defaultAvatarFilename))
            {
                fileRepository.AddFile(new UserFile(defaultAvatarFilename, defaultAvatarContentType));
            }

            var tagFacade   = new TagFacade(tagRepository);
            var emailSender = new EmailSender(emailSettings);
            var notificationsDistributor = new NotificationsDistributor(groupRepository, userRepository, emailSender);

            var groupSettings = new GroupSettings(Configuration.GetValue <int>("MinGroupSize"),
                                                  Configuration.GetValue <int>("MaxGroupSize"),
                                                  Configuration.GetValue <double>("MinGroupValue"),
                                                  Configuration.GetValue <double>("MaxGroupValue"));

            var eventBusSettings = new EventBusSettings(Configuration.GetValue <string>("RabbitMqServerHostName"),
                                                        Configuration.GetValue <string>("RabbitMqServerVirtualHost"),
                                                        Configuration.GetValue <string>("RabbitMqAdminUserName"),
                                                        Configuration.GetValue <string>("RabbitMqAdminPassword"));
            var eventBus = new EventBus(eventBusSettings);

            eventBus.StartListening();

            var adminsEventConsumer     = new AdminsEventConsumer(notificationsDistributor, eventRepository);
            var courseEventConsumer     = new CourseEventConsumer(notificationsDistributor, eventRepository);
            var curriculumEventConsumer = new CurriculumEventConsumer(notificationsDistributor, eventRepository);
            var groupEventsConsumer     = new GroupEventsConsumer(notificationsDistributor, eventRepository);
            var invitationConsumer      = new InvitationConsumer(notificationsDistributor, eventRepository);
            var memberActionsConsumer   = new MemberActionsConsumer(notificationsDistributor, eventRepository);

            eventBus.RegisterConsumer(new TagPopularityConsumer(tagFacade));
            eventBus.RegisterConsumer <ReportMessageEvent>(adminsEventConsumer);
            eventBus.RegisterConsumer <SanctionsAppliedEvent>(adminsEventConsumer);
            eventBus.RegisterConsumer <SanctionCancelledEvent>(adminsEventConsumer);
            eventBus.RegisterConsumer <TeacherFoundEvent>(courseEventConsumer);
            eventBus.RegisterConsumer <CourseFinishedEvent>(courseEventConsumer);
            eventBus.RegisterConsumer <ReviewReceivedEvent>(courseEventConsumer);
            eventBus.RegisterConsumer <CurriculumAcceptedEvent>(curriculumEventConsumer);
            eventBus.RegisterConsumer <CurriculumDeclinedEvent>(curriculumEventConsumer);
            eventBus.RegisterConsumer <CurriculumSuggestedEvent>(curriculumEventConsumer);
            eventBus.RegisterConsumer <NewCreatorEvent>(groupEventsConsumer);
            eventBus.RegisterConsumer <GroupIsFormedEvent>(groupEventsConsumer);
            eventBus.RegisterConsumer <InvitationAcceptedEvent>(invitationConsumer);
            eventBus.RegisterConsumer <InvitationDeclinedEvent>(invitationConsumer);
            eventBus.RegisterConsumer <InvitationReceivedEvent>(invitationConsumer);
            eventBus.RegisterConsumer <NewMemberEvent>(memberActionsConsumer);
            eventBus.RegisterConsumer <MemberLeftEvent>(memberActionsConsumer);

            var publisher = eventBus.GetEventPublisher();

            var userFacade      = new UserFacade(userRepository, groupRepository, eventRepository, publisher);
            var groupEditFacade = new GroupEditFacade(groupRepository, groupSettings, publisher);
            var userEditFacade  = new UserEditFacade(userRepository, fileRepository, sanctionRepository);
            var groupFacade     = new GroupFacade(groupRepository, userRepository, sanctionRepository, groupSettings,
                                                  publisher);
            var fileFacade        = new FileFacade(fileRepository);
            var chatFacade        = new ChatFacade(groupRepository, userRepository);
            var sanctionsFacade   = new SanctionFacade(sanctionRepository, userRepository, publisher);
            var userAccountFacade = new AccountFacade(keysRepository, userRepository, emailSender, userSettings);
            var reportFacade      = new ReportFacade(userRepository, eventRepository, publisher);

            services.AddSingleton <IUserFacade>(userFacade);
            services.AddSingleton <IGroupFacade>(groupFacade);
            services.AddSingleton <IFileFacade>(fileFacade);
            services.AddSingleton <IChatFacade>(chatFacade);
            services.AddSingleton <IGroupEditFacade>(groupEditFacade);
            services.AddSingleton <IUserEditFacade>(userEditFacade);
            services.AddSingleton <ITagFacade>(tagFacade);
            services.AddSingleton <ISanctionFacade>(sanctionsFacade);
            services.AddSingleton <IAccountFacade>(userAccountFacade);
            services.AddSingleton <IReportFacade>(reportFacade);
            services.AddSingleton(Env);

            userAccountFacade.CheckAdminExistence(Configuration.GetValue <string>("AdminEmail"));

            services.AddSwaggerGen(current =>
            {
                current.SwaggerDoc("v1", new Info
                {
                    Title   = "EduHub API",
                    Version = "v1"
                });
                current.AddSecurityDefinition("Bearer", new ApiKeyScheme
                {
                    Description =
                        "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name = "Authorization",
                    In   = "header",
                    Type = "apiKey"
                });
                current.OperationFilter <ExamplesOperationFilter>();
                current.DescribeAllEnumsAsStrings();
                var a = string.Format(@"{0}\EduHub.xml", AppDomain.CurrentDomain.BaseDirectory);
                current.IncludeXmlComments(string.Format(@"{0}/EduHub.xml", AppDomain.CurrentDomain.BaseDirectory));
            });
            ConfigureSecurity(services);
            if (Configuration.GetValue <bool>("Authorization"))
            {
                services.AddMvc(o =>
                {
                    o.Filters.Add(new ExceptionFilter());
                    o.Filters.Add(new ActionFilter());
                });
            }
            else
            {
                services.AddMvc(o =>
                {
                    o.Filters.Add(new AllowAnonymousFilter());
                    o.Filters.Add(new ExceptionFilter());
                    o.Filters.Add(new ActionFilter());
                });
            }
            services.AddCors(options =>
            {
                options.AddPolicy("AllowAnyOrigin",
                                  builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            });
        }
Exemplo n.º 28
0
        public static List <Task> GenerateAddImageTagTasks(ITagManager tagManager, IEnumerable <EntryViewModel> entries, string tagName)
        {
            List <Task> tasks = new List <Task>();

            var ita = new ImageTagAdding();

            tasks.Add(new Task(() =>
            {
                if (TagFacade.Exists(tagName))
                {
                    ita._tag = TagFacade.FindByTagName(tagName);
                }
                else
                {
                    ita._tag = new TagViewModel(Guid.NewGuid(), tagName);
                    TagFacade.Insert(ita._tag);
                }
            }));

            tasks.Add(new Task(() =>
            {
                ita._images = new List <ImageViewModel>();
            }));

            foreach (var entry in entries)
            {
                var book = entry as BookViewModel;
                if (book != null)
                {
                    ita._pages = PageFacade.FindByBookId(book.ID);

                    for (int i = 0; i < ita._pages.Count(); ++i)
                    {
                        var p = ita._pages.ElementAt(i);
                        tasks.Add(new Task(() =>
                        {
                            GetPropertyIfImageIsNull(ref p);
                            ita._images.Add(p.Image);
                        }));
                    }
                    continue;
                }

                var page = entry as PageViewModel;
                if (page != null)
                {
                    tasks.Add(new Task(() =>
                    {
                        GetPropertyIfImageIsNull(ref page);
                        ita._images.Add(page.Image);
                    }));
                    continue;
                }

                var image = entry as ImageViewModel;
                if (image != null)
                {
                    tasks.Add(new Task(() =>
                    {
                        ita._images.Add(image);
                    }));
                    continue;
                }
            }

            tasks.Add(new Task(() =>
            {
                ImageTagFacade.BatchInsert(ita._tag, ita._images);
            }));

            tasks.Add(new Task(() =>
            {
                var chains = from x in ita._images
                             where tagManager.Chains.Count(c => c.ImageID == x.ID && c.TagID == ita._tag.ID) == 0
                             select new ImageTagViewModel(x.ID, ita._tag);

                foreach (var chain in chains)
                {
                    tagManager.Chains.Add(chain);
                }
            }));

            tasks.Add(new Task(() =>
            {
                if (!tagManager.Tags.Contains(ita._tag))
                {
                    tagManager.Tags.Add(ita._tag);
                }
            }));

            tasks.Add(new Task(() => tagManager.SelectedEntityTags = tagManager.GetCommonTags()));
            tasks.Add(new Task(() => tagManager.ObserveSelectedEntityTags()));

            return(tasks);
        }
Exemplo n.º 29
0
        public override void ConfigureTaskImplementation(AsyncTaskSequence sequence)
        {
            sequence.Add(new Task(() =>
            {
                if (TagFacade.Exists(TagName))
                {
                    _tag = TagFacade.FindByTagName(TagName);
                }
                else
                {
                    _tag = new TagViewModel(Guid.NewGuid(), TagName);
                    TagFacade.Insert(_tag);
                }
            }));

            sequence.Add(new Task(() =>
            {
                _images = new List <ImageViewModel>();
            }));

            foreach (var entry in Entries)
            {
                var book = entry as BookViewModel;
                if (book != null)
                {
                    _pages = PageFacade.FindByBookId(book.ID);

                    for (int i = 0; i < _pages.Count(); ++i)
                    {
                        var p = _pages.ElementAt(i);
                        sequence.Add(new Task(() =>
                        {
                            GetPropertyIfImageIsNull(ref p);
                            _images.Add(p.Image);
                        }));
                    }
                    sequence.Add(new Task(() =>
                    {
                        var newEntity = new BookTagViewModel(book, _tag);
                        if (!BookTagFacade.Exists(newEntity))
                        {
                            BookTagFacade.Insert(newEntity);
                        }
                    }));
                    continue;
                }

                var page = entry as PageViewModel;
                if (page != null)
                {
                    sequence.Add(new Task(() =>
                    {
                        GetPropertyIfImageIsNull(ref page);
                        _images.Add(page.Image);
                    }));

                    sequence.Add(new Task(() =>
                    {
                        var newEntity = new BookTagViewModel(page.BookID, _tag.ID);
                        if (!BookTagFacade.Exists(newEntity))
                        {
                            BookTagFacade.Insert(newEntity);
                        }
                    }));
                    continue;
                }

                var image = entry as ImageViewModel;
                if (image != null)
                {
                    sequence.Add(new Task(() =>
                    {
                        _images.Add(image);
                    }));

                    sequence.Add(new Task(() =>
                    {
                        var tempPage  = PageFacade.FindByImageId(image.ID);
                        var newEntity = new BookTagViewModel(tempPage.BookID, _tag.ID);
                        if (!BookTagFacade.Exists(newEntity))
                        {
                            BookTagFacade.Insert(newEntity);
                        }
                    }));
                    continue;
                }
            }

            sequence.Add(new Task(() =>
            {
                ImageTagFacade.BatchInsert(_tag, _images);
            }));

            sequence.Add(new Task(() =>
            {
                var chains = from x in _images
                             where TagManager.Value.Chains.Count(c => c.ImageID == x.ID && c.TagID == _tag.ID) == 0
                             select new ImageTagViewModel(x.ID, _tag);

                foreach (var chain in chains)
                {
                    TagManager.Value.Chains.Add(chain);
                }
            }));

            sequence.Add(new Task(() =>
            {
                if (!TagManager.Value.Tags.Contains(_tag))
                {
                    TagManager.Value.Tags.Add(_tag);
                }
            }));

            sequence.Add(new Task(() => TagManager.Value.SelectedEntityTags = TagManager.Value.GetCommonTags()));
            sequence.Add(new Task(() => TagManager.Value.ObserveSelectedEntityTags()));
        }
Exemplo n.º 30
0
        /// <summary>
        /// obtains the news detail
        /// </summary>
        /// <param name="mod">identifier of module</param>
        /// <param name="id">identifier of section</param>
        /// <returns>returns the result to action</returns>
        public ActionResult Detail(int mod, int id)
        {
            ContentManagement    objcontentman = new ContentManagement(SessionCustom, HttpContext);
            ContentRepository    objcontent    = new ContentRepository(SessionCustom);
            NewsRepository       objnews       = new NewsRepository(SessionCustom);
            FileattachRepository objfiles      = new FileattachRepository(SessionCustom);
            TagRepository        objtag        = new TagRepository(SessionCustom);
            SectionRepository    objsection    = new SectionRepository(SessionCustom);
            TemplateRepository   objtemplate   = new TemplateRepository(SessionCustom);
            MoldRepository       objMold       = new MoldRepository(SessionCustom);
            XmlNodeList          collXmlNode   = null;
            TagFacade            tagFacade     = new TagFacade();

            List <Domain.Entities.Mold> collMold = objMold.GetAll();

            collMold.Insert(
                0,
                new Domain.Entities.Mold()
            {
                Name = Resources.Global.Messages.SELECT
            });

            objtemplate.Entity.Type = 0;

            objnews.Entity.ContentId            =
                objfiles.Entity.ContentId       =
                    objcontent.Entity.ContentId = id;

            objnews.LoadByKey();
            objcontent.LoadByKey();

            if (objnews.Entity.MoldId != null)
            {
                XmlDocument objXmlDocument = new XmlDocument();
                objXmlDocument.LoadXml(objnews.Entity.Xmlcontent);
                collXmlNode = objXmlDocument.GetElementsByTagName("node");
            }

            IEnumerable <Tag> SelectedTags = objtag.GetTagbycontent(id);

            this.ViewBag.SelectedTags = string.Join("|", SelectedTags.Select(t => t.TagId));
            this.ViewBag.NewsTags     = string.Empty;

            return(this.View(
                       "Index",
                       new NewsModel()
            {
                UserPrincipal = this.CustomUser,
                ColModul = CustomMemberShipProvider.GetModuls(this.CustomUser.UserId, this.SessionCustom, HttpContext),
                Module = this.Module,
                ListFiles = objfiles.GetAllReadOnly(),
                News = objnews.Entity,
                IContent = objcontent.Entity,
                Templates = objtemplate.GetAll().Select(t => t.TemplateId),
                ListContent = objcontent.GetContentRelation(CurrentLanguage.LanguageId.Value),
                ListTags = SelectedTags,
                DeepFollower = Business.Utils.GetDeepFollower(objsection.GetAll(), objcontent.Entity.SectionId.Value),
                CurrentLanguage = this.CurrentLanguage,
                CollMold = collMold,
                CollXmlNode = collXmlNode,
                Categories = objcontent.Categories(),
                Tags = tagFacade.GetAll().Select(t => new SelectListItem {
                    Text = t.Name, Value = t.TagId.ToString()
                })
            }));
        }