Beispiel #1
0
 protected TransactedTool(DocumentWorkspace documentWorkspace, ImageResource toolBarImage, string name, string helpText, char hotKey, bool skipIfActiveOnHotKey, ToolBarConfigItems toolBarConfigItems, bool isCommitSupported) : base(documentWorkspace, toolBarImage, name, helpText, hotKey, skipIfActiveOnHotKey, toolBarConfigItems)
 {
     this.commitChangesRegion  = new ProtectedRegion("CommitChanges", ProtectedRegionOptions.ErrorOnPerThreadReentrancy);
     this.updateStatusCallback = new Action(this.UpdateStatus);
     this.state             = TransactedToolState.Inactive;
     base.IsCommitSupported = isCommitSupported;
 }
 public BitmapLayerTransactionHandler(TTool tool, bool autoClipToSelection)
 {
     this.updateLayerOverlayRegion = new ProtectedRegion("UpdateLayerOverlay", ProtectedRegionOptions.ErrorOnPerThreadReentrancy | ProtectedRegionOptions.DisablePumpingWhenEntered);
     Validate.IsNotNull <TTool>(tool, "tool");
     this.tool = tool;
     this.autoClipToSelection = autoClipToSelection;
 }
Beispiel #3
0
 public void Dispose()
 {
     if (this.owner != null)
     {
         this.owner.Exit();
         this.owner = null;
     }
 }
Beispiel #4
0
        protected override void Run()
        {
            exceptionType = TypeSystem.GetTypeByName("System", "Exception");

            InsertBlockProtectInstructions();
            UpdateBlockProtectInstructions();

            MethodCompiler.SetProtectedRegions(ProtectedRegion.CreateProtectedRegions(BasicBlocks, MethodCompiler.Method.ExceptionHandlers));
        }
        protected override void Run()
        {
            if (!MethodCompiler.IsCILDecodeRequired)
            {
                return;
            }

            InsertBlockProtectInstructions();
            UpdateBlockProtectInstructions();

            MethodCompiler.ProtectedRegions = ProtectedRegion.CreateProtectedRegions(BasicBlocks, Method.ExceptionHandlers);
        }
Beispiel #6
0
        private static List <ProtectedRegion> GetRegions(CilMethod method)
        {
            var mtdb = method.MethodBody;

            if (mtdb == null)
            {
                return new List <ProtectedRegion>()
                       {
                           null
                       }
            }
            ;

            var ex = mtdb
                     .ExceptionHandlingClauses
                     .GroupBy(e => new { e.TryOffset, e.TryLength });

            var regions = new List <ProtectedRegion>();

            foreach (var clauseGroup in ex)
            {
                var result = new ProtectedRegion();

                var key = clauseGroup.Key;

                result.TrySpan = new ProtectedRegionSpan(key.TryOffset, key.TryOffset + key.TryLength, RegionKind.Try);

                result.CatchSpan = clauseGroup
                                   .Where(e => e.Flags == ExceptionHandlingClauseOptions.Clause)
                                   .Select(
                    e => new ProtectedRegionSpan(e.HandlerOffset, e.HandlerOffset + e.HandlerLength, RegionKind.Catch)
                {
                    CatchType = e.CatchType
                })
                                   .ToList();

                var finallyClause = clauseGroup.FirstOrDefault(f => f.Flags == ExceptionHandlingClauseOptions.Finally);
                if (finallyClause != null)
                {
                    result.FinallySpan = new ProtectedRegionSpan(finallyClause.HandlerOffset, finallyClause.HandlerOffset + finallyClause.HandlerLength, RegionKind.Finally);
                }

                var faultClause = clauseGroup.FirstOrDefault(f => f.Flags == ExceptionHandlingClauseOptions.Fault);
                if (faultClause != null)
                {
                    result.FaultSpan = new ProtectedRegionSpan(faultClause.HandlerOffset, faultClause.HandlerOffset + faultClause.HandlerLength, RegionKind.Fault);
                }

                regions.Add(result);
            }
            return(regions);
        }
    }
        protected override void Run()
        {
            if (IsMethodPlugged)
            {
                return;
            }

            InsertBlockProtectInstructions();
            UpdateBlockProtectInstructions();

            MethodCompiler.ProtectedRegions = ProtectedRegion.CreateProtectedRegions(BasicBlocks, MethodCompiler.Method.ExceptionHandlers);
        }
        protected override void Run()
        {
            if (IsMethodPlugged)
            {
                return;
            }

            if (!HasProtectedRegions)
            {
                return;
            }

            ProtectedRegion.FinalizeAll(BasicBlocks, MethodCompiler.ProtectedRegions);

            EmitProtectedRegionTable();
        }
Beispiel #9
0
        private static void RewriteBlock(Block block)
        {
            var replacements = new List <List <Block> >();

            var currentAggregate = new List <Block>();

            foreach (var node in block.Ast)
            {
                if (node is TryBlock ||
                    node is CatchBlock ||
                    node is FinallyBlock ||
                    node is FaultBlock)
                {
                    currentAggregate.Add((Block)node);
                    RewriteBlock((Block)node);
                }
                else if (currentAggregate.Count > 0)
                {
                    replacements.Add(currentAggregate);

                    currentAggregate = new List <Block>();
                }
            }

            if (currentAggregate.Count > 0)
            {
                replacements.Add(currentAggregate);

                currentAggregate = new List <Block>();
            }

            foreach (var aggregate in replacements)
            {
                var pr = new ProtectedRegion
                {
                    TryBlock     = aggregate.OfType <TryBlock>().Single(),
                    CatchBlocks  = aggregate.OfType <CatchBlock>().ToList(),
                    FinallyBlock = aggregate.OfType <FinallyBlock>().SingleOrDefault(),
                    FaultBlock   = aggregate.OfType <FaultBlock>().SingleOrDefault()
                };

                block.Ast.ReplaceRange(
                    from: aggregate.First(),
                    to: aggregate.Last(),
                    replacement: new [] { pr });
            }
        }
Beispiel #10
0
        public PersistedObject(T theObject, bool background)
        {
            this.bstrTempFileName         = IntPtr.Zero;
            this.theObjectSaved           = new ManualResetEvent(false);
            this.waitForObjectSavedRegion = new ProtectedRegion("WaitForObjectSaved", ProtectedRegionOptions.DisablePumpingWhenEntered);
            this.persistedToDiskRegion    = new ProtectedRegion("PersistToDisk", ProtectedRegionOptions.DisablePumpingWhenEntered);
            this.objectRef    = new WeakReference(theObject);
            this.tempFileName = FileSystem.GetTempFileName();
            PersistedObject <T> .fileNames.Add(this.tempFileName);

            this.bstrTempFileName = Marshal.StringToBSTR(this.tempFileName);
            if (background)
            {
                ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(this.PersistToDisk), theObject);
            }
            else
            {
                this.PersistToDisk(theObject);
            }
        }
        protected override void Run()
        {
            if (!HasProtectedRegions)
            {
                return;
            }

            ProtectedRegion.FinalizeAll(BasicBlocks, MethodCompiler.ProtectedRegions);

            codeEmitter = MethodCompiler.Pipeline.FindFirst <CodeGenerationStage>().CodeEmitter;

            if (TypeLayout.NativePointerSize == 4)
            {
                NativePatchType = PatchType.I4;
            }
            else
            {
                NativePatchType = PatchType.I8;
            }

            EmitProtectedRegionTable();
        }
Beispiel #12
0
 internal EnterScope(ProtectedRegion owner)
 {
     this.owner = owner;
     this.owner.Enter();
 }
 /// <inheritdoc />
 public override bool RemoveNode(ControlFlowNode <TInstruction> node) =>
 ProtectedRegion.RemoveNode(node) || HandlerRegions.Any(r => r.RemoveNode(node));
Beispiel #14
0
 public MagicWandTool(DocumentWorkspace documentWorkspace) : base(documentWorkspace, PdnResources.GetImageResource("Icons.MagicWandToolIcon.png"), PdnResources.GetString("MagicWandTool.Name"), PdnResources.GetString("MagicWandTool.HelpText"), 's', false, ToolBarConfigItems.FloodMode | ToolBarConfigItems.SampleImageOrLayer | ToolBarConfigItems.SelectionCombineMode | ToolBarConfigItems.Tolerance)
 {
     this.onUIGestureRegion = new ProtectedRegion("OnUIGesture*", ProtectedRegionOptions.None);
 }
Beispiel #15
0
 protected TransactedToolDrawingToken()
 {
     this.commitRegion = new ProtectedRegion("Commit", ProtectedRegionOptions.ErrorOnPerThreadReentrancy);
 }