app center;增加發送ping的秒

This commit is contained in:
Caiyanpeng committed 2021-11-12 16:21:13 +08:00
1 parent 1bd1ffdb5a
commit d754ff3b15
719 files changed
+34172 -2875

No files matched your search

@@ -0,0 +1,241 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_WSA_10_0 && !UNITY_EDITOR
#if ENABLE_DOTNET
#error .NET scripting backed is not supported. Use IL2CPP instead.
#endif
using Microsoft.AppCenter.Unity.Internal.Utils;
using Microsoft.AppCenter.Utils;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System;
namespace Microsoft.AppCenter.Unity.Internal
{
using UWPAppCenter = Microsoft.AppCenter.AppCenter;
class AppCenterInternal
{
private static bool _prepared = false;
private static object _lockObject = new object();
public static void Configure(string appSecret)
{
Prepare();
UWPAppCenter.Configure(appSecret);
}
public static void Start(string appSecret, Type[] services)
{
var nativeServiceTypes = ServicesToNativeTypes(services);
Prepare();
UWPAppCenter.Start(appSecret, nativeServiceTypes);
}
public static void Start(Type[] services)
{
var nativeServiceTypes = ServicesToNativeTypes(services);
Prepare();
UWPAppCenter.Start(nativeServiceTypes);
}
public static void Start(Type service)
{
}
public static string GetSdkVersion()
{
return "";
}
public static void StartServices(Type[] services, int numServices)
{
Prepare();
UWPAppCenter.Start(services);
}
public static void SetLogLevel(int logLevel)
{
Prepare();
UWPAppCenter.LogLevel = (Microsoft.AppCenter.LogLevel)LogLevelFromUnity(logLevel);
}
public static void SetUserId(string userId)
{
Prepare();
UWPAppCenter.SetUserId(userId);
}
public static int GetLogLevel()
{
Prepare();
return (int)LogLevelFromUnity((int)UWPAppCenter.LogLevel);
}
public static bool IsConfigured()
{
Prepare();
return UWPAppCenter.Configured;
}
public static void SetLogUrl(string logUrl)
{
Prepare();
UWPAppCenter.SetLogUrl(logUrl);
}
public static void SetNetworkRequestsAllowed(bool isAllowed)
{
Prepare();
UWPAppCenter.IsNetworkRequestsAllowed = isAllowed;
}
public static bool IsNetworkRequestsAllowed()
{
Prepare();
return UWPAppCenter.IsNetworkRequestsAllowed;
}
public static AppCenterTask SetEnabledAsync(bool isEnabled)
{
Prepare();
return new AppCenterTask(UWPAppCenter.SetEnabledAsync(isEnabled));
}
public static AppCenterTask<bool> IsEnabledAsync()
{
Prepare();
return new AppCenterTask<bool>(UWPAppCenter.IsEnabledAsync());
}
public static AppCenterTask<string> GetInstallIdAsync()
{
Prepare();
var installIdTask = UWPAppCenter.GetInstallIdAsync();
var stringTask = new AppCenterTask<string>();
installIdTask.ContinueWith(t =>
{
var installId = t.Result?.ToString();
stringTask.SetResult(installId);
});
return stringTask;
}
public static void SetCustomProperties(object properties)
{
Prepare();
var uwpProperties = properties as Microsoft.AppCenter.CustomProperties;
UWPAppCenter.SetCustomProperties(uwpProperties);
}
public static void SetWrapperSdk(string wrapperSdkVersion,
string wrapperSdkName,
string wrapperRuntimeVersion,
string liveUpdateReleaseLabel,
string liveUpdateDeploymentKey,
string liveUpdatePackageHash)
{
Prepare();
var wrapperSdk = new Microsoft.AppCenter.WrapperSdk(wrapperSdkName, wrapperSdkVersion, wrapperRuntimeVersion, liveUpdateReleaseLabel, liveUpdateDeploymentKey, liveUpdatePackageHash);
UWPAppCenter.SetWrapperSdk(wrapperSdk);
}
private static int LogLevelToUnity(int logLevel)
{
switch ((Microsoft.AppCenter.LogLevel)logLevel)
{
case Microsoft.AppCenter.LogLevel.Verbose:
return (int)Microsoft.AppCenter.Unity.LogLevel.Verbose;
case Microsoft.AppCenter.LogLevel.Debug:
return (int)Microsoft.AppCenter.Unity.LogLevel.Debug;
case Microsoft.AppCenter.LogLevel.Info:
return (int)Microsoft.AppCenter.Unity.LogLevel.Info;
case Microsoft.AppCenter.LogLevel.Warn:
return (int)Microsoft.AppCenter.Unity.LogLevel.Warn;
case Microsoft.AppCenter.LogLevel.Error:
return (int)Microsoft.AppCenter.Unity.LogLevel.Error;
case Microsoft.AppCenter.LogLevel.Assert:
return (int)Microsoft.AppCenter.Unity.LogLevel.Assert;
case Microsoft.AppCenter.LogLevel.None:
return (int)Microsoft.AppCenter.Unity.LogLevel.None;
default:
return logLevel;
}
}
private static Microsoft.AppCenter.LogLevel LogLevelFromUnity(int logLevel)
{
switch ((Microsoft.AppCenter.Unity.LogLevel)logLevel)
{
case Microsoft.AppCenter.Unity.LogLevel.Verbose:
return Microsoft.AppCenter.LogLevel.Verbose;
case Microsoft.AppCenter.Unity.LogLevel.Debug:
return Microsoft.AppCenter.LogLevel.Debug;
case Microsoft.AppCenter.Unity.LogLevel.Info:
return Microsoft.AppCenter.LogLevel.Info;
case Microsoft.AppCenter.Unity.LogLevel.Warn:
return Microsoft.AppCenter.LogLevel.Warn;
case Microsoft.AppCenter.Unity.LogLevel.Error:
return Microsoft.AppCenter.LogLevel.Error;
case Microsoft.AppCenter.Unity.LogLevel.Assert:
return Microsoft.AppCenter.LogLevel.Assert;
case Microsoft.AppCenter.Unity.LogLevel.None:
return Microsoft.AppCenter.LogLevel.None;
default:
return (Microsoft.AppCenter.LogLevel)logLevel;
}
}
public static void StartFromLibrary(Type[] services)
{
}
public static Type[] ServicesToNativeTypes(Type[] services)
{
var nativeTypes = new List<Type>();
foreach (var service in services)
{
service.GetMethod("AddNativeType").Invoke(null, new object[] { nativeTypes });
}
return nativeTypes.ToArray();
}
public static void SetMaxStorageSize(long size)
{
Prepare();
UWPAppCenter.SetMaxStorageSizeAsync(size);
}
private static void Prepare()
{
lock (_lockObject)
{
if (!_prepared)
{
UnityScreenSizeProvider.Initialize();
DeviceInformationHelper.SetScreenSizeProviderFactory(new UnityScreenSizeProviderFactory());
/**
* Workaround for known IL2CPP issue.
* Currently it is not required, but since this workaround stores settings in separate file,
* and not generic unity mechanism, a migration is required to transition users who store data in old file to built-in mechanism.
* See https://issuetracker.unity3d.com/issues/il2cpp-use-of-windows-dot-foundation-dot-collections-dot-propertyset-throws-a-notsupportedexception-on-uwp
*
* NotSupportedException: Cannot call method
* 'System.Boolean System.Runtime.InteropServices.WindowsRuntime.IMapToIDictionaryAdapter`2::System.Collections.Generic.IDictionary`2.TryGetValue(TKey,TValue&)'.
* IL2CPP does not yet support calling this projected method.
* TODO: Can be removed after migration for settings is added.
*/
UnityApplicationSettings.Initialize();
UWPAppCenter.SetApplicationSettingsFactory(new UnityApplicationSettingsFactory());
_prepared = true;
}
}
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0ae3729a942dd41ca8c8152ae46b232e
timeCreated: 1498600933
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_WSA_10_0 && !UNITY_EDITOR
using UnityEngine;
using System.Threading.Tasks;
namespace Microsoft.AppCenter.Unity
{
public partial class AppCenterTask
{
// Task parameter should be started already!
public AppCenterTask(Task task)
{
// Use the *actual* TPL's ContinueWith implementation to
// perform the user's ContinueWith callbacks
task.ContinueWith(t => {
CompletionAction();
});
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b970ebe9345904544b42d260f6785283
timeCreated: 1501281270
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,89 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_WSA_10_0 && !UNITY_EDITOR
using System;
using System.Collections;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
namespace Microsoft.AppCenter.Unity
{
public partial class AppCenterTask<TResult>
{
private Task<TResult> _task;
private ManualResetEvent _completionEvent = new ManualResetEvent(false);
private TResult _result;
private Exception _exception;
// This will block if it is called before the task is complete
public TResult Result
{
get
{
_completionEvent.WaitOne();
if (_exception == null)
{
return _result;
}
else
{
throw _exception;
}
}
}
public Exception Exception
{
get
{
return _exception;
}
}
public AppCenterTask(Task<TResult> task) : base(task)
{
// Need to save the task to access result later
_task = task;
}
protected override void CompletionAction()
{
lock (_lockObject)
{
if (IsComplete)
{
return;
}
_result = _task.Result;
_completionEvent.Set();
base.CompletionAction();
}
}
internal void SetResult(TResult result)
{
lock (_lockObject)
{
ThrowIfCompleted();
_result = result;
_completionEvent.Set();
base.CompletionAction();
}
}
internal void SetException(Exception exception)
{
lock (_lockObject)
{
ThrowIfCompleted();
_exception = exception;
_completionEvent.Set();
base.CompletionAction();
}
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 54f6a05c3c11840eb8a1f3b76554ff94
timeCreated: 1501281270
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_WSA_10_0 && !UNITY_EDITOR
using System;
namespace Microsoft.AppCenter.Unity.Internal
{
using UWPCustomProperties = Microsoft.AppCenter.CustomProperties;
class CustomPropertiesInternal
{
public static object Create()
{
return new UWPCustomProperties();
}
public static void SetString(object properties, string key, string val)
{
var uwpProperties = properties as UWPCustomProperties;
uwpProperties.Set(key, val);
}
public static void SetNumber(object properties, string key, int val)
{
var uwpProperties = properties as UWPCustomProperties;
uwpProperties.Set(key, val);
}
public static void SetNumber(object properties, string key, long val)
{
var uwpProperties = properties as UWPCustomProperties;
uwpProperties.Set(key, val);
}
public static void SetNumber(object properties, string key, float val)
{
var uwpProperties = properties as UWPCustomProperties;
uwpProperties.Set(key, val);
}
public static void SetNumber(object properties, string key, double val)
{
var uwpProperties = properties as UWPCustomProperties;
uwpProperties.Set(key, val);
}
public static void SetBool(object properties, string key, bool val)
{
var uwpProperties = properties as UWPCustomProperties;
uwpProperties.Set(key, val);
}
public static void SetDate(object properties, string key, DateTime val)
{
var uwpProperties = properties as UWPCustomProperties;
uwpProperties.Set(key, val);
}
public static void Clear(object properties, string key)
{
var uwpProperties = properties as UWPCustomProperties;
uwpProperties.Clear(key);
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e4a40f8a8c4ac5b4e80acd82f5bb940e
timeCreated: 1498670691
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,114 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_WSA_10_0 && ENABLE_IL2CPP && !UNITY_EDITOR
using Microsoft.AppCenter.Utils;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Microsoft.AppCenter.Unity.Internal.Utils
{
public class UnityApplicationSettings : IApplicationSettings
{
private const string AppCenterSettingsKey = "AppCenterSettings";
private static readonly object _lockObject = new object();
private static IDictionary<string, object> _current;
private static bool _dirty = false;
public T GetValue<T>(string key, T defaultValue)
{
lock (_lockObject)
{
object result;
var found = _current.TryGetValue(key, out result);
if (found)
{
// This is a workaround for a bug on UWP where Install-Id cannot be read
// from Unity.PlayerPrefs, because it is saved as System.Guid, but read as a string.
if (typeof(T) == typeof(Guid?) && result is string)
{
try
{
object guid = new Guid((string)result);
return (T)guid;
}
catch (FormatException ex)
{
Debug.LogErrorFormat("Guid cannot be parsed due to a format exception: {0}", ex.Message);
return defaultValue;
}
}
return (T)result;
}
}
SetValue(key, defaultValue);
return defaultValue;
}
public void SetValue(string key, object value)
{
lock (_lockObject)
{
_current[key] = value;
_dirty = true;
}
}
public bool ContainsKey(string key)
{
lock (_lockObject)
{
return _current.ContainsKey(key);
}
}
public void Remove(string key)
{
lock (_lockObject)
{
_current.Remove(key);
_dirty = true;
}
}
private static IDictionary<string, object> ReadAll()
{
var json = PlayerPrefs.GetString(AppCenterSettingsKey, null);
var settings = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
return settings != null ? settings : new Dictionary<string, object>();
}
public static void Initialize()
{
// Read current values.
_current = ReadAll();
// Create helper for coroutine.
UnityCoroutineHelper.StartCoroutine(MainThreadCoroutine);
}
private static IEnumerator MainThreadCoroutine()
{
while (true)
{
yield return null;
if (_dirty)
{
string json;
lock (_lockObject)
{
json = JsonConvert.SerializeObject(_current);
_dirty = false;
}
PlayerPrefs.SetString(AppCenterSettingsKey, json);
PlayerPrefs.Save();
}
}
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9ce97215d8cac604bb8592f172a20089
timeCreated: 1502878843
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_WSA_10_0 && ENABLE_IL2CPP && !UNITY_EDITOR
using Microsoft.AppCenter.Utils;
namespace Microsoft.AppCenter.Unity.Internal.Utils
{
public class UnityApplicationSettingsFactory : IApplicationSettingsFactory
{
public IApplicationSettings CreateApplicationSettings()
{
return new UnityApplicationSettings();
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c5f91c5d3f7aebb4999bb4dc6d6b0f0c
timeCreated: 1502882164
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_WSA_10_0
using UnityEngine;
namespace Microsoft.AppCenter.Unity.Internal.Utils
{
public class UnityApplicationSettingsHelper : MonoBehaviour
{
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bb2b96fcb50fa4d91902322f2530fdf9
timeCreated: 1502882164
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_WSA_10_0 && !UNITY_EDITOR
using System;
using System.Threading.Tasks;
using UnityEngine;
using Microsoft.AppCenter.Utils;
namespace Microsoft.AppCenter.Unity.Internal.Utils
{
public class UnityScreenSizeProvider : ScreenSizeProviderBase
{
private static int _height;
private static int _width;
private static TaskCompletionSource<bool> _initializationTaskSource = new TaskCompletionSource<bool>();
public override int Height => _height;
public override int Width => _width;
public static void Initialize()
{
// This must occur on the main thread
_height = Screen.currentResolution.height;
_width = Screen.currentResolution.width;
_initializationTaskSource.SetResult(true);
}
#pragma warning disable 0067
public override event EventHandler ScreenSizeChanged;
#pragma warning restore 0067
public override Task WaitUntilReadyAsync()
{
return _initializationTaskSource.Task;
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f31145d1cb97b6b4e96ec422fc7e1b7d
timeCreated: 1500921084
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_WSA_10_0 && !UNITY_EDITOR
using Microsoft.AppCenter.Utils;
namespace Microsoft.AppCenter.Unity.Internal.Utils
{
public class UnityScreenSizeProviderFactory : IScreenSizeProviderFactory
{
public IScreenSizeProvider CreateScreenSizeProvider()
{
return new UnityScreenSizeProvider();
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 285d8e08793969346b271d56b8c696f3
timeCreated: 1500923200
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: