Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/slmml/Compiler.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 99 - (hide annotations) (download)
Thu May 7 13:36:40 2009 UTC (14 years, 11 months ago) by hikarin
File size: 3985 byte(s)
[ocmml/slmml] * added CompileAsync to compile asynchronously
1 hikarin 58 /*
2     Copyright (c) 2009, hkrn All rights reserved.
3    
4     Redistribution and use in source and binary forms, with or without
5     modification, are permitted provided that the following conditions are met:
6    
7     Redistributions of source code must retain the above copyright notice, this
8     list of conditions and the following disclaimer. Redistributions in binary
9     form must reproduce the above copyright notice, this list of conditions and
10     the following disclaimer in the documentation and/or other materials
11     provided with the distribution. Neither the name of the hkrn nor
12     the names of its contributors may be used to endorse or promote products
13     derived from this software without specific prior written permission.
14    
15     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18     ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
19     ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24     OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
25     DAMAGE.
26     */
27    
28     //
29     // $Id$
30     //
31    
32     using System;
33 hikarin 37 using System.Collections.Generic;
34     using System.IO;
35     using System.Text;
36     using System.Windows.Controls;
37 hikarin 99 using System.Windows.Threading;
38 hikarin 37 using SlMML.Parsers;
39    
40     namespace SlMML
41     {
42 hikarin 99 public delegate void CompileCompletedEventHandler(object sender, CompileCompletedEventArgs e);
43    
44     public class CompileCompletedEventArgs : EventArgs
45     {
46     public CompileCompletedEventArgs(MediaElement me)
47     {
48     m_element = me;
49     }
50    
51     public MediaElement Result
52     {
53     get
54     {
55     return m_element;
56     }
57     }
58    
59     private MediaElement m_element;
60     }
61    
62 hikarin 37 public class Compiler
63     {
64 hikarin 99 public event CompileCompletedEventHandler CompileCompleted;
65    
66     #region ������������������������������������
67 hikarin 37 public static MediaElement Compile(string stringToParse)
68     {
69     MediaElement element = new MediaElement();
70     IParsable parser = new FlMMLStyleParser();
71 hikarin 51 element.Volume = 1;
72 hikarin 37 element.SetSource(parser.Parse(stringToParse));
73     return element;
74     }
75 hikarin 99 #endregion
76    
77     #region ���������������������������
78     public void CompileAsync(string stringToParse)
79     {
80     m_stringToParse = stringToParse;
81     DispatcherTimer timer = new DispatcherTimer();
82     timer.Interval = TimeSpan.FromDays(1);
83     timer.Tick += new EventHandler(CompileAsync_Tick);
84     timer.Start();
85     timer.Stop();
86     }
87 hikarin 67 #if DEBUG
88     public static List<List<Dictionary<string, string>>> Dump(string stringToParse)
89     {
90     FlMMLStyleParser parser = new FlMMLStyleParser();
91     parser.Parse(stringToParse);
92     return parser.Dump();
93     }
94     #endif
95 hikarin 37 #endregion
96 hikarin 99
97     #region ������������������������������
98     protected virtual void OnCompileCompleted(CompileCompletedEventArgs e)
99     {
100     if (CompileCompleted != null)
101     CompileCompleted(this, e);
102     }
103    
104     private void CompileAsync_Tick(object sender, EventArgs e)
105     {
106     MediaElement me = Compiler.Compile(m_stringToParse);
107     OnCompileCompleted(new CompileCompletedEventArgs(me));
108     }
109     #endregion
110    
111     #region ���������������������������
112     private string m_stringToParse;
113     #endregion
114 hikarin 37 }
115     }

Properties

Name Value
svn:keywords Id

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26