Exemple #1
0
        public int Execute(Dictionary <string, string> argsLc, Dictionary <string, string> argsCased)
        {
            var jsonInput      = GetJsonInput(argsLc);
            var alerts         = json.DeserializeObject <List <Alert> >(jsonInput);
            var todayStr       = DateTime.UtcNow.ToShortDateString();
            var today          = DateTime.Parse(todayStr);
            var fixedAlertDays = GetFixedAlertDays(argsLc);

            List <string> expiredAlerts = new List <string>();
            List <string> warningAlerts = new List <string>();

            foreach (var eachAlert in alerts)
            {
                var expireTime = eachAlert.GetDate();
                var alertDays  = fixedAlertDays ?? eachAlert.alertDays;
                var alertTime  = expireTime - TimeSpan.FromDays(alertDays);

                if (today >= expireTime)
                {
                    expiredAlerts.Add("Expired alert: " + eachAlert.name + " on: " + eachAlert.date);
                }
                else if (today >= alertTime)
                {
                    warningAlerts.Add("Approaching deadline: " + eachAlert.name + " on: " + eachAlert.date);
                }
            }

            JcuUtil.FancyWriteToConsole(ConsoleColor.White, "\n\n================================================");
            foreach (var eachWarning in warningAlerts)
            {
                JcuUtil.FancyWriteToConsole(ConsoleColor.Yellow, eachWarning);
            }
            foreach (var eachAlert in expiredAlerts)
            {
                JcuUtil.FancyWriteToConsole(ConsoleColor.Red, eachAlert);
            }

            if (warningAlerts.Count + expiredAlerts.Count == 0)
            {
                JcuUtil.FancyWriteToConsole(ConsoleColor.Green, "No Calendar alerts");
            }
            JcuUtil.FancyWriteToConsole(ConsoleColor.White, "================================================\n\n");

            // Strictly speaking, we want to fail the job if there's any alerts at all.
            return(warningAlerts.Count + expiredAlerts.Count);
        }
Exemple #2
0
    private void Load_LocalStorage()
    {
        VirtualCurrency[GhostTokensIdentifier] = PlayerPrefsHelpers.TryGet(GhostTokensIdentifier, 0);
        VirtualCurrency[EnergieIdentifier]     = PlayerPrefsHelpers.TryGet(EnergieIdentifier, 0);

        int numberOfItemsToLoad = PlayerPrefsHelpers.TryGet(NumberOfItemsIdentifier, 0);

        ISerializerPlugin serializer = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer);

        for (int index = 0; index < Inventory.Count; index++)
        {
            string ItemJson = PlayerPrefsHelpers.TryGet(ItemIdentifier + index.ToString("000"), "");
            if (string.IsNullOrWhiteSpace(ItemJson) == false)
            {
                ItemInstance Item = serializer.DeserializeObject <ItemInstance>(ItemJson);
            }
        }
    }
        public bool ExecuteCloudScript <TIn, TOut>(string functionName, TIn functionParameter, Dictionary <string, string> extraHeaders, out TOut result, out string errorReport)
        {
            // Perform the request
            var request = new ExecuteCloudScriptRequest
            {
                FunctionName            = functionName,
                FunctionParameter       = functionParameter,
                GeneratePlayStreamEvent = true
            };
            var task = clientApi.ExecuteCloudScriptAsync(request, null, extraHeaders);

            task.Wait();
            errorReport = PlayFabUtil.GetCloudScriptErrorReport(task.Result);

            if (task.Result.Error != null)
            {
                Console.WriteLine("Execute Cloudscript failure: " + functionName + ":\n" + json.SerializeObject(functionParameter));
                Console.WriteLine(errorReport);
                result = default(TOut);
                return(false);
            }

            // Re-serialize as the target type
            var resultJson = json.SerializeObject(task.Result.Result.FunctionResult);

            if (verbose)
            {
                Console.WriteLine("===== Verbose ExecuteCloudScript Json: =====");
                Console.WriteLine(resultJson);
                Console.WriteLine("===== End =====");
            }
            try
            {
                result = json.DeserializeObject <TOut>(resultJson);
            }
            catch (Exception)
            {
                Console.WriteLine("Could not serialize text: \"" + resultJson + "\" as " + typeof(TOut).Name);
                result = default(TOut);
                return(false);
            }
            return(task.Result.Error == null && task.Result.Result.Error == null && (result != null || resultJson == "null"));
        }
        public static void Start()
        {
            _jsonWrapper = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer);

            string fileName = Environment.GetEnvironmentVariable(GsdkConfigFileEnvVarKey);

            if (!string.IsNullOrEmpty(fileName) && File.Exists(fileName))
            {
                _gsdkconfig = _jsonWrapper.DeserializeObject <GSDKConfiguration>(File.ReadAllText(fileName));
            }
            else
            {
                Debug.LogError(string.Format("Environment variable {0} not defined", GsdkConfigFileEnvVarKey));
                Application.Quit();
            }

            _baseUrl = string.Format("http://{0}/v1/sessionHosts/{1}/heartbeats", _gsdkconfig.HeartbeatEndpoint, _gsdkconfig.SessionHostId);
            CurrentState.CurrentGameState = GameState.Initializing;
            CurrentErrorState             = ErrorStates.Ok;
            CurrentState.CurrentPlayers   = new List <ConnectedPlayer>();
            if (_configMap == null)
            {
                _configMap = CreateConfigMap(_gsdkconfig);
            }
            if (IsDebugging)
            {
                Debug.Log(_baseUrl);
                Debug.Log(_gsdkconfig.SessionHostId);
                Debug.Log(_gsdkconfig.LogFolder);
            }

            //Create an agent that can talk on the main-tread and pull on an interval.
            //This is a unity thing, need an object in the scene.
            GameObject agentView = new GameObject("PlayFabAgentView");

            agentView.AddComponent <PlayFabMultiplayerAgentView>();
        }
Exemple #5
0
        internal static void SendHeartBeatRequest()
        {
            var payload = _jsonWrapper.SerializeObject(CurrentState);

            if (string.IsNullOrEmpty(payload))
            {
                return;
            }
            var payloadBytes = Encoding.ASCII.GetBytes(payload);

            PlayFabHttp.SimplePostCall(baseURL, payloadBytes, (success) => {
                var json = System.Text.Encoding.UTF8.GetString(success);
                Debug.Log(json);
                if (string.IsNullOrEmpty(json))
                {
                    return;
                }
                var hb = _jsonWrapper.DeserializeObject <SessionHostHeartbeatInfo>(json);
                if (hb != null)
                {
                    ProcessAgentResponse(hb);
                }
                CurrentErrorState = ErrorStates.Ok;
                IsProcessing      = false;
            }, (error) => {
                var guid = Guid.NewGuid();
                Debug.LogFormat("CurrentError: {0} - {1}", error, guid.ToString());
                //Exponential backoff for 30 minutes for retries.
                switch (CurrentErrorState)
                {
                case ErrorStates.Ok:
                    CurrentErrorState = ErrorStates.Retry30s;
                    if (IsDebugging)
                    {
                        Debug.Log("Retrying heartbeat in 30s");
                    }
                    break;

                case ErrorStates.Retry30s:
                    CurrentErrorState = ErrorStates.Retry5m;
                    if (IsDebugging)
                    {
                        Debug.Log("Retrying heartbeat in 5m");
                    }
                    break;

                case ErrorStates.Retry5m:
                    CurrentErrorState = ErrorStates.Retry10m;
                    if (IsDebugging)
                    {
                        Debug.Log("Retrying heartbeat in 10m");
                    }
                    break;

                case ErrorStates.Retry10m:
                    CurrentErrorState = ErrorStates.Retry15m;
                    if (IsDebugging)
                    {
                        Debug.Log("Retrying heartbeat in 15m");
                    }
                    break;

                case ErrorStates.Retry15m:
                    CurrentErrorState = ErrorStates.Cancelled;
                    if (IsDebugging)
                    {
                        Debug.Log("Agent reconnection cannot be established - cancelling");
                    }
                    break;
                }

                if (OnAgentError != null)
                {
                    OnAgentError.Invoke(error);
                }
                IsProcessing = false;
            });
        }
        internal static void SendHeartBeatRequest()
        {
            string payload = _jsonWrapper.SerializeObject(CurrentState);

            if (string.IsNullOrEmpty(payload))
            {
                return;
            }

            byte[] payloadBytes = Encoding.ASCII.GetBytes(payload);

            if (IsDebugging)
            {
                Debug.Log(payload);
            }

            PlayFabHttp.SimplePostCall(_baseUrl, payloadBytes, success =>
            {
                string json = Encoding.UTF8.GetString(success);
                Debug.Log(json);
                if (string.IsNullOrEmpty(json))
                {
                    return;
                }

                HeartbeatResponse hb = _jsonWrapper.DeserializeObject <HeartbeatResponse>(json);
                if (hb != null)
                {
                    ProcessAgentResponse(hb);
                }

                CurrentErrorState = ErrorStates.Ok;
                IsProcessing      = false;
            }, error =>
            {
                Guid guid = Guid.NewGuid();
                Debug.LogFormat("CurrentError: {0} - {1}", error, guid.ToString());
                //Exponential backoff for 30 minutes for retries.
                switch (CurrentErrorState)
                {
                case ErrorStates.Ok:
                    CurrentErrorState = ErrorStates.Retry30S;
                    if (IsDebugging)
                    {
                        Debug.Log("Retrying heartbeat in 30s");
                    }

                    break;

                case ErrorStates.Retry30S:
                    CurrentErrorState = ErrorStates.Retry5M;
                    if (IsDebugging)
                    {
                        Debug.Log("Retrying heartbeat in 5m");
                    }

                    break;

                case ErrorStates.Retry5M:
                    CurrentErrorState = ErrorStates.Retry10M;
                    if (IsDebugging)
                    {
                        Debug.Log("Retrying heartbeat in 10m");
                    }

                    break;

                case ErrorStates.Retry10M:
                    CurrentErrorState = ErrorStates.Retry15M;
                    if (IsDebugging)
                    {
                        Debug.Log("Retrying heartbeat in 15m");
                    }

                    break;

                case ErrorStates.Retry15M:
                    CurrentErrorState = ErrorStates.Cancelled;
                    if (IsDebugging)
                    {
                        Debug.Log("Agent reconnection cannot be established - cancelling");
                    }

                    break;
                }

                if (OnAgentErrorCallback != null)
                {
                    OnAgentErrorCallback.Invoke(error);
                }

                IsProcessing = false;
            });
        }
 public static T DeserializeObject <T>(string json)
 {
     return(_instance.DeserializeObject <T>(json));
 }