public static Type GetMemberType(this MemberInfo member)
        {
            if (member is FieldInfo) return member.As<FieldInfo>().FieldType;
            if (member is PropertyInfo) return member.As<PropertyInfo>().PropertyType;

            throw new NotSupportedException();
        }
        public static string GetContentName(this IContent content)
        {
            if (content.Has<TitlePart>()) { return content.As<TitlePart>().Title; }
            if (content.Has<WidgetPart>()) { return content.As<WidgetPart>().Title; }
            if (content.Has<UserPart>()) { return content.As<UserPart>().UserName; }
            if (content.Has<WidgetPart>()) { return content.As<WidgetPart>().Title; }
            if (content.Has<LayerPart>()) { return content.As<LayerPart>().Name; }

            return "Unknown";
        }
        public static string GetComponentsHandlerOrder(this IProductElement endpoint)
        {
            var sb = new StringBuilder();
            var app = endpoint.Root.As<NServiceBusStudio.IApplication>();
            var endpoints = app.Design.Endpoints.GetAll();
            var sourceComponents = (endpoint.As<IToolkitInterface>() as IAbstractEndpoint).EndpointComponents.AbstractComponentLinks.OrderBy(o => o.Order);
            var components = sourceComponents.Select(ac => ac.ComponentReference.Value)
                                       .Where(c => c.Subscribes.ProcessedCommandLinks.Any() || c.Subscribes.SubscribedEventLinks.Any())
                                       .Select(cmp => HandlerTypeFromComponent(cmp));

            // Add authentication first if needed
            if (app.HasAuthentication && (endpoint.As<IToolkitInterface>() as IAbstractEndpoint).Project != null)
            {
                components = new string[] { string.Format("{0}.Infrastructure.Authentication", (endpoint.As<IToolkitInterface>() as IAbstractEndpoint).Project.Data.RootNamespace) }.Union(components);
            }

            ////
            if (components.Count() > 1)
            {
                sb.Append(@"
            public void SpecifyOrder(Order order)
            {
            order.Specify(");

                int pos = 1;
                foreach (var c in components)
                {
                    if (pos == 1)
                    {
                        sb.AppendFormat("First<{0}>", c);
                    }
                    else if (pos == 2)
                    {
                        sb.AppendFormat(".Then<{0}>()", c);
                    }
                    else
                    {
                        sb.AppendFormat(".AndThen<{0}>()", c);
                    }
                    pos++;
                }
                sb.Append(@");
            }");
            }

            ////

            return sb.ToString();
        }
        public static Type GetMemberType(this MemberInfo member)
        {
            Type rawType = null;

            if (member is FieldInfo)
            {
                rawType = member.As<FieldInfo>().FieldType;
            }
            if (member is PropertyInfo)
            {
                rawType = member.As<PropertyInfo>().PropertyType;
            }

            return rawType.IsNullable() ? rawType.GetInnerTypeFromNullable() : rawType;
        }
 public static TableGrammar AsTable(this IGrammar inner, string title, string leafName)
 {
     return new TableGrammar(inner.As<IGrammarWithCells>(), leafName)
     {
         LabelName = title
     };
 }
        /// <summary>
        /// Starts a build of the solution.
        /// </summary>
        public static Task<bool> Build(this ISolutionNode solution)
        {
            var sln = solution.As<EnvDTE.Solution>();
            if (sln == null)
                throw new ArgumentException(Strings.ISolutionNodeExtensions.BuildNotSupported);

            return System.Threading.Tasks.Task.Factory.StartNew<bool>(() =>
            {
                var mre = new ManualResetEventSlim();
                var events = sln.DTE.Events.BuildEvents;
                EnvDTE._dispBuildEvents_OnBuildDoneEventHandler done = (scope, action) => mre.Set();
                events.OnBuildDone += done;
                try
                {
                    // Let build run async.
                    sln.SolutionBuild.Build(false);

                    // Wait until it's done.
                    mre.Wait();

                    // LastBuildInfo == # of projects that failed to build.
                    return sln.SolutionBuild.LastBuildInfo == 0;
                }
                catch (Exception ex)
                {
                    tracer.Error(ex, Strings.ISolutionNodeExtensions.BuildException);
                    return false;
                }
                finally
                {
                    // Cleanup handler.
                    events.OnBuildDone -= done;
                }
            }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
        }
        public static ServiceGraph ToGraph(this IServiceRegistry registry)
        {
            var behaviorGraph = new BehaviorGraph();
            registry.As<IConfigurationAction>().Configure(behaviorGraph);

            return behaviorGraph.Services;
        }
 public static string DisplayName(this IUser user)
 { 
     var userProfilePart = user.As<UserProfilePart>();
     if (userProfilePart != null && !string.IsNullOrWhiteSpace(userProfilePart.Name)) return userProfilePart.Name;
     if (!string.IsNullOrWhiteSpace(user.Email)) return user.Email;
     return user.UserName;
 }
        public static string GetMessageConventions(this IProductElement endpoint)
        {
            var generatedConventions = string.Empty;
            try
            {
                var app = endpoint.Root.As<NServiceBusStudio.IApplication>();

                var rootNameSpace = string.Empty;
                var applicationName = app.CodeIdentifier;
                var projectNameForInternal = app.ProjectNameInternalMessages;
                var projectNameForContracts = app.ProjectNameContracts;

                var project = endpoint.As<IAbstractEndpoint>().As<IProductElement>().GetProject();
                if (project != null)
                {
                    rootNameSpace = project.Data.RootNamespace;
                }
                generatedConventions = GetMessageConventions(rootNameSpace, applicationName, projectNameForInternal, projectNameForContracts);
            }
            catch (Exception ex)
            {
                //TODO: Why are we catching the exception here??
            }
            return generatedConventions;
        }
        public static string GetMessageConventions(this IProductElement endpoint)
        {
            var generatedConventions = string.Empty;
            try
            {
                var app = endpoint.Root.As<IApplication>();

                var rootNameSpace = string.Empty;
                var applicationName = app.InstanceName;
                var projectNameForInternal = app.ProjectNameInternalMessages;
                var projectNameForContracts = app.ProjectNameContracts;

                var project = endpoint.As<IAbstractEndpoint>().As<IProductElement>().GetProject();
                if (project != null)
                {
                    rootNameSpace = project.Data.RootNamespace;
                }

                generatedConventions =
                    app.TargetNsbVersion == TargetNsbVersion.Version4
                    ? GetMessageConventionsV4(rootNameSpace, applicationName, projectNameForInternal, projectNameForContracts)
                    : GetMessageConventionsV5(rootNameSpace, applicationName, projectNameForInternal, projectNameForContracts);
            }
            catch (Exception ex)
            {
                //TODO: Why are we catching the exception here??
            }

            return generatedConventions;
        }
Exemple #11
0
 public static AndConstraint<RangeVariableToken> ShouldBeRangeVariableToken(this QueryToken token, string expectedName)
 {
     token.Should().BeOfType<RangeVariableToken>();
     var parameterQueryToken = token.As<RangeVariableToken>();
     parameterQueryToken.Kind.Should().Be(QueryTokenKind.RangeVariable);
     parameterQueryToken.Name.Should().Be(expectedName);
     return new AndConstraint<RangeVariableToken>(parameterQueryToken);
 }
Exemple #12
0
 public static AndConstraint<UnaryOperatorToken> ShouldBeUnaryOperatorQueryToken(this QueryToken token, UnaryOperatorKind expectedOperatorKind)
 {
     token.Should().BeOfType<UnaryOperatorToken>();
     var propertyAccessQueryToken = token.As<UnaryOperatorToken>();
     propertyAccessQueryToken.Kind.Should().Be(QueryTokenKind.UnaryOperator);
     propertyAccessQueryToken.OperatorKind.Should().Be(expectedOperatorKind);
     return new AndConstraint<UnaryOperatorToken>(propertyAccessQueryToken);
 }
 /// <summary>
 /// indicates the task is synchronous
 /// </summary>
 /// <param name="task"></param>
 /// <returns></returns>
 public static ISynchronousDecoration IsSynchronous(this ITask task)
 {
     Condition.Requires(task).IsNotNull();
     var rv =  task.As<SynchronousDecoration>();
     if (rv == null)
         rv = new SynchronousDecoration(task);
     return rv;
 }
Exemple #14
0
 public static AndConstraint<EndPathToken> ShouldBeEndPathToken(this QueryToken token, string expectedName)
 {
     token.Should().BeOfType<EndPathToken>();
     var propertyAccessQueryToken = token.As<EndPathToken>();
     propertyAccessQueryToken.Kind.Should().Be(QueryTokenKind.EndPath);
     propertyAccessQueryToken.Identifier.Should().Be(expectedName);
     return new AndConstraint<EndPathToken>(propertyAccessQueryToken);
 }
 /// <summary>
 /// Decoration that flags a task as being asynchronous and provides the conditions needed to trigger completion and error.
 /// Automatically decorates with TriggerConditions.
 /// </summary>
 /// <param name="task"></param>
 /// <returns></returns>
 public static IAsynchronousDecoration IsAsynchronous(this ITask task, ICondition markCompleteCondition, ICondition markErrorCondition)
 {
     Condition.Requires(task).IsNotNull();
     var rv = task.As<AsynchronousDecoration>();
     if (rv == null)
         rv = new AsynchronousDecoration(task, markCompleteCondition, markErrorCondition);
     return rv;
 }
Exemple #16
0
 public static AndConstraint<AllToken> ShouldBeAllToken(this QueryToken token, string expectedParameterName)
 {
     token.Should().BeOfType<AllToken>();
     var allToken = token.As<AllToken>();
     allToken.Kind.Should().Be(QueryTokenKind.Any);
     allToken.Parameter.Should().Be(expectedParameterName);
     return new AndConstraint<AllToken>(allToken);
 }
        public static void CheckNameUniqueness(this IAbstractEndpoint endpoint)
        {
            // If opening existing endpoint, return
            if (endpoint.As<IProductElement>().IsSerializing)
            {
                return;
            }

            var endpoints = endpoint.As<IProductElement>().Root.As<IApplication>().Design.Endpoints.GetAll();

            if (endpoints.Any(x => String.Compare(x.InstanceName, endpoint.InstanceName, true) == 0 && x != endpoint))
            {
                var error = "There is already an endpoint with the same name. Please, select a new name for your endpoint.";
                System.Windows.MessageBox.Show(error, "ServiceMatrix - New Endpoint Name Uniqueness", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                throw new ElementAlreadyExistsException(error, endpoint.As<IProductElement>().DefinitionName, endpoint.InstanceName);
            }
        }
Exemple #18
0
 public static AndConstraint<FunctionCallToken> ShouldBeFunctionCallToken(this QueryToken token, string name)
 {
     token.Should().BeOfType<FunctionCallToken>();
     var functionCallQueryToken = token.As<FunctionCallToken>();
     functionCallQueryToken.Kind.Should().Be(QueryTokenKind.FunctionCall);
     functionCallQueryToken.Name.Should().Be(name);
     return new AndConstraint<FunctionCallToken>(functionCallQueryToken);
 }
 public static MethodInfo GetMethodInfoOrNull(this HttpActionDescriptor actionDescriptor)
 {
     if (actionDescriptor is ReflectedHttpActionDescriptor)
     {
         return actionDescriptor.As<ReflectedHttpActionDescriptor>().MethodInfo;
     }
     
     return null;
 }
Exemple #20
0
        public static IViewToken Resolve(this IViewToken token)
        {
            if (token is ProfileViewToken)
            {
                return token.As<ProfileViewToken>().View;
            }

            return token;
        }
 public static bool SharesIdentifierWith(this ContentItem item1, ContentItem item2)
 {
     if (item1.Has<IdentityPart>() && item2.Has<IdentityPart>())
     {
         return item1.As<IdentityPart>().Identifier.Equals(item2.As<IdentityPart>().Identifier,
                                                        StringComparison.InvariantCultureIgnoreCase);
     }
     return false;
 }
Exemple #22
0
 public static string ActiveTabKey(this TabsObject tabs)
 {
     var href = tabs.As<jQueryObject>().Children("ul").Children("li").Eq(tabs.Active.As<int>()).Children("a").GetAttribute("href").ToString();
     var prefix = "_Tab";
     var lastIndex = href.LastIndexOf(prefix);
     if (lastIndex >= 0)
         href = href.Substr(lastIndex + prefix.Length);
     return href;
 }
 /// <summary>
 /// Undeletes this entity by setting <see cref="ISoftDelete.IsDeleted"/> to false and
 /// <see cref="IDeletionAudited"/> properties to null.
 /// </summary>
 public static void UnDelete(this ISoftDelete entity)
 {
     entity.IsDeleted = false;
     if (entity is IDeletionAudited)
     {
         var deletionAuditedEntity = entity.As<IDeletionAudited>();
         deletionAuditedEntity.DeletionTime = null;
         deletionAuditedEntity.DeleterUserId = null;
     }
 }
Exemple #24
0
 public static VatRatePart GetVatRate(this IContent content)
 {
     if (content != null) {
         var vatPart = content.As<VatPart>();
         return vatPart != null ? vatPart.VatRate : null;
     }
     else {
         return null;
     }
 }
        public static object Value(this Expression expression)
        {
            if (expression is PartialEvaluationExceptionExpression)
            {
                var partialEvaluationExceptionExpression = expression.As<PartialEvaluationExceptionExpression>();
                var inner = partialEvaluationExceptionExpression.Exception;

                throw new BadLinqExpressionException($"Error in value expression inside of the query for '{partialEvaluationExceptionExpression.EvaluatedExpression}'. See the inner exception:", inner);
            }

            if (expression is ConstantExpression)
            {
                // TODO -- handle nulls
                // TODO -- check out more types here.
                return expression.As<ConstantExpression>().Value;
            }

            throw new NotSupportedException();
        }
        public static MethodInfo GetMethodInfoOrNull(this ActionDescriptor actionDescriptor)
        {
            if (actionDescriptor is ReflectedActionDescriptor)
            {
                return actionDescriptor.As<ReflectedActionDescriptor>().MethodInfo;
            }

            if (actionDescriptor is ReflectedAsyncActionDescriptor)
            {
                return actionDescriptor.As<ReflectedAsyncActionDescriptor>().MethodInfo;
            }

            if (actionDescriptor is TaskAsyncActionDescriptor)
            {
                return actionDescriptor.As<TaskAsyncActionDescriptor>().MethodInfo;
            }

            return null;
        }
Exemple #27
0
 public static string Owner(this ContentItem contentItem)
 {
     if (contentItem == null) {
         return "";
     }
     var commontPart = contentItem.As<CommonPart>();
     if (commontPart == null || commontPart.Owner == null) {
         return "";
     }
     return commontPart.Owner.UserName;
 }
        public static GraphNodeId GetId(this IProjectNode node)
        {
            var project = node.As<Project>();
            if (project.Kind == EnvDTE.Constants.vsProjectKindUnmodeled)
                return null;

            var fileName = GetProjectFileUri(project);
            if (fileName == null)
                return null;

            return GraphNodeId.GetNested(CodeGraphNodeIdName.Assembly, fileName);
        }
Exemple #29
0
		internal static object GetValue(this Element element)
		{
			object r;
			var type = (ReflectionFn.Get(element, "type")??"").ToString();
			if ( type == "select-one" || type == "select-multiple") {
				var index = element.As<SelectElement> ().SelectedIndex;
				r= index < 0 
					? null 
						: ReflectionFn.Get (element.As<SelectElement> ().Options[index], "object");

			}
			else if (element.HasAttribute ("autonumeric")) {
				r=jQuery.FromElement (element).Execute ("autoNumeric", "get").ParseNullableFloat();
			} else if (element.HasAttribute ("datepicker")) {
				r=jQuery.FromElement (element).Execute ("datepicker", "getDate");
			} else {
				r=ReflectionFn.Get (element, "object")??ReflectionFn.Get (element, "value");
			}

			return r;

		}
        /// <summary>
        /// Gets the item that represents the file currently opened in an editor.
        /// </summary>
        /// <param name="solution">The solution to find the active editing document in.</param>
        /// <returns>The item or <see langword="null"/> if no item is currently being edited.</returns>
        public static IItem GetActiveEditorItem(this ISolution solution)
        {
            var vsSolution = solution.As<EnvDTE.Solution>();

            if (vsSolution == null)
                throw new NotSupportedException(Resources.VsItemContainerExtensions_ErrorNoSolution);

            var activeDocument = vsSolution.DTE.ActiveDocument;
            if (activeDocument == null)
                return null;

            return solution.Traverse().OfType<IItem>().FirstOrDefault(i => i.PhysicalPath == activeDocument.FullName);
        }