private static async Task <bool> ValidateConnectionToFirestore(ServerProperties properties) { string collectionName = "Test_firestore_collection"; string docName = "Test_firestore_document"; CredentialList credentialList = FindCredentialsAsset(); FirestoreDb db = FirestoreDb.Create(GetProjectId(properties, credentialList)); // Create a document with a random ID in the "Test_firestore_collection" collection. CollectionReference collection = db.Collection(collectionName); DocumentReference document = await collection.AddAsync(new { Name = docName }); // A DocumentReference doesn't contain the data - it's just a path. // Let's fetch the current document. DocumentSnapshot snapshot = await document.GetSnapshotAsync(); string receivedDocName = snapshot.GetValue <string>("Name"); if (receivedDocName != docName) { await document.DeleteAsync(); Debug.LogError($"Could not write a test document to firebase"); return(false); } await document.DeleteAsync(); return(true); }
private static bool ValidateJsonFileExist(ServerProperties properties) { CredentialList credentialList = FindCredentialsAsset(); Credentials credentials = properties.IsProduction ? credentialList.prodCredentials : credentialList.devCredentials; string credentialsJson = JsonConvert.SerializeObject(credentials, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new ShouldSerializeContractResolver() }); var filePathTmp = Path.Combine(Application.temporaryCachePath, GetJsonFilename(properties)); try { File.WriteAllText(filePathTmp, credentialsJson.Replace("\\\\", "\\")); } catch (Exception e) { Debug.LogError(e.Message); return(false); } return(true); }
public static bool CreateServerPropertiesFile(ServerProperties properties) { CredentialList credentialList = FindCredentialsAsset(); Credentials credentials = properties.IsProduction ? credentialList.prodCredentials : credentialList.devCredentials; string credentialsJson = JsonConvert.SerializeObject(credentials, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new ShouldSerializeContractResolver() }); string serverSettings = $"host.local={properties.IsLocal}{System.Environment.NewLine}" + $"host.production={properties.IsProduction}{System.Environment.NewLine}" + $"host.prod.credentials={JSON_FILENAME_PROD}{System.Environment.NewLine}" + $"host.prod.projectId={GetProjectId(true, credentialList)}{System.Environment.NewLine}" + $"host.dev.credentials={JSON_FILENAME_DEV}{System.Environment.NewLine}" + $"host.dev.projectId={GetProjectId(false, credentialList)}"; var filePathServerCredentials = Path.Combine(Application.dataPath, "Server~/src/main/resources", GetJsonFilename(properties)); var filePathServerSettings = Path.Combine(Application.dataPath, "Server~/src/main/resources", SERVER_SETTINGS_FILENAME); try { File.WriteAllText(filePathServerCredentials, credentialsJson.Replace("\\\\", "\\")); File.WriteAllText(filePathServerSettings, serverSettings); } catch (Exception e) { Debug.LogError(e.Message); return(false); } return(true); }
public static CredentialList FindCredentialsAsset() { CredentialList instance = null; AssetDatabase.FindAssets($"t:{typeof(CredentialList).FullName}").Any(guid => { var path = AssetDatabase.GUIDToAssetPath(guid); instance = AssetDatabase.LoadAssetAtPath <CredentialList>(path); return(true); }); return(instance); }
private static bool ValidateCredentialsNotEmpty() { CredentialList credentialList = FindCredentialsAsset(); foreach (FieldInfo fi in credentialList.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { if (fi.FieldType == typeof(string)) { string value = (string)fi.GetValue(credentialList); if (string.IsNullOrEmpty(value)) { Debug.LogError($"'FirebasePlugin/CredentialsSettings' {fi.Name} is empty"); return(false); } } } return(true); }
private static CredentialList FindOrCreateNewScriptableObject() { CredentialList instance = FindCredentialsAsset(); if (instance != null) { return(instance); } instance = ScriptableObject.CreateInstance <CredentialList>(); if (!System.IO.Directory.Exists(ManagerPath)) { System.IO.Directory.CreateDirectory(ManagerPath); } AssetDatabase.CreateAsset(instance, $"{ManagerPath}/{typeof(CredentialList).Name}.asset"); AssetDatabase.SaveAssets(); return(instance); }
private static string GetProjectId(bool isProd, CredentialList credentialList) { return(isProd ? credentialList.prodCredentials.ProjectId : credentialList.devCredentials.ProjectId); }
public static string GetProjectId(ServerProperties properties, CredentialList credentialList) { return(GetProjectId(properties.IsProduction, credentialList)); }