public static void Load()
        {
            try
            {
                var contents = File.ReadAllText(FilePath);
                var json     = new JSONParser(contents).Parse();

                Name          = json.ContainsKey("name") ? json["name"].AsString() : null;
                ServerURL     = json.ContainsKey("serverurl") ? json["serverurl"].AsString() : null;
                ProcessId     = json.ContainsKey("processid") ? (int)json["processid"].AsFloat() : -1;
                OpenDocuments = json.ContainsKey("opendocuments") ? json["opendocuments"].AsList().Select(d => d.AsString()).ToList() : new List <String>();

                if (ProcessId >= 0)
                {
                    Process.GetProcessById(ProcessId);
                }
            }
            catch (FileNotFoundException)
            {
                Clear();
                Save();
            }
            catch (Exception e)
            {
                Logger.Log(e);
                Clear();
                Save();
            }
        }
 public static void Load()
 {
     try
     {
         JSONValue value6;
         JSONValue value2 = new JSONParser(File.ReadAllText(FilePath)).Parse();
         Name      = !value2.ContainsKey("name") ? null : value2["name"].AsString();
         ServerURL = !value2.ContainsKey("serverurl") ? null : value2["serverurl"].AsString();
         ProcessId = !value2.ContainsKey("processid") ? -1 : ((int)value2["processid"].AsFloat());
         if (value2.ContainsKey("opendocuments"))
         {
             value6 = value2["opendocuments"];
         }
         OpenDocuments = (< > f__am$cache5 != null) ? new List <string>() : value6.AsList().Select <JSONValue, string>(< > f__am$cache5).ToList <string>();
         if (ProcessId >= 0)
         {
             Process.GetProcessById(ProcessId);
         }
     }
     catch (FileNotFoundException)
     {
         Clear();
         Save();
     }
     catch (Exception exception)
     {
         Logger.Log(exception);
         Clear();
         Save();
     }
 }
 public static void Load()
 {
     try
     {
         JSONValue jsonValue = new JSONParser(File.ReadAllText(ScriptEditorSettings.FilePath)).Parse();
         ScriptEditorSettings.Name          = !jsonValue.ContainsKey("name") ? (string)null : jsonValue["name"].AsString();
         ScriptEditorSettings.ServerURL     = !jsonValue.ContainsKey("serverurl") ? (string)null : jsonValue["serverurl"].AsString();
         ScriptEditorSettings.ProcessId     = !jsonValue.ContainsKey("processid") ? -1 : (int)jsonValue["processid"].AsFloat();
         ScriptEditorSettings.OpenDocuments = !jsonValue.ContainsKey("opendocuments") ? new List <string>() : jsonValue["opendocuments"].AsList().Select <JSONValue, string>((Func <JSONValue, string>)(d => d.AsString())).ToList <string>();
         if (ScriptEditorSettings.ProcessId < 0)
         {
             return;
         }
         Process.GetProcessById(ScriptEditorSettings.ProcessId);
     }
     catch (FileNotFoundException ex)
     {
         ScriptEditorSettings.Clear();
         ScriptEditorSettings.Save();
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
         ScriptEditorSettings.Clear();
         ScriptEditorSettings.Save();
     }
 }
        public static void GetAuthorizationCodeAsync(string clientId, Action <AuthCodeResponse> callback)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentException("clientId is null or empty.", "clientId");
            }

            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            if (string.IsNullOrEmpty(UnityConnect.instance.GetAccessToken()))
            {
                throw new InvalidOperationException("User is not logged in or user status invalid.");
            }

            string url = string.Format("{0}/v1/oauth2/authorize", UnityConnect.instance.GetConfigurationURL(CloudConfigUrl.CloudIdentity));

            AsyncHTTPClient client = new AsyncHTTPClient(url);

            client.postData = string.Format("client_id={0}&response_type=code&format=json&access_token={1}&prompt=none",
                                            clientId,
                                            UnityConnect.instance.GetAccessToken());
            client.doneCallback = delegate(IAsyncHTTPClient c)
            {
                AuthCodeResponse response = new AuthCodeResponse();
                if (!c.IsSuccess())
                {
                    response.Exception = new InvalidOperationException("Failed to call Unity ID to get auth code.");
                }
                else
                {
                    try
                    {
                        var json = new JSONParser(c.text).Parse();
                        if (json.ContainsKey("code") && !json["code"].IsNull())
                        {
                            response.AuthCode = json["code"].AsString();
                        }
                        else if (json.ContainsKey("message"))
                        {
                            response.Exception = new InvalidOperationException(string.Format("Error from server: {0}", json["message"].AsString()));
                        }
                        else
                        {
                            response.Exception = new InvalidOperationException("Unexpected response from server.");
                        }
                    }
                    catch (JSONParseException)
                    {
                        response.Exception = new InvalidOperationException("Unexpected response from server: Failed to parse JSON.");
                    }
                }

                callback(response);
            };
            client.Begin();
        }
 public static void Load()
 {
     try
     {
         string    jsondata  = File.ReadAllText(ScriptEditorSettings.FilePath);
         JSONValue jSONValue = new JSONParser(jsondata).Parse();
         ScriptEditorSettings.Name      = ((!jSONValue.ContainsKey("name")) ? null : jSONValue["name"].AsString());
         ScriptEditorSettings.ServerURL = ((!jSONValue.ContainsKey("serverurl")) ? null : jSONValue["serverurl"].AsString());
         ScriptEditorSettings.ProcessId = ((!jSONValue.ContainsKey("processid")) ? -1 : ((int)jSONValue["processid"].AsFloat()));
         List <string> arg_102_0;
         if (jSONValue.ContainsKey("opendocuments"))
         {
             arg_102_0 = (from d in jSONValue["opendocuments"].AsList()
                          select d.AsString()).ToList <string>();
         }
         else
         {
             arg_102_0 = new List <string>();
         }
         ScriptEditorSettings.OpenDocuments = arg_102_0;
         if (ScriptEditorSettings.ProcessId >= 0)
         {
             Process.GetProcessById(ScriptEditorSettings.ProcessId);
         }
     }
     catch (FileNotFoundException)
     {
         ScriptEditorSettings.Clear();
         ScriptEditorSettings.Save();
     }
     catch (Exception an_exception)
     {
         Logger.Log(an_exception);
         ScriptEditorSettings.Clear();
         ScriptEditorSettings.Save();
     }
 }
Esempio n. 6
0
        public static void GetAuthorizationCodeAsync(string clientId, Action <UnityOAuth.AuthCodeResponse> callback)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentException("clientId is null or empty.", "clientId");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            if (string.IsNullOrEmpty(UnityConnect.instance.GetAccessToken()))
            {
                throw new InvalidOperationException("User is not logged in or user status invalid.");
            }
            string toUrl = string.Format("{0}/v1/oauth2/authorize", UnityConnect.instance.GetConfigurationURL(CloudConfigUrl.CloudIdentity));

            new AsyncHTTPClient(toUrl)
            {
                postData     = string.Format("client_id={0}&response_type=code&format=json&access_token={1}&prompt=none", clientId, UnityConnect.instance.GetAccessToken()),
                doneCallback = delegate(AsyncHTTPClient c)
                {
                    UnityOAuth.AuthCodeResponse obj = default(UnityOAuth.AuthCodeResponse);
                    if (!c.IsSuccess())
                    {
                        obj.Exception = new InvalidOperationException("Failed to call Unity ID to get auth code.");
                    }
                    else
                    {
                        try
                        {
                            JSONValue jSONValue = new JSONParser(c.text).Parse();
                            if (jSONValue.ContainsKey("code") && !jSONValue["code"].IsNull())
                            {
                                obj.AuthCode = jSONValue["code"].AsString();
                            }
                            else if (jSONValue.ContainsKey("message"))
                            {
                                obj.Exception = new InvalidOperationException(string.Format("Error from server: {0}", jSONValue["message"].AsString()));
                            }
                            else if (jSONValue.ContainsKey("location") && !jSONValue["location"].IsNull())
                            {
                                UnityConnectConsentView unityConnectConsentView = UnityConnectConsentView.ShowUnityConnectConsentView(jSONValue["location"].AsString());
                                if (!string.IsNullOrEmpty(unityConnectConsentView.Code))
                                {
                                    obj.AuthCode = unityConnectConsentView.Code;
                                }
                                else if (!string.IsNullOrEmpty(unityConnectConsentView.Error))
                                {
                                    obj.Exception = new InvalidOperationException(string.Format("Error from server: {0}", unityConnectConsentView.Error));
                                }
                                else
                                {
                                    obj.Exception = new InvalidOperationException("Consent Windows was closed unexpected.");
                                }
                            }
                            else
                            {
                                obj.Exception = new InvalidOperationException("Unexpected response from server.");
                            }
                        }
                        catch (JSONParseException)
                        {
                            obj.Exception = new InvalidOperationException("Unexpected response from server: Failed to parse JSON.");
                        }
                    }
                    callback(obj);
                }
            }.Begin();
        }