/// <summary>
 /// Metoda pro kontrolu validnosti zadaných údajů pro simulaci. Předpokládá se použití na straně serveru.
 /// </summary>
 /// <param name="instance">Instance parametrů simulace ke kontrole.</param>
 /// <returns>Úspěch kontroly.</returns>
 /// <remarks>Při neplatných údajích dochází k vyhození výjimky<see cref="FaultException<GeneratorServiceFault>"/></remarks>
 /// <exception cref="FaultException<GeneratorServiceFault>"
 public static bool CheckSimulationParams(SimulationParams instance)
 {
     if (instance == null)
     {
         throw new FaultException <GeneratorServiceFault>(new GeneratorServiceFault("Non initialiazed simulation parameters."), new FaultReason("SimulationsParams is null."));
     }
     UserIdentity.CheckUserIdentity(instance.User); //kontrola uzivatelske identity
     if (instance.Senates == null)                  //test zda jsou zadany nejake senaty
     {
         throw new FaultException <GeneratorServiceFault>(new GeneratorServiceFault("Non initialiazed list of senates."), new FaultReason("List of Senates is null."));
     }
     instance.Senates.ForEach((x) => Senate.CheckSenate(x));//kontrola konzistence senatu v seznamu
     if (instance.AlgorithmsToSimulate == null)
     {
         throw new FaultException <GeneratorServiceFault>(new GeneratorServiceFault("Non initialiazed list of algorithms."), new FaultReason("List of AlgorithmsToSimulate is null."));
     }
     if (instance.IterationsCount < 1)//pocet simulaci musi byt alespon jedna
     {
         throw new FaultException <GeneratorServiceFault>(new GeneratorServiceFault(String.Format("Number of iteration of simulation: {0} is less then 1", instance.IterationsCount)), new FaultReason("No iteration."));
     }
     if (instance.CasesToDistribution < 1)//pocet pripadu k rozdeleni musi byt alespon jedna
     {
         throw new FaultException <GeneratorServiceFault>(new GeneratorServiceFault(String.Format("Cases to distribution: {0} is less then 1", instance.CasesToDistribution)), new FaultReason("No cases to distribution."));
     }
     return(true);
 }
コード例 #2
0
        /// <summary>
        /// Testy vytváření senátů
        /// </summary>
        /// <remarks>
        /// Kontrola validnosti údajů senátů, použití helperů atd.
        /// </remarks>
        /// <param name="name"></param>
        /// <param name="enabled"></param>
        /// <param name="load"></param>
        /// <param name="activecases"></param>
        public static void SimulationCreateSenateTests(string name, bool enabled, double load, int activecases)
        {
            try
            {
                Console.WriteLine("Testing FrontEnd:Creation of senats: via name: Name {0}", name);
                Senate s = new Senate(name);
                Console.WriteLine("Senate created:ID:{0}\tLoad:{1}\tEnabled:{2}\tActiveCases:{3}", s.ID, s.Load, s.Enabled, s.ActiveCases);

                Console.WriteLine("Testing FrontEnd:Creation of senats: via name: Name {0} and Enabled {1}", name, enabled);
                s = new Senate(name, enabled);
                Console.WriteLine("Senate created:ID:{0}\tLoad:{1}\tEnabled:{2}\tActiveCases:{3}", s.ID, s.Load, s.Enabled, s.ActiveCases);

                Console.WriteLine("Testing FrontEnd:Creation of senats: via name: Name {0} and Enabled {1}", name, !enabled);
                s = new Senate(name, !enabled);
                Console.WriteLine("Senate created:ID:{0}\tLoad:{1}\tEnabled:{2}\tActiveCases:{3}", s.ID, s.Load, s.Enabled, s.ActiveCases);

                Console.WriteLine("Testing FrontEnd:Creation of senats: via name: Name {0} and Enabled {1} and Load {2}", name, enabled, load);
                s = new Senate(name, enabled, load);
                Console.WriteLine("Senate created:ID:{0}\tLoad:{1}\tEnabled:{2}\tActiveCases:{3}", s.ID, s.Load, s.Enabled, s.ActiveCases);

                try
                {
                    Console.WriteLine("Testing FrontEnd:Creation of senats: via name: Name {0} and Enabled {1} and Load {2}", name, enabled, 3 * load);
                    s = new Senate(name, enabled, 3 * load);
                    Console.WriteLine("Senate created:ID:{0}\tLoad:{1}\tEnabled:{2}\tActiveCases:{3}", s.ID, s.Load, s.Enabled, s.ActiveCases);
                }
                catch (Exception e)//odchytnuti vyjimky z klienta
                {
                    Console.WriteLine("Client:{0}", e.Message);
                }
                Console.WriteLine("Testing FrontEnd:Creation of senats: via name: Name {0} and Enabled {1} and Load {2} and ActiveCases {3}", name, enabled, load, activecases);
                s = new Senate(name, enabled, load, activecases);
                Console.WriteLine("Senate created:ID:{0}\tLoad:{1}\tEnabled:{2}\tActiveCases:{3}", s.ID, s.Load, s.Enabled, s.ActiveCases);
                try
                {
                    Console.WriteLine("Testing FrontEnd:Creation of senats: via name: Name {0} and Enabled {1} and Load {2} and ActiveCases {3}", name, enabled, load, -activecases);
                    s = new Senate(name, enabled, load, -activecases);
                    Console.WriteLine("Senate created:ID:{0}\tLoad:{1}\tEnabled:{2}\tActiveCases:{3}", s.ID, s.Load, s.Enabled, s.ActiveCases);
                }
                catch (Exception e)//odchytnuti vyjimky z klienta
                {
                    Console.WriteLine("Client:{0}", e.Message);
                }
            }
            catch (FaultException <GeneratorServiceFault> fault)//odchytavani vyjimek ze serveru
            {
                ConsoleServerMessage(fault);
            }
            catch (Exception e)//odchytnuti vyjimky z klienta
            {
                Console.WriteLine("Client:{0}", e.Message);
            }
            finally
            {
                Console.WriteLine("-".Repeat(70));
            }
        }
        /// <summary>
        /// Ukázka použití volání služeb generátoru přidělení
        /// </summary>
        public static void ExampleUsage()
        {
            string username = "******";             //ID uzivatele, melo by byt ziskano na frontendu (FE) prihlasenim
            UserID user     = new UserID(username); //uzivatel-je predavan serveru

            try
            {
                //vytvoreni senatu-informace o senatech musi byt nactene z databaze a zde vytvoreny jejich instance
                //Dochazi k volani konstruktoru na strane klienta, viz DataContractHelpers.cs, kde jsou tyto konstruktory implementovany
                Senate s1 = new Senate("INS-tester-1", true);  //senat, ktery je povoleny,zatizeni 100, pocet aktivnich pripadu 0
                Senate s2 = new Senate("INS-tester-2", false); //senat je zakazany-nebude pouzit v simulaci
                Senate s3 = new Senate("INS-tester-3", true);  //senat je povoleny,
                Senate s4 = new Senate("INS-tester-4", true);  //senat je povoleny,
                Senate s5 = new Senate("INS-tester-5", true);
                //po odkomentovani vyjimka-volana na strane klienta
                //Senate s6 = new Senate("INS-tester-6",true,120);//zpusobi vyjimku na strane klienta, nepovolena hodnota zatizeni 120
                AssignCaseParams par = new AssignCaseParams();
                par.User    = user;//nastav si uzivatele ktery provede akci
                par.Senates = new List <Senate>()
                {
                    s1, s2, s3, s4, s5
                };                      //musi se vytvorit seznam senatu pro ze kterých se bude vybírat
                //vyber algoritmu pro simulaci, na FE uzivatel vybere
                par.AlgorithmToUse = 0; //vyber algoritmu pro vyber-platne hodnoty k 10.1.2018 jsou 0,1

                for (int i = 0; i < 1; i++)
                {
                    par.CaseIdentificator = string.Format("CASE {0}", i);
                    var results = proxy_generation.AssignCase(par); //proved vyber
                    Console.WriteLine("Byl vybran senat: {0}", results);
                }
            }
            catch (FaultException <GeneratorServiceFault> fault)//odchytavani vyjimek ze serveru
            {
                ConsoleServerMessage(fault);
            }
            catch (Exception e)//odchytnuti vyjimky z klienta
            {
                ConsoleClientMessage(e);
            }
            finally
            {
                Console.WriteLine("Hotovo");
            }
        }
 /// <summary>
 /// Metoda pro kontrolu validnosti zadaných údajů pro přidělování případů. Předpokládá se použití na straně služby.
 /// </summary>
 /// <param name="instance">Instance parametrů přidělení ke kontrole.</param>
 /// <returns>Úspěch kontroly.</returns>
 /// <remarks>Při neplatných údajích dochází k vyhození výjimky<see cref="FaultException<GeneratorServiceFault>"/></remarks>
 /// <exception cref="FaultException<GeneratorServiceFault>"
 public static bool CheckAssignCaseParams(AssignCaseParams instance)
 {
     if (instance == null)
     {
         throw new FaultException <GeneratorServiceFault>(new GeneratorServiceFault("Non initialiazed simulation parameters."), new FaultReason("SimulationsParams is null."));
     }
     UserIdentity.CheckUserIdentity(instance.User); //kontrola uzivatelske identity
     if (instance.Senates == null)                  //test zda jsou zadany nejake senaty
     {
         throw new FaultException <GeneratorServiceFault>(new GeneratorServiceFault("Non initialiazed list of senates."), new FaultReason("List of Senates is null."));
     }
     instance.Senates.ForEach((x) => Senate.CheckSenate(x));//kontrola konzistence senatu v seznamu
     if (instance.CaseIdentificator == null)
     {
         throw new FaultException <GeneratorServiceFault>(new GeneratorServiceFault("Non initialiazed case identificator."), new FaultReason("Case Identificator is null."));
     }
     return(true);
 }
コード例 #5
0
        /// <summary>
        /// Ukazka pouziti volani simulaci. Kazde volani simuluje jednoho klienta.
        /// </summary>
        public void ClientRun(string username)
        {
            try
            {
                UserID user = new UserID(username);    //uzivatel-je predavan serveru

                //zjisteni informaci o algoritmech
                Console.WriteLine("Zjistuji informace o implementovanych algoritmech:");
                var algoritms = proxy_simulation.GetAlgorithmInfo(user);    //seznam informaci o algoritmech, volani pomoci proxy_simulation objektu
                foreach (var item in algoritms)
                {
                    Console.WriteLine("ID:{0}\tJmeno:{1}\tPopis:{2}", item.AlgorithmID, item.AlgorithmName, item.AlgorithmDescription);
                }
                //vytvoreni senatu-informace o senatech musi byt nactene z databaze a zde vytvoreny jejich instance
                //Dochazi k volani konstruktoru na strane klienta, viz DataContractHelpers.cs, kde jsou tyto konstruktory implementovany
                Senate s1 = new Senate("INS-tester-1");                //senat, ktery je povoleny,zatizeni 100, pocet aktivnich pripadu 0
                Senate s2 = new Senate("INS-tester-2", false);         //senat je zakazany-nebude pouzit v simulaci
                Senate s3 = new Senate("INS-tester-3", true, 50);      //senat je povoleny, zatizeni je 50, pocet aktivnich pripadu 0
                Senate s4 = new Senate("INS-tester-4", true, 100, 20); //senat je povoleny, zatizeni 100, pocet aktivnich pripadu 20
                Senate s5 = new Senate("INS-tester-5");
                //po odkomentovani vyjimka-volana na strane klienta
                //Senate s6 = new Senate("INS-tester-6",true,120);//zpusobi vyjimku na strane klienta, nepovolena hodnota zatizeni 120
                SimulationParams par = new SimulationParams(); //vytvoreni tridy pro simulacni parametry, pred odeslanim na server musi byt vse nastaveno
                par.User    = user;                            //nastav si uzivatele
                par.Senates = new List <Senate>()
                {
                    s1, s2, s3, s4, s5
                };                                                                                         //musi se vytvorit seznam senatu pro simulaci
                //vyber algoritmu pro simulaci, na FE uzivatel vybere
                par.AlgorithmsToSimulate = (from a in algoritms select int.Parse(a.AlgorithmID)).ToList(); //zjisti-vem ID vsech implementovanych algoritmu pro pouziti v simulaci
                par.IterationsCount      = 100;                                                            //nastaveni poctu iteraci
                par.CasesToDistribution  = 1000;                                                           //pocet rozdelovanych pripadu v kazde iteraci
                var results = proxy_simulation.DoSimulation(par);                                          //proved simulaci-bezi na serveru

                if (results.Count != par.AlgorithmsToSimulate.Count)                                       //test zda ma spravny pocet vysledku
                {
                    throw new Exception("WRONG RESULTS: Algorithm to simulate inconsistence.");
                }
                else    //kdyz ok
                {
                    foreach (var result in results)
                    {
                        if (result.Data.Count != par.IterationsCount)
                        {
                            throw new Exception("WRONG RESULTS: Iteration counts.");
                        }
                        StatisticInfo(result.Data, username);
                    }
                }
            }
            catch (FaultException <GeneratorServiceFault> fault)//odchytavani vyjimek ze serveru
            {
                ConsoleServerMessage(fault);
            }
            catch (Exception e)//odchytnuti vyjimky z klienta
            {
                ConsoleClientMessage(e);
            }
            finally
            {
                Console.WriteLine("DONE: {0}", username);
            }
        }
コード例 #6
0
        /// <summary>
        /// Ukazka pouziti volani simulaci
        /// </summary>
        public static void ExampleUsage()
        {
            string username = "******";             //ID uzivatele, melo by byt ziskano na frontendu (FE) prihlasenim
            UserID user     = new UserID(username); //uzivatel-je predavan serveru

            try
            {
                //zjisteni informaci o algoritmech
                Console.WriteLine("Zjistuji informace o implementovanych algoritmech:");
                var algoritms = proxy_simulation.GetAlgorithmInfo(user);//seznam informaci o algoritmech, volani pomoci proxy_simulation objektu
                foreach (var item in algoritms)
                {
                    Console.WriteLine("ID:{0}\tJmeno:{1}\tPopis:{2}", item.AlgorithmID, item.AlgorithmName, item.AlgorithmDescription);
                }
                //vytvoreni senatu-informace o senatech musi byt nactene z databaze a zde vytvoreny jejich instance
                //Dochazi k volani konstruktoru na strane klienta, viz DataContractHelpers.cs, kde jsou tyto konstruktory implementovany
                Senate s1 = new Senate("INS-tester-1");               //senat, ktery je povoleny,zatizeni 100, pocet aktivnich pripadu 0
                Senate s2 = new Senate("INS-tester-2", false);        //senat je zakazany-nebude pouzit v simulaci
                Senate s3 = new Senate("INS-tester-3", true, 100);    //senat je povoleny, zatizeni je 100, pocet aktivnich pripadu 0
                Senate s4 = new Senate("INS-tester-4", true, 100, 0); //senat je povoleny, zatizeni 100, pocet aktivnich pripadu 0
                Senate s5 = new Senate("INS-tester-5");
                //po odkomentovani vyjimka-volana na strane klienta
                //Senate s6 = new Senate("INS-tester-6",true,120);//zpusobi vyjimku na strane klienta, nepovolena hodnota zatizeni 120
                SimulationParams par = new SimulationParams(); //vytvoreni tridy pro simulacni parametry, pred odeslanim na server musi byt vse nastaveno
                par.User    = user;                            //nastav si uzivatele
                par.Senates = new List <Senate>()
                {
                    s1, s2, s3, s4, s5
                };                                                                                         //musi se vytvorit seznam senatu pro simulaci
                //vyber algoritmu pro simulaci, na FE uzivatel vybere
                par.AlgorithmsToSimulate = (from a in algoritms select int.Parse(a.AlgorithmID)).ToList(); //zjisti-vem ID vsech implementovanych algoritmu pro pouziti v simulaci
                par.IterationsCount      = 10;                                                             //nastaveni poctu iteraci
                par.CasesToDistribution  = 100;                                                            //pocet rozdelovanych pripadu v kazde iteraci
                var results = proxy_simulation.DoSimulation(par);                                          //proved simulaci-bezi na serveru

                //vlozeno 24.1. test exportu do xls
                var report = new SimulationReport(algoritms, par, results);
                report.CreateReportToFile("report.xlsx");//zapise do souboru-pro spousteni v konzoli-pouzije si PLASTIAK
                //Pro DANA MAJEROVA -vytvorenisouboru v pameti pro posilani-ODKOMENTOVAT nasledujici radek a zakomentovat ReportToFile
                //  var memory = report.CreateReportOnTheFly();//vytvor v pameti--je to mozne prevest na pole bytu a poslat response -viz http://howtodomssqlcsharpexcelaccess.blogspot.cz/2014/05/aspnet-how-to-create-excel-file-in.html


                //test Kubera-jestli to funguje-Vezmu vytvoreny memory stream a ulozim ho do souboru- funguje
                using (var memory = report.CreateReportOnTheFly())
                { //nutno pridat nahoru using System.IO; pro praci se soubory
                    using (FileStream fs = new FileStream("reportfly.xlsx", FileMode.OpenOrCreate))
                    {
                        memory.Position = 0; //nastav to na zacatek
                        memory.CopyTo(fs);   //kopiruj pamet do file streamu
                        fs.Flush();          //zapis
                    }
                }



                //konec testu exportu
                foreach (var data in results)//pro kazdy algoritmus pouzity v simulaci, data jsou kompletni data pro jeden algoritmus
                {
                    Console.WriteLine("+".Repeat(70));
                    var name = (from a in algoritms where a.AlgorithmID == data.UsedAlgorithm.ToString() select a.AlgorithmName).First();
                    Console.WriteLine("Pouzity algoritmus {0}:{1}", data.UsedAlgorithm, name);
                    Console.WriteLine("+".Repeat(70));
                    int iterace = 0;
                    foreach (var array in data.Data) //zpracuj data-vypis za jednotlive iterace,array je distribuce pripadu mezi senaty
                    {
                        foreach (var item in array)  //vypis hodnot pres senaty
                        {
                            Console.Write("{0}\t", item);
                        }
                        Console.WriteLine("MAXDIF:{0}", data.MaxDifference[iterace]);
                        iterace++;
                        Console.WriteLine();
                    }
                    Console.WriteLine("-".Repeat(70));
                    Console.WriteLine("\nStatisticke informace");
                    Console.WriteLine("-".Repeat(70));
                    StatisticInfo(data.Data);
                    Console.WriteLine("-".Repeat(70));
                }
            }
            catch (FaultException <GeneratorServiceFault> fault)//odchytavani vyjimek ze serveru
            {
                ConsoleServerMessage(fault);
            }
            catch (Exception e)//odchytnuti vyjimky z klienta
            {
                ConsoleClientMessage(e);
            }
            finally
            {
                Console.WriteLine("Hotovo");
            }
        }