private static void Migrate(Context context, ExportSettingModel exportSettingModel)
        {
            var ss = Rds.ExecuteScalar_string(
                context: context,
                statements: Rds.SelectSites(
                    column: Rds.SitesColumn().SiteSettings(),
                    where : Rds.SitesWhere().SiteId(exportSettingModel.ReferenceId)))
                     .Deserialize <SiteSettings>();

            if (ss != null)
            {
                ss.SiteId  = exportSettingModel.ReferenceId;
                ss.Exports = ss.Exports ?? new SettingList <Export>();
                ss.Exports.Add(new Export(
                                   id: ss.Exports.Any()
                        ? ss.Exports.Max(o => o.Id) + 1
                        : 1,
                                   name: exportSettingModel.Title.Value,
                                   header: exportSettingModel.AddHeader,
                                   columns: exportSettingModel.ExportColumns.Columns
                                   .Where(o => o.Value)
                                   .Select((o, i) => new ExportColumn(
                                               context: context,
                                               ss: ss,
                                               columnName: o.Key,
                                               id: i + 1))
                                   .ToList()));
                Rds.ExecuteNonQuery(
                    context: context,
                    statements: Rds.UpdateSites(
                        param: Rds.SitesParam().SiteSettings(ss.RecordingJson(context: context)),
                        where : Rds.SitesWhere().SiteId(exportSettingModel.ReferenceId)));
            }
        }
        private static void Migrate(Context context, ExportSettingModel exportSettingModel)
        {
            var ss = Repository.ExecuteScalar_string(
                context: context,
                statements: Rds.SelectSites(
                    column: Rds.SitesColumn().SiteSettings(),
                    where : Rds.SitesWhere().SiteId(exportSettingModel.ReferenceId)))
                     .DeserializeSiteSettings(context: context);

            if (ss != null)
            {
                ss.SiteId  = exportSettingModel.ReferenceId;
                ss.Exports = ss.Exports ?? new SettingList <Export>();
                ss.Exports.Add(new Export(
                                   id: ss.Exports.Any()
                        ? ss.Exports.Max(o => o.Id) + 1
                        : 1,
                                   type: Export.Types.Csv,
                                   name: exportSettingModel.Title.Value,
                                   header: exportSettingModel.AddHeader,
                                   columns: exportSettingModel.ExportColumns.Columns
                                   .Where(o => o.Value)
                                   .Select((o, i) => new ExportColumn(
                                               context: context,
                                               column: ss.GetColumn(
                                                   context: context,
                                                   columnName: o.Key),
                                               id: i + 1))
                                   .ToList(),
                                   delimiterType: Export.DelimiterTypes.Comma,
                                   encloseDoubleQuotes: true,
                                   executionType: Export.ExecutionTypes.Direct));
                Repository.ExecuteNonQuery(
                    context: context,
                    statements: Rds.UpdateSites(
                        param: Rds.SitesParam().SiteSettings(ss.RecordingJson(context: context)),
                        where : Rds.SitesWhere().SiteId(exportSettingModel.ReferenceId)));
            }
        }
        /// <summary>
        /// QEDデータ構造をテキストデータに変換する
        /// </summary>
        /// <returns></returns>
        static public string ToText(QuartetEditorDescription data, ExportSettingModel setting)
        {
            StringBuilder export = new StringBuilder();
            int           level  = 0;

            if (setting.EnableLineWrap)
            {
                // 折り返しありの場合
                foreach (var item in data.Node)
                {
                    ToTextWithLineWrap(item, export, setting, level);
                }
                return(export.ToString());
            }
            else
            {
                // 折り返しなしの場合
                foreach (var item in data.Node)
                {
                    ToText(item, export, level);
                }
                return(export.ToString());
            }
        }
        /// <summary>
        /// ノードをテキストデータに変換する(折り返しあり)
        /// </summary>
        /// <returns></returns>
        static private void ToTextWithLineWrap(QuartetEditorDescriptionItem item, StringBuilder result, ExportSettingModel setting, int level)
        {
            // タイトルを変換
            result.AppendLine(new string(' ', level * 2) + "【" + item.Name + "】");

            // コンテンツ変換
            string indent    = new string(' ', (level + 1) * 2);
            int    lineWidth = setting.LineWrap;

            if (lineWidth - indent.GetSJISByte() < lineWidth / 2)
            {
                lineWidth = indent.GetSJISByte() + lineWidth / 2;
            }

            int index = 0;

            // 改行コードが2文字だと都合が悪いので一時的に置き換え
            string content = item.Content.Trim(Environment.NewLine.ToCharArray()).Replace(Environment.NewLine, "\r");

            while (index < content.Length)
            {
                var line = new StringBuilder(indent);
                while (line.GetSJISByte() < lineWidth && index < content.Length)
                {
                    if (content.Substring(index, 1) == "\r")
                    {
                        // 追加するのが改行コードだった場合、空白を入れなおす
                        ++index;
                        break;
                    }

                    line.Append(content.Substring(index, 1));
                    ++index;
                }
                result.AppendLine(line.ToString());
            }
            result.LineBreak();

            foreach (var child in item.Children)
            {
                ToTextWithLineWrap(child, result, setting, level + 1);
            }
        }
Пример #5
0
 /// <summary>
 /// エクスポートを実行
 /// </summary>
 /// <param name="model"></param>
 public void Export(ExportSettingModel model)
 {
     this.Model.Export(model);
 }