Ejemplo n.º 1
0
 /// <summary>
 /// Read element from the XML reader
 /// </summary>
 /// <param name="context">XML context</param>
 /// <param name="reader">Reader</param>
 public override void ReadXml(IXsContext context, XmlReader reader)
 {
     base.ReadXml(context, reader);
     if (WithTypes)
     {
         ScriptContext c = (ScriptContext)context;
         c.AddAssembly(AddReference(c, true), true);
     }
 }
Ejemplo n.º 2
0
 internal void RunWithTypes(IXsContext context)
 {
     if (WithTypes)
     {
         Initialize();
         ScriptContext c = (ScriptContext)context;
         c.Compiler.AddHeaders(GetTransformedValueStr());
         Code code = new Code();
         c.Initialize(code);
         Assembly a = c.GetClassInstanceType(code).Assembly;
         c.AddAssembly(a, true);
     }
 }
Ejemplo n.º 3
0
        private static List<IScriptAction> getCommandlineReferences(ScriptContext context)
        {
            List<IScriptAction> preScript = new List<IScriptAction>();
            if (context.IsSet(xs.@ref))
            {
                foreach (var param in context.GetStr(xs.@ref ?? string.Empty).Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
                {
                    string r = param.Trim();
                    bool withTypes = false;
                    bool file = false;

                    if (r.StartsWith("#", StringComparison.Ordinal))
                    {
                        withTypes = true;
                        r = r.Substring(1);
                    }
                    if (r.EndsWith(".dll",StringComparison.OrdinalIgnoreCase))
                        file = true;

                    if (!string.IsNullOrEmpty(r))
                    {
                        Reference rr = null;
                        bool addUsing = false;
                        if (r.StartsWith("@", StringComparison.Ordinal))
                        {
                            r = r.Substring(1);
                            addUsing = true;
                        }
                        if (file)
                        {
                            rr = new Reference {From = r, WithTypes = withTypes, Transform = TransformRules.None, AddUsing = addUsing};
                            preScript.Add(new Embed { From = r, IsAssembly = true, Transform = TransformRules.None });
                        }
                        else
                            rr = new Reference { Name = r, WithTypes = withTypes, Transform = TransformRules.None, AddUsing = addUsing };
                        if (withTypes)
                            context.AddAssembly(rr.AddReference(context, true),true);
                        preScript.Add(rr);
                    }
                }
            }
            return preScript;
        }
Ejemplo n.º 4
0
        private static Script execGenerator(ScriptContext context, string c, string prefix, string suffix)
        {
            Script script = createEmptyScript(context,"generated");
            if (context.Compiler.DefaultNETVersion>=new Version(3,5))
            {
                // Yeah, I know it's deprecated, and it's best to use full assembly names, but
                // but I don't really want to scan GAC myself
            #pragma warning disable 618
               context.AddAssembly(Assembly.LoadWithPartialName("System.Xml.Linq"),false);
               context.AddAssembly(Assembly.LoadWithPartialName("System.Core"),false);
            #pragma warning restore 618
            }
            script.Add(new Rem { Text = "----- Generated from command line -------"+Environment.NewLine+"\t"+ c + Environment.NewLine+"\t ------------"});
            script.Parameters.Add(new CommandLineParameter("arg", CommandLineValueCount.Multiple) {Last = true, Default = "",Required = false});
            script.UnknownSwitches = true;

            c = c.Trim();
            if (c.StartsWith("\"", StringComparison.Ordinal) && c.EndsWith("\"", StringComparison.Ordinal))
                c = c.Substring(1, c.Length - 2);
            if (c == "-")
                c = Console.In.ReadToEnd();
            if (c.StartsWith("="))
            {
                prefix = "=" + prefix;
                c = "${=" + c.Substring(1) + "}";
            }
            if (prefix!=null || suffix!=null)
                c = prefix + Environment.NewLine + c + Environment.NewLine + suffix;
            c = c.Replace("`", "\"");

            AppDomainLoader.progress("Read script begin");
            using (new ScriptContextScope(context))
                script.Load(c);
            AppDomainLoader.progress("Read script end");
            return script;
        }