コード例 #1
0
        public override string GetNameForRequestField(SdkMessageRequest request, SdkMessageRequestField requestField, IServiceProvider services)
        {
            string returnValue  = string.Empty;
            string defaultValue = base.GetNameForRequestField(request, requestField, services);

            foreach (var namer in _namers)
            {
                Trace.Debug($"Executing naming rule {nameof(GetNameForRequestField)} using {namer.GetType().FullName}");

                returnValue = namer.GetNameForRequestField(request, requestField, services);
            }

            if (string.IsNullOrEmpty(returnValue))
            {
                returnValue = defaultValue;
            }

            var cacheItem = DynamicsMetadataCache.SdkMessagePairs.GetOrParse(request.MessagePair);

            if (cacheItem != null)
            {
                cacheItem.GeneratedRequestTypeName = returnValue;
            }

            DynamicsMetadataCache.SdkMessagePairs.Set(cacheItem);

            return(string.IsNullOrEmpty(returnValue) ? defaultValue : returnValue);
        }
        public override string GetNameForOption(OptionSetMetadataBase optionSetMetadata, OptionMetadata optionMetadata, IServiceProvider services)
        {
            string returnValue  = string.Empty;
            string defaultValue = base.GetNameForOption(optionSetMetadata, optionMetadata, services);

            foreach (var namer in _namers)
            {
                Trace.Debug($"Executing naming rule {nameof(GetNameForOption)} using {namer.GetType().FullName}");

                returnValue = namer.GetNameForOption(optionSetMetadata, optionMetadata, services);

                if (!string.IsNullOrEmpty(returnValue))
                {
                    var cacheItem = DynamicsMetadataCache.Options.GetOrParse(optionMetadata);

                    if (cacheItem != null)
                    {
                        cacheItem.GeneratedTypeName = returnValue;
                    }

                    DynamicsMetadataCache.Options.Set(cacheItem);
                }
            }

            return(returnValue);
        }
コード例 #3
0
        public override string GetNameForEntitySet(EntityMetadata entityMetadata, IServiceProvider services)
        {
            string returnValue  = string.Empty;
            string defaultValue = base.GetNameForEntitySet(entityMetadata, services);

            foreach (var namer in _namers)
            {
                Trace.Debug($"Executing naming rule {nameof(GetNameForEntity)} using {namer.GetType().FullName}");

                returnValue = namer.GetNameForEntity(entityMetadata, services);
            }

            if (string.IsNullOrEmpty(returnValue))
            {
                returnValue = defaultValue;
            }

            var cacheItem = DynamicsMetadataCache.Entities.GetOrParse(entityMetadata);

            if (cacheItem != null)
            {
                cacheItem.GeneratedSetName = returnValue;
            }

            DynamicsMetadataCache.Entities.Set(cacheItem);

            return(returnValue);
        }
コード例 #4
0
        protected override void DoDataReceived(string value)
        {
            if (value.IndexOf((char)'\r') > -1)
            {
                var items  = new List <MetterValue>();
                var values = value.Split((char)'\r', (char)'\t');

                for (int i = 0; i < values.Length; i++)
                {
                    var number = 0.0d;
                    if (values[i].Trim() != string.Empty)
                    {
                        var isNumeric = double.TryParse(values[i], out number);
                        if (isNumeric)
                        {
                            //var sampleDateTime = DateTimeOffset.Now.Subtract(this.startInspectionDateTime);
                            items.Add(new MetterValue()
                            {
                                Date = DateTimeOffset.Now, Index = 0, Value = number
                            });
                        }
                        else
                        {
                            Trace.Debug("The value {0} is not a number", value[i]);
                        }
                    }
                }

                if (DataChanged != null)
                {
                    this.DataChanged(this, new DataChangedEventArgs(items));
                }
            }
        }
        public override string GetNameForAttribute(EntityMetadata entityMetadata, AttributeMetadata attributeMetadata, IServiceProvider services)
        {
            string returnValue = string.Empty;

            foreach (var namer in _namers)
            {
                Trace.Debug($"Executing naming rule {nameof(GetNameForAttribute)} using {namer.GetType().FullName}");

                returnValue = namer.GetNameForAttribute(entityMetadata, attributeMetadata, services);

                if (!string.IsNullOrEmpty(returnValue))
                {
                    var cacheItem = DynamicsMetadataCache.Attributes.GetOrParse(attributeMetadata);

                    if (cacheItem != null)
                    {
                        cacheItem.GeneratedTypeName = returnValue;
                    }

                    DynamicsMetadataCache.Attributes.Set(cacheItem);
                }
            }

            return(returnValue);
        }
        public override string GetNameForMessagePair(SdkMessagePair messagePair, IServiceProvider services)
        {
            string returnValue  = string.Empty;
            string defaultValue = base.GetNameForMessagePair(messagePair, services);

            foreach (var namer in _namers)
            {
                Trace.Debug($"Executing naming rule {nameof(GetNameForMessagePair)} using {namer.GetType().FullName}");

                returnValue = namer.GetNameForMessagePair(messagePair, services);

                if (!string.IsNullOrEmpty(returnValue))
                {
                    var cacheItem = DynamicsMetadataCache.SdkMessagePairs.GetOrParse(messagePair);

                    if (cacheItem != null)
                    {
                        cacheItem.GeneratedTypeName = returnValue;
                    }

                    DynamicsMetadataCache.SdkMessagePairs.Set(cacheItem);
                }
            }

            return(returnValue);
        }
        private bool DoesMatchSettings(string logicalName, string kind, IFilterElement[] filters)
        {
            bool result = filters.Length == 0;

            for (int index = 0; index < filters.Length && !result; index++)
            {
                IFilterElement filterElement = filters[index];
                Trace.Debug($"Match {kind} filter: {filterElement.Expression} on logical name: {logicalName}");

                try
                {
                    RegexOptions options = filterElement.IgnoreCase ? RegexOptions.IgnoreCase : ~RegexOptions.IgnoreCase;
                    Regex        regex   = new Regex(filterElement.Expression, options);
                    bool         isMatch = regex.IsMatch(kind == "entity" ? logicalName : logicalName.Replace("*.", ""));

                    Trace.Debug("{0} {1}", filterElement.Expression, isMatch ? "matches" : "does not match");
                    result |= isMatch;
                }
                catch (ArgumentException ex)
                {
                    Trace.LogExceptionWarning(ex);
                }
            }

            return(result);
        }
コード例 #8
0
        public override void Build()
        {
            var sw = new Stopwatch();

            sw.Start();

            var kvUsageMemoryStream = new MemoryStream();

            KvUsage = new KeyValueUsage(kvUsageMemoryStream);

            var keyValueStoreFile = new MemoryStream();

            KvIndex = new KeyValueIndex(Settings.Search.KvIndexCapacity, Settings.Search.PrefixLength);
            KvStore = new KeyValueStore(KvIndex, KvUsage, keyValueStoreFile);

            var storeFile = new MemoryStream();

            Store = new ElementStore(KvStore, storeFile, ObjectPool);
            Tree  = new RTree <uint>(65);

            _reader.Read(new ReaderContext
            {
                SourceStream  = _sourceStream,
                Builder       = this,
                ReuseEntities = false,
                SkipTags      = false,
            });
            Clear();
            Complete();

            sw.Stop();
            Trace.Debug(CategoryKey, Strings.IndexBuildInMs, sw.ElapsedMilliseconds.ToString());
        }
コード例 #9
0
        public override string GetNameForRelationship(EntityMetadata entityMetadata, RelationshipMetadataBase relationshipMetadata, EntityRole?reflexiveRole, IServiceProvider services)
        {
            string returnValue  = string.Empty;
            string defaultValue = base.GetNameForRelationship(entityMetadata, relationshipMetadata, reflexiveRole, services);

            foreach (var namer in _namers)
            {
                Trace.Debug($"Executing naming rule {nameof(GetNameForRelationship)} using {namer.GetType().FullName}");

                returnValue = namer.GetNameForRelationship(entityMetadata, relationshipMetadata, reflexiveRole, services);
            }

            if (string.IsNullOrEmpty(returnValue))
            {
                returnValue = defaultValue;
            }

            var cacheItem = DynamicsMetadataCache.Relationships.GetOrParse(relationshipMetadata);

            if (cacheItem != null)
            {
                cacheItem.GeneratedTypeName = returnValue;
            }

            DynamicsMetadataCache.Relationships.Set(cacheItem);

            return(string.IsNullOrEmpty(returnValue) ? defaultValue : returnValue);
        }
コード例 #10
0
        public override void MessageReceived(Paket paket)
        {
            var sequenceId = (ushort)(paket.Array[2] + (paket.Array[3] << 8));

            paket.SeqId = sequenceId;
#if UID
            paket.Offset = 8;
            paket.Uid    = (uint)SimpleTypeReader.ReadInt(paket);
#else
            paket.Offset = 8;
#endif
            // TODO: playoutBuffer calls Playout into user code while having this lock. High deadlock danger when user calls back into send while the lock is held here
            lock (_lock)
            {
                Trace.Debug(">>> Received: {0}", paket);
                var sendAck = (paket.Array[1] & RequireAck) != 0;
                if ((paket.Array[1] & Empty) == 0)
                {
                    _messageReceivedCounter++;
                    var ackResult = _receivedOrderedAcknowledgePlayoutBuffers.Add(paket.SeqId, paket);
                    // not sure whether lateAck is a reason to send acks. Following scenario:
                    // 001
                    // 101 early ack
                    // 111 late ack
                    var ack = ackResult == AckResult.AlreadyAcked || ackResult == AckResult.EarlyAck || ackResult == AckResult.OutOfWindow;
                    if (_messageReceivedCounter++ == 4)
                    {
                        _messageReceivedCounter = 0;
                        _lastAckResult          = AckResult.Unknown;
                    }
                    // Avoid flooding with empty packages. This could happen when for example a paket is missing but pakets
                    // keep on arriving they all would come back here with "EarlyAck". However after 4 pakets we reset.
                    if (ackResult != _lastAckResult)
                    {
                        sendAck |= ack;
                    }
                    _lastAckResult = ackResult;
                    if (sendAck)
                    {
                        Trace.Debug("SendingAck because AckResult: {0}", ackResult);
                    }
                }
                else
                {
                    Trace.Debug("Received empty paket. Not adding to acks");
                }
                if (ResendUnconfirmed(paket))
                {
                    sendAck = false;
                }
                if (sendAck)
                {
                    SendEmptyPaket(Empty);
                }
                Trace.Debug("<<< Received: {0}", paket);
                Monitor.Pulse(_lock);
            }
        }
コード例 #11
0
        private void handleLayersChanged(Object sender, ListChangedEventArgs e)
        {
            Trace.Info(TraceCategories.Presentation, "MapLayersListenerPresenter handling " +
                       "layer collection changed");
            Trace.Debug(TraceCategories.Presentation, "Layer collection change: " +
                        e.ListChangedType);

            NotifyLayersChanged(e.ListChangedType, e.OldIndex, e.NewIndex, e.PropertyDescriptor);
        }
コード例 #12
0
 public static void Debug(String message, [CallerMemberName] String callerName = "", [CallerFilePath] String callerFilePath = "", [CallerLineNumber] Int32 callerLineNumber = 0)
 {
     if (AddCallerInfo)
     {
         Trace?.Debug(message + $"    ({callerName} Ln {callerLineNumber} [{callerFilePath}])");
     }
     else
     {
         Trace?.Debug(message);
     }
 }
コード例 #13
0
 private void SendEmptyPaket(byte byte1)
 {
     lock (_lock)
     {
         var ackOnlyPaket = CreatePaket();
         ackOnlyPaket.Array[1] = byte1;
         ackOnlyPaket.Array[2] = 0;
         ackOnlyPaket.Array[3] = 0;
         Trace.Debug("Sending empty paket byte1: {0}", byte1);
         Channel.Send(ackOnlyPaket.Array, 0, ackOnlyPaket.Count);
     }
 }
コード例 #14
0
        public override void Build()
        {
            var sw = new Stopwatch();

            sw.Start();

            var sourceStream = _fileSystemService.ReadStream(_filePath);
            var format       = _filePath.Split('.').Last();
            var reader       = GetReader(format);

            var kvUsageMemoryStream = new MemoryStream();
            var kvUsage             = new KeyValueUsage(kvUsageMemoryStream);

            var keyValueStoreFile = _fileSystemService.WriteStream(String.Format(MapConsts.KeyValueStorePathFormat, _outputDirectory));
            var index             = new KeyValueIndex(Settings.Search.KvIndexCapacity, Settings.Search.PrefixLength);
            var keyValueStore     = new KeyValueStore(index, kvUsage, keyValueStoreFile);

            var storeFile = _fileSystemService.WriteStream(String.Format(MapConsts.ElementStorePathFormat, _outputDirectory));

            Store = new ElementStore(keyValueStore, storeFile, ObjectPool);
            Tree  = new RTree <uint>(65);

            reader.Read(new ReaderContext
            {
                SourceStream  = sourceStream,
                Builder       = this,
                ReuseEntities = false,
                SkipTags      = false,
            });

            Clear();
            Complete();

            using (var kvFileStream = _fileSystemService.WriteStream(String.Format(MapConsts.KeyValueUsagePathFormat, _outputDirectory)))
            {
                var buffer = kvUsageMemoryStream.GetBuffer();
                kvFileStream.Write(buffer, 0, (int)kvUsageMemoryStream.Length);
            }

            KeyValueIndex.Save(index, _fileSystemService.WriteStream(String.Format(MapConsts.KeyValueIndexPathFormat, _outputDirectory)));
            SpatialIndex.Save(Tree, _fileSystemService.WriteStream(String.Format(MapConsts.SpatialIndexPathFormat, _outputDirectory)));
            Store.Dispose();

            sw.Stop();
            Trace.Debug(CategoryKey, Strings.IndexBuildInMs, sw.ElapsedMilliseconds.ToString());
        }
コード例 #15
0
        static void Main(string[] args)
        {
            Debugger.Debug("Debugger.Debug");
            Debugger.Info("Debugger.Info");
            Debugger.Warn("Debugger.Warn");
            Debugger.Error("Debugger.Error");
            Debugger.Fatal("Debugger.Fatal");



            Trace.Debug("Trace.Debug");
            Trace.Info("Trace.Info");
            Trace.Warn("Trace.Warn");
            Trace.Error("Trace.Error", new Exception("异常信息啊"));
            Trace.Fatal("Trace.Fatal");
            Trace.Write("Trace.Write");

            Console.WriteLine("Hello World!");
        }
コード例 #16
0
        public override string GetNameForServiceContext(IServiceProvider services)
        {
            string returnValue  = string.Empty;
            string defaultValue = base.GetNameForServiceContext(services);

            foreach (var namer in _namers)
            {
                Trace.Debug($"Executing naming rule {nameof(GetNameForServiceContext)} using {namer.GetType().FullName}");

                returnValue = namer.GetNameForServiceContext(services);

                if (returnValue != defaultValue)
                {
                    break;
                }
            }

            return(string.IsNullOrEmpty(returnValue) ? defaultValue : returnValue);
        }
コード例 #17
0
        public override string GetNameForResponseField(SdkMessageResponse response, SdkMessageResponseField responseField, IServiceProvider services)
        {
            string returnValue  = string.Empty;
            string defaultValue = base.GetNameForResponseField(response, responseField, services);

            foreach (var namer in _namers)
            {
                Trace.Debug($"Executing naming rule {nameof(GetNameForResponseField)} using {namer.GetType().FullName}");

                returnValue = namer.GetNameForResponseField(response, responseField, services);

                if (returnValue != defaultValue)
                {
                    break;
                }
            }

            return(string.IsNullOrEmpty(returnValue) ? defaultValue : returnValue);
        }
コード例 #18
0
        private bool ResendUnconfirmed(Paket paket)
        {
            var ackSent = true;

            _acknowledgeSendBuffer.Ack(GetReceivedAckField(paket), GetReceivedAckBase(paket));
            _unconfirmed.Clear();
            _acknowledgeSendBuffer.GetAllUnconfirmed(_unconfirmed);
            if (_unconfirmed.Count == 0)
            {
                ackSent = false;
            }
            for (var i = 0; i < _unconfirmed.Count; i++)
            {
                SetAcksInPaket(_unconfirmed[i]);
#if UID
                SetUid(_unconfirmed[i]);
#endif
                Trace.Debug("Resending paket: {0}", _unconfirmed[i]);
                Channel.Send(_unconfirmed[i].Array, 0, _unconfirmed[i].Count);
            }
            return(ackSent);
        }
コード例 #19
0
 public override bool Send(Paket paket)
 {
     lock (_lock)
     {
         int delta;
         int result;
         result = _acknowledgeSendBuffer.Add(paket, out delta);
         if (result == -1)
         {
             // No space left in ack buffer. Remote side still there? We are not waiting, we are not buffering. Leave it to the user to decide what to do.
             return(false);
         }
         paket.SeqId = (ushort)result;
         if (delta == 3 || delta == 7 || delta == 11 || delta == 15)
         {
             paket.Array[1] = RequireAck;
         }
         paket.Array[2] = (byte)(result & 255);
         paket.Array[3] = (byte)(result >> 8);
         Trace.Debug("Sending paket: {0}", paket);
         Channel.Send(paket.Array, 0, paket.Count);
         return(true);
     }
 }
コード例 #20
0
ファイル: Benchmark.cs プロジェクト: tuongntk/NBench
        /// <summary>
        ///     Warmup phase
        /// </summary>
        private void WarmUp()
        {
            Trace.Debug($"Beginning Warmups for {BenchmarkName}");
            var warmupStopWatch = new Stopwatch();
            var targetTime      = Settings.RunTime;

            Contract.Assert(targetTime != TimeSpan.Zero);
            var runCount = 0L;
            var runTime  = 0L;

            /* Pre-Warmup */


            Trace.Debug("----- BEGIN PRE-WARMUP -----");
            /* Estimate */
            Allocate(); // allocate all collectors needed
            PreRun();

            try
            {
                if (Settings.RunMode == RunMode.Throughput)
                {
                    Trace.Debug(
                        $"Throughput mode: estimating how many invocations of {BenchmarkName} will take {targetTime.TotalSeconds}s");

                    var estimateCount = 3;
                    var runEstimates  = new long[estimateCount];
                    var timeEstimates = new long[estimateCount];
                    for (var i = 0; i <= estimateCount; i++)
                    {
                        warmupStopWatch.Start();
                        while (warmupStopWatch.ElapsedTicks < targetTime.Ticks)
                        {
                            Invoker.InvokeRun(_currentRun.Context);
                            runCount++;
                        }
                        warmupStopWatch.Stop();

                        if (i > 0)
                        {
                            runEstimates[i - 1]  = runCount;
                            timeEstimates[i - 1] = warmupStopWatch.ElapsedTicks;
                        }

                        runCount = 0;
                        warmupStopWatch.Reset();
                    }

                    runCount = (long)Math.Ceiling(runEstimates.Average());
                    runTime  = (long)Math.Ceiling(timeEstimates.Average());

                    Trace.Debug(
                        $"Throughput mode: executed {runCount} instances of {BenchmarkName} in roughly {targetTime.TotalSeconds}s. Using that figure for benchmark.");
                }
                else
                {
                    warmupStopWatch.Start();
                    Invoker.InvokeRun(_currentRun.Context);
                    runCount++;
                    warmupStopWatch.Stop();

                    // elapsed time
                    runTime = warmupStopWatch.ElapsedTicks;
                }
            }
            catch (Exception ex)
            {
                HandleBenchmarkRunException(ex, $"Error occurred during ${BenchmarkName} RUN.");
            }

            PostRun();
            Complete(true);

            // check to see if pre-warmup threw an exception
            var faulted = _currentRun.IsFaulted;

            if (faulted)
            {
                Trace.Error($"Error occurred during pre-warmup. Exiting and producing dump...");

                /*
                 * Normally we don't ever queue up the warmup into the final stats, but we do it
                 * in failure cases so we can capture the exception thrown during warmup into
                 * the final report we're going to deliver to the end-user.
                 */
                CompletedRuns.Enqueue(_currentRun.ToReport(TimeSpan.Zero));

                return;
            }

            Trace.Debug("----- END PRE-WARMUP -----");


            WarmupData = new WarmupData(runTime, runCount);

            if (!Settings.SkipWarmups)
            {
                Trace.Debug("----- BEGIN WARMUPS -----");
                var i = _warmupCount;

                /* Warmup to force CPU caching */
                while (i > 0 && !_currentRun.IsFaulted)
                {
                    RunSingleBenchmark();
                    i--;
                }

                Trace.Debug("----- END WARMUPS -----");
            }
            else
            {
                Trace.Debug("----- SKIPPING WARMUPS -----");
            }
        }
コード例 #21
0
        protected override void DoDataReceived(string value)
        {
            try
            {
                if (value != string.Empty)
                {
                    var response = value[0];
                    switch (response)
                    {
                    case 'o':
                        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => this.Send(" ")));
                        if (this.StartListening != null)
                        {
                            this.StartListening(this, new EventArgs());
                        }
                        break;

                    case 'x': break;

                    case 'r':
                    case 's':
                        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => this.Send(" ")));
                        if (this.StartListening != null)
                        {
                            this.StartListening(this, new EventArgs());
                        }
                        break;

                    case 't':
                        Restart();
                        break;

                    case 'e':
                        Restart();
                        break;

                    case 'i':
                        Restart();
                        break;

                    case 'v':
                        Restart();
                        break;

                    default:
                        var str   = response.ToString();
                        var index = System.Text.Encoding.UTF8.GetBytes(str)[0] - System.Text.Encoding.UTF8.GetBytes("A")[0];
                        switch (index)
                        {
                        case 0:
                        case 1:
                        case 2:
                        case 4:
                        case 5:
                        case 7:
                            Restart();
                            break;

                        case 3:
                            if (this.StartOrder != null)
                            {
                                this.StartOrder(this, new EventArgs());
                            }
                            Restart();
                            break;

                        case 6:
                            if (this.StopOrder != null)
                            {
                                this.StopOrder(this, new EventArgs());
                            }
                            Restart();
                            break;

                        default:
                            //Restart();
                            Trace.Debug("VeearDataReceived DEFAULT {0}", value);
                            break;
                        }
                        break;
                    }
                    Trace.Debug("VeearDataReceived {0}", value);
                }
            }
            catch (Exception ex)
            {
                Trace.Exception(ex, true);
            }
        }