public Excursionist(Context context, string[] Messages, string nrTel)
        {
            this.context = context;

            Nume         = Messages[2];
            Prenume      = Messages[3];
            TipCont      = Messages[4];
            NumarTelefon = Messages[5];
            Distanta     = Messages[7];
            Pozitie      = Messages[8];

            TcpClient     Client = new TcpClient(_Details.ServerIP, _Details.LargeFilesPort);
            NetworkStream ns     = Client.GetStream();

            using (MemoryStream ms = new MemoryStream())
            {
                _TcpDataExchange.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { _Details.GetProfilePic, NumarTelefon }));

                int    ReadedBytes;
                byte[] Buffer = new byte[1000];

                while ((ReadedBytes = ns.Read(Buffer, 0, Buffer.Length)) > 0)
                {
                    ms.Write(Buffer, 0, ReadedBytes);
                }

                Client.Close();
                ns.Dispose();

                Drawable PhotoDrawable = DrawableConverter.ByteArrayToDrawable(ms.ToArray(), context);
                Bitmap   PhotoBitmap   = ((BitmapDrawable)PhotoDrawable).Bitmap;

                Photo = new BitmapDrawable(context.Resources, RoundedBitmap.MakeRound(PhotoBitmap, PhotoBitmap.Width));
            }
        }
예제 #2
0
        public static void Handle(TcpClient Client, NetworkStream ns, string[] Messages)
        {
            //1.Username(NrTel)
            //2.Parola

            string Username = Messages[1];
            string Password = Messages[2];

            string Response = string.Empty;
            string TipCont  = string.Empty;
            string OrgEx    = string.Empty;

            using (SqlConnection Database = new SqlConnection(@"Data Source=.\SQLEXPRESS;User id=Mihawai;" + "Password=11234567;" + "Database = SafeTraveling"))
            {
                Database.Open();

                SqlCommand cmd = new SqlCommand("SELECT NumarTelefon,Parola,TipCont FROM Utilizatori", Database);
                using (SqlDataReader Reader = cmd.ExecuteReader())
                {
                    while (Reader.Read())
                    {
                        if (((string)Reader[0]).Equals(Username))
                        {
                            if (((string)Reader[1]).Equals(Password))
                            {
                                TipCont  = (string)Reader[2];
                                Response = TipCont;
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }

                if (TipCont == "Organizator")
                {
                    cmd = new SqlCommand("SELECT [Numar Telefon] FROM Excursii WHERE [Numar Telefon]='" + Username + "'", Database);
                    SqlDataReader Reader = cmd.ExecuteReader();

                    if (Reader.Read())
                    {
                        OrgEx = "1";
                    }
                    else
                    {
                        OrgEx = "0";
                    }
                }
            }

            _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { TipCont, OrgEx }));

            Client.Close();
            ns.Dispose();
        }
예제 #3
0
        public static void Handle(TcpClient Client, NetworkStream ns, string[] Messages, List <Excursie> Excursii)
        {
            //1.NumePrenume
            //2.NumarTelefon
            //3.TripId

            string NumePrenume          = Messages[1];
            string NumarTelefon         = Messages[2];
            string TripId               = Messages[3];
            string DestinatiePrincipala = string.Empty;
            string TipulParticipantilor = string.Empty;
            string DataPlecare          = string.Empty;
            string DataIntoarcere       = string.Empty;
            string LocatiePlecare       = string.Empty;
            string OraPlecare           = string.Empty;
            string Observatii           = string.Empty;

            string Response = (0).ToString();

            using (SqlConnection Database = new SqlConnection(_Details.DatabaseConnectionString))
            {
                Database.Open();

                SqlCommand    cmd    = new SqlCommand("SELECT * FROM Excursii WHERE [UniqueId] = '" + TripId + "'", Database);
                SqlDataReader Reader = cmd.ExecuteReader();

                if (Reader.Read())
                {
                    DestinatiePrincipala = (string)Reader[0];
                    TipulParticipantilor = (string)Reader[1];
                    DataPlecare          = (string)Reader[2];
                    DataIntoarcere       = (string)Reader[3];
                    LocatiePlecare       = (string)Reader[4];
                    OraPlecare           = (string)Reader[5];
                    Observatii           = (string)Reader[6];

                    Response = (1).ToString();
                }
            }

            if (Response.Equals((1).ToString()))
            {
                _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { Response, DestinatiePrincipala, TipulParticipantilor, DataPlecare, DataIntoarcere, LocatiePlecare, OraPlecare, Observatii }));
            }
            else
            {
                _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { Response }));
            }

            foreach (Excursie e in Excursii)
            {
                if (e.UniqueId == TripId)
                {
                    e.AdaugareUtilizatorNou(new Client(Client, ns), NumarTelefon);
                }
            }
        }
예제 #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);

            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Utilizator_Trip_Galerie);

            PhotosContainer = FindViewById <GridView>(Resource.Id.GridViewLay);

            TcpClient     Client = new TcpClient(_Details.ServerIP, _Details.LargeFilesPort);
            NetworkStream ns     = Client.GetStream();

            _TcpDataExchange.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { _Details.GetGalleryCount, Utilizator_Trip.TripId }));

            int PhotosCount = int.Parse(CryptDecryptData.DecryptData(_TcpDataExchange.ReadStreamString(ns))[0]);

            List <Drawable> Poze = new List <Drawable>();

            for (int i = 0; i < PhotosCount; i++)
            {
                Poze.Add(null);
            }

            PhotosContainer.Adapter = new Utilizator_Trip_Galerie_GridViewAdapter(this, Poze.ToArray());

            new Thread(() => {
                for (int i = 0; i < PhotosCount; i++)
                {
                    Client = new TcpClient(_Details.ServerIP, _Details.LargeFilesPort);
                    ns     = Client.GetStream();

                    _TcpDataExchange.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { _Details.GetGalleryPhotoByIndex, Utilizator_Trip.TripId, i.ToString() }));

                    int ReadedBytes;
                    byte[] Buffer   = new byte[1000];
                    MemoryStream ms = new MemoryStream();

                    while ((ReadedBytes = ns.Read(Buffer, 0, Buffer.Length)) > 0)
                    {
                        ms.Write(Buffer, 0, ReadedBytes);
                    }

                    Client.Close();
                    ns.Dispose();

                    Drawable Photo = DrawableConverter.ByteArrayToDrawable(ms.ToArray(), this);

                    Poze[i] = Photo;

                    RunOnUiThread(() => {
                        PhotosContainer.Adapter = new Utilizator_Trip_Galerie_GridViewAdapter(this, Poze.ToArray());
                    });
                }
            }).Start();
        }
        private void GestionareUtilizatori(object newClient)
        {
            TcpClient     Client = (TcpClient)newClient;
            NetworkStream ns     = Client.GetStream();

            string[] Messages = CryptDecryptData.DecryptData(_Utils.ReadStreamString(ns));

            switch (Messages[0])
            {
            case "TRIPENTER": TripEnter.Handle(Client, ns, Messages, Excursii);
                break;

            case "NEWTRIP": NewTripService.Handle(Client, ns, Messages, LocationService, NotificationService, Excursii);
                break;
            }
        }
        void Vote_Click(object sender, EventArgs e)
        {
            int?CheckedRow = (ListaVariante.Adapter as Utilizator_Trip_VoteQuestionPool_VarianteAdapter).CheckedRow;

            if (CheckedRow != null)
            {
                TcpClient     Client = new TcpClient(_Details.ServerIP, _Details.LargeFilesPort);
                NetworkStream ns     = Client.GetStream();

                string TripId = new SaveUsingSharedPreferences(this).LoadString(SaveUsingSharedPreferences.Tags.Trip.TipId);
                string Index  = CheckedRow.ToString();

                _TcpDataExchange.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { _Details.VoteQuestionPool, TripId, Index, Id }));

                Finish();
            }
        }
예제 #7
0
 public void INPUT_GET(Excursie e)
 {
     new Thread(new ThreadStart(() => {
         while (true)
         {
             try
             {
                 string[] Messages = CryptDecryptData.DecryptData(_Utils.ReadStreamString(INPUT.ns));
                 e.OnClientGetMessage(Messages);
             }
             catch
             {
                 Thread.CurrentThread.Abort();
                 break;
             }
         }
     })).Start();
 }
예제 #8
0
        private void ClientHandle(object c)
        {
            TcpClient     Client = (TcpClient)c;
            NetworkStream ns     = Client.GetStream();

            string[] Messages = CryptDecryptData.DecryptData(_Utils.ReadStreamString(ns));

            switch (Messages[0])
            {
            case "LOGIN":
                LoginService.Handle(Client, ns, Messages);
                break;

            case "SIGNUP":
                SignUpService.Handle(Client, ns, Messages);
                break;
            }
        }
예제 #9
0
        private void ManageClients(object newClient)
        {
            TcpClient     client = (TcpClient)newClient;
            NetworkStream ns     = client.GetStream();

            string[] Messages = CryptDecryptData.DecryptData(_Utils.ReadStreamString(ns));

            //1.TripId
            //2.NumarTelfon

            string TripId      = Messages[0];
            string NumarTelfon = Messages[1];

            foreach (Excursie e in Excursii)
            {
                if (e.UniqueId.Equals(TripId))
                {
                    bool IfExist = false;
                    foreach (LocationableClient lc in e.LocationableClients)
                    {
                        if (lc.NumarTelefon == NumarTelfon)
                        {
                            IfExist = true;
                        }
                    }

                    if (!IfExist)
                    {
                        Client             nClient             = new Client(client, ns);
                        LocationableClient nLocationableClient = new LocationableClient(nClient, NumarTelfon, e);
                        e.LocationableClients.Add(nLocationableClient);

                        // e.OnClientEnterExit();
                    }
                    else
                    {
                        client.Close();
                    }
                }
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            Bundle Extra      = Intent.Extras;
            string NumeProdus = Extra.GetString("Query");
            string Distanta   = Extra.GetString("Distance");

            base.OnCreate(savedInstanceState);

            Window.RequestFeature(WindowFeatures.NoTitle);
            Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);

            SetContentView(Resource.Layout.Extra_BeSmart_ViewResoult);

            TcpClient     Client = new TcpClient(_Details.ServerIP, _Details.LargeFilesPort);
            NetworkStream ns     = Client.GetStream();

            _TcpDataExchange.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { _Details.BeSmartSimpleQuery, NumeProdus, Distanta, new SaveUsingSharedPreferences(this).LoadString(SaveUsingSharedPreferences.Tags.Login.Username) }));

            string[] ListaProduse  = CryptDecryptData.DecryptData(_TcpDataExchange.ReadStreamString(ns));
            string[] ListaPreturi  = CryptDecryptData.DecryptData(_TcpDataExchange.ReadStreamString(ns));
            string[] ListaDistante = CryptDecryptData.DecryptData(_TcpDataExchange.ReadStreamString(ns));
            string[] ListaLocatii  = CryptDecryptData.DecryptData(_TcpDataExchange.ReadStreamString(ns));

            for (int i = 0; i < ListaProduse.Length; i++)
            {
                if (ListaProduse[i].Equals(string.Empty))
                {
                    ListaProduse  = ListaProduse.Take(i).ToArray();
                    ListaPreturi  = ListaPreturi.Take(i).ToArray();
                    ListaDistante = ListaDistante.Take(i).ToArray();
                    ListaLocatii  = ListaLocatii.Take(i).ToArray();

                    break;
                }
            }

            ListView ListaRezultate = FindViewById <ListView>(Resource.Id.listView1);

            ListaRezultate.Adapter = new BeSmart_ViewResoult_Adapter(this, ListaProduse, ListaPreturi, ListaDistante, ListaLocatii);
        }
        private void ManageClients(object newClient)
        {
            TcpClient     client = (TcpClient)newClient;
            NetworkStream ns     = client.GetStream();

            string[] Messages = CryptDecryptData.DecryptData(_Utils.ReadStreamString(ns));

            //1.TripId
            //2.NumePrenume

            string TripId      = Messages[0];
            string NumarTelfon = Messages[1];

            foreach (Excursie e in Excursii)
            {
                if (e.UniqueId.Equals(TripId))
                {
                    bool IfExist = false;
                    foreach (NotificableClient nc in e.NotificableClients)
                    {
                        if (nc.NumarTelefon == NumarTelfon)
                        {
                            IfExist = true;
                        }
                    }

                    if (!IfExist)
                    {
                        Client            nClient            = new Client(client, ns);
                        NotificableClient nNotificableClient = new NotificableClient(nClient, NumarTelfon, e, TripId);
                        e.NotificableClients.Add(nNotificableClient);
                    }
                    else
                    {
                        client.Close();
                    }
                }
            }
        }
        private void JoinOUTPUT(object nClient)
        {
            TcpClient     Client = (TcpClient)nClient;
            NetworkStream ns     = Client.GetStream();

            string[] Messages = CryptDecryptData.DecryptData(_Utils.ReadStreamString(ns));

            string NumarTelefon = Messages[1];
            string TripId       = Messages[2];

            foreach (Excursie e in Excursii)
            {
                if (e.UniqueId == TripId)
                {
                    foreach (TripClient t in e.ClientsList)
                    {
                        if (t.NumarTelefon == NumarTelefon)
                        {
                            t.Client_OUTPUT = new Client(Client, ns);
                        }
                    }
                }
            }
        }
예제 #13
0
        private void Listener()
        {
            while (true)
            {
                string[] Messages = this.Receive();

                try
                {
                    Position       = new LatitudeLongitude(Messages[0], Messages[1]);
                    PositionString = Position.GetCoord();
                    Console.WriteLine(NumarTelefon + ":" + PositionString + "======>>>>>" + System.DateTime.Now.Hour + ":" + System.DateTime.Now.Minute + ":" + System.DateTime.Now.Second);
                    UpdateLocation(NumarTelefon, Position);

                    if (this.Data.TipCont == "Organizator")
                    {
                        List <string> Response = new List <string>();
                        Response.Add("1");

                        foreach (LocationableClient a in e.LocationableClients)
                        {
                            if (a.NumarTelefon != this.NumarTelefon)
                            {
                                Response.Add(NumarTelefon);
                                Response.Add(Position.GetDistance(a.Position));
                                break;
                            }
                        }

                        _Utils.WriteStreamString(Client.ns, CryptDecryptData.CryptData(Response.ToArray()));
                    }
                    else
                    {
                        _Utils.WriteStreamString(Client.ns, CryptDecryptData.CryptData(new string[] { "0" }));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    foreach (LocationableClient a in e.LocationableClients)
                    {
                        if (a.NumarTelefon == this.NumarTelefon)
                        {
                            e.LocationableClients.Remove(a);

                            foreach (NotificableClient nc in e.NotificableClients)
                            {
                                if (nc.NumarTelefon == this.NumarTelefon)
                                {
                                    e.NotificableClients.Remove(nc);
                                    nc.Dispose();
                                    break;
                                }
                            }

                            e.OnClientEnterExit();
                            break;
                        }
                    }
                    break;
                }
            }
        }
예제 #14
0
        public NotificationService(Context context, Client Client, string nrTel)
        {
            while (true)
            {
                string[] Response = CryptDecryptData.DecryptData(_TcpDataExchange.ReadStreamString(Client.ns));

                switch (Response[0])
                {
                case _Details.UpdateLocation:
                {
                    if (Response[1] == "1")
                    {
                        Excursionist Excursionist = new Excursionist(context, Response, nrTel);
                        Excursionisti.Add(Excursionist);
                    }
                    else
                    {
                        Excursionist ExcursionistCurent = new Excursionist(context, Response, nrTel);
                        Excursionisti.Add(ExcursionistCurent);

                        Organizator_Trip_VizualizareExcursionisti.LocationUpdated(Excursionisti);

                        foreach (Excursionist ex in Excursionisti)
                        {
                            try
                            {
                                if (int.Parse(ex.Distanta) > int.Parse(new SaveUsingSharedPreferences(context).LoadString(SaveUsingSharedPreferences.Tags.Organizator.Distanta)))
                                {
                                    Intent        Apel        = new Intent(Intent.ActionView, Android.Net.Uri.Parse("tel:" + ex.NumarTelefon));
                                    PendingIntent PendingApel = PendingIntent.GetActivity(context, 0, Apel, PendingIntentFlags.CancelCurrent);

                                    Notification.Builder nBuilder = new Notification.Builder(context)
                                                                    .SetSmallIcon(Resource.Drawable.NotificationIcon)
                                                                    .SetAutoCancel(true)
                                                                    .SetPriority((int)NotificationPriority.High)
                                                                    .SetSound(Settings.System.DefaultNotificationUri)
                                                                    .AddAction(Resource.Drawable.Apel, "Suna", PendingApel)
                                                                    .SetStyle(new Notification.BigTextStyle().BigText("Utilizatorul " + ex.Nume + " " + ex.Prenume + " a depasit distanta!"))
                                                                    .SetContentTitle("Safe Traveling");

                                    NotificationManager nManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
                                    nManager.Notify(0, nBuilder.Build());
                                }
                            }
                            catch { }
                        }

                        Excursionisti = new List <Excursionist>();
                    }
                } break;

                case _Details.GameInvitation_Bounce:
                {
                    string GameId = Response[1];

                    Intent Accept = new Intent(context, typeof(BounceGameActivity));
                    Accept.PutExtra(_Details.Game_IntentType, "JOIN");
                    Accept.PutExtra(_Details.Game_Player_NrTel, nrTel);
                    Accept.PutExtra(_Details.Game_GameId, GameId);

                    PendingIntent AcceptIntent = PendingIntent.GetActivity(context, 0, Accept, PendingIntentFlags.CancelCurrent);

                    Notification.Builder nBuilder = new Notification.Builder(context)
                                                    .SetSmallIcon(Resource.Drawable.NotificationIcon)
                                                    .SetAutoCancel(true)
                                                    .SetPriority((int)NotificationPriority.High)
                                                    .SetSound(Settings.System.DefaultNotificationUri)
                                                    .SetStyle(new Notification.BigTextStyle().BigText("Ai fost invitat de catre " + Response[2] + " sa jucati Bounce!"))
                                                    .SetContentTitle("Safe Traveling")
                                                    .AddAction(Resource.Drawable.AcceptGame, "Accepta", AcceptIntent)
                                                    .AddAction(Resource.Drawable.Cancel, "Respinge", AcceptIntent);

                    NotificationManager nManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
                    nManager.Notify(0, nBuilder.Build());

                    new Thread(() =>
                        {
                            Thread.Sleep(20000);
                            nManager.Cancel(0);
                        }).Start();
                } break;

                case _Details.GameInvitation_XandO:
                {
                    string GameId = Response[1];

                    Intent Accept = new Intent(context, typeof(XandOActivity));
                    Accept.PutExtra(_Details.Game_IntentType, "JOIN");
                    Accept.PutExtra(_Details.Game_Player_NrTel, nrTel);
                    Accept.PutExtra(_Details.Game_GameId, GameId);

                    PendingIntent AcceptIntent = PendingIntent.GetActivity(context, 0, Accept, PendingIntentFlags.CancelCurrent);

                    Notification.Builder nBuilder = new Notification.Builder(context)
                                                    .SetSmallIcon(Resource.Drawable.NotificationIcon)
                                                    .SetAutoCancel(true)
                                                    .SetPriority((int)NotificationPriority.High)
                                                    .SetSound(Settings.System.DefaultNotificationUri)
                                                    .SetStyle(new Notification.BigTextStyle().BigText("Ai fost invitat de catre " + Response[2] + " sa jucati X si O!"))
                                                    .SetContentTitle("Safe Traveling")
                                                    .AddAction(Resource.Drawable.AcceptGame, "Accepta", AcceptIntent)
                                                    .AddAction(Resource.Drawable.Cancel, "Respinge", AcceptIntent);

                    NotificationManager nManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
                    nManager.Notify(1, nBuilder.Build());

                    new Thread(() =>
                        {
                            Thread.Sleep(20000);
                            nManager.Cancel(0);
                        }).Start();
                } break;

                case _Details.QuestionPoolForVote: {
                    string Intrebare = Response[1];
                    string Variante  = Response[2];
                    string Id        = Response[3];

                    Intent Accept = new Intent(context, typeof(Utilizator_Trip_VoteQuestionPool));
                    Accept.PutExtra(_Details.QuestionPoolId, Id);
                    Accept.PutExtra(_Details.QuestionPoolIntrebare, Intrebare);
                    Accept.PutExtra(_Details.QuestionPoolVariante, Variante);

                    PendingIntent AcceptIntent = PendingIntent.GetActivity(context, 0, Accept, PendingIntentFlags.CancelCurrent);

                    Notification.Builder nBuilder = new Notification.Builder(context)
                                                    .SetSmallIcon(Resource.Drawable.Vote)
                                                    .SetAutoCancel(true)
                                                    .SetPriority((int)NotificationPriority.High)
                                                    .SetSound(Settings.System.DefaultNotificationUri)
                                                    .SetStyle(new Notification.BigTextStyle().BigText(Response[1]))
                                                    .SetContentTitle("Safe Traveling")
                                                    .AddAction(Resource.Drawable.Vote, "Voteaza", AcceptIntent);

                    NotificationManager nManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
                    nManager.Notify(1, nBuilder.Build());
                } break;
                }
            }
        }
예제 #15
0
        private void SendOrUpload(object newClient)
        {
            TcpClient     Client = (TcpClient)newClient;
            NetworkStream ns     = Client.GetStream();

            string[] Tag = CryptDecryptData.DecryptData(_Utils.ReadStreamString(ns));

            switch (Tag[0])
            {
            case _Details.GetGalleryPhotoByIndex:
            {
                string IdExcursie = Tag[1];
                int    PhotoIndex = int.Parse(Tag[2]);

                using (SqlConnection Database = new SqlConnection(_Details.DatabaseConnectionString))
                {
                    Database.Open();

                    SqlCommand    cmd    = new SqlCommand("SELECT [URL] FROM Excursii WHERE [UniqueId]='" + IdExcursie + "'", Database);
                    SqlDataReader Reader = cmd.ExecuteReader();

                    if (Reader.Read())
                    {
                        string[] PhotosPath = Directory.GetFiles(Reader[0] as string + @"\Galerie");

                        Reader.Close();

                        using (FileStream fs = File.Open(PhotosPath[PhotoIndex], FileMode.Open))
                        {
                            int PackSize    = 1000;
                            int TotalLength = (int)fs.Length;
                            int NoOfPackets = (int)Math.Ceiling((double)fs.Length / (double)PackSize);
                            int CurrentPackSize;

                            for (int i = 0; i < NoOfPackets; i++)
                            {
                                if (TotalLength > PackSize)
                                {
                                    CurrentPackSize = PackSize;
                                    TotalLength    -= CurrentPackSize;
                                }
                                else
                                {
                                    CurrentPackSize = TotalLength;
                                }

                                byte[] CurrentBytes = new byte[CurrentPackSize];
                                int    ReadedLength = fs.Read(CurrentBytes, 0, CurrentBytes.Length);

                                ns.Write(CurrentBytes, 0, ReadedLength);
                            }
                        }
                    }
                }

                Client.Close();
            } break;

            case _Details.GetGalleryCount:
            {
                string IdExcursie = Tag[1];

                using (SqlConnection Database = new SqlConnection(_Details.DatabaseConnectionString))
                {
                    Database.Open();

                    SqlCommand    cmd    = new SqlCommand("SELECT [URL] FROM Excursii WHERE [UniqueId]='" + IdExcursie + "'", Database);
                    SqlDataReader Reader = cmd.ExecuteReader();

                    if (Reader.Read())
                    {
                        string[] PhotosPath = Directory.GetFiles(Reader[0] as string + @"\Galerie");
                        _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { PhotosPath.Length.ToString() }));

                        Reader.Close();
                    }
                }

                Client.Close();
            } break;

            case _Details.AddPhotoToGallery:
            {
                string       IdExcursie = Tag[1];
                MemoryStream ms         = new MemoryStream();
                byte[]       Buffer     = new byte[1000];

                int ReadedBytes;
                while ((ReadedBytes = ns.Read(Buffer, 0, Buffer.Length)) > 0)
                {
                    ms.Write(Buffer, 0, ReadedBytes);
                }

                using (SqlConnection Database = new SqlConnection(_Details.DatabaseConnectionString))
                {
                    Database.Open();

                    SqlCommand    cmd    = new SqlCommand("SELECT [URL] FROM Excursii WHERE [UniqueId]='" + IdExcursie + "'", Database);
                    SqlDataReader Reader = cmd.ExecuteReader();

                    if (Reader.Read())
                    {
                        Image i       = Image.FromStream(ms);
                        Guid  newGuid = Guid.NewGuid();
                        i.Save((string)Reader[0] + @"\Galerie\" + newGuid.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);

                        Reader.Close();
                    }
                }

                Client.Close();
            } break;

            case _Details.UpdateProfilePic:
            {
                string       NrTel  = Tag[1];
                MemoryStream ms     = new MemoryStream();
                byte[]       Buffer = new byte[1000];

                int ReadedBytes;
                while ((ReadedBytes = ns.Read(Buffer, 0, Buffer.Length)) > 0)
                {
                    ms.Write(Buffer, 0, ReadedBytes);
                }

                using (SqlConnection Database = new SqlConnection(_Details.DatabaseConnectionString))
                {
                    Database.Open();

                    SqlCommand    cmd    = new SqlCommand("SELECT [URL] FROM Utilizatori WHERE [NumarTelefon]='" + NrTel + "'", Database);
                    SqlDataReader Reader = cmd.ExecuteReader();

                    if (Reader.Read())
                    {
                        Image i = Image.FromStream(ms);
                        i.Save((string)Reader[0] + @"\Profile.png", System.Drawing.Imaging.ImageFormat.Png);

                        string LowSizePhoto = CreateLowSizePhoto.GetLowSizePhotoBase64((string)Reader[0] + @"\Profile.png");

                        Reader.Close();

                        cmd = new SqlCommand("UPDATE Utilizatori SET [LowSizePhoto]='" + LowSizePhoto + "' WHERE [NumarTelefon]='" + NrTel + "'", Database);
                        cmd.ExecuteNonQuery();
                    }
                }

                Client.Close();
            } break;

            case _Details.GetProfilePic:
            {
                string NrTel = Tag[1];

                using (SqlConnection Database = new SqlConnection(_Details.DatabaseConnectionString))
                {
                    Database.Open();

                    string t = "SELECT * FROM Utilizatori WHERE [NumarTelefon]='" + NrTel + "'";

                    SqlCommand    cmd    = new SqlCommand(t, Database);
                    SqlDataReader Reader = cmd.ExecuteReader();

                    if (Reader.Read())
                    {
                        string UserLowSizePhoto = (string)Reader[8];

                        using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(UserLowSizePhoto)))
                        {
                            int PackSize    = 1000;
                            int TotalLength = (int)ms.Length;
                            int NoOfPackets = (int)Math.Ceiling((double)ms.Length / (double)PackSize);
                            int CurrentPackSize;

                            for (int i = 0; i < NoOfPackets; i++)
                            {
                                if (TotalLength > PackSize)
                                {
                                    CurrentPackSize = PackSize;
                                    TotalLength    -= CurrentPackSize;
                                }
                                else
                                {
                                    CurrentPackSize = TotalLength;
                                }

                                byte[] CurrentBytes = new byte[CurrentPackSize];
                                int    ReadedLength = ms.Read(CurrentBytes, 0, CurrentBytes.Length);

                                ns.Write(CurrentBytes, 0, ReadedLength);
                            }
                        }
                    }

                    Client.Close();
                }
            } break;

            case _Details.GetTripId:
            {
                string NrTel  = Tag[1];
                string TripId = "error";

                using (SqlConnection Database = new SqlConnection(_Details.DatabaseConnectionString))
                {
                    Database.Open();

                    SqlCommand    cmd    = new SqlCommand("SELECT [UniqueId] FROM Excursii WHERE [Numar Telefon]='" + NrTel + "'", Database);
                    SqlDataReader Reader = cmd.ExecuteReader();

                    if (Reader.Read())
                    {
                        TripId = (string)Reader[0];
                    }

                    _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { TripId }));

                    ns.Dispose();
                    Client.Close();
                }
            } break;

            case _Details.GetUserName:
            {
                string NrTel          = Tag[1];
                string NumeUtilizator = "error";

                using (SqlConnection Database = new SqlConnection(_Details.DatabaseConnectionString))
                {
                    Database.Open();

                    SqlCommand    cmd    = new SqlCommand("SELECT [Nume],[Prenume] FROM Utilizatori WHERE [NumarTelefon]='" + NrTel + "'", Database);
                    SqlDataReader Reader = cmd.ExecuteReader();

                    if (Reader.Read())
                    {
                        NumeUtilizator = (string)Reader[0] + " " + (string)Reader[1];
                    }

                    _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { NumeUtilizator }));

                    ns.Dispose();
                    Client.Close();
                }
            } break;

            case _Details.NewQuestionPool:
            {
                string NrTel  = Tag[1];
                string TripId = Tag[2];

                foreach (Excursie e in Excursii)
                {
                    if (TripId.Equals(e.UniqueId))
                    {
                        e.QuestionPools.Add(new QuestionPool(e, Tag));
                    }
                }
            } break;

            case _Details.VoteQuestionPool:
            {
                string TripId = Tag[1];
                int    index  = int.Parse(Tag[2]);
                string Id     = Tag[3];

                foreach (Excursie e in Excursii)
                {
                    if (TripId.Equals(e.UniqueId))
                    {
                        foreach (QuestionPool q in e.QuestionPools)
                        {
                            if (q.Id.Equals(Id))
                            {
                                q.Vote(index);
                            }
                        }
                    }
                }

                ns.Dispose();
                Client.Close();
            } break;

            case _Details.RequestVotesQuestionPool:
            {
                string TripId = Tag[1];

                string[] Intrebari = null;
                string[] Ids       = null;

                foreach (Excursie e in Excursii)
                {
                    if (TripId.Equals(e.UniqueId))
                    {
                        Intrebari = new string[e.QuestionPools.Count];
                        Ids       = new string[e.QuestionPools.Count];

                        for (int i = 0; i < Intrebari.Length; i++)
                        {
                            Intrebari[i] = e.QuestionPools[i].Intrebare;
                            Ids[i]       = e.QuestionPools[i].Id;
                        }
                    }
                }

                _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { string.Join(",", Intrebari), string.Join(",", Ids) }));

                //string Id = CryptDecryptData.DecryptData(_Utils.ReadStreamString(ns))[0];

                foreach (Excursie e in Excursii)
                {
                    if (TripId.Equals(e.UniqueId))
                    {
                        foreach (QuestionPool q in e.QuestionPools)
                        {
                            string[] Votes = new string[q.Variante.Length];

                            for (int i = 0; i < q.Variante.Length; i++)
                            {
                                Votes[i] = q.Variante[i] + "," + q.GetPercentageOf(i);
                            }

                            _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(Votes));
                        }
                    }
                }

                ns.Dispose();
                Client.Close();
            } break;

            case _Details.BeSmartSimpleQuery:
            {
                HandleBeSmartClient.Handle(Tag, ns);

                ns.Dispose();
                Client.Close();
            } break;
            }
        }
예제 #16
0
        public static void Handle(TcpClient Client, NetworkStream ns, string[] Messages)
        {
            //1.Nume
            //2.Prenume
            //3.Varsta
            //4.Sex
            //5.Email
            //6.Numar Telefon
            //7.Tip Cont
            //8.Parola

            string
                Nume         = Messages[1],
                Prenume      = Messages[2],
                Varsta       = Messages[3],
                Sex          = Messages[4],
                Email        = Messages[5],
                NumarTelefon = Messages[6],
                TipCont      = Messages[7],
                Parola       = Messages[8];
            string URL;
            string LowSizePhoto;

            string Response = string.Empty;

            using (SqlConnection Database = new SqlConnection(@"Data Source=.\SQLEXPRESS;User id=Mihawai;" + "Password=11234567;" + "Database = SafeTraveling"))
            {
                Database.Open();

                URL = CreateUserURL(Nume + Prenume, NumarTelefon);
                AddUserPhoto(URL);
                LowSizePhoto = CreateLowSizePhoto.GetLowSizePhotoBase64(URL + @"\test.png");

                SqlCommand cmd = new SqlCommand(@"INSERT INTO Utilizatori ([Nume],[Prenume],[Varsta],[Sex],[Email],[NumarTelefon],[TipCont],[Parola],[LowSizePhoto],[URL]) VALUES 
                ('" + Nume + "'," +
                                                "'" + Prenume + "'," +
                                                "'" + Varsta + "'," +
                                                "'" + Sex + "'," +
                                                "'" + Email + "'," +
                                                "'" + NumarTelefon + "'," +
                                                "'" + TipCont + "'," +
                                                "'" + Parola + "'," +
                                                "'" + LowSizePhoto + "'," +
                                                "'" + URL + "')", Database);
                cmd.ExecuteNonQuery();

                Response = "ok";
            }

            /*using (SmtpClient EmailSender = new SmtpClient("smtp.gmail.com", 587))
             * {
             *  EmailSender.Credentials = new NetworkCredential("","");
             *  EmailSender.EnableSsl = true;
             *
             *  try
             *  {
             *      EmailSender.Send("from","to","subject","content");
             *  }
             *  catch (Exception exception)
             *  {
             *      MessageBox.Show("Unexpected error has happend! (" + exception.Message + ")");
             *  }
             * }*/

            _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { Response }));

            Client.Close();
            ns.Dispose();
        }
예제 #17
0
        public GameLayer(Activity context, float Size_X, float Size_Y, string IntentType, string NrTel, string GameId)
            : base(CCColor4B.Black)
        {
            this.context = context;

            this.Size_X     = Size_X;
            this.Size_Y     = Size_Y;
            this.IntentType = IntentType;
            GetDataThread   = new Thread(GetData);

            float offset = Size_Y / 15;

            X_Y_Table             = new CCSprite("X_O_Table");
            X_Y_Table.AnchorPoint = CCPoint.AnchorUpperLeft;
            X_Y_Table.PositionX   = offset;
            X_Y_Table.PositionY   = Size_Y - offset;
            X_Y_Table.ContentSize = new CCSize(Size_Y - 2 * offset, Size_Y - 2 * offset);

            Score             = new CCLabel("Score", "Fonts/MarkerFelt", 200, CCLabelFormat.SystemFont);
            Score.AnchorPoint = CCPoint.AnchorUpperRight;
            Score.PositionX   = Size_X - 100;
            Score.PositionY   = Size_Y - 100;

            Player1             = new CCLabel("You : 0", "Fonts/MarkerFelt", 100, CCLabelFormat.SystemFont);
            Player1.AnchorPoint = CCPoint.AnchorUpperLeft;
            Player1.PositionX   = Score.PositionX - Score.ContentSize.Width;
            Player1.PositionY   = Score.PositionY - 100;

            Player2             = new CCLabel("Player 2 : 0", "Fonts/MarkerFelt", 100, CCLabelFormat.SystemFont);
            Player2.AnchorPoint = CCPoint.AnchorUpperLeft;
            Player2.PositionX   = Score.PositionX - Score.ContentSize.Width;
            Player2.PositionY   = Player1.PositionY - 50;

            CreateTouchArea();

            if (IntentType == "CREATE")
            {
                TcpClient     client = new TcpClient(_Details.ServerIP, _Details.GamesHostPort);
                NetworkStream ns     = client.GetStream();
                Client = new Client(client, ns);

                _TcpDataExchange.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { _Details.Game_XandO, "CREATE", Utilizator_Trip.Me.NumarTelefon, NrTel }));
                string Response = CryptDecryptData.DecryptData(_TcpDataExchange.ReadStreamString(ns))[0];

                if (Response == "1")
                {
                    AddChild(Player1);
                    AddChild(Player2);
                    AddChild(Score);
                    AddChild(X_Y_Table);

                    MyTurn     = true;
                    PlayerType = PlayerType.X;
                    GetDataThread.Start();
                }
                else
                {
                    context.Finish();
                }
            }
            else
            {
                TcpClient     client = new TcpClient(_Details.ServerIP, _Details.GamesHostPort);
                NetworkStream ns     = client.GetStream();
                Client = new Client(client, ns);

                _TcpDataExchange.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { _Details.Game_XandO, "JOIN", GameId, NrTel }));
                string Response = CryptDecryptData.DecryptData(_TcpDataExchange.ReadStreamString(ns))[0];

                if (Response == "1")
                {
                    AddChild(Player1);
                    AddChild(Player2);
                    AddChild(Score);
                    AddChild(X_Y_Table);

                    GetDataThread.Start();
                    PlayerType = PlayerType.O;
                    MyTurn     = false;
                }
                else
                {
                    context.Finish();
                }
            }

            X_Clone = new CCSprite("X");
            O_Clone = new CCSprite("O");
            X_Win   = new CCSprite("X_Win");
            O_Win   = new CCSprite("O_Win");
        }
예제 #18
0
        public static void Handle(TcpClient Client, NetworkStream ns, string[] Messages, LocationService LocationService, NotificationService NotificationService, List <Excursie> Excursii)
        {
            //1.Destinatia principala
            //2.Tipul participantilor
            //3.Data plecare
            //4.Data intoarcere
            //5.Locatie plecare
            //6.Ora plecare
            //7.Observatii
            //8.Nume organizator
            //9.Numar telefon

            string
                DestinatiePrincipala = Messages[1],
                TipulParticipantilor = Messages[2],
                DataPlecare          = Messages[3],
                DataIntoarcere       = Messages[4],
                LocatiePlecare       = Messages[5],
                OraPlecare           = Messages[6],
                Observatii           = Messages[7],
                NumeOrganizator      = Messages[8],
                NumarTelefon         = Messages[9];

            string UniqueId = GenerateUniqueTripId();
            string URL      = CreateTripURL(NumeOrganizator, NumarTelefon, UniqueId);

            string Response = (0).ToString();

            using (SqlConnection Database = new SqlConnection(_Details.DatabaseConnectionString))
            {
                Database.Open();

                SqlCommand cmd = new SqlCommand("SELECT [Nume],[Prenume] FROM Utilizatori WHERE [NumarTelefon]='" + NumarTelefon + "'", Database);
                {
                    using (SqlDataReader Reader = cmd.ExecuteReader())
                        if (Reader.Read())
                        {
                            NumeOrganizator = (string)Reader[0] + " " + (string)Reader[1];
                        }
                }

                cmd = new SqlCommand(@"INSERT INTO Excursii ([Destinatie Principala],[Tipul Participantilor],[Data Plecare],[Data Intoarcere],[Locatie Plecare],[Ora Plecare],[Observatii],[Nume Organizator],[Numar Telefon],[UniqueId],[URL]) " +
                                     "VALUES ('" + DestinatiePrincipala + "','" +
                                     TipulParticipantilor + "','" +
                                     DataPlecare + "','" +
                                     DataIntoarcere + "','" +
                                     LocatiePlecare + "','" +
                                     OraPlecare + "','" +
                                     Observatii + "','" +
                                     NumeOrganizator + "','" +
                                     NumarTelefon + "','" +
                                     UniqueId + "','" +
                                     URL + "')", Database);

                cmd.ExecuteNonQuery();

                Excursie Excursie = new Excursie(LocationService, NotificationService, DestinatiePrincipala, TipulParticipantilor, DataPlecare, DataIntoarcere, LocatiePlecare, OraPlecare, Observatii, NumeOrganizator, NumarTelefon, UniqueId, URL);
                Excursii.Add(Excursie);

                Response = (1).ToString();
            }
            _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { Response }));

            ns.Close();
            Client.Close();
        }
예제 #19
0
 public virtual void OUTPUT_SEND(string[] Messages)
 {
     _Utils.WriteStreamString(OUTPUT.ns, CryptDecryptData.CryptData(Messages));
 }
예제 #20
0
        public static void Handle(string[] Response, NetworkStream ns)
        {
            string Produs   = Response[1];
            int    Distanta = int.Parse(Response[2]);
            string Username = Response[3];

            string UserPosition = string.Empty;

            using (SqlConnection Database = new SqlConnection(_Details.DatabaseConnectionString))
            {
                Database.Open();

                SqlCommand cmd = new SqlCommand("SELECT [LastKnowPosition] FROM Utilizatori WHERE [NumarTelefon]=@UserPhone", Database);
                cmd.Parameters.AddWithValue("UserPhone", Username);

                SqlDataReader Reader = cmd.ExecuteReader();

                if (Reader.Read())
                {
                    UserPosition = Reader[0] as string;
                }

                Reader.Dispose();

                cmd    = new SqlCommand("SELECT [Locatie],[Id_Magazin] FROM BeSmart_Magazine", Database);
                Reader = cmd.ExecuteReader();

                LatitudeLongitude DistanceCalculator = new LatitudeLongitude(UserPosition.Split(',')[0].Replace('.', ','), UserPosition.Split(',')[1].Replace('.', ','));

                List <string> ListaProduse    = new List <string>();
                List <string> PozitieProduse  = new List <string>();
                List <string> DistantaProduse = new List <string>();
                List <string> PretProduse     = new List <string>();

                while (Reader.Read())
                {
                    string PozitieMagazin = Reader[0] as string;
                    string dist           = DistanceCalculator.GetDistance(new LatitudeLongitude(PozitieMagazin.Split(',')[0].Replace('.', ','), PozitieMagazin.Split(',')[1].Replace('.', ',')));

                    if (int.Parse(dist) < Distanta)
                    {
                        using (SqlConnection Database2 = new SqlConnection(_Details.DatabaseConnectionString))
                        {
                            Database2.Open();

                            SqlCommand cmd2 = new SqlCommand("SELECT * FROM BeSmart_Produse WHERE [Id_Magazin]=@IdMagazin", Database2);
                            cmd2.Parameters.AddWithValue("IdMagazin", Reader[1] as int?);
                            SqlDataReader Reader2 = cmd2.ExecuteReader();

                            while (Reader2.Read())
                            {
                                string ActualProd = Reader2[4] as string;

                                if (ActualProd.Contains(Produs))
                                {
                                    ListaProduse.Add(ActualProd);
                                    PretProduse.Add(Reader2[5] as string + " lei");
                                    DistantaProduse.Add(dist + "m");
                                    PozitieProduse.Add(PozitieMagazin);
                                }
                            }
                        }
                    }
                }

                _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(ListaProduse.ToArray()));
                _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(PretProduse.ToArray()));
                _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(DistantaProduse.ToArray()));
                _Utils.WriteStreamString(ns, CryptDecryptData.CryptData(PozitieProduse.ToArray()));
            }
        }
예제 #21
0
 public void Send(string[] Messages)
 {
     _Utils.WriteStreamString(Client.ns, CryptDecryptData.CryptData(Messages));
 }
예제 #22
0
 public void Send(string Message)
 {
     _Utils.WriteStreamString(Client.ns, CryptDecryptData.CryptData(new string[] { Message }));
 }
예제 #23
0
        private void RedirectClient(object newClient)
        {
            TcpClient     Client = (TcpClient)newClient;
            NetworkStream ns     = Client.GetStream();

            string[] Request = CryptDecryptData.DecryptData(_Utils.ReadStreamString(ns));

            //1.GameType
            //2.Intent-p1,p2
            //        -p1
            //3.GameId


            switch (Request[0])
            {
            case _Details.Game_XandO: {
                if (Request[1] == "CREATE")
                {
                    string            NrTel_P1      = Request[2];
                    string            NrTel_P2      = Request[3];
                    NotificableClient NotificableP2 = null;

                    foreach (Excursie e in Excursii)
                    {
                        foreach (NotificableClient nc in e.NotificableClients)
                        {
                            if (nc.NumarTelefon == NrTel_P2)
                            {
                                NotificableP2 = nc;
                            }
                        }
                    }

                    XandO newBounceGame = new XandO(new Client(Client, ns), NotificableP2, Games, GetUserName(NrTel_P1));
                    Games.Add((Game)newBounceGame);
                }
                if (Request[1] == "JOIN")
                {
                    string GameId  = Request[2];
                    bool   IfExist = false;

                    foreach (XandO bg in Games.ToList())
                    {
                        if (bg.GameId == GameId)
                        {
                            IfExist = true;
                            bg.Join(new Client(Client, ns));
                            break;
                        }
                    }

                    if (IfExist)
                    {
                    }
                    else
                    {
                    }
                }
            } break;

            case _Details.Game_Bounce: {
                if (Request[1] == "CREATE")
                {
                    string            NrTel_P1      = Request[2];
                    string            NrTel_P2      = Request[3];
                    NotificableClient NotificableP2 = null;

                    foreach (Excursie e in Excursii)
                    {
                        foreach (NotificableClient nc in e.NotificableClients)
                        {
                            if (nc.NumarTelefon == NrTel_P2)
                            {
                                NotificableP2 = nc;
                            }
                        }
                    }

                    BounceGame newBounceGame = new BounceGame(new Client(Client, ns), NotificableP2, Games, GetUserName(NrTel_P1));
                    Games.Add(newBounceGame);
                }
                if (Request[1] == "JOIN")
                {
                    string GameId  = Request[2];
                    bool   IfExist = false;

                    foreach (BounceGame bg in Games)
                    {
                        if (bg.GameId == GameId)
                        {
                            IfExist = true;
                            bg.Join(new Client(Client, ns));
                            break;
                        }
                    }

                    if (IfExist)
                    {
                    }
                    else
                    {
                    }
                }
            } break;
            }
        }
예제 #24
0
 public string[] Receive()
 {
     return(CryptDecryptData.DecryptData(_Utils.ReadStreamString(Client.ns)));
 }