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));
                }
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
 public MainCmd(ICmdSwitcher cmdSwitcher, CmdLineExtension cmdLineExtension = null) : base(cmdSwitcher, cmdLineExtension)
 {
     SettingsProp = StorageHardDrive.Get <Settings>("all_settings").Result ?? new Settings();
 }