Log() public static method

public static Log ( Module module, string message ) : void
module Module
message string
return void
コード例 #1
0
        public static void FireUnityJavascriptEvent(string method, object data)
        {
            UIViewController viewController = UIApplication.SharedApplication.KeyWindow.RootViewController;

            JavaScriptSerializer Serialiser = new JavaScriptSerializer();
            string dataJSONString           = "null";

            if (data != null)
            {
                dataJSONString = Serialiser.Serialize(data);
                if (data is String)
                {
                    dataJSONString = "'" + (data as String) + "'";
                }
            }
            string jsCallbackFunction = "if(" + method + "){" + method + "(" + dataJSONString + ");}";

            //only for testing
            SystemLogger.Log(SystemLogger.Module.PLATFORM, "NotifyJavascript (single object): " + method + ", dataJSONString: " + dataJSONString);

            bool webViewFound = false;

            if (viewController != null && viewController.View != null)
            {
                UIView[] subViews = viewController.View.Subviews;

                foreach (UIView subView in subViews)
                {
                    if (subView is UIWebView)
                    {
                        webViewFound = true;

                        // evaluate javascript as a UIWebView
                        (subView as UIWebView).EvaluateJavascript(jsCallbackFunction);
                    }
                    else if (subView is WKWebView)
                    {
                        webViewFound = true;

                        // evaluate javascript as a WKWebView
                        (subView as WKWebView).EvaluateJavaScript(new NSString(jsCallbackFunction), delegate(NSObject result, NSError error) {
                            SystemLogger.Log(SystemLogger.Module.PLATFORM, "NotifyJavascript COMPLETED (" + method + ")");
                        });
                    }
                }
            }

            if (webViewFound)
            {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "NotifyJavascript EVALUATED (" + method + ")");
            }
            else
            {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "It was not possible to find a WebView to evaluate the javascript method");
            }
        }
コード例 #2
0
 public static String JSONSerialize(object data)
 {
     try {
         JavaScriptSerializer Serialiser = new JavaScriptSerializer();
         return(Serialiser.Serialize(data));
     } catch (Exception ex) {
         SystemLogger.Log(SystemLogger.Module.PLATFORM, "Error trying to serialize object to JSON.", ex);
     }
     return(null);
 }
コード例 #3
0
        public NSDictionary ConvertToNSDictionary(Dictionary <String, Object> dictionary)
        {
            NSMutableDictionary prunedDictionary = new NSMutableDictionary();

            foreach (String key in dictionary.Keys)
            {
                Object dicValue = dictionary[key];

                if (dicValue is Dictionary <String, Object> )
                {
                    prunedDictionary.Add(new NSString(key), ConvertToNSDictionary((dicValue as Dictionary <String, Object>)));
                }
                else
                {
                    //SystemLogger.Log(SystemLogger.Module.PLATFORM, "***** key["+key+"] is instance of: " + dicValue.GetType().FullName);
                    if (dicValue != null)
                    {
                        if (dicValue is String)
                        {
                            prunedDictionary.Add(new NSString(key), new NSString((dicValue as String)));
                        }
                        else if (dicValue is int)
                        {
                            prunedDictionary.Add(new NSString(key), new NSNumber((int)dicValue));
                        }
                        else if (dicValue is Object[])
                        {
                            prunedDictionary.Add(new NSString(key), ConvertToNSArray((Object[])dicValue));
                        }
                        else if (dicValue is System.Collections.ArrayList)
                        {
                            prunedDictionary.Add(new NSString(key), ConvertToNSArray((dicValue as System.Collections.ArrayList).ToArray()));
                        }
                        else
                        {
                            SystemLogger.Log(SystemLogger.Module.PLATFORM, "*** exception parsing key[" + key + "] instance of: " + dicValue.GetType().FullName + ". No complex object are valid inside this dictionary");
                        }
                    }
                }
            }
            return(prunedDictionary);
        }