Exemple #1
0
        Task <TProperty> IPropertyProvider <TInput, TProperty> .GetProperty <T>(InitializeContext <T, TInput> context)
        {
            if (!context.HasInput)
            {
                return(TaskUtil.Default <TProperty>());
            }

            Task <Task <TProperty> > propertyTask = _provider.GetProperty(context);

            if (propertyTask.IsCompleted)
            {
                Task <TProperty> valueTask = propertyTask.Result;
                if (valueTask.IsCompleted)
                {
                    return(valueTask);
                }
            }

            async Task <TProperty> GetPropertyAsync()
            {
                Task <TProperty> valueTask = await propertyTask.ConfigureAwait(false);

                return(await valueTask.ConfigureAwait(false));
            }

            return(GetPropertyAsync());
        }
 public Task <Task <TProperty> > GetProperty <T>(InitializeContext <T, TInput> context)
     where T : class
 {
     return(Task.FromResult(context.HasInput
         ? _provider.GetProperty(context)
         : TaskUtil.Default <TProperty>()));
 }
        Task <TProperty> IPropertyConverter <TProperty, TProperty> .Convert <TMessage>(InitializeContext <TMessage> context, TProperty input)
        {
            if (input == null || !context.TryGetPayload(out TransformContext <TMessage> transformContext) || !transformContext.HasInput)
            {
                return(TaskUtil.Default <TProperty>());
            }

            var propertyTransformContext = new PropertyTransformContext <TMessage, TProperty>(transformContext, input);

            InitializeContext <TProperty> messageContext = _initializer.Create(propertyTransformContext);

            Task <InitializeContext <TProperty> > initTask = _initializer.Initialize(messageContext, input);

            if (initTask.IsCompleted)
            {
                return(Task.FromResult(initTask.Result.Message));
            }

            async Task <TProperty> ConvertAsync()
            {
                InitializeContext <TProperty> result = await initTask.ConfigureAwait(false);

                return(result.Message);
            }

            return(ConvertAsync());
        }
        public static Task <ParsedDocument> ParseFile(ParseOptions options, string mimeType, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (options.FileName == null)
            {
                throw new ArgumentNullException("options.FileName");
            }

            var parser = GetParser(mimeType);

            if (parser == null)
            {
                return(TaskUtil.Default <ParsedDocument>());
            }

            var t = Counters.ParserService.FileParsed.BeginTiming(options.FileName);

            try {
                var result = parser.Parse(options, cancellationToken);
                return(result ?? TaskUtil.Default <ParsedDocument>());
            } catch (OperationCanceledException) {
                return(TaskUtil.Default <ParsedDocument>());
            } catch (Exception e) {
                LoggingService.LogError("Exception while parsing: " + e);
                return(TaskUtil.Default <ParsedDocument>());
            } finally {
                t.Dispose();
            }
        }
Exemple #5
0
 public Task <TProperty> Convert <T>(InitializeContext <T, TInput> context, object propertyValue)
     where T : class
 {
     return(_converter == null
         ? TaskUtil.Default <TProperty>()
         : _converter.Convert(context, (TObject)propertyValue));
 }
Exemple #6
0
        Task <TProperty> IPropertyConverter <TProperty, TProperty> .Convert <TMessage>(InitializeContext <TMessage> context, TProperty input)
        {
            if (input == null)
            {
                return(TaskUtil.Default <TProperty>());
            }

            InitializeContext <TProperty> messageContext = MessageFactoryCache <TProperty> .Factory.Create(context);

            Task <InitializeContext <TProperty> > initTask = _initializer.Initialize(messageContext, input);

            if (initTask.IsCompleted)
            {
                return(Task.FromResult(initTask.Result.Message));
            }

            async Task <TProperty> ConvertAsync()
            {
                InitializeContext <TProperty> result = await initTask.ConfigureAwait(false);

                return(result.Message);
            }

            return(ConvertAsync());
        }
Exemple #7
0
 public Task <TProperty> GetProperty <T>(InitializeContext <T, TInput> context)
     where T : class
 {
     return(context.HasInput && _converter.TryConvert(_inputProperty.Get(context.Input), out var result)
         ? Task.FromResult(result)
         : TaskUtil.Default <TProperty>());
 }
Exemple #8
0
 public Task <MessageData <Stream> > Convert <T>(InitializeContext <T> context, Stream input)
     where T : class
 {
     return(input == null
         ? TaskUtil.Default <MessageData <Stream> >()
         : Task.FromResult <MessageData <Stream> >(new PutMessageData <Stream>(input)));
 }
Exemple #9
0
        public Task <TProperty> GetProperty <T>(InitializeContext <T, TInput> context)
            where T : class
        {
            if (!context.TryGetPayload <TransformContext <TInput> >(out TransformContext <TInput> transformContext))
            {
                return(TaskUtil.Default <TProperty>());
            }

            if (!context.HasInput)
            {
                return(TaskUtil.Default <TProperty>());
            }

            Task <TProperty> inputTask = _inputProvider.GetProperty(context);

            if (inputTask.IsCompleted)
            {
                var propertyContext = new MessageTransformPropertyContext <TProperty, TInput>(transformContext, inputTask.Result);

                return(_valueProvider(propertyContext));
            }

            async Task <TProperty> GetPropertyAsync()
            {
                var inputValue = await inputTask.ConfigureAwait(false);

                var propertyContext = new MessageTransformPropertyContext <TProperty, TInput>(transformContext, inputValue);

                return(await _valueProvider(propertyContext).ConfigureAwait(false));
            }

            return(GetPropertyAsync());
        }
Exemple #10
0
 public static Task <ICodingConventionContext> GetEditorConfigContext(string fileName, CancellationToken token = default(CancellationToken))
 {
     if (string.IsNullOrEmpty(fileName))
     {
         return(TaskUtil.Default <ICodingConventionContext> ());
     }
     lock (contextCacheLock) {
         if (contextCache.TryGetValue(fileName, out Task <ICodingConventionContext> result))
         {
             return(result);
         }
         try {
             result = codingConventionsManager.GetConventionContextAsync(fileName, token);
         } catch (OperationCanceledException) {
         } catch (Exception e) {
             LoggingService.LogError("Error while getting coding conventions,", e);
         }
         if (result == null)
         {
             return(TaskUtil.Default <ICodingConventionContext> ());
         }
         contextCache = contextCache.SetItem(fileName, result);
         return(result);
     }
 }
Exemple #11
0
        public Task <TProperty> GetProperty <T>(InitializeContext <T, TInput> context)
            where T : class
        {
            Task <object> propertyTask = _provider.GetProperty(context);

            if (propertyTask.IsCompleted)
            {
                var propertyValue = propertyTask.Result;
                if (propertyValue == default)
                {
                    return(TaskUtil.Default <TProperty>());
                }

                var converter = _converters.GetOrAdd(propertyValue.GetType(), CreateConverter);

                return(converter.Convert(context, propertyValue));
            }

            async Task <TProperty> GetPropertyAsync()
            {
                var propertyValue = await propertyTask.ConfigureAwait(false);

                var converter = _converters.GetOrAdd(propertyValue.GetType(), CreateConverter);

                return(await converter.Convert(context, propertyValue).ConfigureAwait(false));
            }

            return(GetPropertyAsync());
        }
Exemple #12
0
 public Task <MessageData <byte[]> > Convert <T>(InitializeContext <T> context, MessageData <byte[]> input)
     where T : class
 {
     return(input != null
         ? Task.FromResult(input)
         : TaskUtil.Default <MessageData <byte[]> >());
 }
        Task <TProperty> IPropertyConverter <TProperty, TInput> .Convert <TMessage>(InitializeContext <TMessage> context, TInput input)
        {
            if (input == null)
            {
                return(TaskUtil.Default <TProperty>());
            }

            InitializeContext <TProperty> messageContext = MessageFactoryCache <TProperty> .Factory.Create(context);

            IMessageInitializer <TProperty> initializer = typeof(TInput) == typeof(object)
                ? MessageInitializerCache <TProperty> .GetInitializer(input.GetType())
                : MessageInitializerCache <TProperty> .GetInitializer(typeof(TInput));

            Task <InitializeContext <TProperty> > initTask = initializer.Initialize(messageContext, input);

            if (initTask.IsCompleted)
            {
                return(Task.FromResult(initTask.Result.Message));
            }

            async Task <TProperty> ConvertAsync()
            {
                InitializeContext <TProperty> result = await initTask.ConfigureAwait(false);

                return(result.Message);
            }

            return(ConvertAsync());
        }
 public static Task PostProcessKeyEvent(KeyDescriptor descriptor)
 {
     if (!IsVisible)
     {
         return(TaskUtil.Default <object> ());
     }
     return(wnd.PostProcessKeyEvent(descriptor));
 }
Exemple #15
0
        public Task <TProperty> GetProperty <T>(InitializeContext <T, TInput> context)
            where T : class
        {
            if (context.HasInput && context.Input.TryGetValue(_key, out var value))
            {
                return(Task.FromResult(value));
            }

            return(TaskUtil.Default <TProperty>());
        }
Exemple #16
0
        public Task <MessageData <byte[]> > Convert <T>(InitializeContext <T> context, byte[] input)
            where T : class
        {
            if (input == null)
            {
                return(TaskUtil.Default <MessageData <byte[]> >());
            }

            return(Task.FromResult <MessageData <byte[]> >(new PutMessageData <byte[]>(input)));
        }
        public Task <MessageData <TValue> > GetProperty <T>(InitializeContext <T, TInput> context)
            where T : class
        {
            if (!context.HasInput)
            {
                return(TaskUtil.Default <MessageData <TValue> >());
            }

            Task <MessageData <TValue> > inputTask = _inputProvider.GetProperty(context);

            if (inputTask.IsCompleted)
            {
                MessageData <TValue> messageData = inputTask.Result;
                if (messageData is IInlineMessageData)
                {
                    return(Task.FromResult(messageData));
                }

                if (messageData?.Address != null)
                {
                    var repository = _repository;
                    if (repository != null || context.TryGetPayload(out repository))
                    {
                        return(Task.FromResult(_reader.GetMessageData(repository, messageData.Address, context.CancellationToken)));
                    }
                }

                return(Task.FromResult(EmptyMessageData <TValue> .Instance));
            }

            async Task <MessageData <TValue> > GetPropertyAsync()
            {
                MessageData <TValue> messageData = await inputTask.ConfigureAwait(false);

                if (messageData is IInlineMessageData)
                {
                    return(messageData);
                }

                if (messageData?.Address != null)
                {
                    var repository = _repository;
                    if (repository != null || context.TryGetPayload(out repository))
                    {
                        return(_reader.GetMessageData(repository, messageData.Address, context.CancellationToken));
                    }
                }

                return(EmptyMessageData <TValue> .Instance);
            }

            return(GetPropertyAsync());
        }
        IPropertyConverter <IEnumerable <KeyValuePair <TKey, TElement> >, IEnumerable <KeyValuePair <TKey, TElement> > > .Convert <TMessage>(
            InitializeContext <TMessage> context, IEnumerable <KeyValuePair <TKey, TElement> > input)
        {
            switch (input)
            {
            case null:
                return(TaskUtil.Default <IEnumerable <KeyValuePair <TKey, TElement> > >());

            default:
                return(Task.FromResult(input));
            }
        }
        Task <IEnumerable <TElement> > IPropertyConverter <IEnumerable <TElement>, IEnumerable <TElement> > .Convert <T>(InitializeContext <T> context,
                                                                                                                         IEnumerable <TElement> input)
        {
            switch (input)
            {
            case null:
                return(TaskUtil.Default <IEnumerable <TElement> >());

            default:
                return(Task.FromResult(input));
            }
        }
Exemple #20
0
        Task <MessageData <byte[]> > IPropertyConverter <MessageData <byte[]>, string> .Convert <T>(InitializeContext <T> context, string input)
        {
            if (input == null)
            {
                return(TaskUtil.Default <MessageData <byte[]> >());
            }

            var bytes = Encoding.UTF8.GetBytes(input);

            return(Task.FromResult(bytes.Length < MessageDataDefaults.Threshold
                ? (MessageData <byte[]>) new BytesInlineMessageData(bytes)
                : new PutMessageData <byte[]>(bytes)));
        }
        public Task <TProperty> GetProperty <T>(InitializeContext <T, TInput> context)
            where T : class
        {
            var inputTask = _inputProvider.GetProperty(context);

            if (inputTask.IsCompleted)
            {
                return(context.HasInput
                    ? _converter.Convert(context, inputTask.Result)
                    : TaskUtil.Default <TProperty>());
            }

            return(GetPropertyAsync(context, inputTask));
        }
Exemple #22
0
        public Task <TElement[]> Convert <TMessage>(InitializeContext <TMessage> context, IEnumerable <TElement> input)
            where TMessage : class
        {
            switch (input)
            {
            case null:
                return(TaskUtil.Default <TElement[]>());

            case TElement[] array:
                return(Task.FromResult(array));

            default:
                return(Task.FromResult(input.ToArray()));
            }
        }
        Task <IReadOnlyDictionary <TKey, TElement> > IPropertyConverter <IReadOnlyDictionary <TKey, TElement>, IEnumerable <KeyValuePair <TKey, TElement> > >
        .Convert <TMessage>(InitializeContext <TMessage> context, IEnumerable <KeyValuePair <TKey, TElement> > input)
        {
            switch (input)
            {
            case null:
                return(TaskUtil.Default <IReadOnlyDictionary <TKey, TElement> >());

            case IReadOnlyDictionary <TKey, TElement> dictionary:
                return(Task.FromResult(dictionary));

            default:
                return(Task.FromResult <IReadOnlyDictionary <TKey, TElement> >(input.ToDictionary(x => x.Key, x => x.Value)));
            }
        }
        public Task <List <TElement> > Convert <TMessage>(InitializeContext <TMessage> context, IEnumerable <TElement> input)
            where TMessage : class
        {
            switch (input)
            {
            case null:
                return(TaskUtil.Default <List <TElement> >());

            case List <TElement> list:
                return(Task.FromResult(list));

            default:
                return(Task.FromResult(input.ToList()));
            }
        }
        public Task <Dictionary <TKey, TElement> > Convert <TMessage>(InitializeContext <TMessage> context,
                                                                      IEnumerable <KeyValuePair <TKey, TElement> > input)
            where TMessage : class
        {
            switch (input)
            {
            case null:
                return(TaskUtil.Default <Dictionary <TKey, TElement> >());

            case Dictionary <TKey, TElement> dictionary:
                return(Task.FromResult(dictionary));

            default:
                return(Task.FromResult(input.ToDictionary(x => x.Key, x => x.Value)));
            }
        }
        public static Task <ParsedDocument> ParseFile(Project project, string fileName, CancellationToken cancellationToken = default(CancellationToken))
        {
            StringTextSource text;

            try {
                if (!File.Exists(fileName))
                {
                    return(TaskUtil.Default <ParsedDocument>());
                }
                text = StringTextSource.ReadFrom(fileName);
            } catch (Exception) {
                return(TaskUtil.Default <ParsedDocument>());
            }

            return(ParseFile(project, fileName, DesktopService.GetMimeTypeForUri(fileName), text, cancellationToken));
        }
        public static Task <TooltipInformation> CreateTooltipInformation(CancellationToken ctoken, MonoDevelop.Ide.Editor.TextEditor editor, MonoDevelop.Ide.Editor.DocumentContext ctx, ISymbol entity, bool smartWrap, bool createFooter = false, SemanticModel model = null)
        {
            if (entity == null)
            {
                return(TaskUtil.Default <TooltipInformation> ());
            }
            var tooltipInfo = new TooltipInformation();

            var sig = new SignatureMarkupCreator(ctx, editor != null ? editor.CaretOffset : 0);

            sig.SemanticModel            = model;
            sig.BreakLineAfterReturnType = smartWrap;

            return(Task.Run(() => {
                if (ctoken.IsCancellationRequested)
                {
                    return null;
                }
                try {
                    tooltipInfo.SignatureMarkup = sig.GetMarkup(entity);
                } catch (Exception e) {
                    LoggingService.LogError("Got exception while creating markup for :" + entity, e);
                    return new TooltipInformation();
                }

                if (ctoken.IsCancellationRequested)
                {
                    return null;
                }

                tooltipInfo.SummaryMarkup = Ambience.GetSummaryMarkup(entity) ?? "";

                if (entity is IMethodSymbol)
                {
                    var method = (IMethodSymbol)entity;
                    if (method.IsExtensionMethod)
                    {
                        tooltipInfo.AddCategory(GettextCatalog.GetString("Extension Method from"), method.ContainingType.Name);
                    }
                }
                if (createFooter)
                {
                    tooltipInfo.FooterMarkup = sig.CreateFooter(entity);
                }
                return tooltipInfo;
            }));
        }
Exemple #28
0
        public Task <TProperty> GetProperty <T>(InitializeContext <T, TInput> context)
            where T : class
        {
            if (!context.HasInput)
            {
                return(TaskUtil.Default <TProperty>());
            }

            if (context.Input.TryGetValue(_key, out var value))
            {
                return(Task.FromResult(value));
            }

            // var matchingKey = context.Input.Keys.FirstOrDefault(x => string.Compare(x, _key, StringComparison.OrdinalIgnoreCase) == 0);
            // if (matchingKey != default && context.Input.TryGetValue(matchingKey, out value))
            //     return Task.FromResult(value);

            return(TaskUtil.Default <TProperty>());
        }
        public Task <TProperty?> GetProperty <T>(InitializeContext <T, TInput> context)
            where T : class
        {
            if (context.HasInput)
            {
                var propertyTask = _provider.GetProperty(context);
                if (propertyTask.IsCompleted)
                {
                    return(Task.FromResult <TProperty?>(propertyTask.Result));
                }

                async Task <TProperty?> GetPropertyAsync()
                {
                    return(await propertyTask.ConfigureAwait(false));
                }

                return(GetPropertyAsync());
            }

            return(TaskUtil.Default <TProperty?>());
        }
Exemple #30
0
        public Task <MessageData <TValue> > GetProperty <T>(InitializeContext <T, TInput> context)
            where T : class
        {
            if (!context.HasInput)
            {
                return(TaskUtil.Default <MessageData <TValue> >());
            }

            Task <MessageData <TValue> > inputTask = _inputProvider.GetProperty(context);

            if (inputTask.IsCompleted)
            {
                MessageData <TValue> messageData = inputTask.Result;
                if (messageData is PutMessageData <TValue> putMessageData && putMessageData.HasValue)
                {
                    return(Put(context, putMessageData.Value));
                }

                if (messageData is IInlineMessageData && messageData.HasValue && messageData.Address == null)
                {
                    return(Put(context, messageData.Value));
                }

                return(Task.FromResult(messageData));
            }

            async Task <MessageData <TValue> > GetPropertyAsync()
            {
                MessageData <TValue> messageData = await inputTask.ConfigureAwait(false);

                if (messageData is PutMessageData <TValue> putMessageData && putMessageData.HasValue)
                {
                    return(await Put(context, putMessageData.Value));
                }

                return(messageData);
            }

            return(GetPropertyAsync());
        }