예제 #1
0
 public IHttpActionResult Post(Persona persona)
 {
     if (persona == null || string.IsNullOrEmpty(persona.Nombre))//validamos nombre
     {
         return(BadRequest("Datos incorrectos."));
     }
     PersonaData.Insert(persona);
     return(Ok());
 }
예제 #2
0
 // DELETE: api/Persona/5
 public IHttpActionResult Delete(int id)
 {
     if (PersonaData.ObtenerPorId(id) == null)
     {
         return(NotFound());
     }
     PersonaData.Delete(id);
     return(Ok());
 }
예제 #3
0
    public static void Guardar(Persona persona)
    {
        BinaryFormatter bf     = new BinaryFormatter();
        FileStream      stream = new FileStream(Application.persistentDataPath + "/persona.xml", FileMode.Create);

        PersonaData data = new PersonaData(persona);

        bf.Serialize(stream, data);
        stream.Close();
    }
예제 #4
0
        public IHttpActionResult Get(int id)
        {
            Persona persona = PersonaData.ObtenerPorId(id);

            if (persona == null)
            {
                return(NotFound());
            }
            return(Ok(persona));
        }
예제 #5
0
        public IHttpActionResult Get(string nombre)
        {
            List <Persona> lista = new List <Persona>();

            lista = PersonaData.ObtenerPorNombre(nombre);
            if (lista.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(lista));
        }
예제 #6
0
 // PUT: api/Persona/5
 public IHttpActionResult Put(int id, Persona persona)
 {
     if (id != persona.Id)//Nos tiene que llegar el objeto correctamente
     {
         return(BadRequest("El id de la persona es incorrecto."));
     }
     if (PersonaData.ObtenerPorId(id) == null)
     {
         return(NotFound());
     }
     PersonaData.Update(persona);
     return(Ok());
 }
예제 #7
0
    public static int[] CargarPersona()
    {
        if (File.Exists(Application.persistentDataPath + "/persona.xml"))
        {
            BinaryFormatter bf     = new BinaryFormatter();
            FileStream      stream = new FileStream(Application.persistentDataPath + "/persona.xml", FileMode.Open);

            PersonaData data = bf.Deserialize(stream) as PersonaData;
            stream.Close();
            return(data.stats);
        }
        else
        {
            Debug.LogError("Archivo no existe");
            return(new int[4]);
        }
    }
예제 #8
0
        public bool Add(PersonaData persona)
        {
            try
            {
                using (SchoolEntities db = new SchoolEntities())
                {
                    Person nuevo = new Person();

                    nuevo.PersonID       = persona.id;
                    nuevo.FirstName      = persona.FirstName;
                    nuevo.LastName       = persona.LastName;
                    nuevo.HireDate       = DateTime.Today;
                    nuevo.EnrollmentDate = DateTime.Today;

                    db.People.Add(nuevo);
                    db.SaveChanges();
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
예제 #9
0
        public List <PersonaData> GetAll()
        {
            List <PersonaData> datos = new List <PersonaData>();

            try
            {
                using (SchoolEntities db = new SchoolEntities())
                {
                    var consulta = from personas in db.People
                                   select personas;
                    foreach (Person p in consulta)
                    {
                        PersonaData pData = new PersonaData()
                        {
                            id        = p.PersonID,
                            LastName  = p.LastName,
                            FirstName = p.FirstName,
                        };
                        if (p.HireDate.HasValue)
                        {
                            pData.HireDate = p.HireDate.Value;
                        }
                        if (p.EnrollmentDate.HasValue)
                        {
                            pData.EnrollmentDate = p.EnrollmentDate.Value;
                        }
                        datos.Add(pData);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("ERROR EN ACCESO A DATOS," + ex.Message);
            }
            return(datos);
        }
예제 #10
0
 public Form1()
 {
     InitializeComponent();
     _personaData = new PersonaData();
 }
예제 #11
0
 public ProcesadorGastos()
 {
     PersonaData = new PersonaData();
 }
예제 #12
0
        public static List <Persona> RecuperarPorTipoPersona(int id)
        {
            PersonaData tp = new PersonaData();

            return(tp.RecuperarPorTipoPersona(id));
        }
예제 #13
0
        public static void Agregar(Persona persona)
        {
            PersonaData per = new PersonaData();

            per.Agregar(persona);
        }
예제 #14
0
        public static List <Persona> RecuperarTodos()
        {
            PersonaData per = new PersonaData();

            return(per.RecuperarTodos());
        }
예제 #15
0
 // GET: api/Persona
 public IList <Persona> Get()
 {
     return(PersonaData.ObtenerTodos());
 }
예제 #16
0
        private async void RunGame(string ServerGuid)
        {
            Busy = true;
            toolStripDropDownButton1.Enabled = true;
            toolStripStatusLabel1.Text       = "Getting server info...";
            ServerInfo serverInfo = (await DeserializeResponseAsync <ServerInfoResponse>(await DoHttpRequestAsync(String.Format(URL.BF3ServerInfoShort, ServerGuid)))).data;

            Globals.CurrentGameId = serverInfo.gameId;

            toolStripStatusLabel1.Text = "Getting user info...";
            PersonaData personaData = (await DeserializeResponseAsync <PlayablePersonaResponse>(await DoHttpRequestAsync(URL.BF3PlayablePersona))).data;

            Globals.PersonaId = personaData.personaId;

            toolStripStatusLabel1.Text = "Reservating server slot...";
            ReservationInfo reservation = (await DeserializeResponseAsync <SlotReservationResponse>(await DoHttpRequestAsync(String.Format(URL.BF3ReserveSlot, Globals.PersonaId, Globals.CurrentGameId, ServerGuid)))).data;
            bool            queued      = false;

            if (reservation.joinState == "IN_QUEUE")
            {
                queued = true;
            }

            if (queued)
            {
                while (true)
                {
                    if (Cancel)
                    {
                        await LeaveServer();

                        return;
                    }
                    try
                    {
                        QueueStatusInfo queueStatusInfo = (await DeserializeResponseAsync <QueueStatusResponse>(await DoHttpRequestAsync(String.Format(URL.BF3QueueStatus, Globals.PersonaId, Globals.CurrentGameId)))).data;
                        if (queueStatusInfo.queuePosition == -1)
                        {
                            break;
                        }
                        toolStripStatusLabel1.Text = String.Format("Queued: {0}", queueStatusInfo.queuePosition);
                    }
                    catch (WebException)
                    {
                        toolStripStatusLabel1.Text = "Queue status unknown";
                    }
                    await Task.Delay(1000);
                }
            }

            toolStripStatusLabel1.Text = "Retrieving auth data...";
            string authJsonRaw;

            authJsonRaw = await DoHttpRequestAsync(String.Format(URL.BF3AuthData, Globals.PersonaId));

            authJsonRaw = authJsonRaw.Substring(1);
            authJsonRaw = authJsonRaw.Substring(0, authJsonRaw.Length - 2);
            AuthData authData   = (await DeserializeResponseAsync <AuthDataResponse>(authJsonRaw)).data;
            string   loginToken = authData.encryptedToken;
            string   authCode   = authData.authCode;

            if (Cancel)
            {
                await LeaveServer();

                toolStripStatusLabel1.Text = "Idle";
                Cancel = false;
                toolStripDropDownButton1.Enabled = false;
                Busy = false;
                return;
            }

            toolStripStatusLabel1.Text = "Starting game...";

            ProcessStartInfo process = new ProcessStartInfo();

            process.FileName         = Globals.BF3ExePath;
            process.Arguments        = String.Format(Globals.GameArgs, authCode, Globals.CurrentGameId, Globals.PersonaId, loginToken);
            process.WorkingDirectory = Globals.BF3GameDir;
            Process.Start(process);

            bool webHelperStarted = false;
            bool leavedServer     = false;

            while (true)
            {
                if (Cancel)
                {
                    if (!leavedServer)
                    {
                        toolStripStatusLabel1.Text = "Leaving server...";
                        await LeaveServer();

                        leavedServer = true;
                    }
                    toolStripStatusLabel1.Text = "Waiting for game to exit...";
                    try
                    {
                        await DoLocalHttpRequestAsync(URL.KillGame);

                        toolStripStatusLabel1.Text       = "Idle";
                        toolStripDropDownButton1.Enabled = false;
                        Cancel = false;
                        Busy   = false;
                        return;
                    }
                    catch (Exception)
                    {
                        await Task.Delay(500);

                        continue;
                    }
                }
                string state;
                try
                {
                    state = await DoLocalHttpRequestAsync(URL.WebHelper);
                }
                catch (Exception)
                {
                    if (webHelperStarted)
                    {
                        toolStripStatusLabel1.Text       = "Idle";
                        toolStripDropDownButton1.Enabled = false;
                        Busy = false;
                        return;
                    }
                    await Task.Delay(500);

                    continue;
                }
                if (state != "null")
                {
                    webHelperStarted           = true;
                    toolStripStatusLabel1.Text = state.Replace("\t", " ").Trim();
                    if (state.Contains("GAMEISGONE"))
                    {
                        toolStripStatusLabel1.Text       = "Idle";
                        toolStripDropDownButton1.Enabled = false;
                        Busy = false;
                        return;
                    }
                }
            }
        }