Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/slmml/Compiler.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 116 - (hide annotations) (download)
Sat May 23 14:39:36 2009 UTC (14 years, 10 months ago) by hikarin
File size: 8245 byte(s)
[ocmml/slmml] * added NDoc-styled comments
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 116 /// <summary>
43     /// CompileAsync������������������������������������������
44     /// </summary>
45     /// <param name="sender">���������������������������������</param>
46     /// <param name="e">CompileCompletedEventArgs������������������</param>
47 hikarin 99 public delegate void CompileCompletedEventHandler(object sender, CompileCompletedEventArgs e);
48 hikarin 116
49     /// <summary>
50     /// CompileCompleted������������������������������������������������
51     /// </summary>
52 hikarin 99 public class CompileCompletedEventArgs : EventArgs
53     {
54     public CompileCompletedEventArgs(MediaElement me)
55     {
56     m_element = me;
57     }
58 hikarin 116
59     /// <summary>
60     /// CompileAsync���������������������������������������������������������������MediaElement������������������
61     /// </summary>
62 hikarin 99 public MediaElement Result
63     {
64     get
65     {
66     return m_element;
67     }
68     }
69    
70     private MediaElement m_element;
71     }
72    
73 hikarin 116 /// <summary>
74     /// FlMML���������������������������������������������������������������������������������������������������������������
75     /// </summary>
76 hikarin 37 public class Compiler
77     {
78 hikarin 99 public event CompileCompletedEventHandler CompileCompleted;
79    
80     #region ������������������������������������
81 hikarin 116 /// <summary>
82     /// FlMML���������������������������������������������������������������������������
83     /// </summary>
84     /// <remarks>
85     /// FlMML���������������������������������������������������������������������������������
86     /// MediaElement������������������������MediaElement���������������������������������
87     /// Volume���1���������������������
88     /// </remarks>
89     /// <example>
90     /// ���������������������������������������������
91     /// <code>
92     /// MediaElement me = SlMML.Compiler.Compile("cdefgab&lt;c");
93     /// LayoutRoot.Children.Add(me);
94     /// me.Play();
95     /// me.MediaOpened += new RoutedEventHandler(media_MediaOpened);
96     /// void media_MediaOpened(object sender, RoutedEventArgs e)
97     /// {
98     /// MediaElement me = (MediaElement)e.OriginalSource;
99     /// me.Play();
100     /// }
101     /// </code>
102     /// </example>
103     /// <param name="stringToParse">FlMML������������������������������������������������</param>
104     /// <returns>MediaElement������������������</returns>
105 hikarin 37 public static MediaElement Compile(string stringToParse)
106     {
107     MediaElement element = new MediaElement();
108     IParsable parser = new FlMMLStyleParser();
109 hikarin 51 element.Volume = 1;
110 hikarin 37 element.SetSource(parser.Parse(stringToParse));
111     return element;
112     }
113 hikarin 99 #endregion
114    
115     #region ���������������������������
116 hikarin 116 /// <summary>
117     /// Compile������������������������������������������
118     /// </summary>
119     /// <remarks>
120     /// Compile������������������������������������������������������������������
121     /// ���������������������������CompileCompleteEventHandler���������������������������������
122     /// MediaElement���Thread������������������������������������������������������
123     /// ������������DispatcherTimer���������������������������������������
124     /// </remarks>
125     /// <example>
126     /// ���������������������������������������������
127     /// <code>
128     /// SlMML.Compiler compiler = new SlMML.Compiler();
129     /// compiler.CompileCompleted += new SlMML.CompileCompletedEventHandler(compiler_CompileCompleted);
130     /// compiler.CompileAsync("cdefgab&lt;c");
131     /// void compiler_CompileCompleted(object sender, SlMML.CompileCompletedEventArgs e)
132     /// {
133     /// MediaElemenet me = (MediaElement)e.Result;
134     /// LayoutRoot.Children.Add(me);
135     /// me.MediaOpened += new RoutedEventHandler(media_MediaOpened);
136     /// me.Play();
137     /// }
138     /// void media_MediaOpened(object sender, RoutedEventArgs e)
139     /// {
140     /// MediaElement me = (MediaElement)e.OriginalSource;
141     /// me.Play();
142     /// }
143     /// </code>
144     /// </example>
145     /// <param name="stringToParse">FlMML������������������������������������������������</param>
146 hikarin 99 public void CompileAsync(string stringToParse)
147     {
148     m_stringToParse = stringToParse;
149     DispatcherTimer timer = new DispatcherTimer();
150     timer.Interval = TimeSpan.FromDays(1);
151     timer.Tick += new EventHandler(CompileAsync_Tick);
152     timer.Start();
153     timer.Stop();
154     }
155 hikarin 67 #if DEBUG
156 hikarin 116 /// <summary>
157     /// ������������������������������������������������������������������������������������������������
158     /// </summary>
159     /// <remarks>
160     /// ������������������������������������������������������������������������
161     /// ������������JSON������������������������������������������������������
162     /// ���������������������������������������������������������������
163     /// </remarks>
164     /// <param name="stringToParse">FlMML������������������������������������������������</param>
165     /// <returns>���������������������������������������������������������</returns>
166 hikarin 67 public static List<List<Dictionary<string, string>>> Dump(string stringToParse)
167     {
168     FlMMLStyleParser parser = new FlMMLStyleParser();
169     parser.Parse(stringToParse);
170     return parser.Dump();
171     }
172     #endif
173 hikarin 37 #endregion
174 hikarin 99
175     #region ������������������������������
176 hikarin 116 /// <summary>
177     /// ���������������������������������������������������������������������
178     /// </summary>
179     /// <param name="e">���������������������������������CompileCompletedEventArgs������������������</param>
180 hikarin 99 protected virtual void OnCompileCompleted(CompileCompletedEventArgs e)
181     {
182     if (CompileCompleted != null)
183     CompileCompleted(this, e);
184     }
185    
186     private void CompileAsync_Tick(object sender, EventArgs e)
187     {
188     MediaElement me = Compiler.Compile(m_stringToParse);
189     OnCompileCompleted(new CompileCompletedEventArgs(me));
190     }
191     #endregion
192    
193     #region ���������������������������
194     private string m_stringToParse;
195     #endregion
196 hikarin 37 }
197     }

Properties

Name Value
svn:keywords Id

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