/// <summary>
        ///     Creates new settings provider, using the
        ///     <see cref="PrefixTruncatingKeyFilter" />
        ///     for the path filtering logic
        /// </summary>
        /// <param name="settingsProvider">
        ///     The settings provider.
        /// </param>
        /// <param name="prefix">
        ///     The prefix to look for and then truncate.
        /// </param>
        /// <returns>
        ///     new instance of the settings provider, created by filtering and applying transformations
        /// </returns>
        public static ISettingsProvider FilteredByPrefix([NotNull] this ISettingsProvider settingsProvider, [NotNull] string prefix)
        {
            Enforce.Argument(() => settingsProvider);
            Enforce.ArgumentNotEmpty(() => prefix);

            return(settingsProvider.Filtered(new PrefixTruncatingKeyFilter(prefix)));
        }
예제 #2
0
        /// <summary>
        /// Retrieves via IL the information of the <b>local</b> variable passed in the expression.
        /// <code>
        /// var myVar = "string";
        /// var info = Reflect.Variable(() =&gt; myVar)
        /// </code>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="expression">The expression containing the local variable to reflect.</param>
        /// <returns>information about the variable (if able to retrieve)</returns>
        public static Maybe <FieldInfo> VariableSafely <T>(Func <T> expression)
        {
            Enforce.Argument(() => expression);
            var method = expression.Method;
            var body   = method.GetMethodBody();

            if (null == body)
            {
                return(Maybe <FieldInfo> .Empty);
            }
            var il = body.GetILAsByteArray();

            // in DEBUG we end up with stack
            // in release, there is a ret at the end
            if ((il[0] == Ldarg_0) && (il[1] == Ldfld) && ((il[6] == Stloc_0) || (il[6] == Ret)))
            {
                var fieldHandle = BitConverter.ToInt32(il, 2);

                var module         = method.Module;
                var expressionType = expression.Target.GetType();

                if (!expressionType.IsGenericType)
                {
                    return(module.ResolveField(fieldHandle));
                }
                var genericTypeArguments = expressionType.GetGenericArguments();
                // method does not have any generics
                //var genericMethodArguments = method.GetGenericArguments();
                return(module.ResolveField(fieldHandle, genericTypeArguments, Type.EmptyTypes));
            }
            return(Maybe <FieldInfo> .Empty);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DatasetGraphModel"/> class.
        /// </summary>
        /// <param name="context">The context that is used to execute actions on the UI thread.</param>
        /// <param name="facade">The project that holds the graph of datasets.</param>
        /// <param name="datasetModelBuilder">The function that builds <see cref="DatasetModel"/> objects.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="context"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="facade"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="datasetModelBuilder"/> is <see langword="null" />.
        /// </exception>
        public DatasetGraphModel(
            IContextAware context,
            ProjectFacade facade,
            Func <DatasetFacade, DatasetModel> datasetModelBuilder)
            : base(context)
        {
            {
                Enforce.Argument(() => facade);
            }

            m_Project = facade;
            m_Project.OnDatasetCreated += (s, e) => AddDatasetToGraph();
            m_Project.OnDatasetDeleted += (s, e) => RemoveDatasetFromGraph();

            m_DatasetModelBuilder = datasetModelBuilder;

            LayoutType       = "Tree";
            LayoutParameters = new SimpleTreeLayoutParameters
            {
                LayerGap  = 250,
                VertexGap = 250,
                Direction = LayoutDirection.TopToBottom,
            };

            ReloadProject();
        }
        public static string GetPath <TTarget, TProperty>(Expression <Func <TTarget, TProperty> > prop)
        {
            // slow binding for now
            Enforce.Argument(() => prop);

            var lambda = prop as LambdaExpression;

            Enforce.That(lambda != null, "Must be a lambda expression");
            Enforce.That(lambda.Body.NodeType == ExpressionType.MemberAccess, "Must be member access");

            var memberExpr = lambda.Body as MemberExpression;

            if (null == memberExpr)
            {
                throw new InvalidOperationException("memberExpr");
            }

            string path = memberExpr.Member.Name;

            while (null != (memberExpr.Expression as MemberExpression))
            {
                memberExpr = (MemberExpression)memberExpr.Expression;
                path       = Compose(memberExpr.Member.Name, path);
            }
            return(path);
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LocalDatasetDistributor"/> class.
        /// </summary>
        /// <param name="localDistributor">The object that handles distribution proposals for the local machine.</param>
        /// <param name="loader">The object that handles the actual starting of the dataset application.</param>
        /// <param name="commandHub">The object that sends commands to remote endpoints.</param>
        /// <param name="notificationHub">The object that receives notifications from remote endpoints.</param>
        /// <param name="uploads">The object that stores all the uploads waiting to be started.</param>
        /// <param name="datasetInformationBuilder">The function that builds <see cref="DatasetOnlineInformation"/> objects.</param>
        /// <param name="communicationLayer">The object that handles the communication for the application.</param>
        /// <param name="systemDiagnostics">The object that provides the diagnostics methods for the system.</param>
        /// <param name="scheduler">The scheduler that is used to run the tasks on.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="localDistributor"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="loader"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="commandHub"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="notificationHub"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="uploads"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="datasetInformationBuilder"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="communicationLayer"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="systemDiagnostics"/> is <see langword="null" />.
        /// </exception>
        public LocalDatasetDistributor(
            ICalculateDistributionParameters localDistributor,
            IDatasetActivator loader,
            ISendCommandsToRemoteEndpoints commandHub,
            INotifyOfRemoteEndpointEvents notificationHub,
            IStoreUploads uploads,
            Func <DatasetId, EndpointId, NetworkIdentifier, DatasetOnlineInformation> datasetInformationBuilder,
            ICommunicationLayer communicationLayer,
            SystemDiagnostics systemDiagnostics,
            TaskScheduler scheduler = null)
        {
            {
                Enforce.Argument(() => localDistributor);
                Enforce.Argument(() => loader);
                Enforce.Argument(() => commandHub);
                Enforce.Argument(() => notificationHub);
                Enforce.Argument(() => datasetInformationBuilder);
                Enforce.Argument(() => communicationLayer);
                Enforce.Argument(() => systemDiagnostics);
            }

            m_LocalDistributor          = localDistributor;
            m_Loader                    = loader;
            m_CommandHub                = commandHub;
            m_NotificationHub           = notificationHub;
            m_Uploads                   = uploads;
            m_DatasetInformationBuilder = datasetInformationBuilder;
            m_CommunicationLayer        = communicationLayer;
            m_Diagnostics               = systemDiagnostics;
            m_Scheduler                 = scheduler ?? TaskScheduler.Default;
        }
예제 #6
0
        public void Null_Collection_Is_Detected()
        {
            var v = Visitor.CreateValid();

            v.Programs = null;
            Enforce.Argument(() => v, BusinessRules.VisitorRules);
        }
        public TextSearchOptionsParamBuilder <TModel> MapQuery <TProperty>(Expression <Func <TModel, TProperty> > property)
        {
            Enforce.Argument(() => property);

            _queryMapper.Property(property, _param.Name);
            return(this);
        }
예제 #8
0
        /// <summary>
        /// Adds a new child.
        /// </summary>
        /// <param name="persistenceInformation">The persistence information that describes the dataset that should be copied.</param>
        /// <returns>
        /// The newly created dataset.
        /// </returns>
        public DatasetFacade AddChild(IPersistenceInformation persistenceInformation)
        {
            {
                Enforce.Argument(() => persistenceInformation);
            }

            // For user created datasets we have some default settings:
            // - We don't ever allow nodes to be adopted, it just creates too much of a hassle with
            //   updating the node links etc.
            // - We always allow user created datasets to become parents, they may need to split
            //   of their calculations
            // - We allow all user created datasets to be copied
            // - User created datasets can always be deleted
            var creationInformation = new DatasetCreationInformation
            {
                CanBeAdopted       = false,
                CanBecomeParent    = true,
                CanBeCopied        = true,
                CanBeDeleted       = true,
                CreatedOnRequestOf = DatasetCreator.User,
                LoadFrom           = persistenceInformation,
            };

            var child = m_Dataset.CreateNewChild(creationInformation);

            return(new DatasetFacade(child));
        }
예제 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShutdownApplicationCommand"/> class.
        /// </summary>
        /// <param name="shutdownAction">The <see cref="Action"/> that performs the shutdown.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="shutdownAction"/> is <see langword="null"/>.
        /// </exception>
        internal ShutdownApplicationCommand(Action shutdownAction)
        {
            {
                Enforce.Argument(() => shutdownAction);
            }

            m_Action = shutdownAction;
        }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandId"/> class.
 /// </summary>
 /// <param name="name">The ID of the command.</param>
 /// <exception cref="ArgumentNullException">
 /// Thrown if <paramref name="name"/> is <see langword="null"/>.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// Thrown if <paramref name="name"/> is an empty string.
 /// </exception>
 public CommandId(string name)
     : base(name)
 {
     {
         Enforce.Argument(() => name);
         Enforce.Argument(() => name, StringIs.NotEmpty);
     }
 }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NotificationName"/> class.
 /// </summary>
 /// <param name="name">The name of the notification.</param>
 public NotificationName(string name)
     : base(name)
 {
     {
         Enforce.Argument(() => name);
         Enforce.Argument(() => name, StringIs.NotEmpty);
     }
 }
예제 #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectHub"/> class.
        /// </summary>
        /// <param name="service">
        /// The user interface service that handles the communication with the rest of the system.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="service"/> is <see langword="null" />.
        /// </exception>
        internal ProjectHub(IUserInterfaceService service)
        {
            {
                Enforce.Argument(() => service);
            }

            m_Service = service;
        }
예제 #13
0
        public virtual THtmlTag InnerText(string value)
        {
            Enforce.Argument(() => value);
            Enforce.That(RenderMode != TagRenderMode.SelfClosing);

            HtmlTagBuilder.SetInnerText(value);
            return((THtmlTag)this);
        }
예제 #14
0
        /// <summary>
        /// Provides the view with a function that can build output pipes.
        /// </summary>
        /// <param name="builder">The function that builds script output pipes.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="builder"/> is <see langword="null" />.
        /// </exception>
        public void OutputPipeBuilder(Func <ISendScriptOutput> builder)
        {
            {
                Enforce.Argument(() => builder);
            }

            m_CreateNewScriptOutputPipe = builder;
        }
예제 #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Bootstrapper"/> class.
        /// </summary>
        /// <param name="shutdownEvent">The event that signals to the application that it is safe to shut down.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="shutdownEvent"/> is <see langword="null" />.
        /// </exception>
        protected Bootstrapper(AutoResetEvent shutdownEvent)
        {
            {
                Enforce.Argument(() => shutdownEvent);
            }

            m_ShutdownEvent = shutdownEvent;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DatasetDistributionGenerator"/> class.
        /// </summary>
        /// <param name="distributors">The collection of objects that handle distributing to the available machines.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="distributors"/> is <see langword="null" />.
        /// </exception>
        public DatasetDistributionGenerator(IEnumerable <IGenerateDistributionProposals> distributors)
        {
            {
                Enforce.Argument(() => distributors);
            }

            m_Distributors = distributors;
        }
예제 #17
0
        public virtual ISD GetSD()
        {
            var sd = this as ISD;

            Enforce.Argument(() => sd);

            return(sd);
        }
예제 #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FeedbackReportTransmitter"/> class.
        /// </summary>
        /// <param name="sender">The object that sends the reports to the remote server.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="sender"/> is <see langword="null" />.
        /// </exception>
        public FeedbackReportTransmitter(IReportSender sender)
        {
            {
                Enforce.Argument(() => sender);
            }

            m_Sender = sender;
        }
예제 #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UserInterfaceModule"/> class.
        /// </summary>
        /// <param name="ownerService">The owner service.</param>
        public UserInterfaceModule(IUserInterfaceService ownerService)
        {
            {
                Enforce.Argument(() => ownerService);
            }

            m_Owner = ownerService;
        }
예제 #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Observable"/> class.
        /// </summary>
        /// <param name="context">The context that is used to execute actions on the UI thread.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="context"/> is <see langword="null" />.
        /// </exception>
        protected Observable(IContextAware context)
        {
            {
                Enforce.Argument(() => context);
            }

            m_Context = context;
        }
예제 #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnloadProjectCommand"/> class.
        /// </summary>
        /// <param name="unloadMethod">The method used to unload the project.</param>
        /// <param name="scheduler">The scheduler that is used to run the tasks.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="unloadMethod"/> is <see langword="null"/>.
        /// </exception>
        internal UnloadProjectCommand(Action unloadMethod, TaskScheduler scheduler = null)
        {
            {
                Enforce.Argument(() => unloadMethod);
            }

            m_UnloadMethod = unloadMethod;
            m_Scheduler    = scheduler ?? TaskScheduler.Default;
        }
예제 #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DistributionSuggestion"/> class.
        /// </summary>
        /// <param name="plan">The suggested plan.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when <paramref name="plan"/> is <see langword="null" />.
        /// </exception>
        public DistributionSuggestion(DistributionPlan plan)
        {
            {
                Enforce.Argument(() => plan);
            }

            Rating = plan.Proposal.Rate();
            Plan   = plan;
        }
예제 #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CreateProjectCommand"/> class.
        /// </summary>
        /// <param name="projectCreator">The function that is used to create the new project.</param>
        /// <param name="scheduler">The scheduler that is used to run the tasks.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="projectCreator"/> is <see langword="null"/>.
        /// </exception>
        internal CreateProjectCommand(Func <IProject> projectCreator, TaskScheduler scheduler = null)
        {
            {
                Enforce.Argument(() => projectCreator);
            }

            m_Creator   = projectCreator;
            m_Scheduler = scheduler ?? TaskScheduler.Default;
        }
예제 #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LoadProjectCommand"/> class.
        /// </summary>
        /// <param name="loader">The function that is used to load the project.</param>
        /// <param name="scheduler">The scheduler that is used to run the tasks.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="loader"/> is <see langword="null"/>.
        /// </exception>
        internal LoadProjectCommand(Func <IPersistenceInformation, IProject> loader, TaskScheduler scheduler = null)
        {
            {
                Enforce.Argument(() => loader);
            }

            m_Loader    = loader;
            m_Scheduler = scheduler ?? TaskScheduler.Default;
        }
 public HtmlTagBuilder MergeStyle(HtmlTextWriterStyle style, object value,
                                  bool replaceExisting = false)
 {
     Enforce.Argument(() => value);
     if (replaceExisting || !StyleValues.ContainsKey(style))
     {
         StyleValues[style] = value;
     }
     return(this);
 }
 public HtmlTagBuilder MergeAttribute(HtmlTextWriterAttribute attribute, object value,
                                      bool replaceExisting = false)
 {
     Enforce.Argument(() => value);
     if (replaceExisting || !Attributes.ContainsKey(attribute))
     {
         Attributes[attribute] = value;
     }
     return(this);
 }
예제 #27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CoreProxy"/> class.
        /// </summary>
        /// <param name="owner">The <see cref="Kernel"/> to which this proxy is linked.</param>
        /// <param name="diagnostics">The object that handles the diagnostics for the application.</param>
        /// <param name="scheduler">The scheduler that is used to run tasks.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="owner"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="diagnostics"/> is <see langword="null"/>.
        /// </exception>
        public CoreProxy(IKernel owner, SystemDiagnostics diagnostics, TaskScheduler scheduler = null)
            : base(diagnostics)
        {
            {
                Enforce.Argument(() => owner);
            }

            m_Owner     = owner;
            m_Scheduler = scheduler ?? TaskScheduler.Default;
        }
예제 #28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DatasetViewVertex"/> class.
        /// </summary>
        /// <param name="context">The context that is used to execute actions on the UI thread.</param>
        /// <param name="model">The model of the dataset.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="model"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="context"/> is <see langword="null" />.
        /// </exception>
        public DatasetViewVertex(IContextAware context, DatasetModel model)
            : base(context)
        {
            {
                Enforce.Argument(() => model);
            }

            m_Dataset                = model;
            m_Dataset.OnActivated   += (s, e) => Notify(() => IsDatasetActivated);
            m_Dataset.OnDeactivated += (s, e) => Notify(() => IsDatasetActivated);
        }
예제 #29
0
        /// <summary>
        /// Configures the logging system to write to the debug listeners
        /// </summary>
        /// <param name="configure">The configuration option.</param>
        /// <returns>log syntax</returns>
        public static LogSyntax UseDebugLog([NotNull] Action <ListeningLogOptions> configure)
        {
            Enforce.Argument(() => configure);
            var options = ConfiguratorHelper.GetDefaultListeningOptions();

            configure(options);
            var appender = ConfiguratorHelper.BuildDebugLog(options);

            Configure(appender);
            return(new LogSyntax(appender));
        }
예제 #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KernelBootstrapper"/> class.
        /// </summary>
        /// <param name="shutdownEvent">The event that signals to the application that it is safe to shut down.</param>
        /// <param name="onStartUserInterface">The function used to store the DI container which holds the kernel UI references.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="shutdownEvent"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown when <paramref name="onStartUserInterface"/> is <see langword="null"/>.
        /// </exception>
        public KernelBootstrapper(
            AutoResetEvent shutdownEvent,
            Action <IContainer> onStartUserInterface)
            : base(shutdownEvent)
        {
            {
                Enforce.Argument(() => onStartUserInterface);
            }

            m_OnStartUserInterface = onStartUserInterface;
        }