Ejemplo n.º 1
0
        public GeneratedClass ToClass(GenerationRules rules)
        {
            try
            {
                var @class = new GeneratedClass(rules, TypeName)
                {
                    BaseType = typeof(RouteHandler)
                };

                var frames = DetermineFrames();
                var method = new GeneratedMethod(nameof(RouteHandler.Handle),
                                                 new Argument[] { Argument.For <HttpContext>(RouteGraph.Context) }, frames)
                {
                    Overrides = true
                };

                method.Sources.Add(new ContextVariableSource());
                method.DerivedVariables.AddRange(HttpContextVariables);

                @class.AddMethod(method);

                return(@class);
            }
            catch (Exception e)
            {
                throw new CodeGenerationException(this, e);
            }
        }
        public static IEnumerable <int> GenerateIntegers(int count)
        {
            GeneratedClass ret = new GeneratedClass(-2);

            ret.count = count;
            return(ret);
        }
        static void Main(string[] args)
        {
            GeneratedClass G = new GeneratedClass();

            G.CreatePackage("Test.docx");
            //Trying to generate PDF from Word

            /*
             * object oMissing = System.Reflection.Missing.Value;
             * // Use the dummy value as a placeholder for optional arguments
             * mw.Document doc = word.Documents.Open("Test.docx", ref oMissing,
             *  ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
             *  ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
             *  ref oMissing, ref oMissing, ref oMissing, ref oMissing);
             * doc.Activate();
             *
             * object outputFileName = wordFile.FullName.Replace(".doc", ".pdf");
             * object fileFormat = WdSaveFormat.wdFormatPDF;
             *
             * // Save document into PDF Format
             * doc.SaveAs(ref outputFileName,
             *  ref fileFormat, ref oMissing, ref oMissing,
             *  ref oMissing, ref oMissing, ref oMissing, ref oMissing,
             *  ref oMissing, ref oMissing, ref oMissing, ref oMissing,
             *  ref oMissing, ref oMissing, ref oMissing, ref oMissing);
             *
             * // Close the Word document, but leave the Word application open.
             * // doc has to be cast to type _Document so that it will find the
             * // correct Close method.
             * object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
             * ((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
             * doc = null;*/
        }
        private void testButton_Click(object sender, EventArgs e)
        {
            GeneratedClass gc = new GeneratedClass(testTXT);

            gc.DoSomething();
            gc.CreatePackage("C:\\Users\\user\\Downloads\\output.docx");
        }
        private void ButtonPreviewFile_Click(object sender, EventArgs e)
        {
            string filePath        = FilePathUtil.DocumentFilePath();
            string examName        = textBoxExamName.Text;
            int    pageSize        = comboBoxPageSize.SelectedIndex;
            int    pageOrientation = comboBoxPageOrientation.SelectedIndex;

            GeneratedClass generater = new GeneratedClass();

            generater.FilePath = filePath;
            generater.ExamName = examName;

            switch (pageSize)
            {
            case (int)PageSizeValues.A3:
                generater.PageSize = PageSizeValues.A3;
                break;

            case (int)PageSizeValues.A4:
                generater.PageSize = PageSizeValues.A4;
                break;
            }
            switch (pageOrientation)
            {
            case (int)PageOrientationValues.Landscape:
                generater.PageOrientation = PageOrientationValues.Landscape;
                break;

            case (int)PageOrientationValues.Portrait:
                generater.PageOrientation = PageOrientationValues.Portrait;
                break;
            }

            generater.Create();

            this.toolStripStatusLabelTip.Text = filePath;
            string filepath = toolStripStatusLabelTip.Text;

            LoadFromViewFile(filepath);

            toolStripProgressBar.Maximum = 100;                          //设置最大长度值
            toolStripProgressBar.Value   = 0;                            //设置当前值
            toolStripProgressBar.Step    = 20;                           //设置没次增长多少
            toolStripProgressBar.Visible = true;
            for (int i = 0; i < 5; i++)                                  //循环
            {
                System.Threading.Thread.Sleep(100);                      //暂停1秒
                toolStripProgressBar.Value += toolStripProgressBar.Step; //让进度条增加一次
            }

            if (MessageBox.Show("文件已生成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question) == DialogResult.OK)
            {
                this.tabControl.SelectedIndex = 1;
                toolStripProgressBar.Visible  = false;
            }
        }
        private void bt_Generate_Click(object sender, RoutedEventArgs e)
        {
            GeneratedClass gc = new GeneratedClass();

            gc.ClassName = "Bob";
            gc.NameSpace = "Bakker";
            gc.AddField("age", typeof(int));

            gc.Generate("test.cs");
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            DataTable dt = Db.ПолучитьТабличнуюЧастьСпецификации(cnString, 71659);

            using (FileStream file = File.Create(@"C:\Temp\TestWord.docx"))
            {
                MemoryStream ms = new GeneratedClass().CreatePackage(dt);
                ms.Position = 0;
                ms.CopyTo(file);
            }
        }
Ejemplo n.º 8
0
 /// <summary>This method is used to generate a file containng the Generated Class</summary>
 /// <param name="gc">the Generated Class
 /// </param>
 /// <param name="packageName">the name of the package
 /// </param>
 /// <param name="filename">the name to save the generated class under
 /// </param>
 public virtual void  generateFile(GeneratedClass gc, System.String packageName, System.String filename)
 {
     //fg.storeFile(gc, filename, packageName);
     try
     {
         fg.storeFile(gc, packageName, filename);
     }
     catch (System.IO.IOException e)
     {
         System.Console.Error.WriteLine(e.Message);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Generates a source to add to the compilation
        /// </summary>
        /// <param name="generator">The generator context</param>
        /// <param name="cls">The class to generate</param>
        /// <param name="code">The code to put in the class</param>
        private void GenerateSource(GeneratorExecutionContext generator, GeneratedClass cls, Action <BindingGeneratorStream> code)
        {
            BindingGeneratorStream stream = new();

            code(stream);
            generator.AddSource(cls.ClassName, stream.ToString());
#if BINDING_SOURCE_GEN_DEBUG
            Console.WriteLine($@"
// {cls.ClassName}.cs
{stream}
");
#endif
        }
            public IEnumerator <int> GetEnumerator()
            {
                GeneratedClass enumerator;

                if (state == -2 && initialThreadId == Environment.CurrentManagedThreadId)
                {
                    state      = 0;
                    enumerator = this;
                }
                else
                {
                    enumerator       = new GeneratedClass(0);
                    enumerator.count = count;
                }
                return(enumerator);
            }
Ejemplo n.º 11
0
            public IEnumerator <string> GetEnumerator()
            {
                GeneratedClass getCollectionD1;

                if (_state == -2 && _initialThreadId == Environment.CurrentManagedThreadId)
                {
                    _state          = 0;
                    getCollectionD1 = this;
                }
                else
                {
                    getCollectionD1 = new GeneratedClass(0);
                }

                return(getCollectionD1);
            }
Ejemplo n.º 12
0
        public GeneratedClass ToClass(GenerationRules rules)
        {
            try
            {
                var @class = new GeneratedClass(rules, TypeName)
                {
                    BaseType = typeof(MessageHandler)
                };

                var method = new HandleMessageMethod(DetermineFrames());
                method.Sources.Add(new MessageHandlerVariableSource(MessageType));

                @class.AddMethod(method);

                return(@class);
            }
            catch (Exception e)
            {
                throw new CodeGenerationException(this, e);
            }
        }
Ejemplo n.º 13
0
 public void Stuff()
 {
     GeneratedClass.GeneratedMethod();
     var x = typeof(Messages.Grains);
 }
Ejemplo n.º 14
0
 public static void DoSomething()
 {
     GeneratedClass.GeneratedMethod();
     ClassInSubmodule.M();
     ClassInVstsSubmodule.M();
 }