Exemplo n.º 1
0
        public static CleanupNotifier.RegistrationToken RegisterForCleanup(IntPtr cleanupObjectCPtr, IntPtr notifyObjectCPtr, object notifyObject, Type notifyObjectType, CleanupNotifier.DisposeObjectDelegate disposeObjectDelegate, CleanupNotifier.DeleteObjectDelegate deleteObjectDelegate)
        {
            object obj = CleanupNotifier.cleanupIdToContext;

            CleanupNotifier.RegistrationToken result;
            lock (obj) {
                result = CleanupNotifier.RegistrationToken.Create(CleanupNotifier.cleanupIdToContext);
                CleanupNotifier.cleanupIdToContext[result.Identifier] = new CleanupNotifier.ObjectCleanupContext {
                    NotifyObjectType  = notifyObjectType,
                    NotifyObject      = notifyObject,
                    DisposeObject     = disposeObjectDelegate,
                    DeleteObject      = deleteObjectDelegate,
                    CleanupObjectCPtr = cleanupObjectCPtr,
                    NotifyObjectCPtr  = notifyObjectCPtr
                };
                if (CleanupNotifier.f__mgcache0 == null)
                {
                    CleanupNotifier.f__mgcache0 = new CleanupNotifierBridge.CleanupDelegate(CleanupNotifier.PerformCleanup);
                }
                if (!CleanupNotifierBridge.RegisterCleanupDelegate(cleanupObjectCPtr, notifyObjectCPtr, CleanupNotifier.f__mgcache0, (IntPtr)result.Identifier))
                {
                    CleanupNotifier.cleanupIdToContext.Remove(result.Identifier);
                    throw new NullReferenceException(string.Format("{0} (instance 0x{1:X}) can't be registered for cleanup with 0x{2:X}.", notifyObjectType, notifyObjectCPtr, cleanupObjectCPtr));
                }
                FirebaseApp.LogMessage(LogLevel.Debug, string.Format("{0} (instance 0x{1:X}) registered for cleanup when 0x{2:X} is destroyed", notifyObjectType, (long)notifyObjectCPtr, (long)cleanupObjectCPtr));
            }
            return(result);
        }
Exemplo n.º 2
0
        public static void UnregisterForCleanup(ref CleanupNotifier.RegistrationToken token)
        {
            object obj = CleanupNotifier.cleanupIdToContext;

            lock (obj) {
                CleanupNotifier.ObjectCleanupContext objectCleanupContext;
                if (CleanupNotifier.cleanupIdToContext.TryGetValue(token.Identifier, out objectCleanupContext))
                {
                    CleanupNotifierBridge.UnregisterCleanupDelegate(objectCleanupContext.CleanupObjectCPtr, objectCleanupContext.NotifyObjectCPtr);
                    CleanupNotifier.DeleteContext(ref token);
                    FirebaseApp.LogMessage(LogLevel.Debug, string.Format("{0} (instance 0x{1:X}) unregistered for cleanup when 0x{2:X} is destroyed", objectCleanupContext.NotifyObjectType, (long)objectCleanupContext.NotifyObjectCPtr, (long)objectCleanupContext.CleanupObjectCPtr));
                }
            }
        }
Exemplo n.º 3
0
        public static void DisposeObject(ref CleanupNotifier.RegistrationToken token, object owner, bool delete)
        {
            object obj = CleanupNotifier.cleanupIdToContext;

            lock (obj) {
                CleanupNotifier.ObjectCleanupContext objectCleanupContext;
                if (CleanupNotifier.cleanupIdToContext.TryGetValue(token.Identifier, out objectCleanupContext))
                {
                    CleanupNotifier.DeleteContext(ref token);
                    if (!CleanupNotifierBridge.GetAndDestroyNotifiedFlag(objectCleanupContext.NotifyObjectCPtr) && delete)
                    {
                        FirebaseApp.LogMessage(LogLevel.Debug, string.Format("{0} (instance 0x{1:X}) being deleted", objectCleanupContext.NotifyObjectType, (long)objectCleanupContext.NotifyObjectCPtr));
                        objectCleanupContext.DeleteObject(new HandleRef(owner, objectCleanupContext.NotifyObjectCPtr));
                        FirebaseApp.LogMessage(LogLevel.Debug, string.Format("{0} (instance 0x{1:X}) deleted", objectCleanupContext.NotifyObjectType, (long)objectCleanupContext.NotifyObjectCPtr));
                    }
                }
            }
        }
Exemplo n.º 4
0
        private static void PerformCleanup(IntPtr cleanupObjectCPtr, IntPtr notifyObjectCPtr, IntPtr context)
        {
            object obj = CleanupNotifier.cleanupIdToContext;

            lock (obj) {
                CleanupNotifier.ObjectCleanupContext objectCleanupContext;
                if (CleanupNotifier.cleanupIdToContext.TryGetValue((long)context, out objectCleanupContext))
                {
                    object notifyObject = objectCleanupContext.NotifyObject;
                    if (notifyObject != null)
                    {
                        FirebaseApp.LogMessage(LogLevel.Debug, string.Format("{0} (instance 0x{1:X}) will be disposed", objectCleanupContext.NotifyObjectType, (long)objectCleanupContext.NotifyObjectCPtr));
                        CleanupNotifierBridge.GetAndDestroyNotifiedFlag(notifyObjectCPtr);
                        objectCleanupContext.DisposeObject(notifyObject);
                    }
                    else
                    {
                        FirebaseApp.LogMessage(LogLevel.Debug, string.Format("{0} (instance 0x{1:X}) is being finalized, deleting object now", objectCleanupContext.NotifyObjectType, (long)objectCleanupContext.NotifyObjectCPtr));
                        objectCleanupContext.DeleteObject(new HandleRef(objectCleanupContext.NotifyObjectType, notifyObjectCPtr));
                    }
                }
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        private static void InitializeAppUtilCallbacks()
        {
            object appUtilCallbacksLock = FirebaseApp.AppUtilCallbacksLock;

            lock (appUtilCallbacksLock)
            {
                if (!FirebaseApp.AppUtilCallbacksInitialized)
                {
                    if (FirebaseApp.f__mgcache0 == null)
                    {
                        FirebaseApp.f__mgcache0 = new FirebaseApp.LogMessageDelegate(FirebaseApp.LogMessage);
                    }
                    AppUtil.SetLogFunction(FirebaseApp.f__mgcache0);
                    AppUtil.AppEnableLogCallback(true);
                    if (!PlatformInformation.IsAndroid)
                    {
                        Dictionary <string, string> dictionary = new Dictionary <string, string>
                        {
                            {
                                "Firebase.Analytics.FirebaseAnalytics, Firebase.Analytics",
                                "analytics"
                            },
                            {
                                "Firebase.Auth.FirebaseAuth, Firebase.Auth",
                                "auth"
                            },
                            {
                                "Firebase.Database.FirebaseDatabase, Firebase.Database",
                                "database"
                            },
                            {
                                "Firebase.DynamicLinks.DynamicLinks, Firebase.DynamicLinks",
                                "dynamic_links"
                            },
                            {
                                "Firebase.Functions.FirebaseFunctions, Firebase.Functions",
                                "functions"
                            },
                            {
                                "Firebase.InstanceId.FirebaseInstanceId, Firebase.InstanceId",
                                "instance_id"
                            },
                            {
                                "Firebase.Invites.FirebaseInvites, Firebase.Invites",
                                "invites"
                            },
                            {
                                "Firebase.Messaging.FirebaseMessaging, Firebase.Messaging",
                                "messaging"
                            },
                            {
                                "Firebase.RemoteConfig.FirebaseRemoteConfig, Firebase.RemoteConfig",
                                "remote_config"
                            },
                            {
                                "Firebase.Storage.FirebaseStorage, Firebase.Storage",
                                "storage"
                            }
                        };
                        AppUtil.SetEnabledAllAppCallbacks(false);
                        foreach (KeyValuePair <string, string> current in dictionary)
                        {
                            try
                            {
                                if (Type.GetType(current.Key) != null)
                                {
                                    FirebaseApp.LogMessage(LogLevel.Debug, string.Format("Enabling module '{0}' for '{1}'", current.Value, current.Key));
                                    AppUtil.SetEnabledAppCallbackByName(current.Value, true);
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    FirebaseApp.AppUtilCallbacksInitialized = true;
                }
            }
        }