5 // Cesar Lopez Nataren (cesar@ciencias.unam.mx)
7 // (C) 2003, Cesar Lopez Nataren
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Reflection;
33 using System.Security.Policy;
34 using System.Threading;
35 using Microsoft.JScript;
36 using Microsoft.JScript.Vsa;
38 namespace Microsoft.Vsa {
40 public abstract class BaseVsaEngine : IVsaEngine {
42 private const int ROOT_MONIKER_MAX_SIZE = 256;
43 private bool monikerAlreadySet;
44 private string rootMoniker;
49 private bool siteAlreadySet;
52 private bool namespaceNotSet;
53 private bool supportDebug;
54 private bool generateDebugInfo;
55 protected bool compiled;
58 private bool initNewCalled;
60 private IVsaSite site;
61 private IVsaItems items;
63 // its default value has to be "JScript"
64 private string language;
66 private string version;
68 private Assembly assembly;
69 private Evidence evidence;
71 private string rootNamespace;
73 // FIXME: must set vars to proper values
74 internal BaseVsaEngine ()
77 public BaseVsaEngine (string language, string version, bool supportDebug)
79 this.language = language;
81 // FIXME: I think we must ensure that version it's
82 // compliant with versionformat Major.Minor.Build.Revision.
83 // Not sure about what Exception throw.
84 this.version = version;
86 this.supportDebug = supportDebug;
88 this.rootMoniker = "";
91 this.compiled = false;
94 this.lcid = Thread.CurrentThread.CurrentCulture.LCID;
97 this.rootNamespace = "";
98 this.namespaceNotSet = true;
100 this.initNewCalled = false;
101 this.generateDebugInfo = false;
104 this.siteAlreadySet = false;
107 public System._AppDomain AppDomain {
108 get { throw new NotImplementedException (); }
109 set { throw new NotImplementedException (); }
112 // FIXME: research if we can use "get" Evidence when: running and busy.
113 public Evidence Evidence {
116 throw new VsaException (VsaError.EngineClosed);
117 else if (!initNewCalled)
118 throw new VsaException (VsaError.EngineNotInitialized);
125 throw new VsaException (VsaError.EngineClosed);
127 throw new VsaException (VsaError.EngineRunning);
129 throw new VsaException (VsaError.EngineBusy);
130 else if (!initNewCalled)
131 throw new VsaException (VsaError.EngineNotInitialized);
137 public string ApplicationBase {
138 get { throw new NotImplementedException (); }
139 set { throw new NotImplementedException (); }
142 public Assembly Assembly {
145 throw new VsaException (VsaError.EngineClosed);
147 throw new VsaException (VsaError.EngineNotRunning);
149 throw new VsaException (VsaError.EngineBusy);
156 // FIXME: research if we can "get" it when running and busy.
157 // FIXME: when do we throw VsaException with
158 // VsaError set to DebugInfoNotSupported?
160 public bool GenerateDebugInfo {
163 throw new VsaException (VsaError.EngineClosed);
164 else if (!initNewCalled)
165 throw new VsaException (VsaError.EngineNotInitialized);
167 return generateDebugInfo;
172 throw new VsaException (VsaError.EngineClosed);
174 throw new VsaException (VsaError.EngineRunning);
176 throw new VsaException (VsaError.EngineBusy);
177 else if (!initNewCalled)
178 throw new VsaException (VsaError.EngineNotInitialized);
179 else if (!supportDebug)
180 throw new VsaException (VsaError.DebugInfoNotSupported);
182 generateDebugInfo = value;
186 public bool IsCompiled {
191 throw new VsaException (VsaError.EngineClosed);
193 throw new VsaException (VsaError.EngineBusy);
194 else if (!initNewCalled)
195 throw new VsaException (VsaError.EngineNotInitialized);
202 // FIXME: Research if we can "set" it when running
203 public bool IsDirty {
206 throw new VsaException (VsaError.EngineClosed);
213 throw new VsaException (VsaError.EngineClosed);
215 throw new VsaException (VsaError.EngineBusy);
216 else if (!initNewCalled)
217 throw new VsaException (VsaError.EngineNotInitialized);
223 public bool IsRunning {
226 throw new VsaException (VsaError.EngineClosed);
228 throw new VsaException (VsaError.EngineBusy);
229 else if (!initNewCalled)
230 throw new VsaException (VsaError.EngineNotInitialized);
236 public IVsaItems Items {
239 throw new VsaException (VsaError.EngineClosed);
241 throw new VsaException (VsaError.EngineBusy);
242 else if (!initNewCalled)
243 throw new VsaException (VsaError.EngineNotInitialized);
246 items = new VsaItems ((VsaEngine) this);
253 public string Language {
256 throw new VsaException (VsaError.EngineClosed);
258 throw new VsaException (VsaError.EngineBusy);
259 else if (!initNewCalled)
260 throw new VsaException (VsaError.EngineNotInitialized);
266 // FIXME: research when LCIDNotSupported gets thrown.
270 throw new VsaException (VsaError.EngineClosed);
272 throw new VsaException (VsaError.EngineBusy);
273 else if (!initNewCalled)
274 throw new VsaException (VsaError.EngineNotInitialized);
276 throw new VsaException (VsaError.EngineRunning);
283 throw new VsaException (VsaError.EngineClosed);
285 throw new VsaException (VsaError.EngineBusy);
286 else if (!initNewCalled)
287 throw new VsaException (VsaError.EngineNotInitialized);
289 throw new VsaException (VsaError.EngineRunning);
296 // FIXME: we must throw VsaException, VsaError set to EngineNameInUse
297 // when setting and name is already in use.
301 throw new VsaException (VsaError.EngineClosed);
303 throw new VsaException (VsaError.EngineBusy);
304 else if (!initNewCalled)
305 throw new VsaException (VsaError.EngineNotInitialized);
307 throw new VsaException (VsaError.EngineRunning);
314 throw new VsaException (VsaError.EngineClosed);
316 throw new VsaException (VsaError.EngineBusy);
317 else if (!initNewCalled)
318 throw new VsaException (VsaError.EngineNotInitialized);
320 throw new VsaException (VsaError.EngineRunning);
326 // FIXME: We have to check - when setting - that the moniker
327 // is not already in use.
328 public string RootMoniker {
331 throw new VsaException (VsaError.EngineClosed);
333 throw new VsaException (VsaError.EngineBusy);
339 if (monikerAlreadySet)
340 throw new VsaException (VsaError.RootMonikerAlreadySet);
342 throw new VsaException (VsaError.EngineClosed);
344 throw new VsaException (VsaError.EngineBusy);
346 MonikerState state = ValidateRootMoniker (value);
349 case MonikerState.Valid:
351 monikerAlreadySet = true;
354 case MonikerState.Invalid:
355 throw new VsaException (VsaError.RootMonikerInvalid);
357 case MonikerState.ProtocolInvalid:
358 throw new VsaException (VsaError.RootMonikerProtocolInvalid);
364 internal static MonikerState ValidateRootMoniker (string n)
366 if (n == null || n == "" || n.Length > ROOT_MONIKER_MAX_SIZE)
367 return MonikerState.Invalid;
370 Uri uri = new Uri (n);
371 string protocol = uri.Scheme;
373 if (protocol == "http" || protocol == "file" ||
374 protocol == "ftp" || protocol == "gopher" ||
375 protocol == "https" || protocol == "mailto")
376 return MonikerState.ProtocolInvalid;
378 return MonikerState.Valid;
380 } catch (UriFormatException e) {
381 return MonikerState.Invalid;
386 // FIXME: we must check - when setting - that the value is a valid
387 // namespace (research what does that mean :-)). If not the case
388 // VsaException must be thrown, set to VsaError.NamespaceInvalid
389 public string RootNamespace {
392 throw new VsaException (VsaError.EngineClosed);
394 throw new VsaException (VsaError.EngineBusy);
395 else if (!initNewCalled)
396 throw new VsaException (VsaError.EngineNotInitialized);
398 throw new VsaException (VsaError.EngineRunning);
400 return rootNamespace;
405 throw new VsaException (VsaError.EngineClosed);
407 throw new VsaException (VsaError.EngineBusy);
408 else if (!initNewCalled)
409 throw new VsaException (VsaError.EngineNotInitialized);
411 throw new VsaException (VsaError.EngineRunning);
413 rootNamespace = value;
414 namespaceNotSet = false;
418 public IVsaSite Site {
421 throw new VsaException (VsaError.EngineClosed);
423 throw new VsaException (VsaError.EngineBusy);
424 else if (!monikerAlreadySet)
425 throw new VsaException (VsaError.RootMonikerNotSet);
431 if (!monikerAlreadySet)
432 throw new VsaException (VsaError.RootMonikerNotSet);
433 else if (siteAlreadySet)
434 throw new VsaException (VsaError.SiteAlreadySet);
436 throw new VsaException (VsaError.EngineClosed);
438 throw new VsaException (VsaError.EngineBusy);
439 else if (value == null)
440 throw new VsaException (VsaError.SiteInvalid);
443 siteAlreadySet = true;
448 // Version Format: Major.Minor.Revision.Build
450 public string Version {
453 throw new VsaException (VsaError.EngineClosed);
455 throw new VsaException (VsaError.EngineBusy);
456 else if (!initNewCalled)
457 throw new VsaException (VsaError.EngineNotInitialized);
463 public virtual void Close ()
468 throw new VsaException (VsaError.EngineClosed);
470 throw new VsaException (VsaError.EngineBusy);
478 // Count that AssemblyExpected exception may be thrown.
480 public virtual bool Compile ()
485 public virtual object GetOption (string name)
490 opt = GetSpecificOption (name);
491 } catch (VsaException e) {
497 protected abstract object GetSpecificOption (string name);
499 protected abstract void SetSpecificOption (string name, object val);
501 public virtual void InitNew ()
504 throw new VsaException (VsaError.EngineClosed);
506 throw new VsaException (VsaError.EngineBusy);
507 else if (initNewCalled)
508 throw new VsaException (VsaError.EngineInitialized);
509 else if (!monikerAlreadySet)
510 throw new VsaException (VsaError.RootMonikerNotSet);
511 else if (!siteAlreadySet)
512 throw new VsaException (VsaError.SiteNotSet);
514 initNewCalled = true;
517 public virtual void LoadSourceState (IVsaPersistSite site)
519 throw new NotImplementedException ();
522 public virtual void Reset ()
525 throw new VsaException (VsaError.EngineClosed);
527 throw new VsaException (VsaError.EngineBusy);
529 throw new VsaException (VsaError.EngineNotRunning);
535 public virtual void RevokeCache ()
537 throw new NotImplementedException ();
540 public virtual void Run ()
543 throw new VsaException (VsaError.EngineClosed);
545 throw new VsaException (VsaError.EngineBusy);
547 throw new VsaException (VsaError.EngineRunning);
548 else if (!monikerAlreadySet)
549 throw new VsaException (VsaError.RootMonikerNotSet);
550 else if (!siteAlreadySet)
551 throw new VsaException (VsaError.SiteNotSet);
552 else if (namespaceNotSet)
553 throw new VsaException (VsaError.RootNamespaceNotSet);
558 public virtual void SetOption (string name, object value)
563 public virtual void SaveCompiledState (out byte [] pe, out byte [] debugInfo)
565 throw new NotImplementedException ();
568 public virtual void SaveSourceState (IVsaPersistSite site)
570 throw new NotImplementedException ();
573 public abstract bool IsValidIdentifier (string ident);
575 internal bool Closed {
576 get { return closed; }
579 internal bool Running {
580 get { return running; }
587 internal bool InitNewCalled {
588 get { return initNewCalled; }
589 set { initNewCalled = value; }
593 public class BaseVsaSite : IVsaSite {
595 public virtual byte [] Assembly {
596 get { throw new NotImplementedException (); }
599 public virtual byte [] DebugInfo {
600 get { throw new NotImplementedException (); }
603 public virtual void GetCompiledState (out byte [] pe, out byte [] debugInfo)
605 throw new NotImplementedException ();
608 public virtual object GetEventSourceInstance (string itemName, string eventSourceName)
610 throw new NotImplementedException ();
613 public virtual object GetGlobalInstance (string name)
615 throw new NotImplementedException ();
618 public virtual void Notify (string notify, object optional)
620 throw new NotImplementedException ();
623 public virtual bool OnCompilerError (IVsaError error)
625 throw new NotImplementedException ();
630 public abstract class BaseVsaStartup {
632 public void SetSite (IVsaSite site)
634 throw new NotImplementedException ();
637 public abstract void Startup ();
639 public abstract void Shutdown ();
642 internal enum MonikerState {