LogoLogo
HomePricingDocumentation
  • 💿Getting Started
    • Installation and Project Setup
    • Hello Perigee!
    • Perigee Application Design
    • Hello Configuration
    • Hello Logs
    • Hello Integration
    • Troubleshooting
    • Case Studies
  • 📃License + Notice
    • 📂Licensing
    • Notice of Third Party Agreements
  • 🚀Perigee and Beyond
    • Extending - Threads
    • Extending - Loaders
    • ⏳All about CRON
  • 🔮API Generation
    • What is API Generation?
    • API Builder
  • 🗺️Architecting YOUR App
    • Design and Requirements
    • Define Sources
    • Requirements
  • 🧩Core Modules
    • 🌐PerigeeApplication
    • 🪡Thread Registry
    • Event Sources
      • Scheduled/Logic
        • CRON Thread
        • Scheduler
        • Sync Agent
      • Watchers
        • SalesForce
        • Sharepoint
        • Directory Watch
        • Directory Notifier
        • IMAP
    • Credential Management
      • Connection Strings
      • Custom Refresh Logic
      • RestSharp Authenticator
      • Credential Store SDK
      • ⁉️Troubleshooting Credentials
    • Integration Utilities
      • HTTP(S) - RestSharp
      • Transaction Coordinator
      • Limiter
      • Watermarking
    • Alert Managers
      • SMS
      • Email
      • Discord
      • Teams
    • File Formats
      • Excel
      • CSV
    • 📁File System Storage
      • File Revision Store
      • Concurrent File Store
      • FileSync + Cache
    • Third Party
      • SmartSheets
      • Microsoft Graph
    • Perigee In Parallel
      • Parallel Processing Reference
      • Extensions
      • GroupProcessor
      • SingleProcessor
    • 🧱Utility Classes
      • Metrics
      • F(x) Expressions
      • Multi-Threaded Processor (Scatter Gather)
      • OpenAI - GPT
      • XML Converter
      • Dynamic Data Table
      • Debounce
      • Thread Conditions
      • Perigee Utility Class
      • Network Utility
      • Lists
      • FileUtil
      • Inclusive2DRange
      • Strings, Numbers, Dates
      • Nested Sets
      • Behavior Trees
      • JsonCompress
      • Topological Sorting
      • DBDownloader
    • 🈁Bit Serializer
  • 📣Examples and Demos
    • API + Perigee
    • 📰Excel Quick Load
    • SalesForce Watcher
    • Report Scheduler
    • Agent Data Synchronization
    • 📩IMAP Echo bot
    • Watch and load CSVs
    • Graph Delegated Authorization + DataVerse
    • Coordinator Demo
    • Azure Service Bus
    • QuickBooks Online
  • 📘Blueprints
    • Perigee With .NET Hosting
    • Web Host Utilities
    • 🔌Plugin Load Context
  • 🎞️Transforms
    • 🌟What is Transforms?
    • 📘Terminology
    • 🦾The Mapping Document
    • 👾Transformation Process
    • 😎Profile
    • 🎒Automation
      • 🕓Package Options
      • 🔳Configuration
    • 🔧Utilities
      • 🧹Clean
      • 📑Map File
      • 🔎File Identification
      • 🗺️Map Generation
      • 🪅Insert Statement Generation
  • 🗃️Transform SDK
    • 👋Quick Start Guide
    • 🥳MapTo
    • 🔌Authoring Plugins
      • 🔘File IO Process
      • 📢Data Quality
      • 🟢Transform Process
    • SDK Reference
      • 🔘FileIOProcessData
      • 📢DataQualityContext
      • 🎛️TransformDataContext
      • 🏅TransformResult
Powered by GitBook
On this page
Export as PDF
  1. Examples and Demos

API + Perigee

PreviousBit SerializerNextExcel Quick Load

Last updated 1 year ago

Grab the code from the blueprint section for API hosting with Perigee

Admin controller example

In this example we create a controller that allows us to turn threads on and off.

  1. Simply add a new empty "API Controller" to the Controllers folder.

  2. Call it AdminController.cs

  3. Paste the code below in to replace the content

using Microsoft.AspNetCore.Mvc;
using Perigee;
using Perigee.Helpers;

// Visit https://docs.perigee.software to learn more
// Visit https://perigee.software to purchase a license!

namespace PerigeeIntroAPI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class AdminController : ControllerBase
    {
        public ThreadRegistry reg { get; }

        public AdminController(ThreadRegistry tr)
        {
            this.reg = tr;
        }


        [HttpGet]
        public IActionResult Taskcontrol([FromQuery] string task, [FromQuery] bool start)
        {
            //Does this thread exist?
            if (reg.ContainsThreadByName(task))
            {
                if (start)
                {
                    reg.StartIfNotRunning(task); //Start if not started
                    return Ok();
                }
                else
                {
                    reg.QueueStop(task, true); //Stop and do not auto restart
                    return Ok();
                }
            }

            return BadRequest();
        }

        [Route("cron")]
        [HttpGet]
        public IActionResult cron([FromQuery] string name, [FromQuery] string cron, [FromQuery] string result)
        {
            if (reg.ContainsThreadByName(name) || string.IsNullOrEmpty(cron) || string.IsNullOrEmpty(result)) return BadRequest();

            reg.AddManagedThread(new ManagedThread(name, (ct, l) =>
            {
                l.LogInformation("result: {result}", result);
            }, cron, reg.CTS, reg.GetLogger<AdminController>()));

            return new JsonResult(new { Message = $"Will run a CRON thread named {name} {Cron.Parse(cron).ToString()}" });
        }

        [Route("delete")]
        [HttpDelete]
        public IActionResult remove([FromQuery] string name)
        {
            reg.RemoveThreadByName(name);
            return Ok();
        }

        [Route("list")]
        [HttpGet]
        public IActionResult list()
        {
            return new JsonResult(new { Threads = reg.GetThreads().Select(f => new { Name = f.Name, Runtime = f.RunTime }).ToArray() });
        }

        [Route("reboot")]
        [HttpGet]
        public IActionResult reboot()
        {
            reg.RestartAllThreads();
            return Ok();
        }

        [Route("exec")]
        [HttpGet]
        public IActionResult exec([FromQuery] string name)
        {
            reg.ExecuteCRONNow(name);
            return Ok();
        }


    }
}

In this example we've created a simple endpoint we can call to turn anything on or off by simply checking the thread registry for the requested thread, then turning it on or off.

The port may be different - but you can see how easy it would be to turn something on or off!

[GET] https://localhost:5001/api/admin?task=ProcessAgent&start=true

Typically speaking this would be secured or unavailable outside the firewall. Don't forget to secure your endpoints!

Perigee With .NET Hosting
📣
Page cover image