public async void UpdateModuleContent_CalledAndRoleIsNotAdmin_ReturnsBadRequestWithError()
        {
            IUnitOfWork    unitOfWork    = Substitute.For <IUnitOfWork>();
            ICookieManager cookieManager = Substitute.For <ICookieManager>();
            var            context       = Substitute.For <HttpContext>();

            long          testId = 1;
            var           testModuleContentView = new ModuleContentUpdateViewModel();
            ModuleContent nullModuleContent     = null;
            string        error = "Only Admins can update module content.";

            unitOfWork.ModuleContents.GetById(testId).Returns(nullModuleContent);
            cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Student.ToString());

            var moduleContentsController = new ModuleContentsController(unitOfWork, cookieManager);

            moduleContentsController.ControllerContext = new ControllerContext()
            {
                HttpContext = context
            };

            var result = await moduleContentsController.UpdateModuleContent(testModuleContentView, testId);

            var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result);
            var returnValue            = Assert.IsType <string>(badRequestObjectResult.Value);

            Assert.Equal(error, returnValue);
        }
        public async void UpdateModuleContent_CalledWithInvalidId_ReturnsNotFoundWithId()
        {
            IUnitOfWork    unitOfWork    = Substitute.For <IUnitOfWork>();
            ICookieManager cookieManager = Substitute.For <ICookieManager>();
            var            context       = Substitute.For <HttpContext>();

            long          notValidId            = 1;
            var           testModuleContentView = new ModuleContentUpdateViewModel();
            ModuleContent nullModuleContent     = null;
            string        error = "Module content cannot be null.";

            unitOfWork.ModuleContents.GetById(notValidId).Returns(nullModuleContent);
            cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Admin.ToString());

            var moduleContentsController = new ModuleContentsController(unitOfWork, cookieManager);

            moduleContentsController.ControllerContext = new ControllerContext()
            {
                HttpContext = context
            };

            var result = await moduleContentsController.UpdateModuleContent(testModuleContentView, notValidId);

            var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result);
            var returnValue          = Assert.IsType <long>(notFoundObjectResult.Value);

            Assert.Equal(notValidId, returnValue);
        }
Пример #3
0
        public string GetModuleContent()
        {
            Stream st;
            StreamReader sr;

            //Script
            string Script = "";
            st = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetType(), "script.js");
            if (st != null)
            {
                sr = new StreamReader(st);
                Script = sr.ReadToEnd();
            }

            //InnerHTML
            string HTML = "";
            st = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetType(), "content.htm");
            if (st != null)
            {
                sr = new StreamReader(st);
                HTML = sr.ReadToEnd();
            }

            //Serialize the (JSON) object
            ModuleContent JsonObject = new ModuleContent();
            JsonObject.Script = Script;
            JsonObject.HTML = HTML;

            return JsonConvert.SerializeObject(JsonObject);
        }
Пример #4
0
        public ModuleContent GetModuleData(string moduleID, int subsectionID, string languageID)
        {
            ModuleContent moduleContent = new ModuleContent();
            double        version       = GetSubsectionVersion(moduleID, subsectionID, languageID.ToUpper());

            con.Open();
            SqlCommand cmd = new SqlCommand("SELECT AuthorID, Content " +
                                            "FROM ModuleContent " +
                                            "WHERE ModuleID = @moduleID AND SubsectionID = @subsectionID " +
                                            "AND LanguageID = @languageID AND VersionNumber = @versionNumber", con);

            cmd.Parameters.AddWithValue("@moduleID", moduleID.Trim());
            cmd.Parameters.AddWithValue("@subsectionID", subsectionID);
            cmd.Parameters.AddWithValue("@languageID", languageID.Trim().ToUpper());
            cmd.Parameters.AddWithValue("@versionNumber", version);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                moduleContent.AuthorID      = reader.GetInt32(0);
                moduleContent.Content       = reader.GetString(1);
                moduleContent.VersionNumber = version;
            }
            con.Close();
            return(moduleContent);
        }
        public async void AddVideo_CalledWithValidVideo_ReturnsOk()
        {
            IUnitOfWork    unitOfWork    = Substitute.For <IUnitOfWork>();
            IVideoManager  videoManager  = Substitute.For <IVideoManager>();
            ICookieManager cookieManager = Substitute.For <ICookieManager>();
            var            context       = Substitute.For <HttpContext>();

            long testId    = 1;
            var  testVideo = new VideoViewModel()
            {
                ModuleContentId = testId
            };
            var    testModuleContent = new ModuleContent();
            string testUrl           = "testurl";
            string convertedUrl      = "converted";
            string testyoutubeId     = "youtubeid";

            unitOfWork.ModuleContents.GetById(testId).Returns(testModuleContent);
            videoManager.ConvertUrl(testUrl).Returns(convertedUrl);
            videoManager.GetYoutubeId(convertedUrl).Returns(testyoutubeId);
            cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Admin.ToString());

            var videosController = new VideosController(unitOfWork, videoManager, cookieManager);

            videosController.ControllerContext = new ControllerContext()
            {
                HttpContext = context
            };

            var result = await videosController.AddVideo(testVideo);

            var okResult = Assert.IsType <OkResult>(result);

            Assert.Equal(200, okResult.StatusCode);
        }
        public async void AddVideo_CalledAndRoleIsNotAdmin_ReturnsBadRequestWithError()
        {
            IUnitOfWork    unitOfWork    = Substitute.For <IUnitOfWork>();
            IVideoManager  videoManager  = Substitute.For <IVideoManager>();
            ICookieManager cookieManager = Substitute.For <ICookieManager>();
            var            context       = Substitute.For <HttpContext>();

            long          testId            = 1;
            var           testVideo         = new VideoViewModel();
            ModuleContent nullModuleContent = null;
            string        testUrl           = "testurl";
            string        convertedUrl      = "converted";
            string        testyoutubeId     = "youtubeid";
            string        error             = "Only Admins can add videos.";

            unitOfWork.ModuleContents.GetById(testId).Returns(nullModuleContent);
            videoManager.ConvertUrl(testUrl).Returns(convertedUrl);
            videoManager.GetYoutubeId(convertedUrl).Returns(testyoutubeId);
            cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Student.ToString());

            var videosController = new VideosController(unitOfWork, videoManager, cookieManager);

            videosController.ControllerContext = new ControllerContext()
            {
                HttpContext = context
            };

            var result = await videosController.AddVideo(testVideo);

            var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result);
            var returnValue            = Assert.IsType <string>(badRequestObjectResult.Value);

            Assert.Equal(error, returnValue);
        }
Пример #7
0
        /// <summary>
        /// 
        /// </summary>
        protected ModuleBase()
        {
            if (this.GetType().IsDefined(typeof(ModuleAttribute), false) == false)
                throw new ApplicationException(
                    String.Format("{0} doesn't contain ModuleAttribute", this.GetType())
                    );

            // get the module attribute
            this._attribute = this.GetType().GetCustomAttributes(typeof(ModuleAttribute), false)[0] as ModuleAttribute;

            // launch event Init
            this.OnInit(EventArgs.Empty);

            // setup content syndication
            this._syndication = new ManagedFusion.Syndication.Feed(this.SectionInformation);

            // create the center place holder
            this._centerHolder = new ModuleContent();
            this._centerHolder.ID = "MainContent";
            this._centerHolder.ContentPlaceHolderID = "Main";

            // configure modules place holder
            this._holders = new ModuleContent[] { new ModuleContent(), new ModuleContent() };

            // process config file
            this._config = this.SectionInformation.Module.Config;
        }
Пример #8
0
        public void Delete(object id)
        {
            ModuleContent moduleContent = Find(id);

            moduleContent.IsDeleted = true;
            InsertOrUpdate(moduleContent);
        }
        public async void UpdateModuleContent_CalledWithValidModuleContentAndId_RetrunsOk()
        {
            IUnitOfWork    unitOfWork    = Substitute.For <IUnitOfWork>();
            ICookieManager cookieManager = Substitute.For <ICookieManager>();
            var            context       = Substitute.For <HttpContext>();

            long testId = 1;
            var  testModuleContentView = new ModuleContentUpdateViewModel();
            var  testModuleContent     = new ModuleContent();

            unitOfWork.ModuleContents.GetById(testId).Returns(testModuleContent);
            cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Admin.ToString());

            var moduleContentsController = new ModuleContentsController(unitOfWork, cookieManager);

            moduleContentsController.ControllerContext = new ControllerContext()
            {
                HttpContext = context
            };

            var result = await moduleContentsController.UpdateModuleContent(testModuleContentView, testId);

            var okResult = Assert.IsType <OkResult>(result);

            Assert.Equal(200, okResult.StatusCode);
        }
        public async void DeleteModuleContent_CalledWithInvalidId_RetrunsNotFoundWithId()
        {
            IUnitOfWork    unitOfWork    = Substitute.For <IUnitOfWork>();
            ICookieManager cookieManager = Substitute.For <ICookieManager>();
            var            context       = Substitute.For <HttpContext>();

            long          notValidId        = 1;
            ModuleContent nullModuleContent = null;
            List <Video>  nullVideos        = null;

            cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Admin.ToString());
            unitOfWork.ModuleContents.GetById(notValidId).Returns(nullModuleContent);
            unitOfWork.Videos.GetVideosByModuleContentId(notValidId).Returns(nullVideos);

            var moduleContentsController = new ModuleContentsController(unitOfWork, cookieManager);

            moduleContentsController.ControllerContext = new ControllerContext()
            {
                HttpContext = context
            };

            var result = await moduleContentsController.DeleteModuleContent(notValidId);

            var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result);
            var returnValue          = Assert.IsType <long>(notFoundObjectResult.Value);

            Assert.Equal(notValidId, returnValue);
        }
        private Hashtable GetSqlModules(DbReplacePostModel model)
        {
            Hashtable htModules = new Hashtable();

            var connstr = GetConnectionString(model);

            SqlConnection con = new SqlConnection(connstr);
            SqlCommand    cmd = new SqlCommand();

            cmd.CommandText = model.SqlSelect;
            cmd.Connection  = con;

            try
            {
                con.Open();
                var reader = cmd.ExecuteReader(); // (CommandBehavior.SingleRow)

                while (reader.Read())
                {
                    int portalid = CheckDbValueInteger(reader, "PortalId", PortalSettings.PortalId);

                    if (model.AllPortals == bool.TrueString || portalid == PortalSettings.PortalId)
                    {
                        // Check if the item was already added
                        string id = reader["ContentId"].ToString();
                        if (!htModules.ContainsKey(id))
                        {
                            var oMod = new ModuleContent
                            {
                                PortalId     = CheckDbValueInteger(reader, "PortalId", PortalSettings.PortalId),
                                TabId        = CheckDbValueInteger(reader, "TabId", -1),
                                ModuleId     = CheckDbValueInteger(reader, "ModuleId", -1),
                                ContentSubId = CheckDbValueInteger(reader, "ContentSubId", -1),
                                ContentId    = (int)reader["ContentId"],
                                Text         = reader["ContentText"].ToString(),
                                Title        = reader["ContentTitle"].ToString()
                            };

                            htModules.Add(id, oMod);
                        }
                    }
                }

                reader.Close();
            }
            finally
            {
                con.Close();
            }


            return(htModules);
        }
Пример #12
0
        //切换模块之间的页面
        private void SwitchModuleUI(ModuleContent module)
        {
            if (module == null || this.curModule == null || module == this.curModule)
            {
                return;
            }

            this.split_Master.BeginInit();
            this.split_Master.Panel2.Controls.Remove(this.curModule.Value.ModulePanel);
            this.split_Master.Panel2.Controls.Add(module.ModulePanel);
            this.split_Master.EndInit();
        }
Пример #13
0
        private void UnInstallUI(ModuleContent module)
        {
            if (module.ModuleNode != null)
            {
                this.tree_nav.Nodes.Remove(module.ModuleNode);
            }

            if (module.ModulePanel != null)
            {
                this.split_Master.Panel2.Controls.Remove(module.ModulePanel);
            }
        }
Пример #14
0
 public void InsertOrUpdate(ModuleContent moduleContent)
 {
     if (moduleContent.Id == default(int))
     {
         // New Entity
         _context.Entry(moduleContent).State = EntityState.Added;
     }
     else
     {
         // Existing User
         _context.Entry(moduleContent).State = EntityState.Modified;
     }
 }
Пример #15
0
        public ifr()
        {
            HttpContext.Current.Response.ContentType = "text/html";
//			if (ForumUtils.IsCrossSitePost(DNTRequest.GetUrlReferrer(), DNTRequest.GetHost()))
//				return;

//			if (userid < 1)
//				return;
            string     url        = DNTRequest.GetQueryString("url");
            int        mid        = DNTRequest.GetQueryInt("mid", 0);
            int        uid        = DNTRequest.GetQueryInt("uid", 0);
            ModuleInfo moduleinfo = Spaces.GetModuleById(mid, uid);

            if (moduleinfo == null)
            {
                return;
            }
            if (url != moduleinfo.ModuleUrl)
            {
                return;
            }
            UserPrefsSaved ups = new UserPrefsSaved(moduleinfo.UserPref);

            string        path           = BaseConfigs.GetForumPath + "space/modules/" + url;
            string        modulefilepath = Utils.GetMapPath(path);
            ModulePref    mp             = ModuleXmlHelper.LoadModulePref(modulefilepath);
            ModuleContent mc             = ModuleXmlHelper.LoadContent(modulefilepath);

#if NET1
            UserPrefCollection upc = ModuleXmlHelper.LoadUserPrefs(modulefilepath);
#else
            UserPrefCollection <UserPref> upc = ModuleXmlHelper.LoadUserPrefs(modulefilepath);
#endif

            StringBuilder registScript = new StringBuilder("<script type=\"text/javascript\">");
            foreach (UserPref up in upc)
            {
                string userprefvalue = ups.GetValueByName(up.Name);
                userprefvalue = userprefvalue == string.Empty ? up.DefaultValue : userprefvalue;
                registScript.AppendFormat(PREF_SCRIPT_FORMAT, mid, up.Name, userprefvalue);
            }
            registScript.Append(ModuleXmlHelper.GetModuleRequireScript(mp, mc.Type == ModuleContentType.HtmlInline));
            registScript.Append("</script>");
            string html = string.Format(IFRAME_HTML, registScript.ToString(), mc.ContentHtml, BaseConfigs.GetForumPath);
            html = html.Replace("__MODULE_ID__", mid.ToString()).Replace("_IG_", "_DS_");


            HttpContext.Current.Response.Write(html);
            HttpContext.Current.Response.End();
        }
Пример #16
0
        public string Export(int moduleid)
        {
            string content = "";

            if (UserPermissions.IsAuthorized(User, "Module", moduleid, "View"))
            {
                try
                {
                    Module module = Modules.GetModule(moduleid);
                    if (module != null)
                    {
                        List <ModuleDefinition> moduledefinitions = ModuleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
                        ModuleDefinition        moduledefinition  = moduledefinitions.Where(item => item.ModuleDefinitionName == module.ModuleDefinitionName).FirstOrDefault();
                        if (moduledefinition != null)
                        {
                            ModuleContent modulecontent = new ModuleContent();
                            modulecontent.ModuleDefinitionName = moduledefinition.ModuleDefinitionName;
                            modulecontent.Version = moduledefinition.Version;
                            modulecontent.Content = "";

                            if (moduledefinition.ServerAssemblyName != "")
                            {
                                Assembly assembly = AppDomain.CurrentDomain.GetAssemblies()
                                                    .Where(item => item.FullName.StartsWith(moduledefinition.ServerAssemblyName)).FirstOrDefault();
                                if (assembly != null)
                                {
                                    Type moduletype = assembly.GetTypes()
                                                      .Where(item => item.Namespace != null)
                                                      .Where(item => item.Namespace.StartsWith(moduledefinition.ModuleDefinitionName.Substring(0, moduledefinition.ModuleDefinitionName.IndexOf(","))))
                                                      .Where(item => item.GetInterfaces().Contains(typeof(IPortable))).FirstOrDefault();
                                    if (moduletype != null)
                                    {
                                        var moduleobject = ActivatorUtilities.CreateInstance(ServiceProvider, moduletype);
                                        modulecontent.Content = ((IPortable)moduleobject).ExportModule(module);
                                    }
                                }
                            }
                            content = JsonSerializer.Serialize(modulecontent);
                            logger.Log(LogLevel.Information, this, LogFunction.Read, "Module Content Exported {ModuleId}", moduleid);
                        }
                    }
                }
                catch
                {
                    // error occurred during export
                }
            }
            return(content);
        }
Пример #17
0
 public void InsertOrUpdateGraph(ModuleContent moduleContentGraph)
 {
     if (moduleContentGraph.Id == default(int))
     {
         // New Entity
         _context.ModuleContents.Add(moduleContentGraph);
     }
     else
     {
         // Existing User
         moduleContentGraph.State = State.Modified;
         _context.ModuleContents.Add(moduleContentGraph);
         _context.ApplyStateChanges();
     }
 }
Пример #18
0
        public bool Import(int moduleid, [FromBody] string Content)
        {
            bool success = false;

            if (ModelState.IsValid && UserPermissions.IsAuthorized(User, "Module", moduleid, "Edit"))
            {
                try
                {
                    Module module = Modules.GetModule(moduleid);
                    if (module != null)
                    {
                        List <ModuleDefinition> moduledefinitions = ModuleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
                        ModuleDefinition        moduledefinition  = moduledefinitions.Where(item => item.ModuleDefinitionName == module.ModuleDefinitionName).FirstOrDefault();
                        if (moduledefinition != null)
                        {
                            ModuleContent modulecontent = JsonSerializer.Deserialize <ModuleContent>(Content);
                            if (modulecontent.ModuleDefinitionName == moduledefinition.ModuleDefinitionName)
                            {
                                if (moduledefinition.ServerAssemblyName != "")
                                {
                                    Assembly assembly = AppDomain.CurrentDomain.GetAssemblies()
                                                        .Where(item => item.FullName.StartsWith(moduledefinition.ServerAssemblyName)).FirstOrDefault();
                                    if (assembly != null)
                                    {
                                        Type moduletype = assembly.GetTypes()
                                                          .Where(item => item.Namespace != null)
                                                          .Where(item => item.Namespace.StartsWith(moduledefinition.ModuleDefinitionName.Substring(0, moduledefinition.ModuleDefinitionName.IndexOf(","))))
                                                          .Where(item => item.GetInterfaces().Contains(typeof(IPortable))).FirstOrDefault();
                                        if (moduletype != null)
                                        {
                                            var moduleobject = ActivatorUtilities.CreateInstance(ServiceProvider, moduletype);
                                            ((IPortable)moduleobject).ImportModule(module, modulecontent.Content, modulecontent.Version);
                                            success = true;
                                            logger.Log(LogLevel.Information, this, LogFunction.Update, "Module Content Imported {ModuleId}", moduleid);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                    // error occurred during import
                }
            }
            return(success);
        }
Пример #19
0
        public string ExportModule(int moduleId)
        {
            string content = "";

            try
            {
                Module module = GetModule(moduleId);
                if (module != null)
                {
                    List <ModuleDefinition> moduledefinitions = _moduleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
                    ModuleDefinition        moduledefinition  = moduledefinitions.FirstOrDefault(item => item.ModuleDefinitionName == module.ModuleDefinitionName);
                    if (moduledefinition != null)
                    {
                        ModuleContent modulecontent = new ModuleContent();
                        modulecontent.ModuleDefinitionName = moduledefinition.ModuleDefinitionName;
                        modulecontent.Version = moduledefinition.Version;
                        modulecontent.Content = "";

                        if (moduledefinition.ServerManagerType != "")
                        {
                            Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
                            if (moduletype != null && moduletype.GetInterface("IPortable") != null)
                            {
                                try
                                {
                                    var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
                                    modulecontent.Content = ((IPortable)moduleobject).ExportModule(module);
                                }
                                catch
                                {
                                    // error in IPortable implementation
                                }
                            }
                        }

                        content = JsonSerializer.Serialize(modulecontent);
                    }
                }
            }
            catch
            {
                // error occurred during export
            }

            return(content);
        }
Пример #20
0
 //绑定模块UI界面
 private void LoadModuleUI(ModuleContent module)
 {
     //如果没有任何模块加载过,则将module的ui加载只界面
     if (this.curModule == null)
     {
         if (module.ModulePanel != null)
         {
             this.split_Master.Panel2.Controls.Add(module.ModulePanel);
         }
         this.curModule = module;
     }
     //如果界面已经在显示一个模块了,只需要加载菜单即可
     if (module.ModuleNode != null)
     {
         this.tree_nav.Nodes.Add(module.ModuleNode);
     }
 }
Пример #21
0
        public string ExportModule(int ModuleId)
        {
            string content = "";

            try
            {
                Models.Module module = GetModule(ModuleId);
                if (module != null)
                {
                    List <ModuleDefinition> moduledefinitions = _moduleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
                    ModuleDefinition        moduledefinition  = moduledefinitions.Where(item => item.ModuleDefinitionName == module.ModuleDefinitionName).FirstOrDefault();
                    if (moduledefinition != null)
                    {
                        ModuleContent modulecontent = new ModuleContent();
                        modulecontent.ModuleDefinitionName = moduledefinition.ModuleDefinitionName;
                        modulecontent.Version = moduledefinition.Version;
                        modulecontent.Content = "";

                        if (moduledefinition.ServerAssemblyName != "")
                        {
                            Assembly assembly = AppDomain.CurrentDomain.GetAssemblies()
                                                .Where(item => item.FullName.StartsWith(moduledefinition.ServerAssemblyName)).FirstOrDefault();
                            if (assembly != null)
                            {
                                Type moduletype = assembly.GetTypes()
                                                  .Where(item => item.Namespace != null)
                                                  .Where(item => item.Namespace.StartsWith(moduledefinition.ModuleDefinitionName.Substring(0, moduledefinition.ModuleDefinitionName.IndexOf(","))))
                                                  .Where(item => item.GetInterfaces().Contains(typeof(IPortable))).FirstOrDefault();
                                if (moduletype != null)
                                {
                                    var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
                                    modulecontent.Content = ((IPortable)moduleobject).ExportModule(module);
                                }
                            }
                        }
                        content = JsonSerializer.Serialize(modulecontent);
                    }
                }
            }
            catch
            {
                // error occurred during export
            }
            return(content);
        }
Пример #22
0
        public bool ImportModule(int moduleId, string content)
        {
            bool success = false;

            try
            {
                Module module = GetModule(moduleId);
                if (module != null)
                {
                    List <ModuleDefinition> moduledefinitions = _moduleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
                    ModuleDefinition        moduledefinition  = moduledefinitions.Where(item => item.ModuleDefinitionName == module.ModuleDefinitionName).FirstOrDefault();
                    if (moduledefinition != null)
                    {
                        ModuleContent modulecontent = JsonSerializer.Deserialize <ModuleContent>(content.Replace("\n", ""));
                        if (modulecontent.ModuleDefinitionName == moduledefinition.ModuleDefinitionName)
                        {
                            if (moduledefinition.ServerManagerType != "")
                            {
                                Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
                                if (moduletype != null && moduletype.GetInterface("IPortable") != null)
                                {
                                    try
                                    {
                                        var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
                                        ((IPortable)moduleobject).ImportModule(module, modulecontent.Content, modulecontent.Version);
                                        success = true;
                                    }
                                    catch
                                    {
                                        // error in IPortable implementation
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // error occurred during import
                string error = ex.Message;
            }

            return(success);
        }
Пример #23
0
        //树节点选择时
        private void tree_nav_AfterSelect(object sender, TreeViewEventArgs e)
        {
            //当前节点父节点
            TreeNode root = e.Node;

            while (root.Parent != null)
            {
                root = root.Parent;
            }


            //找到对应的节点,进行事件处理
            ModuleContent module = this.modules.FirstOrDefault(m => object.ReferenceEquals(root, m.ModuleNode));

            this.SwitchModuleUI(module);
            this.curModule = module;
            module.Handler?.Invoke(e.Node, e.Node.FullPath);
        }
Пример #24
0
        public bool ImportModule(int ModuleId, string Content)
        {
            bool success = false;

            try
            {
                Models.Module module = GetModule(ModuleId);
                if (module != null)
                {
                    List <ModuleDefinition> moduledefinitions = ModuleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
                    ModuleDefinition        moduledefinition  = moduledefinitions.Where(item => item.ModuleDefinitionName == module.ModuleDefinitionName).FirstOrDefault();
                    if (moduledefinition != null)
                    {
                        ModuleContent modulecontent = JsonSerializer.Deserialize <ModuleContent>(Content);
                        if (modulecontent.ModuleDefinitionName == moduledefinition.ModuleDefinitionName)
                        {
                            if (moduledefinition.ServerAssemblyName != "")
                            {
                                Assembly assembly = AppDomain.CurrentDomain.GetAssemblies()
                                                    .Where(item => item.FullName.StartsWith(moduledefinition.ServerAssemblyName)).FirstOrDefault();
                                if (assembly != null)
                                {
                                    Type moduletype = assembly.GetTypes()
                                                      .Where(item => item.Namespace != null)
                                                      .Where(item => item.Namespace.StartsWith(moduledefinition.ModuleDefinitionName.Substring(0, moduledefinition.ModuleDefinitionName.IndexOf(","))))
                                                      .Where(item => item.GetInterfaces().Contains(typeof(IPortable))).FirstOrDefault();
                                    if (moduletype != null)
                                    {
                                        var moduleobject = ActivatorUtilities.CreateInstance(ServiceProvider, moduletype);
                                        ((IPortable)moduleobject).ImportModule(module, modulecontent.Content, modulecontent.Version);
                                        success = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                // error occurred during import
            }
            return(success);
        }
Пример #25
0
        /// <summary>
        /// 返回指定Xml文件中的Content元素所对应的对象
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <returns></returns>
        public static ModuleContent LoadContent(string filename)
        {
            XmlDocument xmlfile = LoadXmlFile(filename);

            if (xmlfile == null)
            {
                return(null);
            }
            XmlNode xmlnode = xmlfile.SelectSingleNode("/Module/Content");

            if (xmlnode == null)
            {
                return(null);
            }

            ModuleContent ct = new ModuleContent();

            ct.Type = xmlnode.Attributes["type"] == null ? ModuleContentType.HtmlInline : ParseContentType(xmlnode.Attributes["type"].Value);
            switch (ct.Type)
            {
            case ModuleContentType.Html:
                //ct.ContentHtml = "<script><!--\r\nremote_modules.push(new RemoteModule(\"{0}\",\"__MODULE_ID__\",\"{1}\",\"ifr.aspx?url={0}&nocache=1&mid=__MODULE_ID__&parent={2}\",false));// -->\r\n</script><div id=remote___MODULE_ID__ style=\"border:0px;padding:0px;margin:0px;width:100%\"><iframe id=remote_iframe___MODULE_ID__ style=\"border:0px;padding:0px;margin:0px;width:100%;height:200px;overflow:hidden;\" frameborder=0 scrolling=no></iframe>";
                ct.ContentHtml = xmlnode.InnerText;
                break;

            case ModuleContentType.HtmlInline:
                ct.ContentHtml = xmlnode.InnerText;
                break;

            case ModuleContentType.Url:
                //<div id="remote_2" style="border: 0px none ; margin: 0px; padding: 0px; width: 100%;"><iframe src="http://offtype.net/google_gadget/gallery_widget.html?lang=en&amp;country=us&amp;.lang=en&amp;.country=us&amp;synd=ig&amp;mid=2&amp;parent=http://www.google.com&amp;libs=xu4k3HB9Ud0/lib/libcore.js" id="remote_iframe_2" style="border: 0px none ; margin: 0px; padding: 0px; overflow: hidden; width: 100%; height: 300px;" frameborder="0" scrolling="no"></iframe></div>
                ct.Href        = xmlnode.Attributes["href"] == null ? "" : xmlnode.Attributes["href"].Value;
                ct.ContentHtml = string.Format("<div id=\"remote___MODULE_ID__\" style=\"border: 0px none ; margin: 0px; padding: 0px; width: 100%;\"><iframe src=\"{0}\"  id=\"remote_iframe___MODULE_ID__\" style=\"border: 0px none ; margin: 0px; padding: 0px; overflow: hidden; width: 100%; height: 300px; background: transparent;\" allowtransparency=\"yes\" frameborder=\"0\" scrolling=\"no\"></iframe></div>", ct.Href + "?{0}");
                break;

            default:
                break;
            }

            return(ct);
        }
        public async void ChangeModuleContentOrder_CalledWithValidIds_ReturnsOk()
        {
            IUnitOfWork    unitOfWork    = Substitute.For <IUnitOfWork>();
            ICookieManager cookieManager = Substitute.For <ICookieManager>();
            var            context       = Substitute.For <HttpContext>();

            long          testId            = 1;
            long          testcontentId     = 1;
            ModuleContent nullModuleContent = null;
            string        error             = "Only Admins can update module content.";

            unitOfWork.ModuleContents.GetById(testId).Returns(nullModuleContent);
            cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Student.ToString());

            var moduleContentsController = new ModuleContentsController(unitOfWork, cookieManager);

            moduleContentsController.ControllerContext = new ControllerContext()
            {
                HttpContext = context
            };
        }
Пример #27
0
        //记录模块信息
        private ModuleContent RegsiterModule(Panel moduleContiner, object[] components)
        {
            ModuleContent module = new ModuleContent();

            foreach (object componet in components)
            {
                if (componet is TreeNode)
                {
                    module.ModuleNode = (TreeNode)componet;
                }
                else if (componet is Control)
                {
                    module.ModulePanel = moduleContiner;
                    moduleContiner.Controls.Add((Control)componet);
                }
                else if (componet is Action <object, string> )
                {
                    module.Handler = (Action <object, string>)componet;
                }
            }
            return(module);
        }
Пример #28
0
        //承载模块UI
        public void VisualModule(IModule module)
        {
            if (module == null)
            {
                return;
            }

            //用一个panel将module包装
            Panel moduleContiner = this.CreateModuleContiner(module);

            object[] components = module.LoadUIComponent(null);
            if (components == null && components.Length < 1)
            {
                return;
            }

            ModuleContent content = this.RegsiterModule(moduleContiner, components);

            content.Module = module;
            this.LoadModuleUI(content);
            this.modules.Add(content);
        }
Пример #29
0
        public async Task <IActionResult> AddModuleContent([FromBody] ModuleContentViewModel ModuleContent)
        {
            if (ModuleContent == null)
            {
                return(BadRequest("Module content cannot be null."));
            }

            var userRole = _cookieManager.GetRoleFromToken(Request.Headers["Authorization"]);

            if (userRole.Equals(Role.Admin.ToString()))
            {
                var Module = await _repository.Modules.GetById(ModuleContent.ModuleId);

                if (Module == null)
                {
                    return(NotFound(ModuleContent.ModuleId));
                }

                var NextContentId    = (await _repository.ModuleContents.GetLastModuleContentByModuleId(ModuleContent.ModuleId)) + 1;
                var NewModuleContent = new ModuleContent()
                {
                    Title        = ModuleContent.Title,
                    Description  = ModuleContent.Description,
                    Module       = Module,
                    ContentId    = NextContentId,
                    AssigmentUrl = ModuleContent.AssigmentUrl,
                    Lesson       = ModuleContent.Lesson
                };

                _repository.ModuleContents.Add(NewModuleContent);
                await _repository.Complete();

                return(Ok());
            }

            return(BadRequest("Only Admins can add new module contents."));
        }
        public async void GetVideosByModuleContentId_CalledWithValidId_ReturnOkWithListOfVideo()
        {
            IUnitOfWork    unitOfWork    = Substitute.For <IUnitOfWork>();
            IVideoManager  videoManager  = Substitute.For <IVideoManager>();
            ICookieManager cookieManager = Substitute.For <ICookieManager>();

            long testId            = 1;
            var  testModuleContent = new ModuleContent()
            {
                Id = testId
            };
            var testVideos = new List <Video>()
            {
                new Video()
                {
                    ModuleContent = testModuleContent
                }, new Video()
                {
                    ModuleContent = testModuleContent
                }, new Video()
                {
                    ModuleContent = testModuleContent
                }
            };

            unitOfWork.Videos.GetVideosByModuleContentId(testId).Returns(testVideos);

            var videosController = new VideosController(unitOfWork, videoManager, cookieManager);

            var result = await videosController.GetVideosByModuleContentId(testId);

            var okObjectResult = Assert.IsType <OkObjectResult>(result);
            var returnValue    = Assert.IsType <List <Video> >(okObjectResult.Value);

            Assert.Equal(testVideos.Count, returnValue.Count);
            Assert.Equal(testId, returnValue[0].ModuleContent.Id);
        }
        public async void AddVideo_CalledWithInvalidContentId_RetrunsNotFoundWithId()
        {
            IUnitOfWork    unitOfWork    = Substitute.For <IUnitOfWork>();
            IVideoManager  videoManager  = Substitute.For <IVideoManager>();
            ICookieManager cookieManager = Substitute.For <ICookieManager>();
            var            context       = Substitute.For <HttpContext>();

            long testId    = 1;
            var  testVideo = new VideoViewModel()
            {
                ModuleContentId = testId
            };
            ModuleContent nullModuleContent = null;
            string        testUrl           = "testurl";
            string        convertedUrl      = "converted";
            string        testyoutubeId     = "youtubeid";

            unitOfWork.ModuleContents.GetById(testId).Returns(nullModuleContent);
            videoManager.ConvertUrl(testUrl).Returns(convertedUrl);
            videoManager.GetYoutubeId(convertedUrl).Returns(testyoutubeId);
            cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Admin.ToString());

            var videosController = new VideosController(unitOfWork, videoManager, cookieManager);

            videosController.ControllerContext = new ControllerContext()
            {
                HttpContext = context
            };

            var result = await videosController.AddVideo(testVideo);

            var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result);
            var retrunValue          = Assert.IsType <long>(notFoundObjectResult.Value);

            Assert.Equal(testId, retrunValue);
        }