示例#1
0
        public async Task <FdaLabelSearchResults> SearchAsync(FdaLabelSearchOptions fdaLabelSearchOptions, PagingSortingOptions pagingOptions = null, string joiner = "AND")
        {
            if (pagingOptions == null)
            {
                pagingOptions = new PagingSortingOptions();
            }

            var parameterDictionary = new ParameterDictionary
            {
                { "search", fdaLabelSearchOptions.ToQuery(joiner) }
            };

            if (pagingOptions.Limit != 0)
            {
                parameterDictionary.Add("limit", pagingOptions.Limit.ToString());
            }
            if (pagingOptions.Skip != 0)
            {
                parameterDictionary.Add("skip", pagingOptions.Skip.ToString());
            }

            if (!string.IsNullOrEmpty(_apiKey))
            {
                parameterDictionary.Add("api_key", _apiKey);
            }

            var json = await GetAsync($"/drug/label.json?{parameterDictionary.ToQueryString()}");


            return(FdaLabelSearchResults.FromJson(json));
        }
示例#2
0
        /// <summary>
        /// Create new upload ticket asynchronously
        /// </summary>
        /// <returns>Upload ticket</returns>
        public async Task <Video> UploadPullLinkAsync(string link)
        {
            try
            {
                var param = new ParameterDictionary();
                param.Add("type", "pull");
                param.Add("link", link);

                var request = ApiRequestFactory.AuthorizedRequest(
                    AccessToken,
                    HttpMethod.Post,
                    Endpoints.UploadTicket,
                    null,
                    param
                    );

                return(await ExecuteApiRequest <Video>(request));
            }
            catch (Exception ex)
            {
                if (ex is VimeoApiException)
                {
                    throw;
                }
                throw new VimeoUploadException("Error generating upload ticket.", null, ex);
            }
        }
        private ParameterDictionary <DependencyData> BuildConstructorParameters(ConstructorInfo constructor)
        {
            // NOTE: We used to use a LINQ query here (which is cleaner code), but we reverted back to using
            // a foreach statement to clean up the stack trace, since this is a very common code path to
            // show up in the stack trace and preventing showing up the Enumerable and Buffer`1 calls here
            // makes it easier for developers (and maintainers) to read the stack trace.
            var parameters = new ParameterDictionary <DependencyData>();

            foreach (ParameterInfo parameter in constructor.GetParameters())
            {
                var              consumer   = new InjectionConsumerInfo(parameter);
                Expression       expression = this.GetPlaceHolderFor(parameter);
                InstanceProducer?producer   = null;

                if (expression is null)
                {
                    producer   = this.Container.Options.GetInstanceProducerFor(consumer);
                    expression = producer.BuildExpression();
                }

                parameters.Add(parameter, new DependencyData(parameter, expression, producer));
            }

            return(parameters);
        }
        public static bool SetExpectedUsers(this Room room, HashSet <string> newExpectedUsers, int?newMaxPlayers = null, WebFlags webFlags = null, bool broadcast = true)
        {
            Hashtable hash     = new Hashtable();
            Hashtable expected = new Hashtable();

            if (newMaxPlayers.HasValue)
            {
                hash.Add(GamePropertyKey.MaxPlayers, newMaxPlayers);
                expected.Add(GamePropertyKey.MaxPlayers, room.MaxPlayers);
            }

            if (newExpectedUsers == null)
            {
                hash.Add(GamePropertyKey.ExpectedUsers, null);
            }
            else
            {
                hash.Add(GamePropertyKey.ExpectedUsers, newExpectedUsers.ToArray());
            }

            if (room.ExpectedUsers != null)
            {
                expected.Add(GamePropertyKey.ExpectedUsers, room.ExpectedUsers);
            }

            ParameterDictionary opParameters = new ParameterDictionary(3);

            opParameters.Add(ParameterCode.Properties, hash);
            opParameters.Add(ParameterCode.ExpectedValues, expected);
            if (broadcast)
            {
                opParameters.Add(ParameterCode.Broadcast, true);
            }
            if (webFlags != null)
            {
                opParameters.Add(ParameterCode.EventForward, webFlags.WebhookFlags);
            }
            return(room.LoadBalancingClient.LoadBalancingPeer.SendOperation(OperationCode.SetProperties, opParameters,
                                                                            SendOptions.SendReliable));
        }
示例#5
0
    public void InitNodeFromDescriptor(NodeDescriptor descriptor)
    {
        nodeType = descriptor.nodeType;
        nodeName = descriptor.nodeName;
        titleBarColor = descriptor.titleBarColor;

        timePointer = new TimePointer();
        timePointer.hasTiming = descriptor.hasTiming;
        timePointer.InitTimePointer(descriptor.defaultAnimationLength);
        timePointer.parentNode = this;

        dragButton = new DragButton();
        dragButton.InitDragButton();
        
        parameters = new ParameterDictionary();
        foreach (KeyValuePair<string, NodeParameter> pair in descriptor.parameters)
        {
            NodeParameter tempParameter = new NodeParameter();
            tempParameter.floatParam = pair.Value.floatParam;
            tempParameter.stringParam = pair.Value.stringParam;
            tempParameter.vectorParam = new Vector3(pair.Value.vectorParam.x, pair.Value.vectorParam.y, pair.Value.vectorParam.z);
            tempParameter.type = pair.Value.type;

            parameters.Add(pair.Key, tempParameter);
        }

        for(int i = 0; i < descriptor.numberOfInputs; i++)
        {
            nodeInputs.Add(new NodeInput());
        }
        numberOfInputs = descriptor.numberOfInputs;
        nodeInputsMin = descriptor.minInputs;
        nodeInputsMax = descriptor.maxInputs;
        for (int i = 0; i < descriptor.numberOfOutputs; i++)
        {
            nodeOutputs.Add(new NodeOutput());
            if(nodeType != NodeType.Graph)
                nodeOutputs[i].outputNode = this;
        }
        numberOfOutputs = descriptor.numberOfOutputs;
        nodeOutputsMin = descriptor.minOutputs;
        nodeOutputsMax = descriptor.maxOutputs;

        multiInput = descriptor.isMultiInput;
        multiOutput = descriptor.isMultiOutput;

        nodeRect = new Rect(10f, 10f, 150f, 100f);
    }
示例#6
0
 public void Execute_ChecksValidatorsForBadParameters()
 {
     var router=new Router();
     var parameters = new ParameterDictionary();
     parameters.Add("id", "1234");
     var badvalidators = new List<RouteParamsMustMatch>();
     badvalidators.Add(x => x["id"] == "xxx");
     var bad=new Route
     {
         Responder=(RequestContext c, ref bool skip) => new WrapperView("bad"),
         Pattern=new FakePatternMatcher("/foo/1234", parameters),
         ParameterValidators=badvalidators
     };
     router.AddRoute(bad);
     var context=new FakeServerContext();
     context.RequestUrl=new Uri("http://meh.com/foo/1234");
     context.HttpMethod="get";
     Assert.IsFalse(router.Execute(context));
 }
示例#7
0
        /**This method returns true(and populates Params) if the input string matches the Pattern string. **/
        public MatchResult Match(string input)
        {
            var Params=new ParameterDictionary();
            string s=input;
            if(Groups.Count==0){
                throw new ApplicationException("Groups.Count==0 matches all. This shouldn't happen");
            }
            foreach(var g in Groups){
                if(!g.IsParam){
                    if(g.Text.Length>=s.Length){
                        if(Groups[Groups.Count-1]==g){
                            return new MatchResult(g.Text==s, Params); //to check for exact matches(but only for the last group)
                        }else{
                            if(g.Optional){
                                return new MatchResult(true, Params);
                            }else{
                                return new MatchResult(false, Params);
                            }
                        }
                    }
                    string tmp=CutString(s,0,g.Text.Length);
                    if(g.Text==tmp){
                        s=s.Substring(g.Text.Length);
                    }else{
                        return new MatchResult(false, Params);
                    }
                }else{
                    int end;
                    if(g.End=='\0'){
                        end=s.Length;
                    }else{
                        end=s.IndexOf(g.End);
                        if(end==-1){
                            return new MatchResult(false, Params);
                        }
                    }
                    if(g.MatchAll){
                        if(s.Substring(0,end)==""){
                            return new MatchResult(false, Params);
                        }
                        int slash=s.IndexOf('/');
                        if(slash==-1 || g.Optional){
                            if(g.MatchType!=null)
                            {
                                if(!g.MatchType.IsMatch(s.Substring(0,end)))
                                {
                                    return new MatchResult(false, Params);
                                }
                            }
                            //Params.Add(g.ParamName, new List<string>());
                            //Params[g.ParamName]=s.Substring(0,end);
                            Params.Add(g.ParamName, s.Substring(0,end));
                            s=""; //doesn't matter.
                        }else{
                            if(g.MatchType!=null)
                            {
                                if(!g.MatchType.IsMatch(s.Substring(0,slash)))
                                {
                                    return new MatchResult(false, Params);
                                }

                            }

                            Params.Add(g.ParamName,s.Substring(0,slash));
                            s=s.Substring(slash); //doesn't matter.

                        }
                    }else{
                        string t=s.Substring(0,end);
                        bool matched=false;
                        foreach(var match in g.ValidMatches){
                            if(match==t){
                                matched=true;
                                //break;
                            }
                        }
                        if(matched==false){
                            return new MatchResult(false, Params);
                        }
                        if(g.MatchType!=null)
                        {
                            if(!g.MatchType.IsMatch(t))
                            {
                                return new MatchResult(false, Params);
                            }
                        }
                        Params.Add(g.ParamName,t);
                        s=s.Substring(end);
                    }
                }

            }
            if(s.Length!=0){
                return new MatchResult(false, Params);
            }else{
                return new MatchResult(true, Params);
            }
        }
示例#8
0
        /// <summary>
        /// Create a care plan with the specified protocols only
        /// </summary>
        public CarePlan CreateCarePlan(Patient p, bool asEncounters, IDictionary <String, Object> parameters, params Guid[] protocols)
        {
            if (p == null)
            {
                return(null);
            }

            try
            {
                var parmDict = new ParameterDictionary <String, Object>();
                if (parameters != null)
                {
                    foreach (var itm in parameters)
                    {
                        parmDict.Add(itm.Key, itm.Value);
                    }
                }

                // Allow each protocol to initialize itself
                var execProtocols = this.Protocols.Where(o => protocols.Contains(o.Id)).OrderBy(o => o.Name).Distinct().ToList();

                Patient currentProcessing   = null;
                bool    isCurrentProcessing = false;
                if (p.Key.HasValue)
                {
                    isCurrentProcessing = this.m_patientPromise.TryGetValue(p.Key.Value, out currentProcessing);
                }
                if (p.Key.HasValue && !isCurrentProcessing)
                {
                    lock (this.m_patientPromise)
                        if (!this.m_patientPromise.TryGetValue(p.Key.Value, out currentProcessing))
                        {
                            currentProcessing = p.Copy() as Patient;

                            // Are the participations of the patient null?
                            if (p.Participations.Count == 0 && p.VersionKey.HasValue)
                            {
                                p.Participations = EntitySource.Current.Provider.Query <Act>(o => o.Participations.Where(g => g.ParticipationRole.Mnemonic == "RecordTarget").Any(g => g.PlayerEntityKey == currentProcessing.Key) &&
                                                                                             o.StatusConceptKey != StatusKeys.Nullified && o.StatusConceptKey != StatusKeys.Obsolete && o.StatusConceptKey != StatusKeys.Cancelled).OfType <Act>()
                                                   .Select(a =>
                                                           new ActParticipation()
                                {
                                    Act = a,
                                    ParticipationRole = new Concept()
                                    {
                                        Mnemonic = "RecordTarget"
                                    },
                                    PlayerEntity = currentProcessing
                                }).ToList();

                                //EntitySource.Current.Provider.Query<SubstanceAdministration>(o => o.Participations.Where(g => g.ParticipationRole.Mnemonic == "RecordTarget").Any(g => g.PlayerEntityKey == currentProcessing.Key)).OfType<Act>()
                                //    .Union(EntitySource.Current.Provider.Query<QuantityObservation>(o => o.Participations.Where(g => g.ParticipationRole.Mnemonic == "RecordTarget").Any(g => g.PlayerEntityKey == currentProcessing.Key))).OfType<Act>()
                                //    .Union(EntitySource.Current.Provider.Query<CodedObservation>(o => o.Participations.Where(g => g.ParticipationRole.Mnemonic == "RecordTarget").Any(g => g.PlayerEntityKey == currentProcessing.Key))).OfType<Act>()
                                //    .Union(EntitySource.Current.Provider.Query<TextObservation>(o => o.Participations.Where(g => g.ParticipationRole.Mnemonic == "RecordTarget").Any(g => g.PlayerEntityKey == currentProcessing.Key))).OfType<Act>()
                                //    .Union(EntitySource.Current.Provider.Query<PatientEncounter>(o => o.Participations.Where(g => g.ParticipationRole.Mnemonic == "RecordTarget").Any(g => g.PlayerEntityKey == currentProcessing.Key))).OfType<Act>()

                                (ApplicationServiceContext.Current.GetService(typeof(IDataCachingService)) as IDataCachingService)?.Add(p);
                            }
                            currentProcessing.Participations = new List <ActParticipation>(p.Participations);

                            // The record target here is also a record target for any /relationships
                            // TODO: I think this can be removed no?
                            //currentProcessing.Participations = currentProcessing.Participations.Union(currentProcessing.Participations.SelectMany(pt =>
                            //{
                            //    if (pt.Act == null)
                            //        pt.Act = EntitySource.Current.Get<Act>(pt.ActKey);
                            //    return pt.Act?.Relationships?.Select(r =>
                            //    {
                            //        var retVal = new ActParticipation(ActParticipationKey.RecordTarget, currentProcessing)
                            //        {
                            //            ActKey = r.TargetActKey,
                            //            ParticipationRole = new Model.DataTypes.Concept() { Mnemonic = "RecordTarget", Key = ActParticipationKey.RecordTarget }
                            //        };
                            //        if (r.TargetAct != null)
                            //            retVal.Act = r.TargetAct;
                            //        else
                            //        {
                            //            retVal.Act = currentProcessing.Participations.FirstOrDefault(o=>o.ActKey == r.TargetActKey)?.Act ?? EntitySource.Current.Get<Act>(r.TargetActKey);
                            //        }
                            //        return retVal;
                            //    }
                            //    );
                            //})).ToList();

                            // Add to the promised patient
                            this.m_patientPromise.Add(p.Key.Value, currentProcessing);
                        }
                }
                else if (!p.Key.HasValue) // Not persisted
                {
                    currentProcessing = p.Clone() as Patient;
                }

                // Initialize for protocol execution
                parmDict.Add("runProtocols", execProtocols.Distinct());
                if (!this.IgnoreViewModelInitializer)
                {
                    foreach (var o in this.Protocols.Distinct())
                    {
                        o.Initialize(currentProcessing, parmDict);
                    }
                }

                parmDict.Remove("runProtocols");

                List <Act> protocolActs = new List <Act>();
                lock (currentProcessing)
                {
                    var thdPatient = currentProcessing.Copy() as Patient;
                    thdPatient.Participations = new List <ActParticipation>(currentProcessing.Participations.ToList().Where(o => o.Act?.MoodConceptKey != ActMoodKeys.Propose && o.Act?.StatusConceptKey != StatusKeys.Nullified && o.Act?.StatusConceptKey != StatusKeys.Obsolete && o.Act?.StatusConceptKey != StatusKeys.Cancelled));

                    // Let's ensure that there are some properties loaded eh?
                    if (this.IgnoreViewModelInitializer)
                    {
                        foreach (var itm in thdPatient.LoadCollection <ActParticipation>("Participations"))
                        {
                            itm.LoadProperty <Act>("TargetAct").LoadProperty <Concept>("TypeConcept");
                            foreach (var itmPtcpt in itm.LoadProperty <Act>("TargetAct").LoadCollection <ActParticipation>("Participations"))
                            {
                                itmPtcpt.LoadProperty <Concept>("ParticipationRole");
                                itmPtcpt.LoadProperty <Entity>("PlayerEntity").LoadProperty <Concept>("TypeConcept");
                                itmPtcpt.LoadProperty <Entity>("PlayerEntity").LoadProperty <Concept>("MoodConcept");
                            }
                            ;
                        }
                    }
                    protocolActs = execProtocols.AsParallel().SelectMany(o => o.Calculate(thdPatient, parmDict)).OrderBy(o => o.StopTime - o.StartTime).ToList();
                }

                // Current processing
                if (asEncounters)
                {
                    List <PatientEncounter> encounters = new List <PatientEncounter>();
                    foreach (var act in new List <Act>(protocolActs).Where(o => o.StartTime.HasValue && o.StopTime.HasValue).OrderBy(o => o.StartTime).OrderBy(o => (o.StopTime ?? o.ActTime.AddDays(7)) - o.StartTime))
                    {
                        act.StopTime = act.StopTime ?? act.ActTime;
                        // Is there a candidate encounter which is bound by start/end
                        var candidate = encounters.FirstOrDefault(e => (act.StartTime ?? DateTimeOffset.MinValue) <= (e.StopTime ?? DateTimeOffset.MaxValue) &&
                                                                  (act.StopTime ?? DateTimeOffset.MaxValue) >= (e.StartTime ?? DateTimeOffset.MinValue) &&
                                                                  !e.Relationships.Any(r => r.TargetAct?.Protocols.Intersect(act.Protocols, new ProtocolComparer()).Count() == r.TargetAct?.Protocols.Count())
                                                                  );

                        // Create candidate
                        if (candidate == null)
                        {
                            candidate = this.CreateEncounter(act, currentProcessing);
                            encounters.Add(candidate);
                            protocolActs.Add(candidate);
                        }
                        else
                        {
                            TimeSpan[] overlap =
                            {
                                (candidate.StopTime ?? DateTimeOffset.MaxValue) - (candidate.StartTime ?? DateTimeOffset.MinValue),
                                (candidate.StopTime ?? DateTimeOffset.MaxValue) - (act.StartTime ?? DateTimeOffset.MinValue),
                                (act.StopTime ?? DateTimeOffset.MaxValue) - (candidate.StartTime ?? DateTimeOffset.MinValue),
                                (act.StopTime ?? DateTimeOffset.MaxValue) - (act.StartTime ?? DateTimeOffset.MinValue)
                            };
                            // find the minimum overlap
                            var minOverlap = overlap.Min();
                            var overlapMin = Array.IndexOf(overlap, minOverlap);
                            // Adjust the dates based on the start / stop time
                            if (overlapMin % 2 == 1)
                            {
                                candidate.StartTime = act.StartTime;
                            }
                            if (overlapMin > 1)
                            {
                                candidate.StopTime = act.StopTime;
                            }
                            candidate.ActTime = candidate.StartTime ?? candidate.ActTime;
                        }

                        // Add the protocol act
                        candidate.Relationships.Add(new ActRelationship(ActRelationshipTypeKeys.HasComponent, act));

                        // Remove so we don't have duplicates
                        protocolActs.Remove(act);
                        currentProcessing.Participations.RemoveAll(o => o.Act == act);
                    }

                    // for those acts which do not have a stop time, schedule them in the first appointment available
                    foreach (var act in new List <Act>(protocolActs).Where(o => !o.StopTime.HasValue))
                    {
                        var candidate = encounters.OrderBy(o => o.StartTime).FirstOrDefault(e => e.StartTime >= act.StartTime);
                        if (candidate == null)
                        {
                            candidate = this.CreateEncounter(act, currentProcessing);
                            encounters.Add(candidate);
                            protocolActs.Add(candidate);
                        }
                        // Add the protocol act
                        candidate.Relationships.Add(new ActRelationship(ActRelationshipTypeKeys.HasComponent, act));

                        // Remove so we don't have duplicates
                        protocolActs.Remove(act);
                        currentProcessing.Participations.RemoveAll(o => o.Act == act);
                    }
                }

                // TODO: Configure for days of week
                foreach (var itm in protocolActs)
                {
                    while (itm.ActTime.DayOfWeek == DayOfWeek.Sunday || itm.ActTime.DayOfWeek == DayOfWeek.Saturday)
                    {
                        itm.ActTime = itm.ActTime.AddDays(1);
                    }
                }

                return(new CarePlan(p, protocolActs.ToList())
                {
                    CreatedByKey = Guid.Parse("fadca076-3690-4a6e-af9e-f1cd68e8c7e8")
                });
            }
            catch (Exception e)
            {
                this.m_tracer.TraceError("Error creating care plan: {0}", e);
                throw;
            }
            finally
            {
                lock (m_patientPromise)
                    if (p.Key.HasValue && this.m_patientPromise.ContainsKey(p.Key.Value))
                    {
                        m_patientPromise.Remove(p.Key.Value);
                    }
            }
        }
示例#9
0
 public void FromXXX_Should_Populate_Model_In_An_Additive_Manner()
 {
     var r = new Router();
     var ctrl = r.Controller(c => new TestController(c));
     var foo = ctrl.Handles("/foo").
         UsingModel(c => new TestModel()).
         FromForm().
         FromRoute().
         With((c, m) => c.TestWithModel(m));
     bool skip = false;
     var formparams=new ParameterDictionary();
     formparams.Add("Foo", new string[]{"bar"});
     var context = new FakeServerContext();
     context.Form = formparams;
     var routeparams = new ParameterDictionary();
     routeparams.Add("Bar", new string[]{"baz"});
     var view=foo.Current.Responder(
         new RequestContext(context, null, null, routeparams), ref skip);
     Assert.AreEqual("foobarbaz", view.ToString());
 }
示例#10
0
 public void WithRouteParamLike_AddsValidatorToRoute()
 {
     var r=new Router();
     var ctrl=r.Controller<TestController>(null);
     var tmp=ctrl.Handles("/foo/{id}");
     tmp.WithRouteParamLike("id", (x) => { int tmpout; return int.TryParse(x, out tmpout); });
     var p = new ParameterDictionary();
     p.Add("id", "123");
     Assert.IsTrue(r.GetRoutes()[0].ParameterValidators.First()(p));
 }