Example #1
0
	public object Get(ContextKey key)
	{
		if(DIC.ContainsKey(key))
		{
			return DIC[key];
		}
		return null;
	}
Example #2
0
	public void Put(ContextKey key, object value)
	{
		if (!DIC.ContainsKey (key)) 
		{
			DIC.Add(key, value);
		}
		else
		{
			DIC[key] = value;
		}
	}
Example #3
0
        public static void ClearCurrentData(ContextKey contextKey, bool removeContextData)
        {
            // Get the current ambient CallContext.
            ContextKey key = s_currentTransaction.Value;

            if (contextKey != null || key != null)
            {
                // removeContextData flag is used for perf optimization to avoid removing from the table in certain nested TransactionScope usage.
                if (removeContextData)
                {
                    // if context key is passed in remove that from the contextDataTable, otherwise remove the default context key.
                    s_contextDataTable.Remove(contextKey ?? key);
                }

                if (key != null)
                {
                    s_currentTransaction.Value = null;
                }
            }
        }
Example #4
0
        private void CommonInitialize()
        {
            ContextKey              = new ContextKey();
            _complete               = false;
            _dependentTransaction   = null;
            _disposed               = false;
            _committableTransaction = null;
            _expectedCurrent        = null;
            _scopeTimer             = null;
            _scopeThread            = Thread.CurrentThread;

            Transaction.GetCurrentTransactionAndScope(
                AsyncFlowEnabled ? TxLookup.DefaultCallContext : TxLookup.DefaultTLS,
                out _savedCurrent,
                out _savedCurrentScope,
                out _contextTransaction
                );

            // Calling validate here as we need to make sure the existing parent ambient transaction scope is already looked up to see if we have ES interop enabled.
            ValidateAsyncFlowOptionAndESInteropOption();
        }
Example #5
0
 /// <summary>
 /// 获取请求线程内的唯一缓存对象
 /// </summary>
 public static T GetFromCallContext <T>(ContextKey key)
 {
     return((T)CallContext.GetData(key.Description()));
 }
 public bool Equals(ContextKey <TKey1> other)
 {
     return(EqualityComparer <TKey1> .Default.Equals(this.Alpha, other.Alpha));
 }
        internal GlobalPersistentContext <TValue> GetContext <TKey1, TKey2, TValue>(TKey1 alpha, TKey2 beta, out bool isNew)
        {
            IContextKey key = new ContextKey <TKey1, TKey2>(alpha, beta);

            return(this.TryGetContext <TValue>(key, out isNew));
        }
Example #8
0
        static public void ClearCurrentData(ContextKey contextKey, bool removeContextData)
        {
            // Get the current ambient CallContext.
            ContextKey key = (ContextKey)CallContext.LogicalGetData(CurrentTransactionProperty);
            if (contextKey != null || key != null)
            {
                // removeContextData flag is used for perf optimization to avoid removing from the table in certain nested TransactionScope usage. 
                if (removeContextData)
                {
                    // if context key is passed in remove that from the contextDataTable, otherwise remove the default context key. 
                    ContextDataTable.Remove(contextKey ?? key);
                }

                if (key != null)
                {
                    CallContext.LogicalSetData(CurrentTransactionProperty, null);
                }
            }
        }
 public static ContextNode GetItem(IContextCache cache, ContextKey key)
 {
     return(cache.ToDictionary(node => node.Key)[key]);
 }
        private async void Editor_Loading(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(CodeContent))
            {
                CodeContent = await FileIO.ReadTextAsync(await StorageFile.GetFileFromApplicationUriAsync(new System.Uri("ms-appx:///Content.txt")));

                // Set the copy of our initial text.
                TextEditor.Text = CodeContent;

                ButtonHighlightRange_Click(null, null);
            }

            // Ready for Code

            var available_languages = Editor.Languages.GetLanguagesAsync();
            //Debugger.Break();

            // Code Action Command - TODO: Should we just encapsulate these in the Provider class anyway as they're only being used there?
            string cmdId = await Editor.AddCommandAsync(async (args) =>
            {
                var md = new MessageDialog($"You hit the CodeAction command, Arg[0] = {args[0]}");
                await md.ShowAsync();
            });

            // Code Lens Command
            string cmdId2 = await Editor.AddCommandAsync(async (args) =>
            {
                var md = new MessageDialog($"You hit the CodeLens command, Arg[0] = {args[0]}, Arg[1] = {args[1]}, Args[2] = {args[2]}");
                await md.ShowAsync();
            });

            _actionProvider = new EditorCodeActionProvider(cmdId);

            await Editor.Languages.RegisterCodeActionProviderAsync("csharp", _actionProvider);

            await Editor.Languages.RegisterCodeLensProviderAsync("csharp", new EditorCodeLensProvider(cmdId2));

            await Editor.Languages.RegisterColorProviderAsync("csharp", new ColorProvider());

            await Editor.Languages.RegisterCompletionItemProviderAsync("csharp", new LanguageProvider());

            await Editor.Languages.RegisterHoverProviderAsync("csharp", new EditorHoverProvider());

            _myCondition = await Editor.CreateContextKeyAsync("MyCondition", false);

            await Editor.AddCommandAsync(KeyCode.F5, async (args) => {
                var md = new MessageDialog("You Hit F5!");
                await md.ShowAsync();

                // Turn off Command again.
                _myCondition?.Reset();

                // Refocus on CodeEditor
                Editor.Focus(FocusState.Programmatic);
            }, _myCondition.Key);

            await Editor.AddCommandAsync(KeyMod.CtrlCmd | KeyCode.KEY_R, async (args) =>
            {
                var range = await Editor.GetModel().GetFullModelRangeAsync();

                var md = new MessageDialog("Document Range: " + range.ToString());
                await md.ShowAsync();

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddCommandAsync(KeyMod.CtrlCmd | KeyCode.KEY_W, async (args) =>
            {
                var word = await Editor.GetModel().GetWordAtPositionAsync(await Editor.GetPositionAsync());

                if (word == null)
                {
                    var md = new MessageDialog("No Word Found.");
                    await md.ShowAsync();
                }
                else
                {
                    var md = new MessageDialog("Word: " + word.Word + "[" + word.StartColumn + ", " + word.EndColumn + "]");
                    await md.ShowAsync();
                }

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddCommandAsync(KeyMod.CtrlCmd | KeyCode.KEY_L, async (args) =>
            {
                var model = Editor.GetModel();
                var line  = await model.GetLineContentAsync((await Editor.GetPositionAsync()).LineNumber);
                var lines = await model.GetLinesContentAsync();
                var count = await model.GetLineCountAsync();

                var md = new MessageDialog("Current Line: " + line + "\nAll Lines [" + count + "]:\n" + string.Join("\n", lines));
                await md.ShowAsync();

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddCommandAsync(KeyMod.CtrlCmd | KeyCode.KEY_U, async (args) =>
            {
                var range = new Range(2, 10, 3, 8);
                var seg   = await Editor.GetModel().GetValueInRangeAsync(range);

                var md = new MessageDialog("Segment " + range.ToString() + ": " + seg);
                await md.ShowAsync();

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddActionAsync(new TestAction());

            // we only need to fire loading once to initialize all our model/helpers
            Editor.Loading -= Editor_Loading;
        }
 public override int GetHashCode()
 {
     return(ContextType.GetHashCode() + ContextKey.GetHashCode());
 }
        private async void Editor_Loading(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(CodeContent))
            {
                CodeContent = await FileIO.ReadTextAsync(await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Content.txt")));

                ButtonHighlightRange_Click(null, null);
            }

            // Ready for Code
            var languages = new Monaco.LanguagesHelper(Editor);

            var available_languages = await languages.GetLanguagesAsync();

            //Debugger.Break();

            await languages.RegisterHoverProviderAsync("csharp", (model, position) =>
            {
                // TODO: See if this can be internalized? Need to figure out the best pattern here to expose async method through WinRT, as can't use Task for 'async' language compatibility in WinRT Component...
                return(AsyncInfo.Run(async delegate(CancellationToken cancelationToken)
                {
                    var word = await model.GetWordAtPositionAsync(position);
                    if (word != null && word.Word != null && word.Word.IndexOf("Hit", 0, StringComparison.CurrentCultureIgnoreCase) != -1)
                    {
                        return new Hover(new string[]
                        {
                            "*Hit* - press the keys following together.",
                            "Some **more** text is here.",
                            "And a [link](https://www.github.com/)."
                        }, new Range(position.LineNumber, position.Column, position.LineNumber, position.Column + 5));
                    }

                    return default(Hover);
                }));
            });

            await languages.RegisterCompletionItemProviderAsync("csharp", new LanguageProvider());

            _myCondition = await Editor.CreateContextKeyAsync("MyCondition", false);

            await Editor.AddCommandAsync(Monaco.KeyCode.F5, async() => {
                var md = new MessageDialog("You Hit F5!");
                await md.ShowAsync();

                // Turn off Command again.
                _myCondition?.Reset();

                // Refocus on CodeEditor
                Editor.Focus(FocusState.Programmatic);
            }, _myCondition.Key);

            await Editor.AddCommandAsync(Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.KEY_R, async() =>
            {
                var range = await Editor.GetModel().GetFullModelRangeAsync();

                var md = new MessageDialog("Document Range: " + range.ToString());
                await md.ShowAsync();

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddCommandAsync(Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.KEY_W, async() =>
            {
                var word = await Editor.GetModel().GetWordAtPositionAsync(await Editor.GetPositionAsync());

                if (word == null)
                {
                    var md = new MessageDialog("No Word Found.");
                    await md.ShowAsync();
                }
                else
                {
                    var md = new MessageDialog("Word: " + word.Word + "[" + word.StartColumn + ", " + word.EndColumn + "]");
                    await md.ShowAsync();
                }

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddCommandAsync(Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.KEY_L, async() =>
            {
                var model = Editor.GetModel();
                var line  = await model.GetLineContentAsync((await Editor.GetPositionAsync()).LineNumber);
                var lines = await model.GetLinesContentAsync();
                var count = await model.GetLineCountAsync();

                var md = new MessageDialog("Current Line: " + line + "\nAll Lines [" + count + "]:\n" + string.Join("\n", lines));
                await md.ShowAsync();

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddCommandAsync(Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.KEY_U, async() =>
            {
                var range = new Range(2, 10, 3, 8);
                var seg   = await Editor.GetModel().GetValueInRangeAsync(range);

                var md = new MessageDialog("Segment " + range.ToString() + ": " + seg);
                await md.ShowAsync();

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddActionAsync(new TestAction());
        }
Example #13
0
 public bool ContainsKey(ContextKey key)
 {
     return DIC.ContainsKey(key);
 }
Example #14
0
 /// <summary>
 /// 设置对象到请求唯一缓存
 /// </summary>
 /// <param name="key"></param>
 /// <param name="theObject"></param>
 public static void SetToCallContext(ContextKey key, object theObject)
 {
     CallContext.SetData(key.Description(), theObject);
 }
Example #15
0
 public static object GetContextKey(this ScenarioContext context, ContextKey key)
 {
     return(GetContextKey(context, key.ToString()));
 }
Example #16
0
        private void CommonInitialize()
        {
            ContextKey = new ContextKey();
            _complete = false;
            _dependentTransaction = null;
            _disposed = false;
            _committableTransaction = null;
            _expectedCurrent = null;
            _scopeTimer = null;
            _scopeThread = Thread.CurrentThread;

            Transaction.GetCurrentTransactionAndScope(
                            AsyncFlowEnabled ? TxLookup.DefaultCallContext : TxLookup.DefaultTLS,
                            out _savedCurrent,
                            out _savedCurrentScope,
                            out _contextTransaction
                            );

            // Calling validate here as we need to make sure the existing parent ambient transaction scope is already looked up to see if we have ES interop enabled.  
            ValidateAsyncFlowOptionAndESInteropOption();
        }
Example #17
0
 public static void SetContextKey(this ScenarioContext context, ContextKey key, object keyValue)
 {
     SetContextKey(context, key.ToString(), keyValue);
 }
Example #18
0
        private async void Editor_Loading(object sender, RoutedEventArgs e)
        {
            // Ready for Code
            var languages = await new Monaco.LanguagesHelper(Editor).GetLanguagesAsync();

            //Debugger.Break();

            _myCondition = await Editor.CreateContextKeyAsync("MyCondition", false);

            await Editor.AddCommandAsync(Monaco.KeyCode.F5, async() => {
                var md = new MessageDialog("You Hit F5!");
                await md.ShowAsync();

                // Turn off Command again.
                _myCondition.Reset();

                // Refocus on CodeEditor
                Editor.Focus(FocusState.Programmatic);
            }, _myCondition.Key);

            await Editor.AddCommandAsync(Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.KEY_W, async() =>
            {
                var word = await Editor.GetModel().GetWordAtPositionAsync(await Editor.GetPositionAsync());

                if (word == null)
                {
                    var md = new MessageDialog("No Word Found.");
                    await md.ShowAsync();
                }
                else
                {
                    var md = new MessageDialog("Word: " + word.Word + "[" + word.StartColumn + ", " + word.EndColumn + "]");
                    await md.ShowAsync();
                }

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddCommandAsync(Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.KEY_L, async() =>
            {
                var model = Editor.GetModel();
                var line  = await model.GetLineContentAsync((await Editor.GetPositionAsync()).LineNumber);
                var lines = await model.GetLinesContentAsync();
                var count = await model.GetLineCountAsync();

                var md = new MessageDialog("Current Line: " + line + "\nAll Lines [" + count + "]:\n" + string.Join("\n", lines));
                await md.ShowAsync();

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddCommandAsync(Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.KEY_U, async() =>
            {
                var range = new Range(2, 10, 3, 8);
                var seg   = await Editor.GetModel().GetValueInRangeAsync(range);

                var md = new MessageDialog("Segment " + range.ToString() + ": " + seg);
                await md.ShowAsync();

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddActionAsync(new TestAction());
        }
 ContextNode IContextCache.GetItem(ContextKey key)
 {
     return(CacheBase.GetItem(this, key));
 }
Example #20
0
 public virtual void Initialize(ContextKey contextKey, BehaviourProcessor behaviourProcessor) =>
 sharedTo = behaviourProcessor.GetData <SharedData <T, C> >(contextKey);
 /// <inheritdoc />
 public bool Equals(ContextKey <T> other) => Key == other.Key && Type == other.Type;
Example #22
0
 public bool ContainsKey(ContextKey key)
 {
     return(DIC.ContainsKey(key));
 }
Example #23
0
 // 
 //  Set CallContext data with the given contextKey. 
 //  return the ContextData if already present in contextDataTable, otherwise return the default value. 
 // 
 static public ContextData CreateOrGetCurrentData(ContextKey contextKey)
 {
    CallContext.LogicalSetData(CurrentTransactionProperty, contextKey);
    return ContextDataTable.GetValue(contextKey, (env) => new ContextData(true));
 }
Example #24
0
 // 
 //  Set CallContext data with the given contextKey. 
 //  return the ContextData if already present in contextDataTable, otherwise return the default value. 
 // 
 public static ContextData CreateOrGetCurrentData(ContextKey contextKey)
 {
     s_currentTransaction.Value = contextKey;
     return s_contextDataTable.GetValue(contextKey, (env) => new ContextData(true));
 }
        public override void Initialize(ContextKey contextKey, BehaviourProcessor behaviourProcessor)
        {
            base.Initialize(contextKey, behaviourProcessor);

            sharedFrom = behaviourProcessor.GetData <SharedData <T, C> >(contextFrom);
        }
Example #26
0
        private async void Editor_Loading(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(CodeContent))
            {
                CodeContent = await FileIO.ReadTextAsync(await StorageFile.GetFileFromApplicationUriAsync(new System.Uri("ms-appx:///Content.txt")));

                ButtonHighlightRange_Click(null, null);
            }

            // Ready for Code
            var languages = new Monaco.LanguagesHelper(Editor);

            var available_languages = await languages.GetLanguagesAsync();

            //Debugger.Break();

            await languages.RegisterHoverProviderAsync("csharp", new EditorHoverProvider());

            await languages.RegisterCompletionItemProviderAsync("csharp", new LanguageProvider());

            _myCondition = await Editor.CreateContextKeyAsync("MyCondition", false);

            await Editor.AddCommandAsync(KeyCode.F5, async() => {
                var md = new MessageDialog("You Hit F5!");
                await md.ShowAsync();

                // Turn off Command again.
                _myCondition?.Reset();

                // Refocus on CodeEditor
                Editor.Focus(FocusState.Programmatic);
            }, _myCondition.Key);

            await Editor.AddCommandAsync(KeyMod.CtrlCmd | KeyCode.KEY_R, async() =>
            {
                var range = await Editor.GetModel().GetFullModelRangeAsync();

                var md = new MessageDialog("Document Range: " + range.ToString());
                await md.ShowAsync();

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddCommandAsync(KeyMod.CtrlCmd | KeyCode.KEY_W, async() =>
            {
                var word = await Editor.GetModel().GetWordAtPositionAsync(await Editor.GetPositionAsync());

                if (word == null)
                {
                    var md = new MessageDialog("No Word Found.");
                    await md.ShowAsync();
                }
                else
                {
                    var md = new MessageDialog("Word: " + word.Word + "[" + word.StartColumn + ", " + word.EndColumn + "]");
                    await md.ShowAsync();
                }

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddCommandAsync(KeyMod.CtrlCmd | KeyCode.KEY_L, async() =>
            {
                var model = Editor.GetModel();
                var line  = await model.GetLineContentAsync((await Editor.GetPositionAsync()).LineNumber);
                var lines = await model.GetLinesContentAsync();
                var count = await model.GetLineCountAsync();

                var md = new MessageDialog("Current Line: " + line + "\nAll Lines [" + count + "]:\n" + string.Join("\n", lines));
                await md.ShowAsync();

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddCommandAsync(KeyMod.CtrlCmd | KeyCode.KEY_U, async() =>
            {
                var range = new Range(2, 10, 3, 8);
                var seg   = await Editor.GetModel().GetValueInRangeAsync(range);

                var md = new MessageDialog("Segment " + range.ToString() + ": " + seg);
                await md.ShowAsync();

                Editor.Focus(FocusState.Programmatic);
            });

            await Editor.AddActionAsync(new TestAction());
        }
        internal GlobalPersistentContext <TValue> GetContext <TKey1, TKey2, TKey3, TKey4, TKey5, TValue>(TKey1 alpha, TKey2 beta, TKey3 gamma, TKey4 delta, TKey5 epsilon, out bool isNew)
        {
            IContextKey key = new ContextKey <TKey1, TKey2, TKey3, TKey4, TKey5>(alpha, beta, gamma, delta, epsilon);

            return(this.TryGetContext <TValue>(key, out isNew));
        }
Example #28
0
 public static bool ContainsKey(this ScenarioContext context, ContextKey key)
 {
     return(context.ContainsKey(key.ToString()));
 }
Example #29
0
 //
 //  Set CallContext data with the given contextKey.
 //  return the ContextData if already present in contextDataTable, otherwise return the default value.
 //
 public static ContextData CreateOrGetCurrentData(ContextKey contextKey)
 {
     s_currentTransaction.Value = contextKey;
     return(s_contextDataTable.GetValue(contextKey, (env) => new ContextData(true)));
 }
 public virtual void Initialize(ContextKey contextKey, BehaviourProcessor behaviourProcessor)
 {
     sharedDataToCompare = behaviourProcessor.GetData <SharedData <T, C> >(contextKey);
     equalityComparer    = EqualityComparer <T> .Default;
 }