DEV Community

Cover image for .NET Diamond shows some of its power
elanatframework
elanatframework

Posted on • Updated on

.NET Diamond shows some of its power

In this article, we teach how to create modular system, scheduled task, startup, reference list before execution and reference list after execution.

In the following article, we had some references to these things; now we will explain their implementation using CodeBehind framework; of course, we only mention how to implement.
https://dev.to/elanatframework/aspnet-core-vs-codebehind-2246

After reading the article, you will understand why CodeBehind is called .NET Diamond.

How to create modular systems by CodeBehind framework?
The project created by using CodeBehind is automatically a modular project, that is, it has the ability to add web parts. In addition, each web part can be used in other projects.

You can add a page to insert a module (web part) on the admin page of your project; this page should include an input for uploading, and after copying, run the CodeBehind compilation methods again; according to the following codes:

// Recompile
CodeBehindCompiler.Initialization();
CodeBehindCompiler.CompileAspx();
Enter fullscreen mode Exit fullscreen mode

How to create Scheduled task system by CodeBehind framework?
First, create an xml file (or json or ini or etc) similar to the following file:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<scheduled_tasks_root>
  <scheduled_tasks_list>
    <scheduled_task name="empty_tmp_directory" path="/action/system_access/scheduled_tasks/empty_tmp_directory/Default.aspx" active="true" corn_hour="86400" type="load" check_type="page" last_run="20230830010903" />
    <scheduled_task name="empty_session_data_directory" path="/action/system_access/scheduled_tasks/empty_session_data_directory/Default.aspx" active="true" corn_hour="86400" type="load" check_type="page" last_run="20230830010903" />
    <scheduled_task name="active_delay_content" path="/action/system_access/scheduled_tasks/active_delay_content/Default.aspx" active="true" corn_hour="600" type="load" check_type="page" last_run="20230830010903" />
    <scheduled_task name="delete_robot_blocked_ip" path="/action/system_access/scheduled_tasks/delete_robot_blocked_ip/Default.aspx" active="true" corn_hour="600" type="load" check_type="page" last_run="20230830010903" />
  </scheduled_tasks_list>
</scheduled_tasks_root>
Enter fullscreen mode Exit fullscreen mode

Scheduled task is one of the most important parts of a high-level project; you can run the Scheduled task method in the Run method in the builder located in the Program.cs class.

app.Run(async context =>
{
+  ScheduledTask.Run(context);

   CodeBehindExecute execute = new CodeBehindExecute();
   await context.Response.WriteAsync(execute.Run(context));
   await context.Response.CompleteAsync();
});
Enter fullscreen mode Exit fullscreen mode

You can perform the scheduled task either by request or by calling a timer (of course, if you don't allow the system to sleep!).

Note: You can implement both of them in a combination.

How to create Startup system by CodeBehind framework?
First, create an xml file (or json or ini or etc) similar to the following file:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<start_up_root>
  <start_up_list>
    <start_up name="start_timer" path="/action/system_access/start_up/start_timer/Default.aspx" active="true" />
    <start_up name="send_start_project_email_to_provider" path="/action/system_access/start_up/send_start_project_email_to_provider/Default.aspx" active="true" />
  </start_up_list>
</start_up_root>
Enter fullscreen mode Exit fullscreen mode

Startup is a structure that allows you to initialize some things before the program is activated; you can run the Startup method before the Run method in the builder located in the Program.cs class.

+  Startup.Run();

app.Run(async context =>
{
   CodeBehindExecute execute = new CodeBehindExecute();
   await context.Response.WriteAsync(execute.Run(context));
   await context.Response.CompleteAsync();
});
Enter fullscreen mode Exit fullscreen mode

Note: In CodeBehind framework version 1.5.1 (and later versions) you can call Run method in CodeBehindExecute without needing HttpContext.

   CodeBehindExecute execute = new CodeBehindExecute();
   execute.Run(StartupNodePath);
Enter fullscreen mode Exit fullscreen mode

In the code above, StartupNodePath can be a path like below.
/action/system_access/start_up/send_start_project_email_to_provider/Default.aspx

How to create Before load path reference system by CodeBehind framework?
First, create an xml file (or json or ini or etc) similar to the following file:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<before_load_path_reference_root>

  <before_load_path_reference_list>

    <reference type="url" check_type="page" exist="true" start_by="false" end_by="false" regex_match="false" active="false" reason="login_try_count_limitation_is_active">
      <path_value>btn_Login=</path_value>
      <load_value><![CDATA[/action/system_access/reference/check_login_try_count_limitation/Default.aspx]]></load_value>
    </reference>

    <reference type="form" check_type="page" exist="true" start_by="false" end_by="false" regex_match="false" active="false" reason="login_try_count_limitation_is_active">
      <path_value>btn_Login=</path_value>
      <load_value><![CDATA[/action/system_access/reference/check_login_try_count_limitation/Default.aspx]]></load_value>
    </reference>

    <reference type="url" check_type="page" exist="true" start_by="false" end_by="false" regex_match="false" active="true" reason="lock_login_is_active">
      <path_value>btn_Login=</path_value>
      <load_value><![CDATA[/action/system_access/reference/check_lock_login/Default.aspx]]></load_value>
    </reference>

    <reference type="form" check_type="page" exist="true" start_by="false" end_by="false" regex_match="false" active="true" reason="lock_login_is_active">
      <path_value>btn_Login=</path_value>
      <load_value><![CDATA[/action/system_access/reference/check_lock_login/Default.aspx]]></load_value>
    </reference>

    <reference type="url" check_type="page" exist="true" start_by="false" end_by="false" regex_match="false" active="true" reason="next_search_time_interval_limitation_is_active">
      <path_value>btn_Search=</path_value>
      <load_value><![CDATA[/action/system_access/reference/check_next_search_time_interval_limitation/Default.aspx]]></load_value>
    </reference>

    <reference type="form" check_type="page" exist="true" start_by="false" end_by="false" regex_match="false" active="true" reason="next_search_time_interval_limitation_is_active">
      <path_value>btn_Search=</path_value>
      <load_value><![CDATA[/action/system_access/reference/check_next_search_time_interval_limitation/Default.aspx]]></load_value>
    </reference>

  </before_load_path_reference_list>

</before_load_path_reference_root>
Enter fullscreen mode Exit fullscreen mode

You can control the url paths before execution. The above example shows that you can execute aspx pages before executing the route and deny access to the routes or change or add to the output hypertext. The first reference in the xml file above shows that there is a restriction to enter the login page; every time the user clicks on the login button, the aspx page is executed and the number of login attempts is reduced by one from the session; if this value becomes 0, it will not allow entry.

you can run the BeforeLoadPathReference method in the Run method in the builder (before execute page) located in the Program.cs class.

app.Run(async context =>
{
+  BeforeLoadPathReference.Run(context);

   CodeBehindExecute execute = new CodeBehindExecute();
   await context.Response.WriteAsync(execute.Run(context));
   await context.Response.CompleteAsync();
});
Enter fullscreen mode Exit fullscreen mode

How to create After load path reference system by CodeBehind framework?
First, create an xml file (or json or ini or etc) similar to the following file:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<after_load_path_reference_root>

  <after_load_path_reference_list>

    <reference type="url" check_type="page" exist="false" start_by="true" end_by="false" regex_match="false" active="true">
      <path_value>/upload/attachment/</path_value>
      <load_value><![CDATA[/action/system_access/reference/increase_attachment_visit/Default.aspx]]></load_value>
    </reference>

  </after_load_path_reference_list>

</after_load_path_reference_root>
Enter fullscreen mode Exit fullscreen mode

You also have the possibility to control the url paths after execution. The example above shows that you can run aspx pages after running the route. In the xml file above, you can see that after the requests, an aspx page is executed in the upload/attachment path, and if the path is an existing file in the path and database, the download value of the attachment file in the database is added by one number.

you can run the AfterLoadPathReference method in the Run method in the builder (before execute page) located in the Program.cs class.

app.Run(async context =>
{
   CodeBehindExecute execute = new CodeBehindExecute();
   await context.Response.WriteAsync(execute.Run(context));

+  AfterLoadPathReference.Run(context);

   await context.Response.CompleteAsync();
});
Enter fullscreen mode Exit fullscreen mode

The advanced features mentioned above mean the features that make your system adjustable. Customers of your system may want to add things that you don't even know about.

CodeBehind in NuGet:
https://www.nuget.org/packages/CodeBehind

CodeBehind repository link:
https://github.com/elanatframework/Code_behind

CodeBehind page in Elanat website:
https://elanat.net/page_content/code_behind

Top comments (0)