Exemplo n.º 1
0
        public void ReadPaths()
        {
            string json;

            using (StreamReader fileReader = new StreamReader(selectedPathsJsonPath))
            {
                json = fileReader.ReadToEnd();
            }
            Paths = PathSettings.Parse(json, Templates);
        }
Exemplo n.º 2
0
        public static PathSettings Parse(string json, IReadOnlyList <Template> templates)
        {
            var jArray = JArray.Parse(json);

            var result = new PathSettings();

            var node = jArray.First;

            if (node != null)
            {
                do
                {
                    PathInformation info = new PathInformation();
                    foreach (var item in node.Children <JProperty>())
                    {
                        switch (item.Name.ToLower())
                        {
                        case "path":
                            info.Path = item.Value.Value <string>();
                            break;

                        case "filter":
                            info.Filter = (string)item.Value;
                            break;

                        case "searchrecursively":
                            info.SearchRecursively = (bool)item.Value;
                            break;

                        case "searchhidden":
                            info.SearchHidden = (bool)item.Value;
                            break;

                        case "selectedtemplateid":
                            info.SelectedTemplateId = (int)item.Value;
                            break;

                        case "inactive":
                            info.Inactive = (bool)item.Value;
                            break;

                        default:
                            break;
                        }
                    }
                    result.Add(info);
                } while ((node = node.Next) != null);
            }

            return(result);
        }
Exemplo n.º 3
0
        public AutomationUploader()
        {
            if (!Directory.Exists("settings"))
            {
                Directory.CreateDirectory("settings");
            }

            if (File.Exists(templatesPath))
            {
                ReadTemplates();
                EnsureTemplateIdsAreUnique();
                EnsureTemplatesHaveCategory();
                EnsureTemplatesHaveLanguage();
            }

            EnsureStandardTemplateExists();

            if (File.Exists(accountJsonPath))
            {
                using (StreamReader reader = new StreamReader(accountJsonPath))
                {
                    string savedAccountJson = reader.ReadToEnd();
                    var    savedAccount     = JsonConvert.DeserializeObject <AccountJson>(savedAccountJson);

                    var categories = savedAccount.categories?.Select(c => new Category(c.id, c.title)).ToArray();
                    if (categories == null)
                    {
                        categories = new[] { Category.Default };
                    }

                    var region = savedAccount.region;
                    if (region == null)
                    {
                        region = "DE";
                    }

                    ActiveAccount = new Account()
                    {
                        Id = savedAccount.id, Title = savedAccount.title, Access = new Authentification()
                        {
                            RefreshToken = savedAccount.refreshToken
                        }, Region = savedAccount.region, AvailableCategories = categories
                    };

                    if (string.IsNullOrWhiteSpace(ActiveAccount?.Access?.AccessToken))
                    {
                        RefreshAccess();
                    }
                }
            }

            if (File.Exists(selectedPathsJsonPath))
            {
                try
                {
                    ReadPaths();
                }
                catch (Exception ex)
                {
                    Debug.Write(ex.Message);

                    Paths = new PathSettings();
                    File.Delete(selectedPathsJsonPath);
                }
            }

            if (File.Exists(languagesPath))
            {
                try
                {
                    ReadLanguages();
                }
                catch (Exception ex)
                {
                    Debug.Write(ex.Message);

                    Languages = new List <Language>(new Language[] { Language.Default });
                    File.Delete(languagesPath);
                }
            }
            else if (ActiveAccount != null && ActiveAccount.Access != null && ActiveAccount.Access.AccessToken != null)
            {
                Languages = AccountCommunication.LoadYoutubeLanguages(ActiveAccount.Access.AccessToken).ToList();

                WriteLanguages();
            }

            foreach (var path in Paths)
            {
                if (!Templates.Any(t => t.Id == path.SelectedTemplateId))
                {
                    path.SelectedTemplateId = 0;
                }
            }

            UnfinishedJob = LoadLastJob();
        }