Esempio n. 1
0
    void Handle_Version_Response(string response, Handler_Type none)
    {
        response = Utils.Clear_Response(response);
        bool success = float.TryParse(response, out float version);

        if (success)
        {
            if (response == Application.version.ToString(new NumberFormatInfo {
                NumberDecimalSeparator = "."
            }))
            {
                Message.ShowMessage("No hay ninguna actualización disponible en este momento.");
            }
            else
            {
                Debug.Log(response + Application.version.ToString(new NumberFormatInfo {
                    NumberDecimalSeparator = "."
                }));
                Message.ShowMessage("¡Hay nuevas actualizaciones disponibles!");
                Message.ShowMessage("Abriendo enlace en tu navegador");
                Invoke("Open_In_Browser", 4);
            }
        }
        else
        {
            Message.ShowMessage("Respuesta del servidor no reconocida: " + response);
            Debug.LogError("Server response not recognized: " + response);
        }
    }
    /// <summary>
    /// Loads and parses a database from the device's cache, if existent.
    /// </summary>
    /// <param name="type">The child class type of Database_Handler that should load and parse its database.</param>
    public static void Load_Data_Cache(Handler_Type type)
    {
        string name = type.ToString() + "_database";

        if (PlayerPrefs.HasKey(name) && Is_Clean(name))
        {
            Parse_Data(PlayerPrefs.GetString(type.ToString() + "_database"), false, type);
        }
    }
    /// <summary>
    /// Called on server response.
    /// </summary>
    /// <param name="response">The server's response.</param>
    /// <param name="type">The child class type of Database_Handler that is going to parse response.</param>
    static void Handle_Data_Response(string response, Handler_Type type)
    {
        Parse_Data(response, true, type);

        if (Calendar_Handler.Singleton != null)
        {
            Calendar_Handler.Singleton.Initialize();
        }
    }
    void Handle_Delete_Response(string response, Handler_Type type)
    {
        if (response.Contains("500"))
        {
            Message.ShowMessage("Error interno del servidor.");
            return;
        }

        Message.ShowMessage("Archivo elminiado con éxito.");
    }
Esempio n. 5
0
    /// <summary>
    /// Called on server response.
    /// </summary>
    protected void Handle_Vote_Response(string response, Handler_Type type)
    {
        if (response.Contains("500"))
        {
            Message.ShowMessage("Error interno del servidor.");
            return;
        }

        if (User.User_Info.Polls_Data.Exists(x => x.id == poll.Id))
        {
            User.User_Info.Polls_Data.Find(x => x.id == poll.Id).response = temp_vote;
        }
        else
        {
            User.User_Info.Polls_Data.Add(new User.Vote_Data()
            {
                id = poll.Id, response = temp_vote
            });
        }

        for (int x = 0; x < poll.Vote_Voters.Count; x++)
        {
            if (poll.Vote_Voters[x].Exists(a => a.Id == User.User_Info.Id))
            {
                poll.Vote_Voters[x].Remove(poll.Vote_Voters[x].Find(a => a.Id == User.User_Info.Id));
            }
        }

        poll.Vote_Voters[temp_vote].Add(User.User_Info);

        poll.Status = poll.Vote_Types[temp_vote];
        poll.Selected_Option_Idx = temp_vote;
        List <Data_struct> polls = Polls.Data_List_Get(typeof(Polls));

        for (int x = 0; x < polls.Count; x++)
        {
            if (polls[x].Id == poll.Id)
            {
                polls[x] = poll;
                Polls.Data_List_Set(typeof(Polls), polls);
                break;
            }
        }

        Message.ShowMessage("Base de datos actualizada con éxito.");

        if (this != null)
        {
            Show_Poll_Details();
            Set_Interactable(true);
        }

        Database_Handler.Update_Unread(Handler_Type.polls);
    }
    void Handle_Save_Response(string response, Handler_Type type)
    {
        if (response.Contains("500"))
        {
            Message.ShowMessage("Error interno del servidor.");
            return;
        }

        Delete_Button.gameObject.SetActive(true);
        Message.ShowMessage("Archivo actualizado con éxito.");
    }
Esempio n. 7
0
 void Handle_Save_Response(string response, Handler_Type type)
 {
     if (response.Contains("VERIFIED"))
     {
         Message.ShowMessage("Ritmo guardado con éxito");
     }
     else
     {
         Message.ShowMessage("Error al guradar el ritmo");
     }
 }
Esempio n. 8
0
    /// <summary>
    /// Called on server response.
    /// </summary>
    protected void Handle_Event_Response(string response, Handler_Type type)
    {
        if (response.Contains("500"))
        {
            Message.ShowMessage("Error interno del servidor.");
            return;
        }

        if (User.User_Info.Events_Data.Exists(x => x.id == calendar_event.Id))
        {
            User.User_Info.Events_Data.Find(x => x.id == calendar_event.Id).response = temp_vote;
        }
        else
        {
            User.User_Info.Events_Data.Add(new User.Vote_Data()
            {
                id = calendar_event.Id, response = temp_vote
            });
        }

        for (int x = 0; x < calendar_event.Vote_Voters.Count; x++)
        {
            if (calendar_event.Vote_Voters[x].Exists(a => a.Id == User.User_Info.Id))
            {
                calendar_event.Vote_Voters[x].Remove(calendar_event.Vote_Voters[x].Find(a => a.Id == User.User_Info.Id));
            }
        }

        calendar_event.Vote_Voters[temp_vote].Add(User.User_Info);

        calendar_event.Status = calendar_event.Vote_Types[temp_vote];
        List <Data_struct> calendar_events = Calendar_Events.Data_List_Get(typeof(Calendar_Events));

        for (int x = 0; x < calendar_events.Count; x++)
        {
            if (calendar_events[x].Id == calendar_event.Id)
            {
                calendar_events[x] = calendar_event;
                Calendar_Events.Data_List_Set(typeof(Calendar_Events), calendar_events);
                break;
            }
        }

        Message.ShowMessage("Base de datos actualizada con éxito.");

        if (this != null)
        {
            Show_Event_Details();
            Set_Interactable(true);
        }

        Database_Handler.Update_Unread(Handler_Type.events);
    }
Esempio n. 9
0
 void Handle_Login_Response(string response, Handler_Type type)
 {
     User.Parse_User_Data(response, true, true);
 }
    public static void Update_Unread(Handler_Type handler_type)
    {
        Debug.Log("Updating Unread " + handler_type.ToString());

        Type type   = typeof(Docs);
        bool unread = false;

        switch (handler_type)
        {
        case Handler_Type.events:
            type = typeof(Calendar_Events);
            foreach (Data_struct data in Data_List_Get(type))
            {
                if (((Calendar_Event)data).Status == "" && (Singleton == null || Singleton.GetType() != type) && Utils.Is_Sooner(DateTime.Now, ((Calendar_Event)data).Date_Deadline))
                {
                    Helper.Menu_Icon = () => {
                        return(Menu.Singleton.Button_Events.GetComponentInChildren <Image>());
                    };
                    Helper.Sprite_Red = () => {
                        return(Menu.Singleton.Sprite_Events_Unread);
                    };
                    Helper.Singleton.StartCoroutine("Update_Button");
                    unread = true;
                    break;
                }
            }
            break;

        case Handler_Type.news:
            type = typeof(News);
            foreach (Data_struct data in Data_List_Get(type))
            {
                if (!((News_Entry)data).Seen && (Singleton == null || Singleton.GetType() != type))
                {
                    Helper.Menu_Icon = () => {
                        return(Menu.Singleton.Button_News.GetComponentInChildren <Image>());
                    };
                    Helper.Sprite_Red = () => {
                        return(Menu.Singleton.Sprite_News_Unread);
                    };
                    Helper.Singleton.StartCoroutine("Update_Button");
                    unread = true;
                    break;
                }
            }
            break;

        case Handler_Type.polls:
            type = typeof(Polls);
            foreach (Data_struct data in Data_List_Get(type))
            {
                if (((Poll)data).Status == "" && (Singleton == null || Singleton.GetType() != type) && Utils.Is_Sooner(DateTime.Now, ((Poll)data).Date_Deadline))
                {
                    Helper.Menu_Icon = () => {
                        return(Menu.Singleton.Button_Polls.GetComponentInChildren <Image>());
                    };
                    Helper.Sprite_Red = () => {
                        return(Menu.Singleton.Sprite_Polls_Unread);
                    };
                    Helper.Singleton.StartCoroutine("Update_Button");
                    unread = true;
                    break;
                }
            }
            break;
        }

        Unread[type] = unread;
        Scroll_Updater.Initialized[type] = true;
    }
 static void Post_Parse(Handler_Type handler_type)
 {
     Update_Unread(handler_type);
 }
    // ______________________________________
    //
    // 4. PARSE DATA.
    // ______________________________________
    //


    /// <summary>
    /// Parses a database gotten from the device's cache or from a server's response.
    /// </summary>
    /// <param name="data_to_parse">Data from cache or server to parse.</param>
    /// <param name="save">If data_to_parse should be saved on the device's cache.</param>
    /// <param name="handler_type">The child class type of Database_Handler that is going to parse data_to_parse.</param>
    static void Parse_Data(string data_to_parse, bool save, Handler_Type handler_type)
    {
        if (!Is_Clean(data_to_parse))
        {
            Message.ShowMessage("Error interno del servidor.");
            return;
        }

        Func <string, Data_struct> Parse_Data_Single = null;
        Func <List <Data_struct> > Sort_List         = null;
        Type type = null;

        switch (handler_type)
        {
        case Handler_Type.news:
            Parse_Data_Single = News.Parse_Single_Data;
            type      = typeof(News);
            Sort_List = News.Sort_List;
            break;

        case Handler_Type.polls:
            Parse_Data_Single = Polls.Parse_Single_Data;
            type      = typeof(Polls);
            Sort_List = Polls.Sort_List;
            break;

        case Handler_Type.events:
            Parse_Data_Single = Calendar_Events.Parse_Single_Data;
            type      = typeof(Calendar_Events);
            Sort_List = Calendar_Events.Sort_List;
            break;

        case Handler_Type.docs:
            Parse_Data_Single = Docs.Parse_Single_Data;
            type = typeof(Docs);
            break;
        }

        List <Data_struct> data_list = new List <Data_struct>();

        if (save)
        {
            Save_Database(handler_type.ToString() + "_database", data_to_parse);
        }

        // Separate news database from initial server information. (E.g. "VERIFIED.|*databases*|")
        string data = Utils.Split(data_to_parse, '~')[1];

        // Separate each row to parse it individually. (E.g. "*row*%*row*")
        if (Encryption.Has_Valid_Key())
        {
            foreach (string element in Utils.Split(data, "%"))
            {
                data_list.Add(Parse_Data_Single(element));
            }
        }

        Data_List_Set(type, data_list);

        if (Singleton != null)
        {
            Singleton.enabled = true;
        }

        Sort_List?.Invoke();
        Scroll_Updater.Disable();

        if (Menu.Active_Item == Menu.Menu_item.Home)
        {
            foreach (Scrollable scrollable in FindObjectsOfType <Scrollable>())
            {
                scrollable.Initialize();
            }
        }

        Post_Parse(handler_type);
    }
 /// <summary>
 /// Loads a database from the server.
 /// </summary>
 /// <param name="type">The child class type of Database_Handler that should load and parse the server's database.</param>
 public static void Load_Data_Server(Handler_Type type)
 {
     string[] field_names  = { "REQUEST_TYPE" };
     string[] field_values = { "get_" + type.ToString() };
     Http_Client.Send_Post(field_names, field_values, Handle_Data_Response, type);
 }
Esempio n. 14
0
    IEnumerator Send_Post_Coroutine(string[] field_name, string[] field_value, Action <string, Handler_Type> concludingMethod, bool add_user_credentials, Handler_Type type)
    {
        WWWForm form = new WWWForm();

        form.AddField("API_USER", "USER");
        form.AddField("API_PASSWORD", "8420b25f4c1ad7ac906364ee943a7bef");
        form.AddField("db_username", "dbu14967");
        form.AddField("db_password", "DrTgcePl06K#");

        if (add_user_credentials)
        {
            form.AddField("username", User.User_Info.Username);
            form.AddField("psswd", User.Psswd);
        }

        for (int x = 0; x < field_name.Length; x++)
        {
            form.AddField(field_name[x], field_value[x]);
        }

        using (UnityWebRequest www = UnityWebRequest.Post(API_URL, form))
        {
            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                string error = www.error;

                if (error == "Cannot resolve destination host")
                {
                    error = "No estás conectad@ a internet.";
                }

                Message.ShowMessage(error);
                Debug.LogWarning(error);
                Scroll_Updater.Disable();
                Login.Singleton.On_Load_Failure();
            }
            else
            {
                StringBuilder sb = new StringBuilder();

                foreach (KeyValuePair <string, string> dict in www.GetResponseHeaders())
                {
                    sb.Append(dict.Key).Append(": \t[").Append(dict.Value).Append("]\n");
                }

                string response_header  = sb.ToString();
                string response_content = www.downloadHandler.text;

                Debug.Log(response_content);
                concludingMethod(response_content, type);
            }
        }
    }
Esempio n. 15
0
    public static void Send_Post(string[] field_name, string[] field_value, Action <string, Handler_Type> concludingMethod, Handler_Type type = Handler_Type.none, bool add_user_credentials = true)
    {
        string data = "";

        for (int x = 0; x < field_name.Length; x++)
        {
            data += field_name[x] + ": " + field_value[x] + "\n";
        }

        Debug.Log("Sending HTTP Request:\n" + data);
        Singleton.StartCoroutine(Singleton.Send_Post_Coroutine(field_name, field_value, concludingMethod, add_user_credentials, type));
    }
Esempio n. 16
0
    void Handle_Data_Response(string response, Handler_Type type)
    {
        string data = Utils.Split(response, '~')[1];

        foreach (string rhythm in Utils.Split(data, "%"))
        {
            Rhythm_Data new_rhythm  = new Rhythm_Data();
            string[]    rhythm_data = Utils.Split(rhythm, '#');

            new_rhythm.Id             = uint.Parse(rhythm_data[0]);
            new_rhythm.Name           = rhythm_data[1];
            new_rhythm.Description    = rhythm_data[2];
            new_rhythm.PPM            = uint.Parse(rhythm_data[3]);
            new_rhythm.Time_Signature = (Rhythm_Data.Time_Signature_Type)Enum.Parse(typeof(Rhythm_Data.Time_Signature_Type), rhythm_data[4]);
            new_rhythm.Creation       = Utils.Get_DateTime(rhythm_data[5]);
            new_rhythm.Last_Update    = Utils.Get_DateTime(rhythm_data[6]);
            new_rhythm.Author_id      = uint.Parse(rhythm_data[7]);

            foreach (Sound_Data.Sound_Type sound_type in (Sound_Data.Sound_Type[])Enum.GetValues(typeof(Sound_Data.Sound_Type)))
            {
                if (sound_type == Sound_Data.Sound_Type.None)
                {
                    continue;
                }

                Sound_Data new_sound = Parse_Sound(sound_type, rhythm_data[8]);
                new_rhythm.Sounds_Data.Add(new_sound);

                if (!Sound_Type_Mono.Sounds.Exists(a => a.Sound_Type == new_sound.Type))
                {
                    continue;
                }

                Sound_Type_Mono sound_mono = Sound_Type_Mono.Sounds.Find(a => a.Sound_Type == new_sound.Type);

                foreach (Sound_Data.Instance instance in new_sound.Instances)
                {
                    sound_mono.Instances[instance.Fire_Time].Set_Enabled(true);
                    sound_mono.Instances[instance.Fire_Time].Instance = instance;
                }

                foreach (Sound_Data.Loop loop in new_sound.Loops)
                {
                    int sibling_index = sound_mono.Instances[loop.Start_Time].transform.GetSiblingIndex();

                    Rhythm_Loop rhythm_loop = Instantiate(loop_prefab, sound_mono.transform).GetComponent <Rhythm_Loop>();
                    rhythm_loop.Data  = loop;
                    rhythm_loop.Sound = sound_mono;
                    rhythm_loop.Sound.Loops.Add(rhythm_loop);
                    rhythm_loop.Update_Core();
                    rhythm_loop.Update_Periphery();
                }
            }

            Rhythms.Add(new_rhythm);
        }

        rhythm_title.text = Rhythms[0].Name.ToString();
        PPM = Rhythms[0].PPM;
        rhythm_speed.text    = PPM.ToString();
        rhythm_length.text   = Song_Length.ToString();
        time_signature.value = (int)Rhythms[0].Time_Signature;
        time_signature.onValueChanged.AddListener((int value) =>
        {
            Rhythms[0].Time_Signature = (Rhythm_Data.Time_Signature_Type)value;
            Update_Separators();
        });

        Update_Numerators();
        Update_Separators();

        Reset_Events();
        Utils.Update_UI = true;
    }