public int[][] izvrsiSabiranje(bool ok, int br)
        {
            #region IZVRSIOCI

            Uri adrPod = new Uri("net.tcp://localhost:8050/ServerPodataka");
            ServerPodatakaClient podaci = new ServerPodatakaClient(new NetTcpBinding(), new EndpointAddress(adrPod));

            if (ok.Equals(true))
            {
                int brojIzvrsilaca = br;

                proxies = new List <SabiranjeClient>();
                List <Process> procesi = new List <Process>();

                int portASCII = 48;

                int kljuc = 0;

                if (brojIzvrsilaca > 10)
                {
                    MyFaultException theFault = new MyFaultException();

                    theFault.Reason = "ne moze se pokrenuti vise od 10 izvrsilaca!";

                    throw new FaultException <MyFaultException>(theFault, new FaultReason("greska u broju izvrsilaca!"));
                }

                if (brojIzvrsilaca > 0)
                {
                    while (brojIzvrsilaca != 0)
                    {
                        try
                        {
                            char   chPort = Convert.ToChar(portASCII);
                            String port   = chPort.ToString();

                            Process p = new Process();


                            file     = new FileInfo("Izvrsilac.exe");
                            fullFile = file.FullName;

                            p.StartInfo.FileName    = fullFile;
                            p.StartInfo.Arguments   = port;
                            p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                            p.Start();
                            procesi.Add(p);



                            Uri             adr          = new Uri("net.tcp://localhost:800" + port + "/Izvrsilac");
                            SabiranjeClient klijentProxy = new SabiranjeClient(new NetTcpBinding(), new EndpointAddress(adr));

                            proxies.Add(klijentProxy);
                            kljuc++;
                            brojIzvrsilaca--;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message + "direkt.: " + fullFile);

                            MyFaultException theFault = new MyFaultException();
                            theFault.Reason = "Greska operacije izvrsiSabiranje: " + e.Message.ToString();
                            throw new FaultException <MyFaultException>(theFault, new FaultReason("greska izvrsi sabiranje!"));
                        }

                        portASCII++;
                    }
                }
                else
                {
                    MyFaultException theFault = new MyFaultException();

                    theFault.Reason = "Unesite br veci od 0!";

                    throw new FaultException <MyFaultException>(theFault, new FaultReason("greska u izvrsi sabiranje(izvrsioci)!"));
                }


                #endregion

                #region SABIRANJE_MATRICA
                try
                {
                    List <int[][]> matrice = podaci.dobaviPodatke();

                    int[][] A = matrice[0];
                    int[][] B = matrice[1];

                    int[] c = Matrica.konvertuj_u_niz(A);
                    int[] d = Matrica.konvertuj_u_niz(B);


                    rez = new int[c.Count()];

                    int jj = 0;

                    listaDelova = new List <Delovi>();
                    List <PodaciZaSabiranje> podaciSab = new List <PodaciZaSabiranje>();

                    foreach (SabiranjeClient s in proxies)
                    {
                        int[] deo1 = Matrica.podeliNiz(c, proxies.Count(), jj, xc);
                        int[] deo2 = Matrica.podeliNiz(d, proxies.Count(), jj, xc);

                        Delovi delovi = new Delovi(deo1, deo2);
                        listaDelova.Add(delovi);

                        jj++;
                        xclength += deo1.Length;
                        xc        = xclength;
                    }


                    int           ind  = 0;
                    List <Thread> niti = new List <Thread>();


                    foreach (SabiranjeClient s in proxies)
                    {
                        SabiranjeClient klijentp = s;

                        PodaciZaSabiranje pod = new PodaciZaSabiranje(listaDelova[ind].deo1, listaDelova[ind].deo2, klijentp, ind);
                        ind++;

                        ParameterizedThreadStart pts = new ParameterizedThreadStart(brIzvrsilaca);
                        Thread thread = new Thread(pts);
                        niti.Add(thread);
                        thread.Start(pod);
                    }

                    for (int ij = 0; ij < niti.Count; ij++)
                    {
                        niti[ij].Join();
                    }


                    List <int[]> nizovilista = new List <int[]>();

                    for (int u = 0; u < proxies.Count; u++)
                    {
                        nizovilista.Add(nizovi[u]);
                    }

                    for (int y = 0; y < nizovilista.Count; y++)
                    {
                        for (int p = 0; p < nizovilista[y].Length; p++)
                        {
                            rez[rn] = nizovilista[y][p];
                            rn++;
                        }
                    }


                    int rows = A.Length;
                    int cols = A[0].Length;

                    C = Matrica.konvertuj_u_matricu(rez, rows, cols);
                    podaci.sacuvajPodatke(C);
                }
                catch (Exception e)
                {
                    MyFaultException theFault = new MyFaultException();

                    theFault.Reason = "Greska operacije izvrsiSabiranje: " + e.Message.ToString();

                    throw new FaultException <MyFaultException>(theFault, new FaultReason("greska u izvrsi sabiranje!"));
                }
                #endregion

                foreach (Process p in procesi)
                {
                    p.Kill();
                }
            }

            return(C);
        }
Exemple #2
0
        private void Ok_Click(object sender, RoutedEventArgs e)
        {
            if (randOpcija == false)
            {
                MessageBoxResult rez = new MessageBoxResult();

                rez = Provera_i_Preuzimanje.proveraUnosa(stackPanel1, matricaA[0].Length);
                if (!rez.Equals(MessageBoxResult.None))
                {
                    return;
                }

                rez = Provera_i_Preuzimanje.proveraUnosa(stackPanel2, matricaA[0].Length);
                if (!rez.Equals(MessageBoxResult.None))
                {
                    return;
                }
            }
            if (tbBrIzvrsilaca.Text.Trim().Length == 0)
            {
                MessageBox.Show("Popunite sva polja!");
                return;
            }

            int br;

            Process pServerPodataka = new Process();

            try
            {
                file     = new FileInfo("ServerPodataka.exe");
                fullFile = file.FullName;

                pServerPodataka.StartInfo.FileName    = fullFile;
                pServerPodataka.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                pServerPodataka.Start();

                MessageBox.Show("Računanje je u toku!");
            }
            catch (FaultException <MyFaultException> exx)
            {
                MessageBox.Show("server podataka" + exx.Message);
            }

            if (randOpcija == true)
            {
                try
                {
                    podaci.sacuvajPodatke(A);
                    podaci.sacuvajPodatke(B);
                }
                catch (FaultException <MyFaultException> ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                try{
                    matricaA = Provera_i_Preuzimanje.preuzmiMatricu(matricaA, stackPanel1);
                    matricaB = Provera_i_Preuzimanje.preuzmiMatricu(matricaB, stackPanel2);

                    podaci.sacuvajPodatke(matricaA);
                    podaci.sacuvajPodatke(matricaB);
                }
                catch (FaultException <MyFaultException> ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            int Nn = Int32.Parse(tbBrIzvrsilaca.Text);

            br = Nn;

            file     = new FileInfo("Rasporedjivac.exe");
            fullFile = file.FullName;

            Process pRasporedjivac = new Process();

            pRasporedjivac.StartInfo.FileName = fullFile;



            pRasporedjivac.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            try
            {
                pRasporedjivac.Start();
            }
            catch (FaultException <MyFaultException> ex)
            {
                MessageBox.Show(ex.Message);
            }


            int[][] D = null;
            try
            {
                D = komanda.izvrsiSabiranje(true, br);
            }
            catch (FaultException <MyFaultException> ex)
            {
                MessageBox.Show(ex.Message + " izvrsiSabFault" + " " + ex.Detail);
            }

            pServerPodataka.Kill();
            pRasporedjivac.Kill();


            Rez rezultat = new Rez(D);

            rezultat.ShowDialog();
        }