/// <summary> /// Fill method for populating an entire collection of ContactPointCollection /// </summary> public virtual void Fill(ContactPointCollection contactPointCollection) { // create the connection to use SqlConnection cnn = new SqlConnection(ContactPoint.GetConnectionString()); try { using (cnn) { // open the connection cnn.Open(); // create an instance of the reader to fill. SqlDataReader datareader = SqlHelper.ExecuteReader(cnn, "gsp_SelectContactPointCollection"); // Send the collection and data to the object factory CreateObjectsFromData(contactPointCollection, datareader); // close the connection cnn.Close(); } // nullify the connection cnn = null; } catch (SqlException sqlex) { throw sqlex; } }
/// <summary> /// The object factory for a particular data collection instance. /// </summary> public virtual void CreateObjectsFromData(ContactPointCollection contactpointcollection, System.Data.DataSet data) { // Do nothing if we have nothing if (data == null || data.Tables.Count == 0 || data.Tables[0].Rows.Count == 0) { return; } // Create a local variable for the new instance. ContactPoint newobj = null; // Create a local variable for the data row instance. System.Data.DataRow dr = null; // Iterate through the table rows for (int i = 0; i < data.Tables[0].Rows.Count; i++) { // Get a reference to the data row dr = data.Tables[0].Rows[i]; // Create a new object instance newobj = System.Activator.CreateInstance(contactpointcollection.ContainsType[0]) as ContactPoint; // Let the instance set its own members newobj.SetMembers(ref dr); // Add the new object to the collection instance contactpointcollection.Add(newobj); } }
void SaveNewDataToFileFromDatabase(DataSnapshot snapshot) { ContactPointCollection contactPoints = new ContactPointCollection(); JsonUtility.FromJsonOverwrite(snapshot.GetRawJsonValue(), contactPoints); TriviaSaveLoadSystem.SaveContactPoints(contactPoints); }
public void CheckDatabaseVersion() { #if !UNITY_EDITOR EnableLoadingIndicator(); string currentDatabaseVersion = PlayerPrefs.GetString("database_version"); FirebaseDatabase.DefaultInstance .GetReference("database_version") .GetValueAsync().ContinueWith(task => { if (task.IsCompleted) { DataSnapshot snapshot = task.Result; string verNumberString = snapshot.GetRawJsonValue(); if (verNumberString != currentDatabaseVersion) { TriviaSaveLoadSystem.DeleteData(); PlayerPrefs.SetString("database_version", verNumberString); //TODO: Implement a function that checks current selected language, possible to do with the localization manager or playerprefabs. DownloadWithNewLanguage(); } else { myPointData = TriviaSaveLoadSystem.LoadContactPoints(); if (myPointData != null) { //trivia up to date SpawnUpToDatePanel(); } } } }, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()); #endif }
/// <summary> /// Gets the objects for the CONTACT_POINT relationship. /// </summary> public ContactPointCollection GetContactPointCollection() { ContactPointCollection contactpointcollection = new ContactPointCollection(); ContactPointBase.ServiceObject.FillByContactPointRoleType(contactpointcollection, _id); return(contactpointcollection); }
/// <summary> /// Gets all the available objects. /// </summary> public virtual ContactPointCollection GetAll() { // create a new instance of the return object ContactPointCollection objects = new ContactPointCollection(); // fill the objects this.Fill(objects); // return the filled object from the service return(objects); }
public static void SaveContactPoints(ContactPointCollection contactPoints) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/collectionPointTest.dat"; FileStream stream = new FileStream(path, FileMode.Create); ContactPointCollection data = new ContactPointCollection(); data = contactPoints; formatter.Serialize(stream, data); stream.Close(); }
public static ContactPointCollection LoadContactPoints() { string path = Application.persistentDataPath + "/collectionPointTest.dat"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); ContactPointCollection data = formatter.Deserialize(stream) as ContactPointCollection; stream.Close(); return(data); } else { return(null); } }
/// <summary> /// Fill method for populating a collection by ContactPointType /// </summary> public void FillByContactPointType(ContactPointCollection contactPointCollection, System.Int16 id) { // create the connection to use SqlConnection cnn = new SqlConnection(ContactPoint.GetConnectionString()); try { // discover the sql parameters SqlParameterHash sqlparams = SqlHelperParameterCache.GetSpParameterSet(ContactPoint.GetConnectionString(), "gsp_SelectContactPointCollectionByContactPointType"); using (cnn) { // open the connection cnn.Open(); // set the parameters sqlparams["@type"].Value = id; // create an instance of the reader to fill. SqlDataReader datareader = SqlHelper.ExecuteReader(cnn, "gsp_SelectContactPointCollectionByContactPointType", sqlparams); // Send the collection and data to the object factory. CreateObjectsFromData(contactPointCollection, datareader); // close the connection cnn.Close(); } // nullify the connection cnn = null; } catch (SqlException sqlex) { throw sqlex; } }
IEnumerator Start() { triviaCanvas.EnableLoadIndicator(); contactPoints = TriviaSaveLoadSystem.LoadContactPoints(); if (contactPoints == null) { //unity error triviaCanvas.DisableLoadIndicator(); questions = SetDummyRoundData(); SuffleQuestionOrder(ref questions); currentQuestion = questions[currentQuestionNumber]; EnableQuestionCanvas(); SetScoreText(); questionCanvas.setNewQuestionUI(currentQuestion); } else { int questionAmount = maxQuestions; triviaCanvas.DisableLoadIndicator(); //id that is inside the contact point;contactpoint.identifier if (PlayerPrefs.GetInt("TriviaAllRandom", 0) == 1) { //reset all random state PlayerPrefs.SetInt("TriviaAllRandom", 0); AllRandomAllQuestions(); questionAmount = maxRandomQs; } else { currentContactPointIndex = SelectContactPointIndex(PlayerPrefs.GetInt("CurrentLocationIdentifier", 0)); questions = contactPoints.points[currentContactPointIndex].questions; } DisplayCurrentQuestionAndEnableCanvas(questionAmount); } yield return(true); }
/// <summary> /// The object factory for a particular data collection instance. /// </summary> public virtual void CreateObjectsFromData(ContactPointCollection contactpointcollection, System.Data.SqlClient.SqlDataReader data) { // Do nothing if we have nothing if (data == null) { return; } // Create a local variable for the new instance. ContactPoint newobj = null; // Iterate through the data reader while (data.Read()) { // Create a new object instance newobj = System.Activator.CreateInstance(contactpointcollection.ContainsType[0]) as ContactPoint; // Let the instance set its own members newobj.SetMembers(ref data); // Add the new object to the collection instance contactpointcollection.Add(newobj); } }
// Activate pop-up and set the correct texts public void PushLocBtn(int locationIndex) { Debug.Log(locationIndex); if (lastLocation != null) { Debug.Log("LAST LOCATION: " + lastLocation.name); } Debug.Log("LOCINDEX LOCATION: " + locations[locationIndex].name); cameraMovementScript.CanMove = false; //load info from a file contactPoints = TriviaSaveLoadSystem.LoadContactPoints(); ContactPoint currentLocationData = null; if (contactPoints == null) { Debug.LogWarning("You propably run in editor. Contact points are null"); } else { for (int i = 0; i < contactPoints.points.Length; i++) { if (contactPoints.points[i].identifier.ToString() == locations[locationIndex].identifier) { currentLocationData = contactPoints.points[i]; break; } } } bool contactPointValidation = (contactPoints != null && locationIndex <= contactPoints.points.Length && currentLocationData != null); string locationNameFromFile = (contactPointValidation) ? currentLocationData.name : locations[locationIndex].name; string locationDescriptionFromFile = (contactPointValidation) ? currentLocationData.description : locations[locationIndex].description; // Open pop-up and show correct info infoPanelObj.GetComponent <DisableScript>().enabled = false; infoPanelObj.SetActive(true); gpsBtnScript.HideOrShowButtons(true); infoAnim.SetBool("ShowPanel", true); locationTitleText.text = locationNameFromFile; locationDescText.text = locationDescriptionFromFile; // Set listener for play button playBtn.onClick.AddListener(delegate { PushPlayBtn(locBtns[locationIndex].transform.name); }); triviaBtn.onClick.AddListener(delegate { PushTriviaBtn(locationIndex); }); if (canOpenMenu && lastLocation != null && lastLocation.name == locations[locationIndex].name) { triviaInactiveText.SetActive(false); triviaActiveText.SetActive(true); // Example classify = (input >= 0) ? "nonnegative" : "negative"; string localizedLocation = (LocalizationManager.Instance != null) ? LocalizationManager.Instance.GetLocalizedValue("location_proximity_in") : "Trivia"; triviaBtn.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = localizedLocation; //popupLocImg.color = Color.green; triviaBtn.GetComponent <Image>().color = activeColor; } else { triviaInactiveText.SetActive(true); triviaActiveText.SetActive(false); // Example classify = (input >= 0) ? "nonnegative" : "negative"; string localizedLocation = (LocalizationManager.Instance != null) ? LocalizationManager.Instance.GetLocalizedValue("location_proximity_off") : " Et ole alueella"; triviaBtn.transform.GetChild(1).GetComponent <TextMeshProUGUI>().text = localizedLocation; //popupLocImg.color = Color.red; triviaBtn.GetComponent <Image>().color = inactiveColor; } }