11.07.2015 Views

y - Net Developer

y - Net Developer

y - Net Developer

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 6 ■ MANAGING WCF SERVICES 201ramrameshreddy.blog.comprivate PerformanceCounterCategory counterCategory = null;private PerformanceCounter totalCounter = null;private PerformanceCounter microsoftCounter = null;const double IBM_Price = 80.50D;const double MSFT_Price = 30.25D;public TradePerfMon(){if (PerformanceCounterCategory.Exists(CounterCategoryName)){PerformanceCounterCategory.Delete(CounterCategoryName);}CounterCreationData totalCounter = new CounterCreationData(TotalCounterName, "Total Dollar value of Trade Servicetransactions.",PerformanceCounterType.NumberOfItemsHEX32);CounterCreationData microsoftCounter = newCounterCreationData(MicrosoftCounterName, "Total Microsoftsecurities being traded", PerformanceCounterType.NumberOfItemsHEX32);CounterCreationDataCollection counterCollection = newCounterCreationDataCollection(new CounterCreationData[]{ totalCounter, microsoftCounter });this.counterCategory = PerformanceCounterCategory.Create(CounterCategoryName,"Trade Service PerfMon Counters",PerformanceCounterCategoryType.MultiInstance,counterCollection);totalValue = 0;microsoftVolume = 0;}}}In this code, first you initialize the variables to implement the Total Value counter and theMicrosoft Volume counter. Then you create the foundations for the performance counters inthe TradePerfMon constructor. You will first check whether the performance counter category(that is, Trade Service PerfMon) is available. If so, delete it because you will create it again.Then you create the Total Value counter and the Microsoft Volume counter and add them tothe performance counter collection.The next step is to initialize the counters. The following code illustrates this concept:public void InitializeCounters(System.ServiceModel.Description.ServiceEndpointCollection endpoints){List names = new List();foreach (ServiceEndpoint endpoint in endpoints){names.Add(string.Format("{0}@{1}",this.GetType().Name, endpoint.Address.ToString()));}ramrameshreddyramrameshreddy

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!