Exemplo n.º 1
0
        public static double Variance(this IEnumerable <double> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(NameOf.GetCallerName() + ": source");
            }

            long   n    = 0;
            double mean = 0;
            double M2   = 0;

            checked
            {
                foreach (double x in source)
                {
                    n++;
                    double delta = x - mean;
                    mean += delta / n;
                    M2   += delta * (x - mean);
                }
            }

            if (source.Count() < 2)
            {
                if (source.Count() == 1)
                {
                    return(double.NaN);
                }

                //TODO : Exception
                throw new InvalidOperationException(NameOf.GetCallerName() + ": source contains no elements.");
            }

            return((double)(M2 / (n - 1)));
        }
Exemplo n.º 2
0
        public void UpdatesNextSourceOnPropertyChange()
        {
            var fakeInpc = new Fake {
                Next = new Level {
                    Name = "1"
                }
            };
            var rootItem = new RootItem(fakeInpc);

            var nextName      = NameOf.Property <Fake>(x => x.Next);
            var nextProp      = typeof(Fake).GetProperty(nextName);
            var firstProperty = new PathProperty(null, nextProp);
            var first         = new NotifyingPathItem(rootItem, firstProperty);

            var isTrueName     = NameOf.Property <Level>(x => x.IsTrue);
            var isTrueProp     = typeof(Level).GetProperty(isTrueName);
            var secondProperty = new PathProperty(firstProperty, isTrueProp);
            var second         = new NotifyingPathItem(first, secondProperty);

            Assert.AreSame(fakeInpc.Next, second.Source);
            fakeInpc.Next = new Level {
                Name = "2"
            };
            Assert.AreSame(fakeInpc.Next, second.Source);
        }
Exemplo n.º 3
0
        public void ArgumentsFunc()
        {
            int i      = 0;
            var actual = NameOf.Arguments(() => DummyMethod(i));

            CollectionAssert.AreEqual(new[] { "arg" }, actual.Select(x => x.Name));
            CollectionAssert.AreEqual(new[] { 0 }, actual.Select(x => x.Value));
        }
Exemplo n.º 4
0
        public void ThrowsOnSettingSourceToWrongType()
        {
            var propertyName = NameOf.Property <Fake>(x => x.IsTrue);
            var propertyInfo = typeof(Fake).GetProperty(propertyName);
            var pathItem     = new NotifyingPathItem(null, new PathProperty(null, propertyInfo));

            Assert.Throws <TargetException>(() => pathItem.Source = new StructLevel());
        }
Exemplo n.º 5
0
        private static DependencyProperty RegisterAttachment()
        {
            TargetUpdatedEventBehavior behavior = new();

            return(RegisterAttachment(NameOf.ReadAccessorEnabledDependencyPropertyName(() => ActionsProperty),
                                      typeof(TargetUpdatedEventBehavior),
                                      behavior.DefaultMetadata));
        }
Exemplo n.º 6
0
 public UnitParts(IUnit baseUnit, IEnumerable <UnitAndPower> parts)
     : base(baseUnit, (up, u) => up.Parent = u, parts)
 {
     base.CollectionChanged += (sender, args) =>
     {
         base.OnPropertyChanged(new PropertyChangedEventArgs(NameOf.Property(() => Expression)));
         base.OnPropertyChanged(new PropertyChangedEventArgs(NameOf.Property(() => BaseUnitExpression)));
     };
 }
Exemplo n.º 7
0
        public void SetSourceToIncorrectTypeThrows()
        {
            var propertyName = NameOf.Property <Fake>(x => x.IsTrue);
            var propertyInfo = typeof(Fake).GetProperty(propertyName);
            var level        = new Level();
            var pathItem     = new NotifyingPathItem(null, new PathProperty(null, propertyInfo));

            Assert.Throws <TargetException>(() => pathItem.Source = level);
        }
Exemplo n.º 8
0
        public void ThrowsOnNotINotifyPropertyChanged()
        {
            var propertyInfo = typeof(NotInpc).GetProperty(NameOf.Property <NotInpc>(x => x.Name));

            Assert.NotNull(propertyInfo);
            var pathItem = new PathProperty(null, propertyInfo);
            var item     = new NotifyingPathItem(null, pathItem);

            Assert.Throws <ArgumentException>(() => new NotifyingPathItem(item, pathItem));
        }
        public SignupSignInViewModel(ISignIn signIn, NameOf welcomeMessage, NameOf startTrialMessage)
        {
            _signinState       = signIn;
            _welcomeMessage    = welcomeMessage;
            _startTrialMessage = startTrialMessage;

            InitializePropertyValues();
            BindPropertyChangedEvents();
            SubscribeToModelEvents();
        }
Exemplo n.º 10
0
        public void SetSourceToSubtype()
        {
            var propertyName = NameOf.Property <IFake>(x => x.IsTrue);
            var propertyInfo = typeof(IFake).GetProperty(propertyName);
            var fakeInpc     = new Fake();
            var pathItem     = new NotifyingPathItem(null, new PathProperty(null, propertyInfo));

            pathItem.Source = fakeInpc;
            Assert.AreSame(fakeInpc, pathItem.Source); // Really just scheking that we don't throw here
        }
Exemplo n.º 11
0
        public void ThrowsOnStruct()
        {
            var propertyInfo = typeof(StructLevel).GetProperty(NameOf.Property <StructLevel>(x => x.Name));

            Assert.NotNull(propertyInfo);
            var pathItem = new PathProperty(null, propertyInfo);
            var item     = new NotifyingPathItem(null, pathItem);

            Assert.Throws <ArgumentException>(() => new NotifyingPathItem(item, pathItem));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Database Store property.
        /// </summary>


        #endregion

        #region Default Constructor method.

        /// <summary>
        /// Default Constructor method.
        /// </summary>
        /// <param name="publicClientId">Public client ID parameter</param>
        public AppOAuthProvider(string publicClientId)
        {
            //TODO: Pull from configuration
            if (publicClientId == null)
            {
                throw new ArgumentNullException(NameOf.nameof(() => publicClientId));
            }

            // Settings.
            _publicClientId = publicClientId;
        }
Exemplo n.º 13
0
        public void NestedPropertyHappyPath()
        {
            var name = NameOf.Property(() => Fake.Next.Name, true);

            Assert.AreEqual("Name", name);

            name = NameOf.Property <PropertyTests>(x => Fake.Next.Name);
            Assert.AreEqual("Name", name);

            name = NameOf.Property <PropertyTests, string>(x => Fake.Next.Name);
            Assert.AreEqual("Name", name);
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            try
            {
                if (CommandLine.Parser.Default.ParseArguments(args, CMDParameters))
                {
                    if (CMDParameters.IsBatch)
                    {
                        // Enable file and console logging.
                        CLogger.ConfigureRollingFileAppender();
                        CLogger.AddAppender(typeof(Program).ToString(), CLogger.GetColoredConsoleAppender());
                    }
                    else
                    {
                        // Enable console logging.
                        CLogger.ConfigureColoredConsoleAppender();
                    }

                    Log.Info("===== " + Assembly.GetExecutingAssembly().GetName().Name + " " + Assembly.GetEntryAssembly().GetName().Version + " =====");

                    if (args.Count() == 0)
                    {
                        Console.WriteLine(CMDParameters.GetUsage());
                    }
                    else if (args.Count() == 1 && CMDParameters.IsBatch == true)
                    {
                        Log.Warn("Missing input parameters.");
                    }
                    else
                    {
                        doActionAccordingToParams(args);
                    }
                }
                else
                {
                    throw new ArgumentNullException(NameOf.nameof(() => CMDParameters), "All CMDParameters should not be null.");
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
            finally
            {
                // if is called from batch mode, remove any required user input.
                if (!CMDParameters.IsBatch)
                {
                    Console.WriteLine("Press the ENTER key to close the program.");
                    Console.ReadLine();
                }
                Log.Info("============= " + "END" + " =============");
            }
        }
Exemplo n.º 15
0
        public void DoesNotNotifyOnNewNullSourceWhenPropGoesFromNullToNull()
        {
            var propertyName = NameOf.Property <Fake>(x => x.Name);
            var propertyInfo = typeof(Fake).GetProperty(propertyName);
            var fakeInpc     = new Fake();
            var pathItem     = new NotifyingPathItem(null, new PathProperty(null, propertyInfo));

            pathItem.ObservePropertyChanged().Subscribe(_changes.Add);
            Assert.AreEqual(0, _changes.Count);
            pathItem.Source = null;
            Assert.AreEqual(0, _changes.Count);
        }
Exemplo n.º 16
0
        public void PropertyHappyPath2()
        {
            var name = NameOf.Property(() => StringProp);

            Assert.AreEqual("StringProp", name);

            name = NameOf.Property <PropertyTests>(x => x.StringProp);
            Assert.AreEqual("StringProp", name);

            name = NameOf.Property <PropertyTests, string>(x => x.StringProp);
            Assert.AreEqual("StringProp", name);
        }
Exemplo n.º 17
0
        public void OnNestedMethod()
        {
            var property = NameOf.Property(() => Fake.Method().Name, true);

            Assert.AreEqual("Name", property);

            property = NameOf.Property <PropertyTests>(x => Fake.Method().Name);
            Assert.AreEqual("Name", property);

            property = NameOf.Property <PropertyTests, string>(x => Fake.Method().Name);
            Assert.AreEqual("Name", property);
        }
Exemplo n.º 18
0
            public void NestedPropertyHappyPath()
            {
                var name = NameOf.Property(() => this.Fake.Next.Name, allowNestedProperty: true);

                Assert.AreEqual("Name", name);

                name = NameOf.Property <Property>(x => this.Fake.Next.Name);
                Assert.AreEqual("Name", name);

                name = NameOf.Property <Property, string?>(x => this.Fake.Next.Name);
                Assert.AreEqual("Name", name);
            }
Exemplo n.º 19
0
            public void PropertyHappyPath()
            {
                var name = NameOf.Property(() => this.StringProp);

                Assert.AreEqual(nameof(this.StringProp), name);

                name = NameOf.Property <Property>(x => this.StringProp);
                Assert.AreEqual(nameof(this.StringProp), name);

                name = NameOf.Property <Property, string?>(x => this.StringProp);
                Assert.AreEqual(nameof(this.StringProp), name);
            }
Exemplo n.º 20
0
            public void BoxedPropertyHappyPath()
            {
                var fakeInpc = new Fake();
                var name     = NameOf.Property(() => fakeInpc.IsTrue, allowNestedProperty: true);

                Assert.AreEqual("IsTrue", name);

                name = NameOf.Property <Fake>(x => x.IsTrue);
                Assert.AreEqual("IsTrue", name);

                name = NameOf.Property <Fake, bool>(x => x.IsTrue);
                Assert.AreEqual("IsTrue", name);
            }
        public static int FindSync(IList <byte> tsData, int offset, int TsPacketSize)
        {
            if (tsData == null)
            {
                throw new ArgumentNullException(NameOf.nameof(() => tsData));
            }

            //not big enough to be any kind of single TS packet
            if (tsData.Count < 188)
            {
                return(-1);
            }

            try
            {
                for (var i = offset; i < tsData.Count; i++)
                {
                    //check to see if we found a sync byte
                    if (tsData[i] != SyncByte)
                    {
                        continue;
                    }
                    if (i + 1 * TsPacketSize < tsData.Count && tsData[i + 1 * TsPacketSize] != SyncByte)
                    {
                        continue;
                    }
                    if (i + 2 * TsPacketSize < tsData.Count && tsData[i + 2 * TsPacketSize] != SyncByte)
                    {
                        continue;
                    }
                    if (i + 3 * TsPacketSize < tsData.Count && tsData[i + 3 * TsPacketSize] != SyncByte)
                    {
                        continue;
                    }
                    if (i + 4 * TsPacketSize < tsData.Count && tsData[i + 4 * TsPacketSize] != SyncByte)
                    {
                        continue;
                    }
                    // seems to be ok
                    return(i);
                }
                return(-1);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Problem in FindSync algorithm... : ", ex.Message);
                throw;
            }
        }
Exemplo n.º 22
0
        public void NotifiesOnSourcePropertyChangedEvent(string eventArgsPropName)
        {
            var propertyName = NameOf.Property <Fake>(x => x.IsTrue);
            var propertyInfo = typeof(Fake).GetProperty(propertyName);
            var fakeInpc     = new Fake();
            var pathItem     = new NotifyingPathItem(null, new PathProperty(null, propertyInfo));

            pathItem.Source = fakeInpc;
            pathItem.ObservePropertyChanged().Subscribe(_changes.Add);
            Assert.AreEqual(0, _changes.Count);
            fakeInpc.OnPropertyChanged(eventArgsPropName);
            Assert.AreEqual(1, _changes.Count);
            Assert.AreEqual(eventArgsPropName, _changes.Single().EventArgs.PropertyName);
            Assert.AreSame(fakeInpc, _changes.Single().Sender);
        }
Exemplo n.º 23
0
        public void NotifiesOnSourceChangeAffectingPropByBeingSetToNull()
        {
            var propertyName = NameOf.Property <Fake>(x => x.IsTrue);
            var propertyInfo = typeof(Fake).GetProperty(propertyName);
            var fakeInpc     = new Fake();
            var pathItem     = new NotifyingPathItem(null, new PathProperty(null, propertyInfo));

            pathItem.Source = fakeInpc;
            pathItem.ObservePropertyChanged().Subscribe(_changes.Add);
            Assert.AreEqual(0, _changes.Count);
            pathItem.Source = null;
            Assert.AreEqual(1, _changes.Count);
            Assert.AreEqual(propertyName, _changes.Single().EventArgs.PropertyName);
            Assert.AreSame(null, _changes.Single().Sender);
        }
Exemplo n.º 24
0
        public void NotifiesOnNewSourceWhenPropGoesFromTrueToTrue()
        {
            var propertyName = NameOf.Property <Fake>(x => x.IsTrue);
            var propertyInfo = typeof(Fake).GetProperty(propertyName);
            var fakeInpc     = new Fake {
                IsTrue = true
            };
            var pathItem = new NotifyingPathItem(null, new PathProperty(null, propertyInfo));

            pathItem.ObservePropertyChanged().Subscribe(_changes.Add);
            Assert.AreEqual(0, _changes.Count);
            pathItem.Source = fakeInpc;
            Assert.AreEqual(1, _changes.Count);
            pathItem.Source = new Fake {
                IsTrue = true
            };
            Assert.AreEqual(2, _changes.Count);
        }
Exemplo n.º 25
0
 /// <summary>
 /// Does the action according to parameters.
 /// </summary>
 /// <param name="args">The arguments.</param>
 private static void doActionAccordingToParams(string[] args)
 {
     if (CMDParameters.fileLst != null && CMDParameters.fileLst.Count() > 0)
     {
         // One/multiple files with command switch.
         //Parallel.ForEach(CMDParameters.fileLst, (file) =>
         foreach (var file in CMDParameters.fileLst)
         {
             String extension = Path.GetExtension(file);
             if (String.IsNullOrEmpty(extension) || extension != @".yaml")
             {
                 throw new Exception("File: " + file + " has wrong extension, it should end with '.yaml'.");
             }
         }
         CWebClient.CheckUpWebsiteWithYAML(CMDParameters.fileLst);
     }
     else if (CMDParameters.urlLst != null && CMDParameters.urlLst.Count() > 0)
     {
         // It's a manual parameter. (command switch with Urls)
         CWebClient.CheckUpWebsiteWithConsoleCommand(CMDParameters.urlLst);
     }
     else if (CMDParameters.fileDragDropLst != null && CMDParameters.fileDragDropLst.Count() > 0)
     {
         // One/multiple files with drag'n'drop.
         //Parallel.ForEach(CMDParameters.fileDragDropLst, (file) =>
         foreach (var file in CMDParameters.fileDragDropLst)
         {
             String extension = Path.GetExtension(file);
             if (String.IsNullOrEmpty(extension) || extension != @".yaml")
             {
                 throw new Exception("File: " + file + " has wrong extension, it should end with '.yaml'.");
             }
         }
         CWebClient.CheckUpWebsiteWithYAML(CMDParameters.fileDragDropLst);
     }
     else
     {
         throw new ArgumentNullException(NameOf.nameof(() => CMDParameters), "All CMDParameters should not be null.");
     }
 }
        private static long Get_TimeStamp(int code, IList <byte> data, int offs)
        {
            if (data == null)
            {
                throw new ArgumentNullException(NameOf.nameof(() => data));
            }

            if (code == 0)
            {
                Debug.WriteLine("Method has been called with incorrect code to match against - check for fault in calling method.");
                throw new Exception("PES Syntax error: 0 value timestamp code check passed in");
            }

            if ((data[offs + 0] >> 4) != code)
            {
                throw new Exception("PES Syntax error: Wrong timestamp code");
            }

            if ((data[offs + 0] & 1) != 1)
            {
                throw new Exception("PES Syntax error: Invalid timestamp marker bit");
            }

            if ((data[offs + 2] & 1) != 1)
            {
                throw new Exception("PES Syntax error: Invalid timestamp marker bit");
            }

            if ((data[offs + 4] & 1) != 1)
            {
                throw new Exception("PES Syntax error: Invalid timestamp marker bit");
            }

            long a = (data[offs + 0] >> 1) & 7;
            long b = (data[offs + 1] << 7) | (data[offs + 2] >> 1);
            long c = (data[offs + 3] << 7) | (data[offs + 4] >> 1);

            return((a << 30) | (b << 15) | c);
        }
Exemplo n.º 27
0
 public Quantity(IUnit unit)
     : base(null)
 {
     _unit          = unit;
     _unit.Quantity = this;
     if (_unit.Settings == null)
     {
         _unit.PropertyChanged += (_, e) =>
         {
             if (e.PropertyName == NameOf.Property(() => _unit.Settings, true))
             {
                 _unit.Settings.SiUnits.CollectionChanged      += (__, _e) => OnPropertyChanged("OperatorOverloads");
                 _unit.Settings.DerivedUnits.CollectionChanged += (__, _e) => OnPropertyChanged("OperatorOverloads");
             }
         };
     }
     else
     {
         _unit.Settings.SiUnits.CollectionChanged      += (_, e) => OnPropertyChanged("OperatorOverloads");
         _unit.Settings.DerivedUnits.CollectionChanged += (_, e) => OnPropertyChanged("OperatorOverloads");
     }
     _unit.PropertyChanged += (_, e) => OnPropertyChanged("Interface");
 }
Exemplo n.º 28
0
        public string Next(NameOf name)
        {
            switch (name)
            {
            case NameOf.First:
                return(NextFirst());

            case NameOf.Last:
                return(NextLast());

            case NameOf.Title:
                return(NextTitle());

            case NameOf.Homeland:
                return(NextHomeland());

            case NameOf.Equipment:
                return(NextEquipment());

            default:
                return(NextAnything());
            }
        }
Exemplo n.º 29
0
            /// <summary>
            /// Deserializes the yaml.
            /// </summary>
            /// <param name="tr">The tr.</param>
            /// <returns></returns>
            /// <exception cref="System.ArgumentNullException"></exception>
            public static DTO_Header DeserializeYAML(TextReader tr)
            {
                try
                {
                    if (tr != null)
                    {
                        var deserializer = new DeserializerBuilder()
                                           .WithNodeDeserializer(inner => new ValidatingNodeDeserializer(inner), s => s.InsteadOf <ObjectNodeDeserializer>())
                                           .Build();

                        DTO_Header header = deserializer.Deserialize <DTO_Header>(tr);

                        return(header);
                    }
                    else
                    {
                        throw new ArgumentNullException(NameOf.nameof(() => tr), "The textreader object must not be null.");
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
Exemplo n.º 30
0
        static void Main(string[] args)
        {
            UsingStatic.Execute();

            NameOf.Execute();

            AutoPropertyInitializer.Execute();

            ExpressionBodiedMember.Execute();

            DictionaryInitializer.Execute();

            ExceptionFilter.Execute();

            PropertyConstructorInitializer.Execute();

            StringInterpolation.Execute();

            AsyncCathFinally.Execute();

            NullConditional.Execute();

            DelegateNull.Execute();
        }