Example #1
0
        private static FirebaseApp CreateAndTrack(FirebaseApp.CreateDelegate createDelegate, FirebaseApp existingProxy)
        {
            FirebaseApp.ThrowIfCheckDependenciesRunning();
            FirebaseHandler.Create(FirebaseAppUtils.Instance);
            object      obj = FirebaseApp.nameToProxy;
            FirebaseApp result2;

            lock (obj)
            {
                FirebaseApp.InitializeAppUtilCallbacks();
                HandleRef   cPtr = new HandleRef(null, IntPtr.Zero);
                FirebaseApp firebaseApp;
                try
                {
                    FirebaseApp.AppSetDefaultConfigPath(PlatformInformation.DefaultConfigLocation);
                    firebaseApp = createDelegate();
                    if (AppUtilPINVOKE.SWIGPendingException.Pending)
                    {
                        throw AppUtilPINVOKE.SWIGPendingException.Retrieve();
                    }
                    if (firebaseApp == null)
                    {
                        throw new InitializationException(InitResult.FailedMissingDependency, "App creation failed with an unknown error.");
                    }
                    cPtr = FirebaseApp.getCPtr(firebaseApp);
                }
                catch (ApplicationException ex)
                {
                    FirebaseApp.OnAllAppsDestroyed();
                    string     text   = ex.Message;
                    InitResult result = InitResult.FailedMissingDependency;
                    int        num    = text.IndexOf(":");
                    if (num >= 0)
                    {
                        result = (InitResult)int.Parse(text.Substring(0, num));
                        text   = text.Substring(num + 1);
                    }
                    if (text.IndexOf("Please verify the AAR") >= 0)
                    {
                        text = text + "\n" + ErrorMessages.DependencyNotFoundErrorMessage;
                    }
                    throw new InitializationException(result, text);
                }
                catch (Exception ex2)
                {
                    FirebaseApp.OnAllAppsDestroyed();
                    throw ex2;
                }
                if (cPtr.Handle == IntPtr.Zero)
                {
                    result2 = null;
                }
                else
                {
                    WeakReference weakReference;
                    if (FirebaseApp.cPtrToProxy.TryGetValue(cPtr.Handle, out weakReference))
                    {
                        FirebaseApp firebaseApp2 = FirebaseApp.WeakReferenceGetTarget(weakReference) as FirebaseApp;
                        if (firebaseApp2 != null)
                        {
                            if (existingProxy != firebaseApp2)
                            {
                                FirebaseApp.LogMessage(LogLevel.Warning, string.Format("Detected multiple FirebaseApp proxies for {0}", existingProxy.Name));
                                existingProxy.Dispose();
                            }
                            result2 = firebaseApp2;
                            return(result2);
                        }
                    }
                    if (FirebaseApp.cPtrToProxy.Count == 0)
                    {
                        string text2 = "fire-" + PlatformInformation.RuntimeName;
                        FirebaseApp.RegisterLibraryInternal(text2, VersionInfo.SdkVersion);
                        FirebaseApp.RegisterLibraryInternal(text2 + "-ver", PlatformInformation.RuntimeVersion);
                    }
                    firebaseApp.name = firebaseApp.NameInternal;
                    firebaseApp.AddReference();
                    if (!FirebaseApp.installedCerts)
                    {
                        FirebaseApp.installedCerts = true;
                        Services.RootCerts.Install(firebaseApp.AppPlatform);
                    }
                    if (!FirebaseApp.crashlyticsInitializationAttempted)
                    {
                        FirebaseApp.crashlyticsInitializationAttempted = true;
                        FirebaseHandler.RunOnMainThread <bool>(() => FirebaseApp.InitializeCrashlyticsIfPresent());
                    }
                    result2 = firebaseApp;
                }
            }
            return(result2);
        }