)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » ServiceController (Ia.Statistics.Wa.Controllers)

Public general use code classes and xml files that we've compiled and used over the years:

    1: using Ia.Statistics.Wa.Models;
    2: using Microsoft.AspNetCore.Mvc;
    3: using System.Diagnostics;
    4: using System.Net;
    5: using System.Text.RegularExpressions;
    6:  
    7: namespace Ia.Statistics.Wa.Controllers
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     ///
   13:     /// </summary>
   14:     /// 
   15:     /// <remarks> 
   16:     /// Copyright � 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   17:     ///
   18:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   19:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   20:     ///
   21:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   22:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   23:     /// 
   24:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   25:     /// 
   26:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   27:     /// </remarks> 
   28:     public class ServiceController : Controller
   29:     {
   30:         private readonly ILogger<ServiceController> _logger;
   31:  
   32:         /////////////////////////////////////////////////////////////////////////////////
   33:  
   34:         /// <summary>
   35:         ///
   36:         /// </summary>
   37:         public ServiceController(ILogger<ServiceController> logger)
   38:         {
   39:             _logger = logger;
   40:         }
   41:  
   42:         /////////////////////////////////////////////////////////////////////////////////
   43:  
   44:         /// <summary>
   45:         ///
   46:         /// </summary>
   47:         public IActionResult Index() { return View(); }
   48:  
   49:         /////////////////////////////////////////////////////////////////////////////////
   50:  
   51:         /// <summary>
   52:         ///
   53:         /// </summary>
   54:         public IActionResult Advertisement() { return View("Advertisement"); }
   55:  
   56:         /////////////////////////////////////////////////////////////////////////////////
   57:  
   58:         /// <summary>
   59:         ///
   60:         /// </summary>
   61:         [Route("/service/api-service")]
   62:         public IActionResult ApiService() 
   63:         {
   64:             var ip = Request.HttpContext.Connection.RemoteIpAddress;
   65:  
   66:             return View((object)ip.ToString()); 
   67:         }
   68:  
   69:         /////////////////////////////////////////////////////////////////////////////////
   70:  
   71:         /// <summary>
   72:         ///
   73:         /// </summary>
   74:         public IActionResult Cloud() { return View(); }
   75:  
   76:         /////////////////////////////////////////////////////////////////////////////////
   77:  
   78:         /// <summary>
   79:         ///
   80:         /// </summary>
   81:         public IActionResult Cryptography() { return View(); }
   82:  
   83:         /////////////////////////////////////////////////////////////////////////////////
   84:  
   85:         /// <summary>
   86:         ///
   87:         /// </summary>
   88:         public IActionResult Dn() { return View(); }
   89:  
   90:         /////////////////////////////////////////////////////////////////////////////////
   91:  
   92:         /// <summary>
   93:         ///
   94:         /// </summary>
   95:         public IActionResult Ecommerce() { return View(); }
   96:  
   97:         /////////////////////////////////////////////////////////////////////////////////
   98:  
   99:         /// <summary>
  100:         ///
  101:         /// </summary>
  102:         public IActionResult GeoIp() 
  103:         {
  104:             var ip = Request.HttpContext.Connection.RemoteIpAddress.ToString();
  105:  
  106:             ViewBag.RemoteIp = ip;
  107:  
  108:             return View((object)ip.ToString()); 
  109:         }
  110:  
  111:         /////////////////////////////////////////////////////////////////////////////////
  112:  
  113:         /// <summary>
  114:         ///
  115:         /// </summary>
  116:         [HttpPost]
  117:         public IActionResult GeoIp(string ipTextInput)
  118:         {
  119:             var ip = WebUtility.HtmlEncode(ipTextInput);
  120:             ip = ip.Trim();
  121:  
  122:             ViewBag.Ip = ip;
  123:  
  124:             var result = new Ia.Cl.Models.Result(); // ProcessEmail(nameTextInput, emailTextInput, phoneTextInput, inquiryTextArea);
  125:  
  126:             var countryInfo = new Ia.Cl.Models.GeoIp.CountryInfo();
  127:  
  128:             if (Ia.Cl.Models.Default.IsValidIpv4(ip))
  129:             {
  130:                 countryInfo = Ia.Cl.Models.Http.GetAsync<Ia.Cl.Models.GeoIp.CountryInfo>("https://api.ia.com.kw", "api/geoip/countries/" + ip).Result;
  131:  
  132:                 if (countryInfo != null)
  133:                 {
  134:                     ViewBag.CountryInfoName = countryInfo.Name;
  135:                     ViewBag.CountryInfoIsoCode = countryInfo.IsoCode;
  136:                     ViewBag.FlagUrlImageUrl = @"https://cdn.ia.com.kw/image/flag/iso/32/" + countryInfo.IsoCode.ToLower() + ".png";
  137:                     ViewBag.FlagUrlImageText = countryInfo.Name;
  138:  
  139:                     result.AddSuccess("");
  140:                 }
  141:                 else
  142:                 {
  143:                     result.AddError("Could not find country from IP.");
  144:                 }
  145:             }
  146:             else
  147:             {
  148:                 result.AddError("Entered string is not in a valid IP format.");
  149:             }
  150:  
  151:             if (result.IsSuccessful)
  152:             {
  153:                 ViewBag.ResultMessage = result.Message;
  154:                 ViewBag.ResultClass = "success";
  155:             }
  156:             else
  157:             {
  158:                 ViewBag.ResultMessage = result.Message;
  159:                 ViewBag.ResultClass = "error";
  160:             }
  161:  
  162:             return View((object)ip.ToString());
  163:         }
  164:  
  165:         /////////////////////////////////////////////////////////////////////////////////
  166:  
  167:         /// <summary>
  168:         ///
  169:         /// </summary>
  170:         public IActionResult Intranet() { return View(); }
  171:  
  172:         /////////////////////////////////////////////////////////////////////////////////
  173:  
  174:         /// <summary>
  175:         ///
  176:         /// </summary>
  177:         public IActionResult Iot() { return View(); }
  178:  
  179:         /////////////////////////////////////////////////////////////////////////////////
  180:  
  181:         /// <summary>
  182:         ///
  183:         /// </summary>
  184:         [Route("/service/ip-camera")]
  185:         public IActionResult IpCamera() { return View(); }
  186:  
  187:         /////////////////////////////////////////////////////////////////////////////////
  188:  
  189:         /// <summary>
  190:         ///
  191:         /// </summary>
  192:         public IActionResult Map() { return View(); }
  193:  
  194:         /////////////////////////////////////////////////////////////////////////////////
  195:  
  196:         /// <summary>
  197:         ///
  198:         /// </summary>
  199:         [Route("/service/qr-code")]
  200:         public IActionResult QrCode() { return View(); }
  201:  
  202:         /////////////////////////////////////////////////////////////////////////////////
  203:  
  204:         /// <summary>
  205:         ///
  206:         /// </summary>
  207:         public IActionResult Regex() { return View(); }
  208:         //[Route("/service/regex")] for razor pages
  209:         //public IActionResult Regex() { return View("/Pages/Regex.cshtml"); }
  210:  
  211:         /////////////////////////////////////////////////////////////////////////////////
  212:  
  213:         /// <summary>
  214:         ///
  215:         /// </summary>
  216:         [HttpPost]
  217:         public IActionResult Regex(string textArea, string patternTextInput, string replacementTextInput)
  218:         {
  219:             string text, patternText, replacementText, l;
  220:  
  221:             var result = new Ia.Cl.Models.Result();
  222:  
  223:             text = WebUtility.HtmlEncode(textArea) ?? string.Empty;
  224:             patternText = WebUtility.HtmlEncode(patternTextInput) ?? string.Empty;
  225:             replacementText = WebUtility.HtmlEncode(replacementTextInput) ?? string.Empty;
  226:  
  227:             if (!string.IsNullOrEmpty(text))
  228:             {
  229:                 if (!string.IsNullOrEmpty(patternText))
  230:                 {
  231:                     if (!string.IsNullOrEmpty(replacementText))
  232:                     {
  233:                         try
  234:                         {
  235:                             l = System.Text.RegularExpressions.Regex.Replace(text, patternText, replacementText);
  236:  
  237:                             // now I will encode string to display HTML code on the HTML page
  238:                             ViewBag.ResultText = Ia.Cl.Models.Html.Encode(l);
  239:  
  240:                             result.AddSuccess("Successful");
  241:                         }
  242:                         catch (Exception ex)
  243:                         {
  244:                             result.AddError("Regular expression could not be evaluated: " + ex.Message);
  245:                         }
  246:                     }
  247:                     else
  248:                     {
  249:                         result.AddError("Replacement field is missing.");
  250:                     }
  251:                 }
  252:                 else
  253:                 {
  254:                     result.AddError("Pattern field is missing.");
  255:                 }
  256:             }
  257:             else
  258:             {
  259:                 result.AddError("Text field is empty.");
  260:             }
  261:  
  262:             if (result.IsSuccessful)
  263:             {
  264:                 ViewBag.ResultMessage = result.Message;
  265:                 ViewBag.ResultClass = "success";
  266:             }
  267:             else
  268:             {
  269:                 ViewBag.ResultMessage = result.Message;
  270:                 ViewBag.ResultClass = "error";
  271:             }
  272:  
  273:             return View();
  274:         }
  275:  
  276:         /////////////////////////////////////////////////////////////////////////////////
  277:  
  278:         /// <summary>
  279:         ///
  280:         /// </summary>
  281:         public IActionResult Server() { return View(); }
  282:  
  283:         /////////////////////////////////////////////////////////////////////////////////
  284:  
  285:         /// <summary>
  286:         ///
  287:         /// </summary>
  288:         public IActionResult Sms() { return View(); }
  289:  
  290:         /////////////////////////////////////////////////////////////////////////////////
  291:  
  292:         /// <summary>
  293:         ///
  294:         /// </summary>
  295:         public IActionResult Telegram() { return View(); }
  296:  
  297:         /////////////////////////////////////////////////////////////////////////////////
  298:  
  299:         /// <summary>
  300:         ///
  301:         /// </summary>
  302:         public IActionResult Unix() { return View(); }
  303:  
  304:         /////////////////////////////////////////////////////////////////////////////////
  305:  
  306:         /// <summary>
  307:         ///
  308:         /// </summary>
  309:         public IActionResult Video() { return View(); }
  310:  
  311:         /////////////////////////////////////////////////////////////////////////////////
  312:  
  313:         /// <summary>
  314:         ///
  315:         /// </summary>
  316:         public IActionResult Winform() { return View(); }
  317:  
  318:         /////////////////////////////////////////////////////////////////////////////////
  319:  
  320:         /// <summary>
  321:         ///
  322:         /// </summary>
  323:         [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
  324:         public IActionResult Error()
  325:         {
  326:             return View(new Ia.Statistics.Wa.Models.ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
  327:         }
  328:  
  329:         /////////////////////////////////////////////////////////////////////////////////
  330:         /////////////////////////////////////////////////////////////////////////////////
  331:     }
  332:  
  333:     /////////////////////////////////////////////////////////////////////////////////
  334:     /////////////////////////////////////////////////////////////////////////////////
  335: }