예제 #1
0
    public static void ExportCulture(string directoryName, CultureInfo ci)
    {
        bool?replace = null;
        bool?delete  = null;

        SyncFolder(ref replace, ref delete, Path.Combine(directoryName, ci.Name, AppendicesDirectory),
                   Database.Query <AppendixHelpEntity>().Where(ah => ah.Culture.Name == ci.Name).ToList(),
                   ah => "{0}.{1}.help".FormatWith(RemoveInvalid(ah.UniqueName), ah.Culture.Name),
                   ah => AppendixXml.ToXDocument(ah));

        SyncFolder(ref replace, ref delete, Path.Combine(directoryName, ci.Name, NamespacesDirectory),
                   Database.Query <NamespaceHelpEntity>().Where(nh => nh.Culture.Name == ci.Name).ToList(),
                   nh => "{0}.{1}.help".FormatWith(RemoveInvalid(nh.Name), nh.Culture.Name),
                   nh => NamespaceXml.ToXDocument(nh));

        SyncFolder(ref replace, ref delete, Path.Combine(directoryName, ci.Name, TypesDirectory),
                   Database.Query <TypeHelpEntity>().Where(th => th.Culture.Name == ci.Name).ToList(),
                   th => "{0}.{1}.help".FormatWith(RemoveInvalid(th.Type.CleanName), th.Culture.Name),
                   th => EntityXml.ToXDocument(th));

        SyncFolder(ref replace, ref delete, Path.Combine(directoryName, ci.Name, QueriesDirectory),
                   Database.Query <QueryHelpEntity>().Where(qh => qh.Culture.Name == ci.Name).ToList(),
                   qh => "{0}.{1}.help".FormatWith(RemoveInvalid(qh.Query.Key), qh.Culture.Name),
                   qh => QueryXml.ToXDocument(qh));
    }
예제 #2
0
    public static void ImportAll(string directoryName)
    {
        var namespaces = HelpLogic.AllTypes().Select(a => a.Namespace !).Distinct().ToDictionary(a => a);

        var types = HelpLogic.AllTypes().ToDictionary(a => a.FullName !);

        foreach (var path in Directory.GetFiles(directoryName, "*.help", SearchOption.AllDirectories))
        {
            try
            {
                XDocument doc = XDocument.Load(path);

                ImportAction action =
                    doc.Root !.Name == AppendixXml._Appendix ? AppendixXml.Load(doc):
                    doc.Root !.Name == NamespaceXml._Namespace ? NamespaceXml.Load(doc, namespaces):
                    doc.Root !.Name == EntityXml._Entity ? EntityXml.Load(doc, types):
                    doc.Root !.Name == QueryXml._Query ? QueryXml.Load(doc) :
                    throw new InvalidOperationException("Unknown Xml root: " + doc.Root.Name);

                ConsoleColor color =
                    action == ImportAction.Inserted ? ConsoleColor.Green :
                    action == ImportAction.Updated ? ConsoleColor.DarkGreen :
                    action == ImportAction.Skipped ? ConsoleColor.Yellow :
                    action == ImportAction.NoChanges ? ConsoleColor.DarkGray :
                    throw new InvalidOperationException("Unexpected action");

                SafeConsole.WriteLineColor(color, " {0} {1}".FormatWith(action, path));
            }
            catch (Exception e)
            {
                SafeConsole.WriteLineColor(ConsoleColor.Red, " Error {0}:\r\n\t".FormatWith(path) + e.Message);
            }
        }
    }
예제 #3
0
파일: HelpXml.cs 프로젝트: ywscr/extensions
        public static void ExportAll(string directoryName = "../../Help")
        {
            bool?replace = null;

            foreach (var ah in Database.Query <AppendixHelpEntity>())
            {
                string path = Path.Combine(directoryName, ah.Culture.Name, AppendicesDirectory, "{0}.{1}.help".FormatWith(RemoveInvalid(ah.UniqueName), ah.Culture.Name));

                FileTools.CreateParentDirectory(path);

                if (!File.Exists(path) || SafeConsole.Ask(ref replace, "Overwrite {0}?".FormatWith(path)))
                {
                    AppendixXml.ToXDocument(ah).Save(path);
                }
            }

            foreach (var nh in Database.Query <NamespaceHelpEntity>())
            {
                string path = Path.Combine(directoryName, nh.Culture.Name, NamespacesDirectory, "{0}.{1}.help".FormatWith(RemoveInvalid(nh.Name), nh.Culture.Name));

                FileTools.CreateParentDirectory(path);

                if (!File.Exists(path) || SafeConsole.Ask(ref replace, "Overwrite {0}?".FormatWith(path)))
                {
                    NamespaceXml.ToXDocument(nh).Save(path);
                }
            }

            foreach (var eh in Database.Query <EntityHelpEntity>())
            {
                string path = Path.Combine(directoryName, eh.Culture.Name, EntitiesDirectory, "{0}.{1}.help".FormatWith(RemoveInvalid(eh.Type.CleanName), eh.Culture.Name));

                FileTools.CreateParentDirectory(path);

                if (!File.Exists(path) || SafeConsole.Ask(ref replace, "Overwrite {0}?".FormatWith(path)))
                {
                    EntityXml.ToXDocument(eh).Save(path);
                }
            }

            foreach (var qh in Database.Query <QueryHelpEntity>())
            {
                string path = Path.Combine(directoryName, qh.Culture.Name, QueriesDirectory, "{0}.{1}.help".FormatWith(RemoveInvalid(qh.Query.Key), qh.Culture.Name));

                FileTools.CreateParentDirectory(path);

                if (!File.Exists(path) || SafeConsole.Ask(ref replace, "Overwrite {0}?".FormatWith(path)))
                {
                    QueryXml.ToXDocument(qh).Save(path);
                }
            }
        }