public WebViewJsInteractor(WebViewJsPojo js)
        {
            _settings = new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                Culture          = System.Globalization.CultureInfo.InvariantCulture,
                ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
            };

            List <string> documentation = new List <string>();

            documentation.Add("Example values for state changes:");
            documentation.Add(
                Serialize(new List <GrimDawnStateEventJson> {
                new GrimDawnStateEventJson {
                    Event = GrimState.Dead.ToString(), Timestamp = Timestamp.UtcMillisecondsNow
                }
            }
                          ));
            documentation.Add("");

            documentation.Add("The possible values for state are:");
            documentation.Add(Serialize(Enum.GetValues(typeof(GrimState)).Cast <GrimState>().Select(m => m.ToString())));
            documentation.Add("");


            documentation.Add("The possible values for entity type are:");
            documentation.Add(Serialize(Enum.GetValues(typeof(EntityType)).Cast <EntityType>().Select(m => m.ToString())));
            documentation.Add("");


            documentation.Add("The possible values for damage type are:");
            documentation.Add(Serialize(Enum.GetValues(typeof(DamageType)).Cast <DamageType>().Select(m => m.ToString())));
            documentation.Add("");


            documentation.Add("\r\n\r\nThe following methods are exposed:");
            MethodInfo[] methodInfos = typeof(WebViewJsPojo).GetMethods(BindingFlags.Public | BindingFlags.Instance);
            foreach (var method in methodInfos)
            {
                var parameterDescriptions = string.Join
                                                (", ", method.GetParameters()
                                                .Select(x => x.ParameterType + " " + x.Name)
                                                .ToArray());

                if (!method.Name.Contains('_') && !"ToString".Equals(method.Name) && !"Equals".Equals(method.Name) && !"GetHashCode".Equals(method.Name) && !"GetType".Equals(method.Name))
                {
                    documentation.Add($"{method.ReturnType} {method.Name}({parameterDescriptions})");
                }
            }

            documentation.Add("\r\n=== END OF DOCUMENTATION ===");

            js.api = string.Join("\r\n\t", documentation);
        }
Example #2
0
        public void InitializeChromium(
            string startPage,
            WebViewJsPojo bindeable,
            EventHandler isBrowserInitializedChanged
            )
        {
            JsPojo       = bindeable;
            JsInteractor = new WebViewJsInteractor(bindeable);

            try {
                Logger.Info("Creating Chromium instance..");

                CefSharpSettings.LegacyJavascriptBindingEnabled = true;

                Cef.EnableHighDPISupport();
                Cef.Initialize(new CefSettings());

                _browser = new ChromiumWebBrowser(startPage);

                _browser.RegisterJsObject("data", bindeable);
                _browser.RequestHandler = new DisableLinksRequestHandler();

                if (isBrowserInitializedChanged != null)
                {
                    _browser.IsBrowserInitializedChanged += isBrowserInitializedChanged;
                }

                //browser.RequestHandler = new TransferUrlHijack { TransferMethod = transferItem };
                Logger.Info("Chromium created..");
            }
            catch (FileNotFoundException ex) {
                MessageBox.Show("Error \"File Not Found\" loading Chromium, did you forget to install Visual C++ runtimes?\n\nvc_redist86 in the IA folder.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Logger.Warn(ex.Message);
                Logger.Warn(ex.StackTrace);
                throw;
            }
            catch (IOException ex) {
                MessageBox.Show("Error loading Chromium, did you forget to install Visual C++ runtimes?\n\nvc_redist86 in the IA folder.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Logger.Warn(ex.Message);
                Logger.Warn(ex.StackTrace);
                throw;
            }
            catch (Exception ex) {
                MessageBox.Show("Unknown error loading Chromium, please see log file for more information.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Logger.Warn(ex.Message);
                Logger.Warn(ex.StackTrace);
                throw;
            }
        }
Example #3
0
        public WebViewJsInteractor(WebViewJsPojo js)
        {
            _settings = new JsonSerializerSettings {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                Culture          = System.Globalization.CultureInfo.InvariantCulture,
                ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
            };

            _js = js;

            var docEntity = new EntityJson {
                Id        = 123,
                Name      = "Peter pan",
                Type      = "Player",
                IsPrimary = false
            };

            var docDamageEntryJson = new SimpleDamageEntryJson {
                DamageType = "Lightning",
                Amount     = 9381
            };

            List <string> documentation = new List <string>();

            documentation.Add($"Example values for state changes:");
            documentation.Add(
                Serialize(new List <GrimDawnStateEventJson> {
                new GrimDawnStateEventJson {
                    Event = GrimState.Dead.ToString(), Timestamp = Timestamp.UTCMillisecondsNow
                }
            }
                          ));
            documentation.Add("");

            /*
             *
             *
             * documentation.Add($"Example values for {nameof(_js.damageBlockedJson)}:");
             * documentation.Add(Serialize(
             *  new Dictionary<int, List<DamageBlockedJson>> {
             *      {default(int), new List<DamageBlockedJson> { new DamageBlockedJson { Amount = 123, AttackerId = 222 } } }
             *  }));
             * documentation.Add("");
             *
             * documentation.Add($"Example values for {nameof(_js.damageTakenJson)}:");
             * documentation.Add(Serialize(
             *  new Dictionary<int, List<SimpleDamageEntryJson>> {
             *  {default(int), new List<SimpleDamageEntryJson> { docDamageEntryJson } }
             * }));
             * documentation.Add("");
             */

            /*
             *
             * documentation.Add($"Example values for {nameof(_js.detailedDamageTakenJson)}:");
             * documentation.Add(Serialize(
             *  new Dictionary<int, List<DetailedDamageTakenJson>> {
             *      {default(int), new List<DetailedDamageTakenJson> { new DetailedDamageTakenJson {
             *          DamageType = "Chaos",
             *          Amount = 123,
             *          AttackerId = 555
             *      } } }
             *  })
             * );
             * documentation.Add("");
             *
             *
             * documentation.Add($"Example values for {nameof(_js.detailedDamageDealtJson)}:");
             * documentation.Add(Serialize(
             *  new Dictionary<int, List<DetailedDamageDealtJson>> {
             *      {default(int), new List<DetailedDamageDealtJson> { new DetailedDamageDealtJson {
             *          DamageType = "Fire",
             *          Amount = 123,
             *          VictimId = 222
             *      } } }
             *  })
             * );
             * documentation.Add("");
             *
             *
             * documentation.Add($"Example values for {nameof(_js.damageDealtToSingleTargetJson)}:");
             * documentation.Add(Serialize(
             *  new Dictionary<int, List<SimpleDamageEntryJson>> {
             *      {default(int), new List<SimpleDamageEntryJson> { docDamageEntryJson } }
             *  })
             * );
             * documentation.Add("");
             *
             *
             * documentation.Add($"Example values for {nameof(_js.playersJson)}:");
             * documentation.Add(Serialize(new List<EntityJson> { docEntity }));
             * documentation.Add("");
             *
             *
             * documentation.Add($"Example values for {nameof(_js.entitiesJson)}:");
             * documentation.Add(Serialize(new List<EntityJson> { docEntity }));
             * documentation.Add("");
             *
             *
             * documentation.Add($"Example values for {nameof(_js.petsJson)}:");
             * documentation.Add(Serialize(new List<EntityJson> { docEntity }));
             * documentation.Add("");
             *
             */
            documentation.Add($"The possible values for state are:");
            documentation.Add(Serialize(Enum.GetValues(typeof(GrimState)).Cast <GrimState>().Select(m => m.ToString())));
            documentation.Add("");


            documentation.Add($"The possible values for entity type are:");
            documentation.Add(Serialize(Enum.GetValues(typeof(EntityType)).Cast <EntityType>().Select(m => m.ToString())));
            documentation.Add("");


            documentation.Add($"The possible values for damage type are:");
            documentation.Add(Serialize(Enum.GetValues(typeof(DamageType)).Cast <DamageType>().Select(m => m.ToString())));
            documentation.Add("");


            documentation.Add("\r\n\r\nThe following methods are exposed:");
            MethodInfo[] methodInfos = typeof(WebViewJsPojo).GetMethods(BindingFlags.Public | BindingFlags.Instance);
            foreach (var method in methodInfos)
            {
                var parameters            = method.GetParameters();
                var parameterDescriptions = string.Join
                                                (", ", method.GetParameters()
                                                .Select(x => x.ParameterType + " " + x.Name)
                                                .ToArray());

                if (!method.Name.Contains('_') && !"ToString".Equals(method.Name) && !"Equals".Equals(method.Name) && !"GetHashCode".Equals(method.Name) && !"GetType".Equals(method.Name))
                {
                    documentation.Add($"{method.ReturnType} {method.Name}({parameterDescriptions})");
                }
            }

            documentation.Add("\r\n=== END OF DOCUMENTATION ===");

            _js.api = string.Join("\r\n\t", documentation);
        }