Ejemplo n.º 1
0
        private static void ExecuteIronPython(string args)
        {
            //TODO: 1)Create ngine
            ScriptEngine engine = Python.CreateEngine();

            //TODO: 2)Provide script and arguments
            string       script = "";
            ScriptSource source = engine.CreateScriptSourceFromFile(script);

            engine.GetSysModule().SetVariable("", "");

            //TODO: 3)Output redirect
            ScriptIO eIO = engine.Runtime.IO;

            MemoryStream errors = new MemoryStream();

            eIO.SetErrorOutput(errors, Encoding.Default);

            var results = new MemoryStream();

            eIO.SetOutput(results, Encoding.Default);
            //TODO: 4)Execute script
            var scope = engine.CreateScope();

            source.Execute(scope);

            //TODO: 5)Display output
            string str(byte[] x) => Encoding.Default.GetString(x);

            Console.WriteLine("ERRORS:");
            Console.WriteLine(str(errors.ToArray()));
            Console.WriteLine();
            Console.WriteLine("Results:");
            Console.WriteLine(str(results.ToArray()));
        }
Ejemplo n.º 2
0
 public ActionResult Edit(PowerShellViewModel vmScript)
 {
     //For now - only editning the file - will need to allow for renames
     if (ScriptIO.Write(vmScript.Name, vmScript.Script))
     {
         return(RedirectToAction("Details", new { id = vmScript.Id }));
     }
     return(View(vmScript));
 }
Ejemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            var psMetadata = _scriptRepository.GetScriptById(id);

            if (ScriptIO.Delete(psMetadata.Name))
            {
                _scriptRepository.DeleteScript(id);
                _scriptRepository.Save();
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        // JSON GET: PowerShell/GetParams/1
        public JsonResult GetParams(int id)
        {
            var scriptName = _scriptRepository.GetScriptById(id).Name;

            if (scriptName == null)
            {
                return(Json(HttpNotFound()));
            }

            var psParams = ScriptIO.ScriptParams(scriptName) ??
                           new Dictionary <string, string> {
                { "Null", "Null" }
            };

            return(Json(psParams));
        }
Ejemplo n.º 5
0
        // GET: PowerShell/Details/1
        public ActionResult Details(int id)
        {
            var script = _scriptRepository.GetScriptById(id);

            if (script == null)
            {
                return(RedirectToAction("Index"));
            }

            var scriptContents = ScriptIO.Read(script.Name);

            var scriptView = new PowerShellViewModel()
            {
                Id     = script.Id,
                Name   = script.Name,
                Script = scriptContents
            };

            return(View(scriptView));
        }
Ejemplo n.º 6
0
        //GET: PowerShell/Schedule/1
        public ActionResult Schedule(int id)
        {
            var script = _scriptRepository.GetScriptById(id);

            if (script == null)
            {
                return(HttpNotFound());
            }

            var scriptParams = ScriptIO.ScriptParams(script.Name) ??
                               new Dictionary <string, string>();

            var scheduleView = new PowerShellSchedule()
            {
                Id        = script.Id,
                Date      = DateTime.Now,
                Recurring = JobServices.RecurringOptions(),
                PSparams  = scriptParams
            };

            return(PartialView(scheduleView));
        }
Ejemplo n.º 7
0
        //private void _A(object obj)
        //{
        //    if (obj == null)
        //        return;
        //    this._destination.Write(obj);
        //}

        //private void _APF(object prefix, MarcField field, string code)
        //{
        //    if (field == null)
        //        return;
        //    this._APS(prefix, (object)field.FM(code[0]), (object)null);
        //}

        //private void _APS(object prefix, object obj, object suffix)
        //{
        //    if (obj == null)
        //        return;
        //    this._A(prefix);
        //    this._A(obj);
        //    this._A(suffix);
        //}

        //private void _APSF(object prefix, MarcField field, string code, object suffix)
        //{
        //    if (field == null)
        //        return;
        //    this._APS(prefix, (object)field.FM(code[0]), suffix);
        //}

        //private void _ASF(MarcField field, string code)
        //{
        //    this._A((object)this._SF(field, code));
        //}

        //private void _CA(bool condition, object onTrue, object onFalse)
        //{
        //    this._A(condition ? onTrue : onFalse);
        //}

        //private object _IIF(object first, object second)
        //{
        //    return first ?? second;
        //}

        //private string _FM(string label)
        //{
        //    return this.Record.FM(label);
        //}

        //private string[] _FMA(string label)
        //{
        //    return this.Record.FMA(label);
        //}

        //private MarcField[] _GFA(string tag)
        //{
        //    return this.Record.Fields.GetAll(tag);
        //}

        //private MarcField _GF(string tag)
        //{
        //    return this.Record.Fields.GetFirst(tag);
        //}

        //private void _NL()
        //{
        //    this._destination.WriteLine();
        //}

        //private bool _P(string label)
        //{
        //    MarcLabel marcLabel = MarcLabel.Parse(label);
        //    MarcField first = this.Record.Fields.GetFirst(marcLabel.Tag);
        //    if (first == null)
        //        return false;
        //    return marcLabel.IsField || first.SubFields.GetFirst(marcLabel.Code) != null;
        //}

        //private string _PF(string prefix, MarcField field, string code)
        //{
        //    if (field != null)
        //    {
        //        string str = field.FM(code[0]);
        //        if (!string.IsNullOrEmpty(str))
        //            return prefix + str;
        //    }
        //    return (string)null;
        //}

        //private bool _PS(MarcField field, string code)
        //{
        //    return field.SubFields.GetFirst(code[0]) != null;
        //}

        //private string _SF(MarcField field, string code)
        //{
        //    if (field == null)
        //        return (string)null;
        //    return field.FM(code[0]);
        //}

        //private void _V(string label)
        //{
        //    string str = this.Record.FM(label);
        //    if (string.IsNullOrEmpty(str))
        //        return;
        //    this._destination.Write(str);
        //}

        //private void _VA(string label, string separator)
        //{
        //    string[] strArray = this.Record.FMA(label);
        //    if (ArrayUtility.IsNullOrEmpty((Array)strArray))
        //        return;
        //    this._destination.Write(string.Join(separator, strArray));
        //}

        //private void _VL(string label)
        //{
        //    this._V(label);
        //    this._NL();
        //}

        //private void _VLA(string label, string separator)
        //{
        //    this._VA(label, separator);
        //    this._NL();
        //}

        ///// <summary>Clears the cache.</summary>
        //public virtual void ClearCache()
        //{
        //    this._codeCache.Clear();
        //}

        #endregion

        #region Public methods

        public void FormatRecord
        (
            [NotNull] TextWriter output,
            [NotNull] MarcRecord record,
            [NotNull] string format
        )
        {
            Code.NotNull(output, "output");
            Code.NotNull(record, "record");
            Code.NotNullNorEmpty(format, "format");

            Output           = output;
            Record           = record;
            Locals["Record"] = record;
            ScriptIO          io          = Interpreter.Runtime.IO;
            InterceptorStream interceptor = new InterceptorStream
                                            (
                Output,
                io.OutputEncoding
                                            );

            io.SetOutput(interceptor, io.OutputEncoding);
        }
Ejemplo n.º 8
0
        public ActionResult Create([Bind("Name,Script")] PowerShellViewModel newScript)
        {
            if (ScriptIO.ScriptExists(newScript.Name)) //TODO: Ensure this works on ViewModel - Having Issues - 11/16/2015
            {
                ModelState.AddModelError("Name", "This Name Already Exists");
                return(View(newScript));
            }
            var script = ConvertServices.CreateScript(newScript, User.Identity.Name);

            if (TryValidateModel(script))
            {
                //Write File and Save Metadata
                if (ScriptIO.Write(newScript.Name, newScript.Script))
                {
                    //Save PowerShell Script
                    _scriptRepository.InsertScript(script);
                    _scriptRepository.Save();
                    //TODO: return RedirectToAction("Details", new { id = psScript.Id });
                    return(RedirectToAction("Index"));
                }
            }
            return(View(newScript));
        }
Ejemplo n.º 9
0
        //Get PowerShell/RunWithParams/1
        public ActionResult RunWithParams(int id)
        {
            var script = _scriptRepository.GetScriptById(id);

            if (script == null)
            {
                return(HttpNotFound());
            }

            var scriptParams = ScriptIO.ScriptParams(script.Name);

            if (scriptParams == null)
            {
                return(HttpNotFound());
            }

            var psParams = new PowerShellParam()
            {
                Id       = id,
                PSparams = scriptParams
            };

            return(PartialView(psParams));
        }
Ejemplo n.º 10
0
 /// <exception cref="ArgumentNullException"><paramref name="io"/> is a <c>null</c> reference.</exception>
 /// <exception cref="SerializationException"><paramref name="io"/> is remote.</exception>
 public static SharedIO GetSharedIO(ScriptIO io)
 {
     ContractUtils.RequiresNotNull(io, nameof(io));
     return(io.SharedIO);
 }