コード例 #1
0
        private void ImportDialog_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (this.DialogResult == DialogResult.OK)
            {
                ImportOptions type = ImportOptions.None;
                if (ckxNewScore.Checked)
                {
                    type |= ImportOptions.New;
                }
                if (ckxMergeExisting.Checked)
                {
                    if (ckxNames.Checked)
                    {
                        type |= ImportOptions.Names;
                    }
                    if (ckxUrl.Checked)
                    {
                        type |= ImportOptions.Parsing;
                    }
                    if (ckxRules.Checked)
                    {
                        type |= ImportOptions.Rules;
                    }
                }

                ExchangeManager.Import(m_center, m_fileName, type);
            }
        }
コード例 #2
0
ファイル: ExchangeManager.cs プロジェクト: mbekoe/scorecenter
        /// <summary>
        /// Import a list of scores in an existing center.
        /// </summary>
        /// <param name="center">The existing center.</param>
        /// <param name="imported">The center to import.</param>
        /// <param name="mergeOptions">The merge options.</param>
        /// <returns>The number of scores imported.</returns>
        public static int Import(ScoreCenter center, ScoreCenter imported, ImportOptions mergeOptions)
        {
            int result = 0;

            if (imported.Scores.Items == null)
            {
                return(result);
            }

            bool             isnew    = center.Scores.Items != null;
            List <BaseScore> toImport = new List <BaseScore>();

            foreach (BaseScore score in imported.Scores.Items)
            {
                BaseScore exist = center.FindScore(score.Id);
                if (exist != null)
                {
                    // merge (or not)
                    bool merged = exist.Merge(score, mergeOptions);
                    if (merged)
                    {
                        result++;
                    }
                }
                else
                {
                    // import new
                    if ((mergeOptions & ImportOptions.New) == ImportOptions.New)
                    {
                        toImport.Add(score);
                        result++;
                        score.SetNew(isnew);
                        score.enable = true;
                    }
                }
            }

            if (toImport.Count > 0)
            {
                if (center.Scores.Items == null)
                {
                    center.Scores.Items = toImport.ToArray();
                }
                else
                {
                    center.Scores.Items = center.Scores.Items.Concat(toImport).ToArray();
                }
            }

            // import parameters
            ExchangeManager.ImportParameters(center, imported);

            return(result);
        }
コード例 #3
0
ファイル: ScoreCenterGui.cs プロジェクト: mbekoe/scorecenter
        private void UpdateSettings(bool force, bool reload)
        {
            bool updated = ExchangeManager.OnlineUpdate(m_center, force);

            if (updated)
            {
                SaveSettings();
                if (reload)
                {
                    LoadScores("");
                }
            }
        }
コード例 #4
0
ファイル: ExportDialog.cs プロジェクト: mbekoe/scorecenter
        private void ExportScores(string fileName)
        {
            List <BaseScore> scores = new List <BaseScore>();

            // navigate through the nodes and export only the checked nodes
            foreach (ThreeStateTreeNode scoreNode in treeView1.GetCheckedNodes())
            {
                if (scoreNode.Checked)
                {
                    BaseScore score = scoreNode.Tag as BaseScore;
                    scores.Add(score);
                }
            }

            ExchangeManager.Export(m_center, fileName, scores);
        }
コード例 #5
0
        private void btnUpdateNow_Click(object sender, EventArgs e)
        {
            UpdateMode mode       = m_center.Setup.UpdateOnlineMode;
            string     strOptions = m_center.Setup.UpdateRule;

            try
            {
                this.Cursor = Cursors.WaitCursor;
                ImportOptions options = ReadImportOptions();

                m_reload = true;
                m_center.Setup.UpdateOnlineMode = UpdateMode.Manually;
                m_center.Setup.UpdateRule       = options.ToString();
                ExchangeManager.OnlineUpdate(m_center, true);
            }
            finally
            {
                m_center.Setup.UpdateOnlineMode = mode;
                m_center.Setup.UpdateRule       = strOptions;
                this.Cursor = Cursors.Default;
            }
        }
コード例 #6
0
ファイル: ExchangeManager.cs プロジェクト: mbekoe/scorecenter
        private static bool OnlineUpdate(ScoreCenter center, string url, ImportOptions options)
        {
            bool result = false;

            if (String.IsNullOrEmpty(url) == false)
            {
                ScoreCenter online = Tools.ReadOnlineSettings(url, false);
                if (online != null)
                {
                    int nb = ExchangeManager.Import(center, online, options);
                    Tools.LogMessage("Imported: {0}", nb);
                    result = (nb > 0);

                    // if scores imported
                    if (result)
                    {
                        // check icons
                        UpdateIcons(center);
                    }
                }
            }

            return(result);
        }
コード例 #7
0
ファイル: ExchangeManager.cs プロジェクト: mbekoe/scorecenter
        /// <summary>
        /// Import scores from an XML file.
        /// </summary>
        /// <param name="center">The existing center.</param>
        /// <param name="fileName">The path of the file to import.</param>
        /// <param name="mergeOptions">The merge options.</param>
        public static void Import(ScoreCenter center, string fileName, ImportOptions mergeOptions)
        {
            ScoreCenter imported = Tools.ReadSettings(fileName, true);

            ExchangeManager.Import(center, imported, mergeOptions);
        }