示例#1
0
        public void MergeFrom(Qualifier other)
        {
            if (other == null)
            {
                return;
            }
            switch (other.GuidOrNameCase)
            {
            case GuidOrNameOneofCase.Anonymous:
                if (Anonymous == null)
                {
                    Anonymous = new global::Bitub.Dto.GlobalUniqueId();
                }
                Anonymous.MergeFrom(other.Anonymous);
                break;

            case GuidOrNameOneofCase.Named:
                if (Named == null)
                {
                    Named = new global::Bitub.Dto.Name();
                }
                Named.MergeFrom(other.Named);
                break;
            }

            _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }
        public virtual void test_of()
        {
            SampleNamed test = Named.of(typeof(SampleNamed), "Standard");

            assertEquals(test, SampleNameds.STANDARD);
            assertThrowsIllegalArg(() => Named.of(typeof(SampleNamed), "Rubbish"));
        }
示例#3
0
        public Type GetMapping(Type currentInterface, object attribute)
        {
            Dictionary <string, Type> currentImplementation = implementations[currentInterface];

            Type type = null;

            if (attribute is Inject)
            {
                if (currentImplementation.Count == 1)
                {
                    type = currentImplementation.Values.First();
                }
                else
                {
                    throw new ArgumentException("No available mapping for class: " + currentInterface.FullName);
                }
            }
            else if (attribute is Named)
            {
                Named  named          = attribute as Named;
                string dependencyName = named.Name;
                type = currentImplementation[dependencyName];
            }

            return(type);
        }
        public void SelectDistribution(int tournamentSize, Named <double[]> expected, Optimize opt)
        {
            if (!Enum.IsDefined(typeof(Optimize), opt))
            {
                throw new InvalidEnumArgumentException(nameof(opt), (int)opt, typeof(Optimize));
            }
            if (!Enum.IsDefined(typeof(Optimize), opt))
            {
                throw new InvalidEnumArgumentException(nameof(opt), (int)opt, typeof(Optimize));
            }
            Retry <Exception>(3, () =>
            {
                const int loops       = 1;
                const int npopulation = PopulationCount;

                //ThreadLocal<LCG64ShiftRandom> random = new LCG64ShiftRandom.ThreadLocal();
                var random = RandomRegistry.GetRandom();
                RandomRegistry.Using(random, r =>
                {
                    var distribution = Distribution(
                        new TournamentSelector <DoubleGene, double>(tournamentSize),
                        opt,
                        npopulation,
                        loops
                        );

                    StatisticsAssert.AssertDistribution(distribution, expected.Value, 0.001, 20);
                });
            });
        }
示例#5
0
        private IKGroupedTable <K1, V1> DoGroup <K1, V1>(IKeyValueMapper <K, V, KeyValuePair <K1, V1> > keySelector, Grouped <K1, V1> grouped)
        {
            var selectName = new Named(grouped.Named).OrElseGenerateWithPrefix(this.builder, SELECT_NAME);

            IKTableProcessorSupplier <K, V, KeyValuePair <K1, V1> > selectSupplier = new KTableRepartitionMap <K, V, K1, V1>(this, keySelector);
            var processorParameters = new TableProcessorParameters <K, V>(selectSupplier, selectName);

            // select the aggregate key and values (old and new), it would require parent to send old values

            var groupByMapNode = new TableProcessorNode <K, V, K1, V1>(
                selectName,
                processorParameters,
                null
                );

            builder.AddGraphNode(this.node, groupByMapNode);

            this.EnableSendingOldValues();

            return(new KGroupedTable <K1, V1>(
                       selectName,
                       grouped,
                       this.setSourceNodes,
                       groupByMapNode,
                       builder));
        }
示例#6
0
 public List <Tuple <int, int> > Call <Name>(Named <List <int>, Name> named)
 {
     return(GDP.Namer.Name(new List <int>()
     {
         4, 5
     }, new ZipFn <Name>(named)));
 }
示例#7
0
        private string DeterminePropertyName(string propertyName, Named nameFallBack)
        {
            string backupName = (nameFallBack == null ? null : nameFallBack.Name);

            return((StringUtils.IsNotBlank(propertyName) && !FixedValueAttributeBeanBridge.FIXED.Equals(propertyName)) ? propertyName
                                 : (backupName == null ? string.Empty : backupName));
        }
示例#8
0
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        Named named = null;

        Data1 d1 = value as Data1;

        if (d1 != null)
        {
            named = d1.Xxx;
        }
        else
        {
            Data2 d2 = value as Data2;
            if (d2 != null)
            {
                named = d2.Yyy;
            }
        }

        if (named != null)
        {
            return(named);
        }

        return(DependencyProperty.UnsetValue);
    }
示例#9
0
        public Type GetMapping(Type someClass, object attribute)
        {
            IDictionary <string, Type> impl = this.implementations[someClass];

            Type type = null;

            if (attribute is Inject)
            {
                if (impl.Count == 1)
                {
                    type = impl.Values.First();
                }
                else
                {
                    throw new ArgumentException("No available mapping for class: " + someClass.FullName);
                }
            }
            else if (attribute is Named)
            {
                Named qualifier = attribute as Named;

                string dependencyName = qualifier.Name;
                return(impl[dependencyName]);
            }



            return(type);
        }
示例#10
0
        public string GetListElement(string name, int index)
        {
            if (variables.Where(v => name.Equals(v.GetName())).Count() == 0)
            {
                return("");
            }

            Named nv = variables.First(v => name.Equals(v.GetName()));

            if (nv is IListable)
            {
                List <string> lst   = (nv as IListable).ToList();
                int           count = lst.Count;

                if (index >= count || index < -count)
                {
                    return("");
                }

                if (index < 0)
                {
                    index += count;
                }

                return(lst[index]);
            }
            return("");
        }
        // If only we could "consume" the lists somehow... ;)
        // We can work around this with immutability at least
        public static SortedBy <int, Comp> GdpSortBy <Comp>(List <int> list, Named <Comparison <int>, Comp> comp)
        {
            List <int> listCopy = list.Select(item => item).ToList();

            listCopy.Sort(comp.GetVal());
            return(new SortedBy <int, Comp>(listCopy));
        }
示例#12
0
        public static string GetBasicPath(this Track track, string pathFormat, Dictionary <string, object> vars)
        {
            // Hacky method to clean the file path
            var formatStrComponents = pathFormat.Split(Path.DirectorySeparatorChar);
            var newFormat           = String.Join("\0", formatStrComponents);
            var finalPath           = Named.Format(newFormat, vars);

            return(PathHelpers.CleanPath(finalPath));
        }
示例#13
0
        /// <summary>
        /// Configure a named argument with a single value.
        /// </summary>
        /// <typeparam name="TArg">Argument type.</typeparam>
        /// <param name="getExpr">
        /// Getter expression describing where the value is stored.
        /// </param>
        /// <returns></returns>
        public Named <TConf, TArg> HasNamedArgument <TArg>(
            Expression <Func <TConf, TArg> > getExpr)
        {
            var named = new Named <TConf, TArg>(this,
                                                GetDefinitionFromExpression(getExpr));

            FluentConfig.Add(named);
            return(named);
        }
示例#14
0
        private IKTable <K, VR> DoMapValues <VR>(IValueMapperWithKey <K, V, VR> mapper, string named, Materialized <K, VR, IKeyValueStore <Bytes, byte[]> > materializedInternal)
        {
            ISerDes <K>  keySerde;
            ISerDes <VR> valueSerde;
            String       queryableStoreName;
            StoreBuilder <TimestampedKeyValueStore <K, VR> > storeBuilder;

            if (materializedInternal != null)
            {
                // we actually do not need to generate store names at all since if it is not specified, we will not
                // materialize the store; but we still need to burn one index BEFORE generating the processor to keep compatibility.
                if (materializedInternal.StoreName == null)
                {
                    builder.NewStoreName(MAPVALUES_NAME);
                }
                keySerde           = materializedInternal.KeySerdes != null ? materializedInternal.KeySerdes : this.keySerdes;
                valueSerde         = materializedInternal.ValueSerdes != null ? materializedInternal.ValueSerdes : null;
                queryableStoreName = materializedInternal.QueryableStoreName;
                // only materialize if materialized is specified and it has queryable name
                storeBuilder = queryableStoreName != null ? new TimestampedKeyValueStoreMaterializer <K, VR>(materializedInternal).Materialize() : null;
            }
            else
            {
                keySerde           = this.keySerdes;
                valueSerde         = null;
                queryableStoreName = null;
                storeBuilder       = null;
            }

            var name = new Named(named).OrElseGenerateWithPrefix(this.builder, MAPVALUES_NAME);

            var processorSupplier   = new KTableMapValues <K, V, VR>(this, mapper, queryableStoreName);
            var processorParameters = new TableProcessorParameters <K, V>(processorSupplier, name);

            var tableNode = new TableProcessorNode <K, V, K, VR>(
                name,
                processorParameters,
                storeBuilder
                );

            builder.AddGraphNode(this.node, tableNode);

            // don't inherit parent value serde, since this operation may change the value type, more specifically:
            // we preserve the key following the order of 1) materialized, 2) parent, 3) null
            // we preserve the value following the order of 1) materialized, 2) null
            return(new KTable <K, V, VR>(
                       name,
                       keySerde,
                       valueSerde,
                       this.setSourceNodes,
                       queryableStoreName,
                       processorSupplier,
                       tableNode,
                       builder
                       ));
        }
示例#15
0
        private IKTable <K, V> DoFilter(Func <K, V, bool> predicate, string named, Materialized <K, V, IKeyValueStore <Bytes, byte[]> > materializedInternal, bool filterNot)
        {
            ISerDes <K> keySerde;
            ISerDes <V> valueSerde;
            String      queryableStoreName;
            StoreBuilder <TimestampedKeyValueStore <K, V> > storeBuilder;

            if (materializedInternal != null)
            {
                // we actually do not need to generate store names at all since if it is not specified, we will not
                // materialize the store; but we still need to burn one index BEFORE generating the processor to keep compatibility.
                if (materializedInternal.StoreName == null)
                {
                    builder.NewStoreName(FILTER_NAME);
                }
                // we can inherit parent key and value serde if user do not provide specific overrides, more specifically:
                // we preserve the key following the order of 1) materialized, 2) parent
                keySerde = materializedInternal.KeySerdes != null ? materializedInternal.KeySerdes : this.keySerdes;
                // we preserve the value following the order of 1) materialized, 2) parent
                valueSerde = materializedInternal.ValueSerdes != null ? materializedInternal.ValueSerdes : this.valueSerdes;

                queryableStoreName = materializedInternal.QueryableStoreName;
                // only materialize if materialized is specified and it has queryable name
                storeBuilder = queryableStoreName != null ? (new TimestampedKeyValueStoreMaterializer <K, V>(materializedInternal)).Materialize() : null;
            }
            else
            {
                keySerde           = this.keySerdes;
                valueSerde         = this.valueSerdes;
                queryableStoreName = null;
                storeBuilder       = null;
            }

            var name = new Named(named).OrElseGenerateWithPrefix(this.builder, FILTER_NAME);

            IProcessorSupplier <K, Change <V> > processorSupplier = new KTableFilter <K, V>(this, predicate, filterNot, queryableStoreName);

            var processorParameters = new TableProcessorParameters <K, V>(processorSupplier, name);

            var tableNode = new TableProcessorNode <K, V, K, V>(
                name,
                processorParameters,
                storeBuilder
                );

            builder.AddGraphNode(this.node, tableNode);

            return(new KTable <K, V, V>(name,
                                        keySerde,
                                        valueSerde,
                                        this.setSourceNodes,
                                        queryableStoreName,
                                        processorSupplier,
                                        tableNode,
                                        builder));
        }
示例#16
0
 public void Del()
 {
     if (this._age > 0)
     {
         ex1 = Output;
     }
     else
     {
         ex1 = OutputAge;
     }
 }
示例#17
0
        public static void Test_02()
        {
            var keyValues = new Dictionary <string, object> {
                { "date", DateTime.Now.ToUniversalTime().ToString("o") }
            };
            string format    = "{{ 'data.LoadFromWebDate': {{ $gt: ISODate('{date}') }} }}";
            var    formatted = Named.Format(format, keyValues);

            Trace.WriteLine($"format    : \"{format}\"");
            Trace.WriteLine($"formatted : \"{formatted}\"");
        }
示例#18
0
 public void Order(string name, OrderBy order)
 {
     if (variables.Where(v => v.GetName().Equals(name)).Count() == 1)
     {
         Named nv = variables.First(v => v.GetName().Equals(name));
         if (nv is ListVariable)
         {
             (nv as ListVariable).Order(order);
         }
     }
 }
示例#19
0
 public void Remove(string name, List <string> values)
 {
     if (variables.Where(v => v.GetName().Equals(name)).Count() == 1)
     {
         Named nv = variables.First(v => v.GetName().Equals(name));
         if (nv is ListVariable)
         {
             (nv as ListVariable).Remove(values);
         }
     }
 }
示例#20
0
        public static string FormatFilePath(object obj, string pathFormat)
        {
            // Hacky method to clean the file path
            var formatStrComponents = Split(pathFormat);
            var newFormat           = string.Join(NullSeparatorChar.ToString(), formatStrComponents);
            var vars = Dictify.ObjectToDictionary(obj);
            // vars["ServiceName"] = title;
            var finalPath = CleanPath(Named.Format(newFormat, vars));

            return(finalPath);
        }
示例#21
0
 private void CheckDict(IDictionary dict, object[] expectedContent)
 {
     Assert.AreEqual(dict.Count, expectedContent.Length);
     for (int i = 0; i < expectedContent.Length; i++)
     {
         Named  named = expectedContent[i] as Named;
         String name  = named.Name();
         string str   = (string)dict[expectedContent[i]];
         Assert.AreEqual(str, name);
     }
 }
示例#22
0
 public void SetElementOfTime(string name, decimal value, TimeVariableType type)
 {
     if (variables.Where(v => v.GetName().Equals(name)).Count() == 1)
     {
         Named nv = variables.First(v => v.GetName().Equals(name));
         if (nv is TimeVariable)
         {
             (nv as TimeVariable).SetElementValue(value, type);
         }
     }
 }
示例#23
0
 public void PlusPlus(string name)
 {
     if (variables.Where(v => v.GetName().Equals(name)).Count() == 1)
     {
         Named nv = variables.First(v => v.GetName().Equals(name));
         if (nv is NumericVariable)
         {
             (nv as NumericVariable).PlusPlus();
         }
     }
 }
示例#24
0
 public void ModuloBy(string name, decimal value)
 {
     if (variables.Where(v => v.GetName().Equals(name)).Count() == 1)
     {
         Named nv = variables.First(v => v.GetName().Equals(name));
         if (nv is NumericVariable)
         {
             (nv as NumericVariable).ModuloBy(value);
         }
     }
 }
示例#25
0
 public void SetElementAtIndex(string name, string value, int index)
 {
     if (variables.Where(v => v.GetName().Equals(name)).Count() == 1)
     {
         Named nv = variables.First(v => v.GetName().Equals(name));
         if (nv is ListVariable)
         {
             (nv as ListVariable).SetElementAtIndex(value, index);
         }
     }
 }
示例#26
0
        public string GetValueString(string name)
        {
            if (variables.Where(v => name.Equals(v.GetName())).Count() == 0)
            {
                return("");
            }

            Named nv = variables.First(v => name.Equals(v.GetName()));

            return(nv.ToString());
        }
示例#27
0
 public static string GetBasicPath(this Track track, string pathFormat, IMediaCollection collection)
 {
     // Hacky method to clean the file path
     var formatStrComponents = pathFormat.Split(Path.DirectorySeparatorChar);
     var newFormat = String.Join("\0", formatStrComponents);
     var vars = Dictify.ObjectToDictionary(track);
     vars["PlaylistName"] = collection.Title;
     vars["CollectionName"] = collection.Title;
     vars["ServiceName"] = collection.Title;
     var finalPath = PathHelpers.CleanPath(Named.Format(newFormat, vars));
     return finalPath;
 }
示例#28
0
 private void SafeRename(Named item, string name)
 {
     _blockFlag = true;
     try
     {
         item.Name = name;
     }
     finally
     {
         _blockFlag = false;
     }
 }
示例#29
0
        public static void Test_01()
        {
            // from https://github.com/kekyo/CenterCLR.NamingFormatter
            var keyValues = new Dictionary <string, object> {
                { "lastName", "Matsui" }, { "firstName", "Kouji" }
            };
            string format    = "FirstName:{firstName}, LastName:{lastName}";
            var    formatted = Named.Format(format, keyValues);

            Trace.WriteLine($"format    : \"{format}\"");
            Trace.WriteLine($"formatted : \"{formatted}\"");
        }
示例#30
0
        public CommonDomainObjects() : base("CommonDomainObjects")
        {
            DomainObject = this.DeclareClass <DomainObject <Guid> >();
            Id           = DomainObject.DeclareDataProperty <DomainObject <Guid>, Guid>(domainObject => domainObject.Id);
            DomainObject.HasKey(Id);

            Named = this.DeclareClass <Named <Guid> >();
            Named.SubClassOf(DomainObject);
            Name = Named.DeclareDataProperty <Named <Guid>, string>(named => named.Name);

            Classifier = this.DeclareClass <Classifier>();
            Classifier.SubClassOf(Named);
        }
示例#31
0
 private void Dump(StringBuilder str, Named data, int indent, string indexes = "", int baseaddress = 1)
 {
     /*TODO#249
     long level = data.LevelNumber.Value;
     string name = (data.DataName != null?data.DataName.Name:"?");
     if (data.MemoryArea is TableInMemory) {
         var table = data.MemoryArea as TableInMemory;
         foreach(var e in table) {
             str.AppendLine(CreateLine(level, name, e.Offset, e.Length, e.Index, table.Count, indent));
             string strindexes = CreateIndexes(indexes, e.Index);
             foreach(var child in data.Subordinates) Dump(str, child, indent+1, strindexes);
         }
     } else {
         str.AppendLine(CreateLine(level, name, data.MemoryArea.Offset, data.MemoryArea.Length, 0, 1, indent));
         foreach(var child in data.Subordinates) Dump(str, child, indent+1, indexes);
     }
     */
 }
示例#32
0
 public ProgramElement(Named<ITypeDeclaration> type)
 {
     ElementType = ProgramElementType.Type;
     Type = type;
 }
示例#33
0
 public ProgramElement(Named<DataDeclaration> data)
 {
     ElementType = ProgramElementType.Data;
     Data = data;
 }