Esempio n. 1
0
    private static void _PreAction(ScriptEngine engine, IScriptAction command) {
      var loadCommand = command as LoadFileCommand;
      if (loadCommand != null) {
        Console.WriteLine("Loading from file " + loadCommand.FileName);
        return;
      }

      var saveCommand = command as SaveFileCommand;
      if (saveCommand != null) {
        Console.WriteLine("Saving to file " + saveCommand.FileName);
      }

      var resizeCommand = command as ResizeCommand;
      if (resizeCommand != null) {
        Console.WriteLine("Applying filter     : {0}", SupportedManipulators.MANIPULATORS.First(k => k.Value == resizeCommand.Manipulator).Key);
        Console.WriteLine("  Target percentage : {0}", (resizeCommand.Percentage == 0 ? "auto" : resizeCommand.Percentage + "%"));
        Console.WriteLine("  Target width      : {0}", (resizeCommand.Width == 0 ? "auto" : resizeCommand.Width + "pixels"));
        Console.WriteLine("  Target height     : {0}", (resizeCommand.Height == 0 ? "auto" : resizeCommand.Height + "pixels"));
        Console.WriteLine("  Hori. BPH         : {0}", resizeCommand.HorizontalBph);
        Console.WriteLine("  Vert. BPH         : {0}", resizeCommand.VerticalBph);
        Console.WriteLine("  Use Thresholds    : {0}", resizeCommand.UseThresholds);
        Console.WriteLine("  Centered Grid     : {0}", resizeCommand.UseCenteredGrid);
        Console.WriteLine("  Radius            : {0}", resizeCommand.Radius);
        Console.WriteLine("  Repeat            : {0} times", resizeCommand.Count);
      }

    }
Esempio n. 2
0
        public void AddControl(IScriptAction action)
        {
            if (action == null)
                throw new ArgumentNullException("action");

            _controlHandlers[action.GetType()](this, action);
        }
Esempio n. 3
0
        public static string GetMessage(IScriptAction action, Exception ex)
        {
            string actionId = (action != null ? action.Id : "unknown");
            string scriptId = (action != null && action.Script != null ? action.Script.Id : "unknown");

            return(String.Format("Exception occured in script '{0}' action '{1}'. See inner exception for details.", scriptId, actionId));
        }
Esempio n. 4
0
 /// <summary>
 /// Find an action with a specified ID
 /// </summary>
 /// <typeparam name="T">Type of action to find</typeparam>
 /// <param name="id">ID of the action to find</param>
 /// <returns>Found action or null if not found</returns>
 public T FindTree <T>(string id) where T : class, IScriptAction
 {
     // Push all objects
     foreach (CallStackItem item in this)
     {
         if (item.ScriptAction != null)
         {
             IScriptAction v = ScriptContext.FindTree(item.ScriptAction, delegate(IScriptAction x)
             {
                 if (!(x is T))
                 {
                     return(false);
                 }
                 if (id != null)
                 {
                     return(string.Compare(id, x.Id, StringComparison.OrdinalIgnoreCase) == 0);
                 }
                 return(false);
             });
             if (v != null)
             {
                 return((T)v);
             }
         }
     }
     return(null);
 }
Esempio n. 5
0
        public bool Execute()
        {
            if (Decision.ConditionsAreMet())
            {
                if (Decision is IDisposable)
                {
                    (Decision as IDisposable).Dispose();
                }

#if DEBUG && PC
                System.Console.WriteLine();
                System.Console.WriteLine(Decision.ToString());
#endif

                for (int i = 0; i < _actions.Count; i++)
                {
                    IScriptAction action = _actions[i];

                    action.Execute();
#if DEBUG && PC
                    System.Console.WriteLine(action.ToString());
#endif
                }


#if DEBUG && PC
                System.Console.WriteLine();
#endif

                return(true);
            }

            return(false);
        }
Esempio n. 6
0
        private static void _PostAction(ScriptEngine engine, IScriptAction command)
        {
            switch (command)
            {
            case LoadFileCommand loadCommand:
                Console.WriteLine("  File   : {0} Bytes", new FileInfo(loadCommand.FileName).Length);
                Console.WriteLine("  Width  : {0} Pixel", engine.SourceImage.Width);
                Console.WriteLine("  Height : {0} Pixel", engine.SourceImage.Height);
                Console.WriteLine("  Size   : {0:0.00} MegaPixel", engine.SourceImage.Width * engine.SourceImage.Height / 1000000.0);
                Console.WriteLine("  Type   : {0}", ImageCodecInfo.GetImageDecoders().First(d => d.FormatID == engine.GdiSource.RawFormat.Guid).FormatDescription);
                Console.WriteLine("  Format : {0}", engine.GdiSource.PixelFormat);
                return;

            case SaveFileCommand saveCommand: {
                var reloadedImage = Image.FromFile(saveCommand.FileName);
                Console.WriteLine("  File   : {0} Bytes", new FileInfo(saveCommand.FileName).Length);
                Console.WriteLine("  Width  : {0} Pixel", reloadedImage.Width);
                Console.WriteLine("  Height : {0} Pixel", reloadedImage.Height);
                Console.WriteLine("  Size   : {0:0.00} MegaPixel", reloadedImage.Width * reloadedImage.Height / 1000000.0);
                Console.WriteLine("  Type   : {0}", ImageCodecInfo.GetImageDecoders().First(d => d.FormatID == reloadedImage.RawFormat.Guid).FormatDescription);
                Console.WriteLine("  Format : {0}", reloadedImage.PixelFormat);
                break;
            }
            }
        }
Esempio n. 7
0
        private static void _PreAction(ScriptEngine engine, IScriptAction command)
        {
            switch (command)
            {
            case LoadFileCommand loadCommand:
                Console.WriteLine("Loading from file " + loadCommand.FileName);
                return;

            case SaveFileCommand saveCommand:
                Console.WriteLine("Saving to file " + saveCommand.FileName);
                break;

            case ResizeCommand resizeCommand:
                Console.WriteLine("Applying filter     : {0}", SupportedManipulators.MANIPULATORS.First(k => k.Value == resizeCommand.Manipulator).Key);
                Console.WriteLine("  Target percentage : {0}", resizeCommand.Percentage == 0 ? "auto" : resizeCommand.Percentage + "%");
                Console.WriteLine("  Target width      : {0}", resizeCommand.Width == 0 ? "auto" : resizeCommand.Width + "pixels");
                Console.WriteLine("  Target height     : {0}", resizeCommand.Height == 0 ? "auto" : resizeCommand.Height + "pixels");
                Console.WriteLine("  Hori. BPH         : {0}", resizeCommand.HorizontalBph);
                Console.WriteLine("  Vert. BPH         : {0}", resizeCommand.VerticalBph);
                Console.WriteLine("  Use Thresholds    : {0}", resizeCommand.UseThresholds);
                Console.WriteLine("  Centered Grid     : {0}", resizeCommand.UseCenteredGrid);
                Console.WriteLine("  Radius            : {0}", resizeCommand.Radius);
                Console.WriteLine("  Repeat            : {0} times", resizeCommand.Count);
                break;
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Add action to Try block
 /// </summary>
 /// <param name="action">Action to add</param>
 public void AddTry(IScriptAction action)
 {
     if (Try == null)
     {
         Try = new Block();
     }
     Try.Add(action);
 }
Esempio n. 9
0
 /// <summary>
 /// Add action to Catch block
 /// </summary>
 /// <param name="action">Action to add</param>
 public void AddCatch(IScriptAction action)
 {
     if (Catch == null)
     {
         Catch = new Block();
     }
     Catch.Add(action);
 }
Esempio n. 10
0
 /// <summary>
 /// Add action to Finally block
 /// </summary>
 /// <param name="action">Action to add</param>
 public void AddFinally(IScriptAction action)
 {
     if (Finally == null)
     {
         Finally = new Block();
     }
     Finally.Add(action);
 }
Esempio n. 11
0
 /// Add an action to Else block
 public void AddElse(IScriptAction action)
 {
     if (Else == null)
     {
         Else = new Block();
     }
     Else.Add(action);
 }
Esempio n. 12
0
        public void AddControl(IScriptAction action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            _controlHandlers[action.GetType()](this, action);
        }
Esempio n. 13
0
 /**
  * Gets all event actions for a scripted event.
  * @param eventID the event ID - usually the script message #
  * @return {@link IScriptAction}[]
  */
 /// <summary>
 /// Gets all event actions for a scripted event.
 /// </summary>
 /// <param name="eventID">the event ID - usually the script message #</param>
 /// <returns><see cref="IScriptAction"/>[]</returns>
 public IScriptAction[] GetEventActions(int eventID)
 {
     IScriptAction[] actions = new IScriptAction[0];
     if (eventActions[eventID] == null)
     {
         eventActions.Add(eventID, actions);
     }
     return(eventActions[eventID]);
 }
Esempio n. 14
0
 TreeNode GetTreeNodeForAction(IScriptAction action, TreeNode parentNode)
 {
     foreach (TreeNode node in parentNode.Nodes)
     {
         if (node.Tag == action)
         {
             return(node);
         }
     }
     return(null);
 }
Esempio n. 15
0
        void compile(IScriptAction action, bool runtime)
        {
            Dictionary <string, Code> newCode = new Dictionary <string, Code>();

            walkBreadthFirst(action, obj =>
            {
                Code c = obj as Code;
                if (c != null && (runtime || !c.Dynamic) && (c as CompiledCode) == null)
                {
                    string classname = c.GetClassName();
                    if (!_loadedCode.ContainsKey(classname) && !newCode.ContainsKey(classname))
                    {
                        newCode[classname] = c;
                    }
                }
            }, false);


            StringBuilder sb = new StringBuilder();

            sb.AppendLine(Compiler.GenerateFileHeader());
            sb.AppendLine();
            foreach (Code s in newCode.Values)
            {
                sb.AppendLine(s.GenerateSourceCode(this, false, true));
            }
            sb.AppendLine();

            string currentId = Compiler.GetFileHeaderCodeId();

            string code = sb.ToString();

            bool shouldCompile = (newCode.Count > 0);

            if (!shouldCompile && !Compiler.IsTrivialFileHeader())
            {
                shouldCompile = !_typeManager.IsCompiled(currentId);
            }

            if (shouldCompile)
            {
                WriteVerbose("Context> Starting script compilation");
                Assembly a = Compiler.Compile(CompiledOutputType.InMemoryAssembly, code, "code_" + action.Id, new CompileOptions
                {
                    CodeOutputDirectory = CodeOutputDirectory,
                    StreamProvider      = FindResourceMemoryStream
                });
                foreach (string d in newCode.Keys)
                {
                    _loadedCode[d] = a;
                }
                _typeManager.AddAssembly(a, false);
            }
        }
Esempio n. 16
0
 /// <summary>
 /// Adds a {@link IScriptAction} to the list of actions for an event.
 /// </summary>
 /// <param name="eventID">the event ID - usually the script message #</param>
 /// <param name="action">the script action</param>
 public void AddScriptAction(int eventID, IScriptAction action)
 {
     if (eventActions[eventID] == null)
     {
         eventActions[eventID] = new IScriptAction[0];
     }
     if (action != null)
     {
         action.SetScript(this);
         eventActions.Add(eventID, ArrayUtilities.Instance.ExtendArray(action, eventActions[eventID]));
     }
 }
Esempio n. 17
0
        private static void walkBreadthFirst(IScriptAction start, Action <IScriptAction> action, bool isFind)
        {
            Queue <IScriptAction> queue = new Queue <IScriptAction>();

            queue.Enqueue(start);
            while (queue.Count > 0)
            {
                IScriptAction obj = queue.Dequeue();
                if (obj == null)
                {
                    continue;
                }

                action(obj);
                obj.ForAllChildren(delegate(IScriptAction s) { queue.Enqueue(s); return(false); }, isFind);
            }
        }
        public void AddAction(IScriptAction action)
        {
            //Need to begin do section when in simple mode
            if (_mode == Modes.Simple && !_inDo)
            {
                ((IDoScriptEngine)this).Begin();
                _inDo = true;
            }

            if (_inActionRegion || _mode == Modes.Simple)
            {
                CurrentScript.Actions.Add(action);
            }
            else
            {
                throw new Exception("Can not add action here.");
            }
        }
Esempio n. 19
0
        /// Call script subroutine with a given ID with parameters
        public object Call(string id, params object[] parameters)
        {
            IScriptAction f = Find <Sub>(id);

            if (f == null)
            {
                throw new ParsingException("A subroutine with id=" + id + " not found");
            }
            List <CallParam> param = new List <CallParam>();

            foreach (var p in parameters)
            {
                param.Add(new CallParam(null, p, TransformRules.None));
            }
            object r = ExecuteAction(f, param, CallIsolation.Default);

            return(ReturnValue.Unwrap(r));
        }
Esempio n. 20
0
        /// Execute the given script action on call stack
        protected object RunOnStack(ScriptOperation operation, IScriptAction action, ScriptExecuteMethod method)
        {
            if (action == null)
            {
                return(null);
            }

            using (var scope = new ScriptContextScope(this))
            {
                _callStack.Push(operation, action);

                OnProgress(0);
                try
                {
                    // one can put a breakpoint here to be called on every method call
                    object ret = method();
                    OnProgressInternal(100, null);
                    return(ret);
                }
                catch (ScriptTerminateException)
                {
                    throw;
                }
                catch (ScriptExceptionWithStackTrace)
                {
                    throw;
                }
                catch (ThreadAbortException)
                {
                    _abortStarted = true;
                    throw;
                }
                catch (Exception e)
                {
                    throw new ScriptExceptionWithStackTrace(this, e);
                }
                finally
                {
                    _callStack.Pop();
                }
            }
        }
Esempio n. 21
0
        public WelcomePage(ScriptRunner runner, IScriptAction action, IScriptContinuation continuation)
        {
            if (runner == null)
            {
                throw new ArgumentNullException("runner");
            }
            if (continuation == null)
            {
                throw new ArgumentNullException("continuation");
            }

            _continuation = continuation;

            InitializeComponent();

            switch (runner.Mode)
            {
            case ScriptRunnerMode.Install:
                _headerLabel.Text = String.Format(UILabels.InstallWelcome, runner.Environment.Config.SetupTitle);
                _wizardLabel.Text = String.Format(UILabels.InstallWelcomeSubText, runner.Environment.Config.SetupTitle);
                break;

            case ScriptRunnerMode.Update:
                _headerLabel.Text = String.Format(UILabels.UpdateWelcome, runner.Environment.Config.SetupTitle);
                _wizardLabel.Text = String.Format(UILabels.UpdateWelcomeSubText, runner.Environment.Config.SetupTitle);
                break;

            case ScriptRunnerMode.Uninstall:
                _headerLabel.Text = String.Format(UILabels.UninstallWelcome, runner.Environment.Config.SetupTitle);
                _wizardLabel.Text = String.Format(UILabels.UninstallWelcomeSubText, runner.Environment.Config.SetupTitle);
                break;
            }

            bool isLast = false;

            if (action is PageInstallWelcome)
            {
                isLast = ((PageInstallWelcome)action).IsLast;
            }

            PageUtil.UpdateAcceptButton(_acceptButton, isLast);
        }
Esempio n. 22
0
        public object ExecuteMember(CallIsolation isolation, string name, object[] par)
        {
            IScriptAction f = Methods.Items.Find(delegate(IScriptAction x) { return(x.Id == name); });

            if (f == null)
            {
                throw new ParsingException("Cannot find method " + name);
            }

            List <CallParam> cp = new List <CallParam>();

            if (par != null)
            {
                foreach (var o in par)
                {
                    cp.Add(new CallParam(null, o, TransformRules.None));
                }
            }
            return(Context.ExecuteAction(f, cp, isolation));
        }
Esempio n. 23
0
        private void AddControlToPage(IScriptAction action)
        {
            if (InvokeRequired)
            {
                Invoke(new Action(() => AddControlToPage(action)));
                return;
            }

            IControlHostPage controlHostPage = null;

            if (Controls.Count > 0)
            {
                controlHostPage = Controls[0] as IControlHostPage;
            }

            if (controlHostPage == null)
            {
                throw new NuGetUpdateException(UILabels.PageNotControlHost);
            }

            controlHostPage.AddControl(action);
        }
Esempio n. 24
0
        /// Add action to the code
        public void Add(IScriptAction action)
        {
            string methodId;

            for (int n = 0; ; ++n)
            {
                if (string.IsNullOrEmpty(action.Id))
                {
                    methodId = "_" + CustomAttributeHelper.First <XsTypeAttribute>(action.GetType()).Name;
                }
                else
                {
                    methodId = action.Id;
                }
                if (n != 0)
                {
                    methodId += n;
                }
                if (!_methodNames.ContainsKey(methodId))
                {
                    _methodNames[methodId] = true;
                    break;
                }
            }
            if (action is Script || methodId == action.Id || action is Sub)
            {
                Methods.Add(action);
            }
            else
            {
                Sequence b = new Sequence {
                    Id = methodId
                };
                b.Add(action);
                Methods.Add(b);
                Value += Environment.NewLine + "{ object __ret=" + methodId + "_inline(); if (__ret!=null) return __ret;}";
            }
        }
Esempio n. 25
0
 public virtual void Initialize(IScriptAction action)
 {
     if (action != null)
     {
         RunOnStack(ScriptOperation.Initializing, action, delegate
         {
             action.Initialize();
             return(null);
         });
         Script s = action as Script;
         if (CallStack.Count == 0 && s != null)
         {
             if (EnableCodePrecompilation)
             {
                 RunOnStack(ScriptOperation.Compiling, s, delegate
                 {
                     compile(s, false);
                     return(null);
                 });
             }
         }
     }
 }
Esempio n. 26
0
        /// <summary>
        /// Executes the given action.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="addToList">if set to <c>true</c> the action will be added to the action list afterwards.</param>
        private void _ExecuteAction(IScriptAction action, bool addToList)
        {
            Contract.Requires(action != null);

            action.SourceImage = this.SourceImage;
            action.TargetImage = this.TargetImage;

            this.IsSourceImageChanged = false;
            this.IsTargetImageChanged = false;

            var result = action.Execute();

            // execution of action failed
            Contract.Assert(result, "action failed somehow");

            if (addToList)
            {
                this.AddWithoutExecution(action);
            }

            if (action.ChangesSourceImage)
            {
                this.SourceImage          = action.SourceImage;
                this.IsSourceImageChanged = true;
            }

            if (action.ChangesTargetImage)
            {
                this.TargetImage          = action.TargetImage;
                this.IsTargetImageChanged = true;
            }

            if (action.ProvidesNewGdiSource)
            {
                this._gdiSource = action.GdiSource;
            }
        }
Esempio n. 27
0
        public WelcomePage(ScriptRunner runner, IScriptAction action, IScriptContinuation continuation)
        {
            if (runner == null)
                throw new ArgumentNullException("runner");
            if (continuation == null)
                throw new ArgumentNullException("continuation");

            _continuation = continuation;

            InitializeComponent();

            switch (runner.Mode)
            {
                case ScriptRunnerMode.Install:
                    _headerLabel.Text = String.Format(UILabels.InstallWelcome, runner.Environment.Config.SetupTitle);
                    _wizardLabel.Text = String.Format(UILabels.InstallWelcomeSubText, runner.Environment.Config.SetupTitle);
                    break;

                case ScriptRunnerMode.Update:
                    _headerLabel.Text = String.Format(UILabels.UpdateWelcome, runner.Environment.Config.SetupTitle);
                    _wizardLabel.Text = String.Format(UILabels.UpdateWelcomeSubText, runner.Environment.Config.SetupTitle);
                    break;

                case ScriptRunnerMode.Uninstall:
                    _headerLabel.Text = String.Format(UILabels.UninstallWelcome, runner.Environment.Config.SetupTitle);
                    _wizardLabel.Text = String.Format(UILabels.UninstallWelcomeSubText, runner.Environment.Config.SetupTitle);
                    break;
            }

            bool isLast = false;

            if (action is PageInstallWelcome)
                isLast = ((PageInstallWelcome)action).IsLast;

            PageUtil.UpdateAcceptButton(_acceptButton, isLast);
        }
Esempio n. 28
0
        /// <summary>
        /// Search action in the tree
        /// </summary>
        /// <param name="start">Node where to start</param>
        /// <param name="func">Predicate to execute</param>
        /// <returns>Found action or null</returns>
        static public IScriptAction FindTree(IScriptAction start, Predicate <IScriptAction> func)
        {
            Queue <IScriptAction> queue = new Queue <IScriptAction>();

            queue.Enqueue(start);
            while (queue.Count > 0)
            {
                IScriptAction obj = queue.Dequeue();
                if (obj != null)
                {
                    if (func(obj))
                    {
                        return(obj);
                    }

                    obj.ForAllChildren(delegate(IScriptAction s)
                    {
                        queue.Enqueue(s);
                        return(false);
                    }, true);
                }
            }
            return(null);
        }
Esempio n. 29
0
        /// <summary>
        /// Execute script action
        /// </summary>
        /// <param name="action">action to execute</param>
        /// <param name="args">list of parameters, in case the action is Call</param>
        /// <param name="isolation">isolation</param>
        /// <returns>action result</returns>
        public object ExecuteAction(IScriptAction action, IEnumerable <CallParam> args, CallIsolation isolation)
        {
            Vars snapshot = null;

            if (isolation != CallIsolation.None)
            {
                snapshot = new Vars(this);
            }
            try
            {
                // Clear vars
                if (isolation == CallIsolation.High)
                {
                    base.Clear();
                }


                return(RunOnStack(ScriptOperation.Executing, action, delegate
                {
                    Sub sub = action as Sub;
                    if (sub != null)
                    {
                        return sub.ExecuteSub(args);
                    }
                    return action.Execute();
                }));
            }
            finally
            {
                if (snapshot != null)
                {
                    base.Clear();
                    AddRange(snapshot);
                }
            }
        }
Esempio n. 30
0
 /// Add an action to Else block
 public void AddElse(IScriptAction action)
 {
     if (Else == null)
         Else = new Block();
     Else.Add(action);
 }
Esempio n. 31
0
 /// <summary>
 /// Add action to Catch block
 /// </summary>
 /// <param name="action">Action to add</param>
 public void AddCatch(IScriptAction action)
 {
     if (Catch== null)
         Catch = new Block();
     Catch.Add(action);
 }
Esempio n. 32
0
 /// <summary>
 /// Add action to Try block
 /// </summary>
 /// <param name="action">Action to add</param>
 public void AddTry(IScriptAction action)
 {
     if (Try == null)
         Try = new Block();
     Try.Add(action);
 }
Esempio n. 33
0
 /// <summary>
 /// Add action to Finally block
 /// </summary>
 /// <param name="action">Action to add</param>
 public void AddFinally(IScriptAction action)
 {
     if (Finally== null)
         Finally = new Block();
     Finally.Add(action);
 }
Esempio n. 34
0
    /// <summary>
    /// Executes the given action.
    /// </summary>
    /// <param name="action">The action.</param>
    /// <param name="addToList">if set to <c>true</c> the action will be added to the action list afterwards.</param>
    private void _ExecuteAction(IScriptAction action, bool addToList) {
      Contract.Requires(action != null);

      action.SourceImage = this.SourceImage;
      action.TargetImage = this.TargetImage;

      this.IsSourceImageChanged = false;
      this.IsTargetImageChanged = false;

      var result = action.Execute();

      // execution of action failed
      Contract.Assert(result, "action failed somehow");

      if (addToList)
        this.AddWithoutExecution(action);

      if (action.ChangesSourceImage) {
        this.SourceImage = action.SourceImage;
        this.IsSourceImageChanged = true;
      }

      if (action.ChangesTargetImage) {
        this.TargetImage = action.TargetImage;
        this.IsTargetImageChanged = true;
      }

      if (action.ProvidesNewGdiSource)
        this._gdiSource = action.GdiSource;
    }
Esempio n. 35
0
 TreeNode GetTreeNodeForAction(IScriptAction action, TreeNode parentNode)
 {
     foreach (TreeNode node in parentNode.Nodes)
     {
         if (node.Tag == action)
         {
             return node;
         }
     }
     return null;            
 }
Esempio n. 36
0
    private static void _PostAction(ScriptEngine engine, IScriptAction command) {

      var loadCommand = command as LoadFileCommand;
      if (loadCommand != null) {
        Console.WriteLine("  File   : {0} Bytes", new FileInfo(loadCommand.FileName).Length);
        Console.WriteLine("  Width  : {0} Pixel", engine.SourceImage.Width);
        Console.WriteLine("  Height : {0} Pixel", engine.SourceImage.Height);
        Console.WriteLine("  Size   : {0:0.00} MegaPixel", (engine.SourceImage.Width * engine.SourceImage.Height / 1000000.0));
        Console.WriteLine("  Type   : {0}", ImageCodecInfo.GetImageDecoders().First(d => d.FormatID == engine.GdiSource.RawFormat.Guid).FormatDescription);
        Console.WriteLine("  Format : {0}", engine.GdiSource.PixelFormat);
        return;
      }

      var saveCommand = command as SaveFileCommand;
      if (saveCommand != null) {
        var reloadedImage = Image.FromFile(saveCommand.FileName);
        Console.WriteLine("  File   : {0} Bytes", new FileInfo(saveCommand.FileName).Length);
        Console.WriteLine("  Width  : {0} Pixel", reloadedImage.Width);
        Console.WriteLine("  Height : {0} Pixel", reloadedImage.Height);
        Console.WriteLine("  Size   : {0:0.00} MegaPixel", (reloadedImage.Width * reloadedImage.Height / 1000000.0));
        Console.WriteLine("  Type   : {0}", ImageCodecInfo.GetImageDecoders().First(d => d.FormatID == reloadedImage.RawFormat.Guid).FormatDescription);
        Console.WriteLine("  Format : {0}", reloadedImage.PixelFormat);
      }
    }
Esempio n. 37
0
 public CallStackItem(ScriptOperation operation, IScriptAction o)
 {
     Operation    = operation;
     ScriptAction = o;
 }
Esempio n. 38
0
    /// <summary>
    /// Gets the command text for a given action.
    /// </summary>
    /// <param name="action">The action.</param>
    /// <returns>The command text needed to reproduce the action.</returns>
    private static string _GetCommandTextForAction(IScriptAction action) {
      Contract.Requires(action != null);
      var loadAction = action as LoadFileCommand;
      if (loadAction != null)
        return (string.Format(@"{0} ""{1}""", LOAD_COMMAND_NAME, loadAction.FileName));

      var saveAction = action as SaveFileCommand;
      if (saveAction != null)
        return (string.Format(@"{0} ""{1}""", SAVE_COMMAND_NAME, saveAction.FileName));

      var resizeAction = action as ResizeCommand;
      if (resizeAction != null) {
        var manipulator = resizeAction.Manipulator;
        string dimensions;
        if (manipulator.SupportsWidth && manipulator.SupportsHeight)
          dimensions = resizeAction.Percentage > 0 ? string.Format("{0}%", resizeAction.Percentage) : string.Format("{0}x{1}", resizeAction.Width, resizeAction.Height);
        else if (manipulator.SupportsWidth)
          dimensions = string.Format("w{0}", resizeAction.Width);
        else if (manipulator.SupportsHeight)
          dimensions = string.Format("h{0}", resizeAction.Height);
        else
          dimensions = "auto";

        var parameters = new List<string> {
          HBOUNDS_PARAMETER_NAME+"="+_ConvertOutOfBoundsModeToText(resizeAction.HorizontalBph),
          VBOUNDS_PARAMETER_NAME+"="+_ConvertOutOfBoundsModeToText(resizeAction.VerticalBph),
        };

        if (manipulator.SupportsRepetitionCount && resizeAction.Count > 1)
          parameters.Add(REPEAT_PARAMETER_NAME + "=" + resizeAction.Count.ToString(CultureInfo.InvariantCulture));

        if (manipulator.SupportsThresholds)
          parameters.Add(THRESHOLDS_PARAMETER_NAME + "=" + (resizeAction.UseThresholds ? "1" : "0"));

        if (manipulator.SupportsGridCentering)
          parameters.Add(CENTERED_GRID_PARAMETER_NAME + "=" + (resizeAction.UseCenteredGrid ? "1" : "0"));

        if (manipulator.SupportsRadius)
          parameters.Add(RADIUS_PARAMETER_NAME + "=" + resizeAction.Radius.ToString(CultureInfo.InvariantCulture));

        return (string.Format(@"{0} {1} ""{2}({3})""", RESIZE_COMMAND_NAME, dimensions, SupportedManipulators.MANIPULATORS.First(m => m.Value == manipulator).Key, string.Join(", ", parameters)));
      }

      return (null);
    }
        /// <summary>
        /// Gets the command text for a given action.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <returns>The command text needed to reproduce the action.</returns>
        private static string _GetCommandTextForAction(IScriptAction action)
        {
            Contract.Requires(action != null);
            var loadAction = action as LoadFileCommand;

            if (loadAction != null)
            {
                return(string.Format(@"{0} ""{1}""", LOAD_COMMAND_NAME, loadAction.FileName));
            }

            var saveAction = action as SaveFileCommand;

            if (saveAction != null)
            {
                return(string.Format(@"{0} ""{1}""", SAVE_COMMAND_NAME, saveAction.FileName));
            }

            var resizeAction = action as ResizeCommand;

            if (resizeAction != null)
            {
                var    manipulator = resizeAction.Manipulator;
                string dimensions;
                if (manipulator.SupportsWidth && manipulator.SupportsHeight)
                {
                    dimensions = resizeAction.Percentage > 0 ? string.Format("{0}%", resizeAction.Percentage) : string.Format("{0}x{1}", resizeAction.Width, resizeAction.Height);
                }
                else if (manipulator.SupportsWidth)
                {
                    dimensions = string.Format("w{0}", resizeAction.Width);
                }
                else if (manipulator.SupportsHeight)
                {
                    dimensions = string.Format("h{0}", resizeAction.Height);
                }
                else
                {
                    dimensions = "auto";
                }

                var parameters = new List <string> {
                    HBOUNDS_PARAMETER_NAME + "=" + _ConvertOutOfBoundsModeToText(resizeAction.HorizontalBph),
                    VBOUNDS_PARAMETER_NAME + "=" + _ConvertOutOfBoundsModeToText(resizeAction.VerticalBph),
                };

                if (manipulator.SupportsRepetitionCount && resizeAction.Count > 1)
                {
                    parameters.Add(REPEAT_PARAMETER_NAME + "=" + resizeAction.Count.ToString(CultureInfo.InvariantCulture));
                }

                if (manipulator.SupportsThresholds)
                {
                    parameters.Add(THRESHOLDS_PARAMETER_NAME + "=" + (resizeAction.UseThresholds ? "1" : "0"));
                }

                if (manipulator.SupportsGridCentering)
                {
                    parameters.Add(CENTERED_GRID_PARAMETER_NAME + "=" + (resizeAction.UseCenteredGrid ? "1" : "0"));
                }

                if (manipulator.SupportsRadius)
                {
                    parameters.Add(RADIUS_PARAMETER_NAME + "=" + resizeAction.Radius.ToString(CultureInfo.InvariantCulture));
                }

                return(string.Format(@"{0} {1} ""{2}({3})""", RESIZE_COMMAND_NAME, dimensions, SupportedManipulators.MANIPULATORS.First(m => m.Value == manipulator).Key, string.Join(", ", parameters)));
            }

            return(null);
        }
Esempio n. 40
0
 public void Push(ScriptOperation operation, IScriptAction action)
 {
     Push(new CallStackItem(operation, action));
 }
Esempio n. 41
0
        /// <summary>
        /// Process inner node
        /// </summary>
        /// <param name="context">XML context</param>
        /// <param name="reader">Reader</param>
        protected override void ProcessInnerNode(IXsContext context, XmlReader reader)
        {
            PropertyInfo collProperty = null;

            switch (reader.NodeType)
            {
            case XmlNodeType.Comment:
                collProperty = FindCollectionForNode(reader);
                if (collProperty != null)
                {
                    SetChildObject(reader, new Rem(reader.Value), null, collProperty);
                }
                reader.Read();
                break;

            case XmlNodeType.ProcessingInstruction:
                IScriptAction a = null;

                if (string.Compare(reader.LocalName, "_", StringComparison.OrdinalIgnoreCase) == 0 ||
                    string.Compare(reader.LocalName, "code", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    a = new Code(reader.Value);
                }
                else if (string.Compare(reader.LocalName, "_d", StringComparison.OrdinalIgnoreCase) == 0 ||
                         string.Compare(reader.LocalName, "codeD", StringComparison.OrdinalIgnoreCase) == 0 ||
                         string.Compare(reader.LocalName, "codeDynamic", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    a = new Code(reader.Value)
                    {
                        Dynamic = true
                    }
                }
                ;
                else if (string.Compare(reader.LocalName, "header", StringComparison.OrdinalIgnoreCase) == 0 ||
                         string.Compare(reader.LocalName, "h", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    a = new Header(reader.Value);
                }
                else if (string.Compare(reader.LocalName, "headerWithTypes", StringComparison.OrdinalIgnoreCase) == 0 ||
                         string.Compare(reader.LocalName, "ht", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    var h = new Header(reader.Value)
                    {
                        WithTypes = true
                    };
                    h.RunWithTypes(context);
                    a = h;
                }
                else if (string.Compare(reader.LocalName, "rem", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    a = new Rem {
                        Text = reader.Value
                    }
                }
                ;
                else if (string.Compare(reader.LocalName, "xsharper-args", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    reader.Read();
                    break;
                }


                if (a == null)
                {
                    throw new XsException(reader, string.Format("Unexpected processing instruction {0}", reader.Name));
                }


                if (this is Code)
                {
                    if (a is Code)
                    {
                        ProcessAttribute(context, string.Empty, reader.Value, null);
                    }
                    else
                    {
                        ((Code)this).Add(a);
                    }
                }
                else
                {
                    collProperty = FindCollectionForNode(reader);
                    try
                    {
                        SetChildObject(reader, a, null, collProperty);
                    }
                    catch (XsException)
                    {
                        if (!(a is Rem))
                        {
                            throw;
                        }
                    }
                }
                //    coll.Add(a);

                reader.Read();
                break;

            default:
                base.ProcessInnerNode(context, reader);
                break;
            }
        }
Esempio n. 42
0
 public void tick()
 {
     if (isRunning)
     {
         if (current == null || current.Finished)
         {
             if (cursor >= actions.Count)
             {
                 if (bLoop && actions.Count > 0)
                 {
                     cursor = 0;
                 }
                 else
                 {
                     isRunning = false;
                 }
             }
             else
             {
                 current = actions[cursor++];
                 current.invoke();
             }
         }
         else
             current.tick();
     }
 }
Esempio n. 43
0
 /// <summary>
 /// Executes the action.
 /// </summary>
 /// <param name="action">The action.</param>
 public void ExecuteAction(IScriptAction action) {
   this._ExecuteAction(action, true);
 }
Esempio n. 44
0
 public void add(IScriptAction action)
 {
     actions.Add(action);
 }
Esempio n. 45
0
 /// <summary>
 /// Adds the given action without executing it.
 /// </summary>
 /// <param name="action">The action.</param>
 public void AddWithoutExecution(IScriptAction action) {
   Contract.Requires(action != null);
   this._actionList.Add(action);
 }
Esempio n. 46
0
 /// Add action to the code
 public void Add(IScriptAction action)
 {
     string methodId;
     for (int n = 0; ; ++n)
     {
         if (string.IsNullOrEmpty(action.Id))
             methodId = "_" + CustomAttributeHelper.First<XsTypeAttribute>(action.GetType()).Name;
         else
             methodId = action.Id;
         if (n != 0)
             methodId += n;
         if (!_methodNames.ContainsKey(methodId))
         {
             _methodNames[methodId] = true;
             break;
         }
     }
     if (action is Script || methodId==action.Id || action is Sub)
     {
         Methods.Add(action);
     }
     else
     {
         Sequence b = new Sequence { Id = methodId };
         b.Add(action);
         Methods.Add(b);
         Value += Environment.NewLine + "{ object __ret=" + methodId + "_inline(); if (__ret!=null) return __ret;}";
     }
 }
Esempio n. 47
0
        public void AddAction(IScriptAction action)
        {
            //Need to begin do section when in simple mode
            if (_mode == Modes.Simple && !_inDo)
            {
                ((IDoScriptEngine)this).Begin();
                _inDo = true;
            }

            if(_inActionRegion || _mode == Modes.Simple)
                CurrentScript.Actions.Add(action);
            else 
                throw new Exception("Can not add action here.");
        }