Exemple #1
0
 public void Settings()
 {
     CmdLineExtension.Inst.WriteLine("Current settings:");
     CmdLineExtension.Inst.WriteLine(SettingsProp, null, true);
     SettingsProp = ReadResource <Settings>("all_settings");
     StorageHardDrive.Set("all_settings", SettingsProp);
 }
Exemple #2
0
        static void Main(string[] args)
        {
            StorageHardDrive.InitDependencies(
                new JsonLocalStorage(
                    "values_storage"
                    )
                );
            CmdLineExtension.Init();
            var switcher = new DefaultConsoleSwitcher();

            switcher.RunDefault(new MainCmd(switcher));
        }
        object readResource(Type objectType, int tryesCount, string resourceName, ReadResourseOptions options, object defaultValue)
        {
            if (options == null)
            {
                options = new ReadResourseOptions();
            }
            string hint        = options.Hint;
            var    longResName = resourceName + "";

            try
            {
                this.WriteLine($"Resource '{longResName}' with type {objectType} requested from console.", ConsoleColor.Yellow);
                if (!string.IsNullOrWhiteSpace(hint))
                {
                    this.WriteLine($"Hint: {hint}", ConsoleColor.Yellow);
                }

                string cachedValueString = StorageHardDrive.Get <string>(longResName).Result;

                if (typeof(IConvertible).IsAssignableFrom(objectType))
                {
                    return(IfResourceIsIConvertible(objectType, longResName, cachedValueString, options));
                }
                else
                {
                    return(IfResourceIsDifficult(objectType, longResName, cachedValueString, defaultValue, options));
                }
            }
            catch (Exception ex)
            {
                if (ThrowConsoleParseExeptions || tryesCount < 0)
                {
                    throw;
                }
                else
                {
                    this.WriteLine("Exeption in console resource receiving method: ", ConsoleColor.DarkRed);
                    this.WriteLine(("\t" + ex.Message).Replace("\n", "\n\t"));

                    //try again
                    return(readResource(objectType, tryesCount - 1, resourceName, options, defaultValue));
                }
            }
        }
Exemple #4
0
        static async Task <List <KworkRecord> > GetNew(ChromiumWebBrowser wv)
        {
            var savedList = await StorageHardDrive.Get <List <KworkRecord> >(SavedMessagesKey) ?? new List <KworkRecord>();

            foreach (var item in savedList.ToArray())
            {
                if (DateTime.Now - item.ParseDate > TimeSpan.FromDays(5))
                {
                    savedList.Remove(item);
                }
            }

            var parsedList = await KworkParser.Parse(wv);

            //magic here
            var savedListClone = savedList.ToArray();

            foreach (var itemP in parsedList.ToArray())
            {
                bool breaked = false;
                foreach (var itemS in savedListClone)
                {
                    if (itemS.Title == itemP.Title)
                    {
                        parsedList.Remove(itemP);
                        breaked = true;
                        break;
                    }
                }

                if (!breaked)
                {
                    WindowLogger.Log("NEW record!!!");
                    WindowLogger.Log(itemP.ToJsonStr());
                    savedList.Add(itemP);
                }
            }

            await StorageHardDrive.Set(SavedMessagesKey, savedList);

            return(parsedList);
        }
Exemple #5
0
        static void Main(string[] args)
        {
            var appDir           = Assembly.GetExecutingAssembly().Location;
            var assemblyFileName = Path.GetFileName(appDir);

            appDir = appDir.Remove(appDir.Length - assemblyFileName.Length);
            StorageHardDrive.InitDependencies(
                new JsonLocalStorage(
                    Path.Combine(appDir, "storage.json")
                    )
                );

            //Простейшая консоль с командами из методов классса.
            CmdLineExtension.Init(new DefaultConsoleHandler());
            var cmds = new CmdSwitcher();

            cmds.PushCmdInStack(new CmdLineFacade());
            cmds.ExecuteStartup(args);
            cmds.RunDefault();
        }
        public App()
        {
            Assembly curAssembly = Assembly.GetExecutingAssembly();

            Environment.CurrentDirectory = Path.GetDirectoryName(curAssembly.Location);

            var cacheDir = Path.Combine(Environment.CurrentDirectory, "webview_cahce");

            if (!Directory.Exists(cacheDir))
            {
                Directory.CreateDirectory(cacheDir);
            }

            var settings = new CefSettings()
            {
                //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
                CachePath = cacheDir,
            };

            settings.DisableTouchpadAndWheelScrollLatching();

            //Example of setting a command line argument
            //Enables WebRTC
            settings.CefCommandLineArgs.Add("enable-media-stream", "1");

            //Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

            //StorageHardDrive.InitDependencies(
            //    new LiteDatabaseLocalStorage()
            //    );

            StorageHardDrive.InitDependencies(
                new JsonLocalStorage()
                );
        }
Exemple #7
0
 public static void Save()
 {
     StorageHardDrive.Set("app_settings", Inst);
 }
        object IfResourceIsIConvertible(Type objectType, string longResName, string cachedValueString, ReadResourseOptions options)
        {
            //If IConvertible
            //
            string cachedValue       = cachedValueString;
            var    cachedValueInHint = cachedValue ?? "";

            if (cachedValueInHint.Length > 80)
            {
                cachedValueInHint = cachedValueInHint.Substring(0, 80) + "... ";
            }

            this.Write(
                $"Input ({cachedValueInHint}): ",
                ConsoleColor.Yellow
                );

            //Если автоматическое считывание, то возвращаем закешированное значение.
            string val = "";

            if (!options.UseAutoread)
            {
                val = this.ReadLine();
            }


            if (val == "" && cachedValue != null)
            {
                val = cachedValue;
            }
            else
            {
                if (options.SaveToCache)
                {
                    StorageHardDrive.Set(longResName, val);
                }
            }


            object res = null;

            if (objectType == typeof(bool) || objectType == typeof(bool?))
            {
                val = val.Trim();
                if (val == "y")
                {
                    res = true;
                }
                if (val == "n")
                {
                    res = false;
                }
            }
            if (res == null)
            {
                res = Convert.ChangeType(val, objectType);
            }
            return(res);
            //
            //If IConvertible
        }
        object IfResourceIsDifficult(Type objectType, string longResName, string cachedValueString, object defaultValue, ReadResourseOptions options)
        {
            //Else, will be converted by json.
            //
            this.WriteLine(
                $"Difficult type. Will be opened in json editor. ",
                ConsoleColor.Yellow
                );

            object cachedValue;

            try
            {
                if (defaultValue == null)
                {
                    cachedValue = JsonSerializeHelper.Inst.FromJson(objectType, cachedValueString);
                }
                else
                {
                    cachedValue = defaultValue;
                }
            }
            catch
            {
                ConstructorInfo ctor = objectType.GetConstructor(new Type[] { });
                cachedValue = ctor.Invoke(new object[] { });
            }

            //Если автоматическое считывание, то возвращаем закешированное значение.
            if (options.UseAutoread)
            {
                return(cachedValue);
            }

            this.ReadLine();

            bool   isAccept;
            string editedJson          = null;
            string jsonPrototypeString = JsonSerializeHelper.Inst.ToJson(
                objectType,
                cachedValue,
                new JsonSerializeOptions()
            {
                WithNormalFormating = true
            }
                );

            do
            {
                editedJson = ConsoleHandler.ReadJson(jsonPrototypeString);



                this.Write("Accept changes? Press y/n (y): ", ConsoleColor.Yellow);
                isAccept = this.ReadLine().Trim().StartsWith("n");
            } while (isAccept);


            object res = JsonSerializeHelper.Inst.FromJson(objectType, editedJson);

            //Convert again to normal parse json.
            if (options.SaveToCache)
            {
                StorageHardDrive.Set(longResName, JsonSerializeHelper.Inst.ToJson(objectType, res));
            }
            return(res);
            //
            //Else, will be converted by json.
        }
Exemple #10
0
 public MainCmd(ICmdSwitcher cmdSwitcher, CmdLineExtension cmdLineExtension = null) : base(cmdSwitcher, cmdLineExtension)
 {
     SettingsProp = StorageHardDrive.Get <Settings>("all_settings").Result ?? new Settings();
 }
Exemple #11
0
 public static void ClearSaved()
 {
     StorageHardDrive.Set(SavedMessagesKey, null);
 }