/// <summary>
        /// Create an intermediate from a passphrase or intermediate code
        /// </summary>
        public Bip38Intermediate(string fromstring, Interpretation interpretation)
        {
            if (interpretation == Interpretation.IntermediateCode) {
                createFromCode(fromstring);
            } else {
                _ownersalt = new byte[8];

                // Get 8 random bytes to use as salt
                SecureRandom sr = new SecureRandom();
                sr.NextBytes(_ownersalt);
                createFromPassphrase(fromstring, _ownersalt);
            }
        }
        /// <summary>
        /// Create an intermediate from a passphrase or intermediate code
        /// </summary>
        public Bip38Intermediate(string fromstring, Interpretation interpretation, int startingSequenceNumber = 0)
        {
            if (interpretation == Interpretation.IntermediateCode) {
                createFromCode(fromstring);
            } else {
                _ownerentropy = new byte[8];

                // Get 8 random bytes to use as salt
                SecureRandom sr = new SecureRandom();
                sr.NextBytes(_ownerentropy);
                // set lot number between 100000 and 999999, and sequence number to 1
                long x = (sr.NextLong () % 900000L + 100000L) * 4096L + (long)startingSequenceNumber;
                for (int i=7; i>=4; i--) {
                    _ownerentropy[i] = (byte)(x & 0xFF);
                    x >>= 8;
                }
                createFromPassphrase(fromstring, _ownerentropy, true);
            }
        }
Ejemplo n.º 3
0
 public override bool BoolValue(Interpretation !interp)
 {
     return(left.BoolValue(interp) || right.BoolValue(interp));
 }
Ejemplo n.º 4
0
            public void WriteValueField(VersionedVariable reference, IFieldDefinition field, Interpretation value)
            {
                int refId = GetIdFromInterpretation(this.GetInterpretation(reference));

                this.WriteField(refId, field, value);
            }
Ejemplo n.º 5
0
            public override int IntValue(Interpretation !interp)
            {
                bool value = BoolValue(interp);

                return(value ? 1 : 0);
            }
Ejemplo n.º 6
0
 public override bool BoolValue(Interpretation !interp)
 {
     return(value);
 }
Ejemplo n.º 7
0
            public override bool BoolValue(Interpretation !interp)
            {
                int value = IntValue(interp);

                return(value == 0 ? true : false);
            }
Ejemplo n.º 8
0
 public override int IntValue(Interpretation !interp)
 {
     return(left.IntValue(interp) % right.IntValue(interp));
 }
Ejemplo n.º 9
0
 public abstract string !StringValue(Interpretation !interp);
Ejemplo n.º 10
0
 private HashSet <NodeReference> getSubstitutedAnswers(Interpretation interpretation)
 {
     //TODO find alternative answers - it is required for generalization measure
     return(new HashSet <NodeReference>());
 }
Ejemplo n.º 11
0
        public void InterpretationIndex(RuleEngine env, ProAi.Clips.DataObject obj)
        {
            Interpretation oInterpret = new Interpretation(env.UserFunctionManager.RtnString(1));

            m_stInferResult.lstInInterpretation.Add(oInterpret);
        }
Ejemplo n.º 12
0
 public void InterpretationIndex(RuleEngine env, ProAi.Clips.DataObject obj)
 {
     Interpretation oInterpret = new Interpretation(env.UserFunctionManager.RtnString(1));
     m_stInferResult.lstInInterpretation.Add(oInterpret);
 }
Ejemplo n.º 13
0
        public void TestRemoteTimer()
        {
            var json        = "";
            var timer       = new RemoteTimer(10);
            var interpretor = Interpretation.Create <IRemoteTimer>(timer, typeof(IRemoteTimerExtensions));

            Assert.IsFalse(timer.IsRunning);
            Assert.AreEqual(10, timer.Interval);

            /* Start the timer and assert it is running */
            json = @"{ ""method-name"": ""Start"" }";
            interpretor.Execute(json);

            Assert.IsTrue(timer.IsRunning);

            Thread.Sleep(50);

            /* Pause the timer twice and assert running state */

            json = @"{ ""method-name"": ""Pause"" }";
            interpretor.Execute(json);
            Assert.IsFalse(timer.IsRunning);

            json = @"{ ""method-name"": ""Pause"" }";
            interpretor.Execute(json);
            Assert.IsTrue(timer.IsRunning);

            Thread.Sleep(50);

            /* Stop the timer, set a new interval and restart it: */
            json = @"[{ ""method-name"": ""Stop""},
                        { ""method-name"": ""SetInterval"", ""newInterval"": 20 },
                        { ""method-name"": ""Start""}]";

            interpretor.Execute(json);
            Assert.AreEqual(20, timer.Interval);

            Thread.Sleep(100);

            /* Get tick information from timer */
            json = @"{ ""method-name"": ""GetTicksTotal""}";
            var ticks = interpretor.Execute(json);

            Assert.IsNotNull(ticks);
            Assert.IsInstanceOfType(ticks, typeof(int));
            Assert.IsTrue(Convert.ToInt32(ticks) > 0);

            /* Try to execute public method on RemoteTimer */
            bool error = false;

            json = @"{ ""method-name"": ""Dispose"" }";

            try
            {
                interpretor.Execute(json);
            }
            catch { error = true; }

            Assert.IsTrue(error);

            //dispose timer because the test is ready
            timer.Dispose();
        }
Ejemplo n.º 14
0
        public override ErrorList Validate()
        {
            var result = new ErrorList();

            result.AddRange(base.Validate());

            if (Name != null)
            {
                result.AddRange(Name.Validate());
            }
            if (Value != null)
            {
                result.AddRange(Value.Validate());
            }
            if (Interpretation != null)
            {
                result.AddRange(Interpretation.Validate());
            }
            if (CommentsElement != null)
            {
                result.AddRange(CommentsElement.Validate());
            }
            if (Applies != null)
            {
                result.AddRange(Applies.Validate());
            }
            if (IssuedElement != null)
            {
                result.AddRange(IssuedElement.Validate());
            }
            if (StatusElement != null)
            {
                result.AddRange(StatusElement.Validate());
            }
            if (ReliabilityElement != null)
            {
                result.AddRange(ReliabilityElement.Validate());
            }
            if (BodySite != null)
            {
                result.AddRange(BodySite.Validate());
            }
            if (Method != null)
            {
                result.AddRange(Method.Validate());
            }
            if (Identifier != null)
            {
                result.AddRange(Identifier.Validate());
            }
            if (Subject != null)
            {
                result.AddRange(Subject.Validate());
            }
            if (Performer != null)
            {
                result.AddRange(Performer.Validate());
            }
            if (ReferenceRange != null)
            {
                ReferenceRange.ForEach(elem => result.AddRange(elem.Validate()));
            }
            if (Component != null)
            {
                Component.ForEach(elem => result.AddRange(elem.Validate()));
            }

            return(result);
        }
Ejemplo n.º 15
0
 public RuledInterpretation(Interpretation interpretation, FeatureKey key)
 {
     Interpretation = interpretation;
     FeatureKey     = key;
 }
Ejemplo n.º 16
0
 public HeapModelValue(IFieldDefinition field, Interpretation value)
 {
     this.Field = field;
     this.Value = value;
 }
Ejemplo n.º 17
0
 public abstract bool BoolValue(Interpretation !interp);
Ejemplo n.º 18
0
 public abstract object !GetValue(Interpretation !interp);
Ejemplo n.º 19
0
 private static int GetIdFromInterpretation(Interpretation interpretation)
 {
     return((int)(long)interpretation.Value);
 }
Ejemplo n.º 20
0
 public abstract int IntValue(Interpretation !interp);
Ejemplo n.º 21
0
        private void HandleDebug(Interpretation interpretation)
        {
            if (interpretation.Command != "debug")
            {
                return;
            }

            var outputSystem = _engine.GetSystem <OutputSystem>();

            if (interpretation.Primary.Count == 0)
            {
                outputSystem.AddLog("Debug command must have a target.");
                return;
            }

            if (interpretation.Primary.Count > 1)
            {
                outputSystem.AddLog("Debug command must have a single target.");
                return;
            }

            long entityIdentifier = -1;

            if (interpretation.Primary[0].Candidates.Count > 1)
            {
                outputSystem.AddLog("Debug command must have a single target.");
                return;
            }
            else if (interpretation.Primary[0].Candidates.Count > 0)
            {
                entityIdentifier = interpretation.Primary[0].Candidates[0];
            }
            else if (!long.TryParse(interpretation.Primary[0].UserInput, out entityIdentifier))
            {
                outputSystem.AddLog("Could not determine EntityIdentifier.");
                return;
            }

            try
            {
                var components = _engine.GetAllComponents(entityIdentifier);

                StringBuilder sb = new StringBuilder();

                sb.AppendLine($"Components for EntityIdentifier {entityIdentifier}: \r\n");

                foreach (var currComponent in components)
                {
                    sb.AppendLine($"\t{currComponent.GetType().FullName}");

                    foreach (var currLine in JsonConvert.SerializeObject(currComponent, Formatting.Indented).Split("\r\n"))
                    {
                        sb.AppendLine("\t" + currLine);
                    }

                    sb.AppendLine();
                }

                outputSystem.AddLog(sb.ToString());
            }
            catch (EntityNotFoundException)
            {
                outputSystem.AddLog($"No Entity found for EntityIdentifier {entityIdentifier}.");
            }
        }
Ejemplo n.º 22
0
            public override string !StringValue(Interpretation !interp)
            {
                int value = IntValue(interp);

                return(value.ToString());
            }
Ejemplo n.º 23
0
 public override void Handle(Interpretation interpretation, Engine engine)
 {
     engine.GetSystem <OutputSystem>().AddLog($"What do you want to {interpretation.Command.ToLower()}?");
 }
Ejemplo n.º 24
0
 public override int IntValue(Interpretation !interp)
 {
     return(value);
 }
Ejemplo n.º 25
0
        public override IDeepCopyable CopyTo(IDeepCopyable other)
        {
            var dest = other as Observation;

            if (dest != null)
            {
                base.CopyTo(dest);
                if (Identifier != null)
                {
                    dest.Identifier = new List <Hl7.Fhir.Model.Identifier>(Identifier.DeepCopy());
                }
                if (StatusElement != null)
                {
                    dest.StatusElement = (Code <Hl7.Fhir.Model.Observation.ObservationStatus>)StatusElement.DeepCopy();
                }
                if (Category != null)
                {
                    dest.Category = (Hl7.Fhir.Model.CodeableConcept)Category.DeepCopy();
                }
                if (Code != null)
                {
                    dest.Code = (Hl7.Fhir.Model.CodeableConcept)Code.DeepCopy();
                }
                if (Subject != null)
                {
                    dest.Subject = (Hl7.Fhir.Model.ResourceReference)Subject.DeepCopy();
                }
                if (Encounter != null)
                {
                    dest.Encounter = (Hl7.Fhir.Model.ResourceReference)Encounter.DeepCopy();
                }
                if (Effective != null)
                {
                    dest.Effective = (Hl7.Fhir.Model.Element)Effective.DeepCopy();
                }
                if (IssuedElement != null)
                {
                    dest.IssuedElement = (Hl7.Fhir.Model.Instant)IssuedElement.DeepCopy();
                }
                if (Performer != null)
                {
                    dest.Performer = new List <Hl7.Fhir.Model.ResourceReference>(Performer.DeepCopy());
                }
                if (Value != null)
                {
                    dest.Value = (Hl7.Fhir.Model.Element)Value.DeepCopy();
                }
                if (DataAbsentReason != null)
                {
                    dest.DataAbsentReason = (Hl7.Fhir.Model.CodeableConcept)DataAbsentReason.DeepCopy();
                }
                if (Interpretation != null)
                {
                    dest.Interpretation = (Hl7.Fhir.Model.CodeableConcept)Interpretation.DeepCopy();
                }
                if (CommentsElement != null)
                {
                    dest.CommentsElement = (Hl7.Fhir.Model.FhirString)CommentsElement.DeepCopy();
                }
                if (BodySite != null)
                {
                    dest.BodySite = (Hl7.Fhir.Model.CodeableConcept)BodySite.DeepCopy();
                }
                if (Method != null)
                {
                    dest.Method = (Hl7.Fhir.Model.CodeableConcept)Method.DeepCopy();
                }
                if (Specimen != null)
                {
                    dest.Specimen = (Hl7.Fhir.Model.ResourceReference)Specimen.DeepCopy();
                }
                if (Device != null)
                {
                    dest.Device = (Hl7.Fhir.Model.ResourceReference)Device.DeepCopy();
                }
                if (ReferenceRange != null)
                {
                    dest.ReferenceRange = new List <Hl7.Fhir.Model.Observation.ObservationReferenceRangeComponent>(ReferenceRange.DeepCopy());
                }
                if (Related != null)
                {
                    dest.Related = new List <Hl7.Fhir.Model.Observation.ObservationRelatedComponent>(Related.DeepCopy());
                }
                if (Component != null)
                {
                    dest.Component = new List <Hl7.Fhir.Model.Observation.ObservationComponentComponent>(Component.DeepCopy());
                }
                return(dest);
            }
            else
            {
                throw new ArgumentException("Can only copy to an object of the same type", "other");
            }
        }
Ejemplo n.º 26
0
 public override object !GetValue(Interpretation !interp)
 {
     return(BoolValue(interp));
 }
Ejemplo n.º 27
0
 public void Interpretation_CannotCreateInterpreterOnClassType()
 {
     var obj         = new MyObject();
     var interpreter = Interpretation.Create(obj, typeof(MyObjectExtensions));
 }
Ejemplo n.º 28
0
            public override string !StringValue(Interpretation !interp)
            {
                bool value = BoolValue(interp);

                return(value.ToString());
            }
Ejemplo n.º 29
0
 public void Interpretation_CannotCreateInterpreterWithNonExtensionType()
 {
     var obj         = new MyObject();
     var interpreter = Interpretation.Create <IMyObject>(obj, typeof(MyObject));
 }
Ejemplo n.º 30
0
 protected int CompareOperands(Interpretation !interp)
 {
     return(CompareTo(left.GetValue(interp), right, interp));
 }
Ejemplo n.º 31
0
 public void Interpretation_CannotCreateInterpreterForNull()
 {
     var interpreter = Interpretation.Create <IMyObject>(null);
 }
Ejemplo n.º 32
0
            public override bool BoolValue(Interpretation !interp)
            {
                int compare = CompareOperands(interp);

                return(compare < 0);
            }
Ejemplo n.º 33
0
        public override IDeepCopyable CopyTo(IDeepCopyable other)
        {
            var dest = other as Observation;

            if (dest != null)
            {
                base.CopyTo(dest);
                if (Name != null)
                {
                    dest.Name = (Hl7.Fhir.Model.CodeableConcept)Name.DeepCopy();
                }
                if (Value != null)
                {
                    dest.Value = (Hl7.Fhir.Model.Element)Value.DeepCopy();
                }
                if (Interpretation != null)
                {
                    dest.Interpretation = (Hl7.Fhir.Model.CodeableConcept)Interpretation.DeepCopy();
                }
                if (CommentsElement != null)
                {
                    dest.CommentsElement = (Hl7.Fhir.Model.FhirString)CommentsElement.DeepCopy();
                }
                if (Applies != null)
                {
                    dest.Applies = (Hl7.Fhir.Model.Element)Applies.DeepCopy();
                }
                if (IssuedElement != null)
                {
                    dest.IssuedElement = (Hl7.Fhir.Model.Instant)IssuedElement.DeepCopy();
                }
                if (StatusElement != null)
                {
                    dest.StatusElement = (Code <Hl7.Fhir.Model.Observation.ObservationStatus>)StatusElement.DeepCopy();
                }
                if (ReliabilityElement != null)
                {
                    dest.ReliabilityElement = (Code <Hl7.Fhir.Model.Observation.ObservationReliability>)ReliabilityElement.DeepCopy();
                }
                if (BodySite != null)
                {
                    dest.BodySite = (Hl7.Fhir.Model.CodeableConcept)BodySite.DeepCopy();
                }
                if (Method != null)
                {
                    dest.Method = (Hl7.Fhir.Model.CodeableConcept)Method.DeepCopy();
                }
                if (Identifier != null)
                {
                    dest.Identifier = (Hl7.Fhir.Model.Identifier)Identifier.DeepCopy();
                }
                if (Subject != null)
                {
                    dest.Subject = (Hl7.Fhir.Model.ResourceReference)Subject.DeepCopy();
                }
                if (Specimen != null)
                {
                    dest.Specimen = (Hl7.Fhir.Model.ResourceReference)Specimen.DeepCopy();
                }
                if (Performer != null)
                {
                    dest.Performer = new List <Hl7.Fhir.Model.ResourceReference>(Performer.DeepCopy());
                }
                if (ReferenceRange != null)
                {
                    dest.ReferenceRange = new List <Hl7.Fhir.Model.Observation.ObservationReferenceRangeComponent>(ReferenceRange.DeepCopy());
                }
                if (Related != null)
                {
                    dest.Related = new List <Hl7.Fhir.Model.Observation.ObservationRelatedComponent>(Related.DeepCopy());
                }
                return(dest);
            }
            else
            {
                throw new ArgumentException("Can only copy to an object of the same type", "other");
            }
        }