public GoogleSpreadSheetLoader(string _spreadSheetId, string _configClassName, string _applicationDataPath)
        {
            if (_configClassName == null || _configClassName.Length < 1 || _spreadSheetId == null || _spreadSheetId.Length < 1)
            {
                Debug.LogError($"Error: InvalidConfig.");
            }

            spreadSheetId       = _spreadSheetId;
            configClassName     = _configClassName;
            applicationDataPath = _applicationDataPath;
            fsWrapper           = new MasterDataFileSystemWrapper(_configClassName, _applicationDataPath);
        }
示例#2
0
        private void OnEnable()
        {
            var configRepo = new MasterBuilderEditorWindowConfigRepository(Application.dataPath);
            var config     = configRepo.LoadOrInitializeMasterBuilderConfig();

            rootVisualElement.Add(new Label("設定"));
            ClassNameTextField       = new TextField("設定クラス(T extends MasterBuilderConfig)");
            ClassNameTextField.value = config.configClassName;
            rootVisualElement.Add(ClassNameTextField);

            SpreadSheetIDTextField       = new TextField("SpreadSheetID(GoogleApps)");
            SpreadSheetIDTextField.value = config.spreadsheetID;
            rootVisualElement.Add(SpreadSheetIDTextField);
            OpenSheetButton = new Button();
            OpenSheetButton.Add(new Label("シートをブラウザで開く"));
            OpenSheetButton.clicked += () =>
            {
                Application.OpenURL(GoogleSpreadSheetHelper.GetSheetUrl(SpreadSheetIDTextField.value));
            };
            rootVisualElement.Add(OpenSheetButton);


            rootVisualElement.Add(new Label("整合性チェックエラー時もローカルのマスタを上書きする"));
            ForceOverWriteOnValidationErrorToggle = new Toggle()
            {
                value = config.forceOverwriteOnValidationError
            };
            rootVisualElement.Add(ForceOverWriteOnValidationErrorToggle);

            SaveConfigButton          = new Button();
            SaveConfigButton.clicked += () => {
                configRepo.SaveConfig(GetCurrentConfig());
            };
            SaveConfigButton.Add(new Label("設定保存"));
            rootVisualElement.Add(SaveConfigButton);

            rootVisualElement.Add(new Label("通信処理"));
            SyncButton          = new Button();
            SyncButton.clicked += async() =>
            {
                System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

                var currentConfig = GetCurrentConfig();
                sw.Start();
                var loader = new GoogleSpreadSheetLoader(currentConfig.spreadsheetID, currentConfig.configClassName, Application.dataPath);
                var result = await loader.LoadAll();

                ErrorLogScrollView.Clear();
                var validationResults = DataValidator.ValidateTables(result.DataPool);
                if (validationResults.Count > 0)
                {
                    Debug.LogWarning($"ValidatonError Count: {validationResults.Count}");
                    if (!currentConfig.forceOverwriteOnValidationError)
                    {
                        foreach (var validationResult in validationResults)
                        {
                            Debug.LogError(validationResult.Message);
                            AddErrorLogScrollViewContent(validationResult, currentConfig, result.AvailableSheetDictionary);
                        }
                        sw.Stop();
                        Debug.LogError($"Synchronization Failured. Elapsed: {sw.ElapsedMilliseconds} ms");


                        return;
                    }

                    foreach (var validationResult in validationResults)
                    {
                        Debug.LogWarning(validationResult.Message);
                        AddErrorLogScrollViewContent(validationResult, currentConfig, result.AvailableSheetDictionary);
                    }
                }
                var fsWrapper = new MasterDataFileSystemWrapper(config.configClassName, Application.dataPath);
                fsWrapper.ExportAll(result.DataPool);

                AddAllClearScrollViewContent();

                sw.Stop();
                Debug.Log($"Syncronization done. Elapsed: {sw.ElapsedMilliseconds} ms");
            };
            SyncButton.Add(new Label("マスタ同期"));
            rootVisualElement.Add(SyncButton);

            rootVisualElement.Add(new Label("整合性チェックエラー行へのリンク"));

            ErrorLogScrollView = new ScrollView();

            rootVisualElement.Add(ErrorLogScrollView);
        }