Ejemplo n.º 1
0
        public static void ConvertToFiles(RuleIndex index, string outputPath, ProgressDialog progress)
        {
            if (progress != null) { progress.SetDescription("Converting elements..."); }
            int max = index.Elements.Count;
            int pos = 0;

            var sourceModules = new List<string>();
            foreach (IGrouping<string, RuleElement> source in index.Elements.GroupBy(r => GetRealSource(r.Source)))
            {
                string sourceSegment = GetSafePathSegment(source.Key);
                string sourcePath = Path.Combine(outputPath, sourceSegment);
                if (!Directory.Exists(sourcePath)) { Directory.CreateDirectory(sourcePath); }

                var modules = new List<string>();
                foreach (IGrouping<string, RuleElement> type in source.GroupBy(r => r.Type.ToString()))
                {
                    string moduleName = type.Key;
                    modules.Add(moduleName);

                    string outFile = Path.Combine(sourcePath, moduleName + ".js");
                    using (TextWriter writer = File.CreateText(outFile))
                    {
                        var converter = new Converter(index, writer);
                        converter.WriteGlobalPrefix();
                        converter.WriteTypePrefix(type.Key);
                        foreach (RuleElement element in type.OrderBy(e => e.Name.ToString()))
                        {
                            if (progress != null) { progress.SetProgress(pos++, max); }
                            converter.WriteGenericRulesElement(element);
                        }
                        converter.WriteTypeSuffix();
                        converter.WriteGlobalSuffix();

                        converter.WriteWarnings();
                    }
                }

                string indexModule = Path.Combine(sourceSegment, "all");
                sourceModules.Add(indexModule);

                string indexFile = Path.Combine(outputPath, indexModule + ".js");
                using(TextWriter writer = File.CreateText(indexFile))
                {
                    var converter = new Converter(index, writer);
                    converter.WriteIndexFile(modules);
                }
            }

            string masterIndex = Path.Combine(outputPath, "all.js");
            using(TextWriter writer = File.CreateText(masterIndex))
            {
                var converter = new Converter(index, writer);
                converter.WriteIndexFile(sourceModules);
            }
        }
Ejemplo n.º 2
0
        static Task<RuleIndex> StartLoadFile(string fileName, ProgressDialog dialog)
        {
            return Task.Factory.StartNew(() =>
            {
                dialog.SetDescription("Loading XML file...");
                dialog.SetProgress(0, -1);

                XDocument document = XDocument.Load(fileName);

                return RuleIndex.Load(fileName, document, dialog);
            });
        }
Ejemplo n.º 3
0
        public static void Convert(RuleIndex index, TextWriter writer, ProgressDialog progress)
        {
            var converter = new Converter(index, writer);

            if (progress != null) { progress.SetDescription("Converting elements..."); }
            int max = index.Elements.Count;
            int pos = 0;

            converter.WriteGlobalPrefix();
            foreach (IGrouping<string, RuleElement> ebt in index.Elements.GroupBy(e => e.Type.ToString()))
            {
                converter.WriteTypePrefix(ebt.Key);
                foreach (RuleElement element in ebt.OrderBy(e => e.Name.ToString()))
                {
                    if (progress != null) { progress.SetProgress(pos++, max); }
                    converter.WriteGenericRulesElement(element);
                }
                converter.WriteTypeSuffix();
            }
            converter.WriteGlobalSuffix();

            converter.WriteWarnings();
        }
Ejemplo n.º 4
0
        public static void ConvertToFiles(RuleIndex index, string outputPath, ProgressDialog progress)
        {
            if (progress != null)
            {
                progress.SetDescription("Converting elements...");
            }
            int max = index.Elements.Count;
            int pos = 0;

            var sourceModules = new List <string>();

            foreach (IGrouping <string, RuleElement> source in index.Elements.GroupBy(r => GetRealSource(r.Source)))
            {
                string sourceSegment = GetSafePathSegment(source.Key);
                string sourcePath    = Path.Combine(outputPath, sourceSegment);
                if (!Directory.Exists(sourcePath))
                {
                    Directory.CreateDirectory(sourcePath);
                }

                var modules = new List <string>();
                foreach (IGrouping <string, RuleElement> type in source.GroupBy(r => r.Type.ToString()))
                {
                    string moduleName = type.Key;
                    modules.Add(moduleName);

                    string outFile = Path.Combine(sourcePath, moduleName + ".js");
                    using (TextWriter writer = File.CreateText(outFile))
                    {
                        var converter = new Converter(index, writer);
                        converter.WriteGlobalPrefix();
                        converter.WriteTypePrefix(type.Key);
                        foreach (RuleElement element in type.OrderBy(e => e.Name.ToString()))
                        {
                            if (progress != null)
                            {
                                progress.SetProgress(pos++, max);
                            }
                            converter.WriteGenericRulesElement(element);
                        }
                        converter.WriteTypeSuffix();
                        converter.WriteGlobalSuffix();

                        converter.WriteWarnings();
                    }
                }

                string indexModule = Path.Combine(sourceSegment, "all");
                sourceModules.Add(indexModule);

                string indexFile = Path.Combine(outputPath, indexModule + ".js");
                using (TextWriter writer = File.CreateText(indexFile))
                {
                    var converter = new Converter(index, writer);
                    converter.WriteIndexFile(modules);
                }
            }

            string masterIndex = Path.Combine(outputPath, "all.js");

            using (TextWriter writer = File.CreateText(masterIndex))
            {
                var converter = new Converter(index, writer);
                converter.WriteIndexFile(sourceModules);
            }
        }
Ejemplo n.º 5
0
 void OnConvert(object sender, EventArgs e)
 {
     var progress = new ProgressDialog
     {
         Title = "Loading file",
         TaskFunction = (p) => Task.Factory.StartNew(() =>
             {
                 string newPath = Path.ChangeExtension(this.currentDocument.Name, ".js");
                 using (FileStream stream = File.Open(newPath, FileMode.Create))
                 {
                     using (var writer = new StreamWriter(stream))
                     {
                         Converter.Convert(this.currentDocument, writer, p);
                     }
                 }
             })
     };
     progress.ShowDialog();
 }
Ejemplo n.º 6
0
 void LoadDocumentAsync(string fileName)
 {
     var progress = new ProgressDialog
     {
         Title = "Loading file",
         TaskFunction = (p) => StartLoadFile(fileName, p),
     };
     if (progress.ShowDialog() == DialogResult.OK)
     {
         var task = (Task<RuleIndex>)progress.Task;
         SetupDocument(task.Result);
     }
 }
Ejemplo n.º 7
0
 void OnConvertToFiles(object sender, EventArgs e)
 {
     var progress = new ProgressDialog
     {
         Title = "Converting file",
         TaskFunction = (p) => Task.Factory.StartNew(() =>
         {
             string newPath = Path.ChangeExtension(this.currentDocument.Name, ".out");
             Converter.ConvertToFiles(this.currentDocument, newPath, p);
         })
     };
     progress.ShowDialog();
 }