Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using Sente.DAL.ORM;
- using Sente.DAL.ORM.Firebird;
- using Sente.Workflow.Client.Concrete;
- using Sente.Workflow.Client.DAL;
- using Sente.Workflow.Client.Models;
- using System;
- using System.Data.Common;
- using System.Linq;
- namespace Sente.Workflow.ConsoleRunner
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- //Case 1.
- using (var dataContext = new FbWorkflowClientDataContext(new FbContext("User=SYSDBA;Password=makumba;Database=/mnt/db/esystem20170808.fdb;Data Source=10.168.0.202;Port=3050;Dialect=3;Charset=WIN1250;Role=;Pooling=true;MinPoolSize=2;MaxPoolSize=10;IsolationLevel=ReadCommitted;ServerType=0")))
- {
- var client = new FbWorkflowClient(dataContext);
- dataContext.StartTransaction();
- // wywołanie utworzenia procesu
- var process = CreateProcess(client);
- dataContext.Commit();
- dataContext.StartTransaction();
- // wywołanie inicjalizacji procesu (metoda nie dokona tranzycji)
- var transitionResult1 = InitProcess2(client, process.Id);
- Console.WriteLine(JsonConvert.SerializeObject(transitionResult1));
- // wywołanie inicjalizacji procesu (metoda poprawnie dokona tranzycji)
- // zapisanie wyników
- dataContext.Commit();
- // po zacommitowaniu (można było to zrobić po każdej operacji:)) - proces powinien być w stanie INITIALIZING.
- // do uruchomienia workflow (Everest.Workflow) - który wykona asynchronizcznie aktywność
- // i zmieni stan na WAITING FOR CLIENT INPUT
- //
- // W kolejnej metodzie na WS prawdopodonie odbierzemy dane z portalu, zapiszemy je w tabelce
- // i spróbujemy wykonać tranzycję (tak jak w InitProcess1 / 2).
- // Jeżeli wystąpią problemy z walidacją -
- }
- Console.ReadLine();
- }
- /// <summary>
- /// Przykład utworzenia procesu
- /// </summary>
- /// <typeparam name="TConnection"></typeparam>
- /// <param name="dbContext"></param>
- /// <param name="workflowClient"></param>
- public static Process CreateProcess(FbWorkflowClient workflowClient)
- {
- // var task = .... - sprawdzenie i zapisanie oferty po stronie bazy danych, zwrócenie jakiś danych do rozpoczęcia procesu
- // startujemy nową instancję procesu
- var process = workflowClient.StartProcess(3);
- // zapisujemy parametr (można to też docelowo dodać jako opcjonalny parametr w metodzie wyżej)
- workflowClient.SetProcessParameter(process.Id, "Task.Id", 1234);
- return process;
- }
- /// <summary>
- /// Przykład tranzycji - sukces
- /// </summary>
- /// <param name="workflowClient"></param>
- public static TransitionResult InitProcess2(FbWorkflowClient workflowClient, int processId)
- {
- // próba wykonania dozwolonej tranzycji (z opcjonalną listą parametrów)
- // z uwagi na sukces - parametry powinny zostać zapisane
- try
- {
- return workflowClient.ProcessTransition(
- processId,
- "GENERATE_ANNEX",
- new Parameter { Name = "AnnexOffer.Duration", Value = "82" },
- new Parameter { Name = "AnnexOffer.Amount", Value = "1000" },
- new Parameter { Name = "AnnexOffer.Installment", Value = "50" },
- new Parameter { Name = "AnnexOffer.TotalDebt", Value = "5000" },
- new Parameter { Name = "AnnexOffer.WithMedicalService", Value = "1" },
- new Parameter { Name = "AnnexOffer.WithLegalService", Value = "1" }
- );
- }
- catch (Exception exc)
- {
- Console.WriteLine(exc);
- throw exc;
- }
- }
- }
- public class AnnexOffer
- {
- /// <summary>
- /// Czas trwania aneksu podwyższenia
- /// </summary>
- public int Duration { get; set; }
- /// <summary>
- /// Kwota aneksu podwyższenia
- /// </summary>
- public decimal Amount { get; set; }
- /// <summary>
- /// Rata aneksu podwyższenia
- /// </summary>
- public decimal Installment { get; set; }
- /// <summary>
- /// Całośc zadłużenia
- /// </summary>
- public decimal TotalDebt { get; set; }
- /// <summary>
- /// Czy oferta jest z pakietem medycznym?
- /// </summary>
- public bool WithMedicalService { get; set; }
- /// <summary>
- /// Czy oferta jest z pakietem prawnym?
- /// </summary>
- public bool WithLegalService { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement