예제 #1
0
 public void SetValue(Java.Lang.String value)
 {
     returnValue = value.ToString();
     try { latch.CountDown(); } catch (System.Exception ex) {
         DLogger.WriteLog(ex);
     }
 }
예제 #2
0
        public void Test()
        {
#if DEBUG
#if WIN
            //ensures CEF is referenced as expected
            CefErrorCode err = CefErrorCode.Aborted;
            DLogger.WriteLog(err.ToString());
#endif
#endif
        }
예제 #3
0
        public virtual void OpenUrlInSystemBrowser(string url)
        {
            try {
                System.Diagnostics.Process.Start(url);
            } catch (Exception ex) {
                DLogger.WriteLog(ex);
#if WIN
                System.Diagnostics.Process.Start("IEXPLORE.EXE", url);
#endif
            }
        }
예제 #4
0
                public virtual string RestoreWorkingCopyOfDatabase(string databaseWorkingPath)
                {
                    string dataBaseName         = Path.GetFileName(databaseWorkingPath);
                    string databaseInAssetsPath = PathUtils.PathCombineCrossPlatform(AppHelper.Paths.DatafilesAssetPath, dataBaseName);

                    try {
                        File.Delete(databaseWorkingPath);
                    } catch (Exception ex) {
                        DLogger.WriteLog(ex);
                    }

                    databaseWorkingPath = PathUtils.PathCombineCrossPlatform(AppHelper.Paths.DatafilesWorkingPath, dataBaseName);

                    File.Copy(databaseInAssetsPath, databaseWorkingPath);

                    return(databaseWorkingPath);
                }
예제 #5
0
        /// <summary>
        /// Evaluates the expression and returns the value.
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public string EvaluateScript(BaseWebView webView, string expression)
        {
            latch = new CountDownLatch(1);
            string code = "javascript:window." + Name + ".setValue((function(){try{return " + expression
                          + "+\"\";}catch(js_eval_err){console.log('js_eval_err : ' + js_eval_err); return '';}})());";

            webView.LoadUrl(code);

            try {
                // Set a 1 second timeout in case there's an error
                latch.Await(1, TimeUnit.Seconds);
                return(returnValue);
            } catch (System.Exception ex) {
                DLogger.WriteLog(ex);
            }
            return(null);
        }
예제 #6
0
        public static CallConfig FromJsonString(string jsonString)
        {
            try {
                CallConfig result = SerializationHelper.Instance.Deserialize <CallConfig>(jsonString);
                if (result.Params == null)  //Params supposedly are not empty
                {
                    var tempObject = SerializationHelper.Instance.JsonDeserialize(jsonString);
                    try {
                        result.Params = ((Dictionary <string, object>)tempObject)["Params"];
                    } catch { }
                }

                return(result);
            } catch (Exception ex) {
                DLogger.WriteLog(ex);
            }
            return(null);
        }
예제 #7
0
            public static void ConnectDatabase(string databaseWorkingCopyPath)
            {
                try {
                    if (!FileExists(databaseWorkingCopyPath))
                    {
                        Manager.Instance.RestoreWorkingCopyOfDatabase(databaseWorkingCopyPath);
                    }

                    CSConfig.SetDB(new CSDataProviderSqlite("Data Source=" + databaseWorkingCopyPath));

                    DLogger.WriteLog(string.Format("Connected to Db: " + databaseWorkingCopyPath));

                    return;
                } catch (Exception ex) {
                    DLogger.WriteLog(ex);
                    throw new Exception(string.Format("Can't connect to database at \"{0}\"", databaseWorkingCopyPath), ex);
                }
            }
예제 #8
0
        private byte[] GetBinaryAssetContent(string pathOfItemInAssets)
        {
            byte[] result = null;

            string baseDirectoryNameInAssets = Path.GetDirectoryName(pathOfItemInAssets);
            string baseDirectoryInRoot       = "/";

            try {
                baseDirectoryInRoot = baseDirectoryNameInAssets.Split(new string[] { AppHelper.Paths.AssetRootFolder }, StringSplitOptions.RemoveEmptyEntries)[0];
            } catch { }

            string baseFileName = Path.GetFileName(pathOfItemInAssets);

            HashSet <string> chunkFileNames = new HashSet <string>(context.Assets.List(baseDirectoryInRoot).Where(fn => fn.StartsWith(baseFileName)));

            using (MemoryStream memoryStream = new MemoryStream()) {
                int    i             = 0;
                string chunkFileName = baseFileName;

                while (chunkFileNames.Contains(chunkFileName))
                {
                    using (Stream stream = context.Assets.Open(Path.Combine(baseDirectoryInRoot, chunkFileName))) {
                        byte[] buffer = new byte[32 * 1024];

                        int read;
                        while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            memoryStream.Write(buffer, 0, read);
                        }

                        i++;
                        chunkFileName = string.Format("{0}.part_{1}", baseFileName, i);
                    }
                }

                result = memoryStream.ToArray();
            }

            DLogger.WriteLog("GetBinaryAssetContent: {0} ({1})", pathOfItemInAssets, (result == null) ? "null" : result.Length.ToString());

            return(result);
        }
예제 #9
0
        public void EnsureDatabaseReadWriteWorksCorrectly()
        {
            DLogger.WriteLog("EnsureDatabaseReadWriteWorksCorrectly");
            TestData     entrySaved = TestData.New();
            const string TextToTestDatabaseIoWith = "Text to test";

            entrySaved.TestText = TextToTestDatabaseIoWith;

            const double DoubleToTestDatabaseIoWith = 777d;

            entrySaved.TestDouble = DoubleToTestDatabaseIoWith;

            byte[] ImageToTestDatabaseIoWith = new byte[] { 250, 250, 250, 100, 156, 156, 90, 60, 100 };
            entrySaved.TestBlob = ImageToTestDatabaseIoWith;

            entrySaved.Save();

            var entryRead = TestData.ReadFirst("ID = @ID", "@ID", entrySaved.ID);

            Assert.True(entrySaved.ID == entryRead.ID, string.Format("ID mismatch, was {0} and now is: {1}", entrySaved.ID, entryRead.ID));
            Assert.True(entrySaved.TestText == entryRead.TestText, string.Format("TestText mismatch, was {0} and now is {1}", entrySaved.TestText, entryRead.TestText));
            Assert.True(ComparisonHelper.Equality(entrySaved.TestBlob, entryRead.TestBlob), string.Format("TestBlob mismatch, was {0} and now is {1}", entrySaved.TestBlob, entryRead.TestBlob));
            entrySaved.Delete();
        }
예제 #10
0
        public virtual CallResult ProcessCallFromFrontend(CallConfig config)               //dict["name"]
        {
            DLogger.WriteLog("Call from frontend of method name:{0} with arguments:{1}", config.MethodName, config.Params);

            object     instance  = webView.Page;
            MethodInfo theMethod = null;

            if (Page != null)  //first lets look for the method in the page
            {
                theMethod = Page.GetType().GetMethod(config.MethodName);
            }

            if (theMethod == null)
            {
                theMethod = webView.GetType().GetMethod(config.MethodName);
                instance  = webView;
            }

            if (theMethod == null)  //if the method is not found in current view, then lets search for it in other loaded views
            {
                foreach (var view in LoadedViews.ViewForEachType)
                {
                    theMethod = view.GetType().GetMethod(config.MethodName);
                    if (theMethod != null)
                    {
                        instance = view;
                        break;
                    }
                }
            }

            if (theMethod == null)  //if the method is not found in loaded views, then lets search for it in parent window
            {
                theMethod = ParentWindow.GetType().GetMethod(config.MethodName);
                instance  = ParentWindow;
            }

            if (theMethod == null)  //if the method is not found in parent window, then lets search for it in AppDelegate.Instance
            {
                theMethod = BaseAppDelegate.Instance.GetType().GetMethod(config.MethodName);
                instance  = BaseAppDelegate.Instance;
            }

            CallResult result = new CallResult(string.Empty);

            try {
                //BaseAppDelegate.Instance.InvokeOnMainThread(()=>{
                result = (CallResult)theMethod.Invoke(instance, new object[] { config.Params });
                //});
            } catch (Exception ex) {
                DLogger.WriteLog(ex);
                try {//try parameter less
                    //BaseAppDelegate.Instance.InvokeOnMainThread(()=>{
                    result = (CallResult)theMethod.Invoke(instance, null);
                    //});
                } catch (Exception ex2) {
                    DLogger.WriteLog(ex2);
                }
            }

            return(result);
        }
예제 #11
0
        public void Start(string instanceUid = null, string instancePort = null, string instanceIP = null, Func <CallConfig, CallResult> requestHandleCallback = null)
        {
            if (string.IsNullOrWhiteSpace(instanceUid))
            {
                instanceUid = ServerInstanceUid;//Guid.NewGuid().ToString("N");
                DLogger.WriteLog("Warning: MicroServer instance UID value was empty, setting default of {0}", ServerInstanceUid);
            }

            if (string.IsNullOrWhiteSpace(instanceIP))
            {
                instanceIP = ServerIP;
                DLogger.WriteLog("Warning: MicroServer instance IP value was empty, setting default of {0}", ServerIP);
            }

            if (string.IsNullOrWhiteSpace(instancePort))
            {
                instancePort = ServerInstancePort;
                DLogger.WriteLog("Warning: MicroServer instance port value was empty, setting default of {0}", ServerInstancePort);
            }
            else
            {
                int instancePortValueAsInteger;
                if (int.TryParse(instancePort, out instancePortValueAsInteger))
                {
                    if (instancePortValueAsInteger > MinSafeInstancePortValue && instancePortValueAsInteger < MaxSafeInstancePortValue)
                    {
                        instancePort = instancePortValueAsInteger.ToString();
                    }
                    else
                    {
                        DLogger.WriteLog("Warning: MicroServer instance port value was {1}, beyond safe range of {2} - {3}, setting default of {0}",
                                         ServerInstancePort, instancePort, MinSafeInstancePortValue, MaxSafeInstancePortValue);
                        instancePort = ServerInstancePort;
                    }
                }
                else
                {
                    DLogger.WriteLog("Warning: MicroServer instance port value was {1}, non integer, beyond safe range of {2} - {3}, setting default of {0}",
                                     ServerInstancePort, instancePort, MinSafeInstancePortValue, MaxSafeInstancePortValue);
                    instancePort = ServerInstancePort;
                }
            }

            serverInstanceUid  = instanceUid;
            serverInstancePort = instancePort;
            serverIP           = instanceIP;

            DLogger.WriteLog("Warning: MicroServer instance IP:port/UID/  set to {0}:{1}/{2}/", ServerIP, ServerInstancePort, ServerInstanceUid);

            if (requestHandleCallback != null)
            {
                OnHandleRequest = requestHandleCallback;
            }


            listener = new HttpListener();
            //listener.Prefixes.Add(string.Format("http://*:{1}/", ServerInstanceUid, ServerInstancePort));
            //listener.Prefixes.Add(string.Format("http://{2}:{1}/{0}/", ServerInstanceUid, ServerInstancePort, ServerIP));
            listener.Prefixes.Add(string.Format("http://*:{1}/{0}/", ServerInstanceUid, ServerInstancePort, ServerIP));
            listener.Start();

            listener.BeginGetContext(new AsyncCallback(HandleRequest), listener);
        }
예제 #12
0
        private void HandleRequest(IAsyncResult result)
        {
            //Get the listener context

            HttpListenerContext context = null;

            try {
                context = listener.EndGetContext(result);
            } catch {
                listener.Stop();
                listener.Start();
            }

            //Start listening for the next request
            listener.BeginGetContext(new AsyncCallback(HandleRequest), listener);

            if (context == null)
            {
                return;
            }

            //process query string and make CallConfig object
            CallConfig config = null;

            //missing on mobile platforms
            //HttpUtility.ParseQueryString(context.Request.Url.Query).Get("params");

            //if (context.Request.Url.ToString().Contains("callnative")) {
            //response = "native code reply";
            string url = context.Request.Url.ToString();
            string callConfigAsJson = Uri.UnescapeDataString(url.Split(new string[] { "callbackend?params=" }, StringSplitOptions.RemoveEmptyEntries)[1]);

            try {
                config = CallConfig.FromJsonString(callConfigAsJson);
            } catch (Exception ex) {
                DLogger.WriteLog(ex);
            }

            if (config == null)
            {
                SendServerErrorCodeToResponse(context);
                return;
            }

            CallResult handleRequestResult = null;

            try {
                handleRequestResult = OnHandleRequest.Invoke(config);
            } catch (Exception ex) {
                DLogger.WriteLog(ex);
                SendServerErrorCodeToResponse(context);
#if DEBUG
                throw ex;
#endif
            }

            if (handleRequestResult != null)
            {
                context.Response.AddHeader("Access-Control-Allow-Origin", "*");
                context.Response.ContentType     = handleRequestResult.ContentType;
                context.Response.StatusCode      = (int)HttpStatusCode.OK;
                context.Response.ContentLength64 = handleRequestResult.Bytes.LongLength;
                context.Response.OutputStream.Write(handleRequestResult.Bytes, 0, handleRequestResult.Bytes.Length);
                context.Response.OutputStream.Flush();
                context.Response.OutputStream.Close();
                context.Response.Close();
            }
        }
예제 #13
0
 public void WriteToLog()
 {
     DLogger.WriteLog(Log);
 }