Difference between revisions of "Sample Module"

Line 77: Line 77:
 
3. Clear the contents of TCAdmin2\Cache and restart the monitor
 
3. Clear the contents of TCAdmin2\Cache and restart the monitor
  
4. You can then navigate to your module in your browser e.g http://127.0.0.1/Service/HelloWorld/1
+
4. You can then navigate to the module in your browser e.g http://127.0.0.1/Service/HelloWorld/1
  
 
<br/>
 
<br/>

Revision as of 22:24, 20 May 2020

This is an example of a module that can be installed onto your master which will work with TCAdmin.

Sample View Page - HelloWorld.cshtml

@model Game.HelloWorldModel
@{
    Layout = this.GetTemplateFile("Shared/Main.cshtml", true);

    <script>
        $(document).ready(function () {
            document.title = "@TCAdmin.SDK.Web.MVC.Template.GetSelectedTemplateTitle() " + "Hello World!";
            $('.header-text').html("Hello World - A Sample Module")
        });
    </script>
}

@section head{

}

@section sidebar{
    @Html.Action("_PageIcons", "Service", new { id = Model.Service.ServiceId })
}
<br />
@Model.Message
<br />
<br />
@Model.ServiceStartedOn

Sample Controller - HelloWorldController.cs

using System.Web.Mvc;
using TCAdmin.SDK.Web.MVC.Controllers;

namespace Game
{
    public class HelloWorldModel
    {
        public string Message { get; set; }
        public string ServiceStartedOn { get; set; }
        public TCAdmin.GameHosting.SDK.Objects.Service Service { get; set; }
    }

    public class HelloWorldController : BaseServiceController
    {
        [HttpGet]
        [ParentAction("Service", "Home")]
        public ActionResult Index(int id)
        {
            //Make sure the user has permission this feature
            EnforceFeaturePermission("FileManager");

            var model = new HelloWorldModel();
            model.Service = TCAdmin.GameHosting.SDK.Objects.Service.GetSelectedService();
            model.Message = "Hello World!";
            model.ServiceStartedOn = string.Format($"{model.Service.ConnectionInfo} was started on {TCAdmin.SDK.Misc.Dates.UniversalTimeToCurrentTimeZone(model.Service.Status.StartTime)} with process id {model.Service.Status.ProcessId}");


            return View("HelloWorld", model);
        }
    }
}


How to install the module after compiling it with TCAdmin:


1. Copy SampleController.dll to TCAdmin2\ControlPanel.MVC\bin-extensions

2. Copy HelloWorld.cshtml to ControlPanel.MVC\Views\[ThemeFolder]\Game\Service

3. Clear the contents of TCAdmin2\Cache and restart the monitor

4. You can then navigate to the module in your browser e.g http://127.0.0.1/Service/HelloWorld/1


What this module looks like:

ModuleView1.png

Retrieved from "https://help.tcadmin.com/index.php?title=Sample_Module&oldid=2097"