Advertisement
Guest User

Untitled

a guest
Sep 7th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.03 KB | None | 0 0
  1. using Newtonsoft.Json;
  2. using Sente.DAL.ORM;
  3. using Sente.DAL.ORM.Firebird;
  4. using Sente.Workflow.Client.Concrete;
  5. using Sente.Workflow.Client.DAL;
  6. using Sente.Workflow.Client.Models;
  7. using System;
  8. using System.Data.Common;
  9. using System.Linq;
  10.  
  11. namespace Sente.Workflow.ConsoleRunner
  12. {
  13.     public class Program
  14.     {
  15.         public static void Main(string[] args)
  16.         {
  17.             //Case 1.
  18.             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")))
  19.             {
  20.                 var client = new FbWorkflowClient(dataContext);
  21.                 dataContext.StartTransaction();
  22.  
  23.                 // wywołanie utworzenia procesu
  24.                 var process = CreateProcess(client);
  25.  
  26.                 dataContext.Commit();
  27.                 dataContext.StartTransaction();
  28.  
  29.                 // wywołanie inicjalizacji procesu (metoda nie dokona tranzycji)
  30.                 var transitionResult1 = InitProcess2(client, process.Id);
  31.                 Console.WriteLine(JsonConvert.SerializeObject(transitionResult1));
  32.  
  33.                 // wywołanie inicjalizacji procesu (metoda poprawnie dokona tranzycji)
  34.  
  35.                 // zapisanie wyników
  36.                 dataContext.Commit();
  37.  
  38.                 // po zacommitowaniu (można było to zrobić po każdej operacji:)) - proces powinien być w stanie INITIALIZING.
  39.                 // do uruchomienia workflow (Everest.Workflow) - który wykona asynchronizcznie aktywność
  40.                 // i zmieni stan na WAITING FOR CLIENT INPUT
  41.                 //
  42.                 // W kolejnej metodzie na WS prawdopodonie odbierzemy dane z portalu, zapiszemy je w tabelce
  43.                 // i spróbujemy wykonać tranzycję (tak jak w InitProcess1 / 2).
  44.                 // Jeżeli wystąpią problemy z walidacją -
  45.             }
  46.  
  47.             Console.ReadLine();
  48.         }
  49.  
  50.         /// <summary>
  51.         /// Przykład utworzenia procesu
  52.         /// </summary>
  53.         /// <typeparam name="TConnection"></typeparam>
  54.         /// <param name="dbContext"></param>
  55.         /// <param name="workflowClient"></param>
  56.         public static Process CreateProcess(FbWorkflowClient workflowClient)
  57.         {
  58.  
  59.             // var task = .... - sprawdzenie i zapisanie oferty po stronie bazy danych, zwrócenie jakiś danych do rozpoczęcia procesu
  60.  
  61.             // startujemy nową instancję procesu
  62.             var process = workflowClient.StartProcess(3);
  63.  
  64.             // zapisujemy parametr (można to też docelowo dodać jako opcjonalny parametr w metodzie wyżej)
  65.             workflowClient.SetProcessParameter(process.Id, "Task.Id", 1234);
  66.  
  67.             return process;
  68.         }
  69.  
  70.        
  71.  
  72.         /// <summary>
  73.         /// Przykład tranzycji - sukces
  74.         /// </summary>
  75.         /// <param name="workflowClient"></param>
  76.         public static TransitionResult InitProcess2(FbWorkflowClient workflowClient, int processId)
  77.         {
  78.             // próba wykonania dozwolonej tranzycji (z opcjonalną listą parametrów)
  79.             // z uwagi na sukces - parametry powinny zostać zapisane
  80.  
  81.             try
  82.             {
  83.                 return workflowClient.ProcessTransition(
  84.                         processId,
  85.                         "GENERATE_ANNEX",
  86.                         new Parameter { Name = "AnnexOffer.Duration", Value = "82" },
  87.                         new Parameter { Name = "AnnexOffer.Amount", Value = "1000" },
  88.                         new Parameter { Name = "AnnexOffer.Installment", Value = "50" },
  89.                         new Parameter { Name = "AnnexOffer.TotalDebt", Value = "5000" },
  90.                         new Parameter { Name = "AnnexOffer.WithMedicalService", Value = "1" },
  91.                         new Parameter { Name = "AnnexOffer.WithLegalService", Value = "1" }
  92.                     );
  93.             }
  94.             catch (Exception exc)
  95.             {
  96.                 Console.WriteLine(exc);
  97.                 throw exc;
  98.             }
  99.         }
  100.     }
  101.  
  102.     public class AnnexOffer
  103.     {
  104.         /// <summary>
  105.         /// Czas trwania aneksu podwyższenia
  106.         /// </summary>
  107.         public int Duration { get; set; }
  108.  
  109.         /// <summary>
  110.         /// Kwota aneksu podwyższenia
  111.         /// </summary>
  112.         public decimal Amount { get; set; }
  113.  
  114.         /// <summary>
  115.         /// Rata aneksu podwyższenia
  116.         /// </summary>
  117.         public decimal Installment { get; set; }
  118.  
  119.         /// <summary>
  120.         /// Całośc zadłużenia
  121.         /// </summary>
  122.         public decimal TotalDebt { get; set; }
  123.  
  124.         /// <summary>
  125.         /// Czy oferta jest z pakietem medycznym?
  126.         /// </summary>
  127.         public bool WithMedicalService { get; set; }
  128.  
  129.         /// <summary>
  130.         /// Czy oferta jest z pakietem prawnym?
  131.         /// </summary>
  132.         public bool WithLegalService { get; set; }
  133.  
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement