Example #1
0
 internal ZetboxContextProvider(ZetboxContextImpl ctx, InterfaceType ifType, IProxy proxy, IPerfCounter perfCounter)
 {
     _context         = ctx;
     _type            = ifType;
     _proxy           = proxy;
     this.perfCounter = perfCounter;
 }
Example #2
0
        /// <summary>
        /// Initializes a new instances of the QueryTranslatorProvider class
        /// with the specified components. If no Identity is passed,
        /// unrestricted queries are executed.
        /// </summary>
        /// <param name="metaDataResolver"></param>
        /// <param name="identity">the user who is making the query; if null, a unrestricted query is executed.</param>
        /// <param name="source"></param>
        /// <param name="ctx"></param>
        /// <param name="iftFactory"></param>
        /// <param name="perfCounter"></param>
        protected QueryTranslatorProvider(IMetaDataResolver metaDataResolver, Identity identity, IQueryable source, IZetboxContext ctx, InterfaceType.Factory iftFactory, IPerfCounter perfCounter)
        {
            if (metaDataResolver == null)
            {
                throw new ArgumentNullException("metaDataResolver");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (perfCounter == null)
            {
                throw new ArgumentNullException("perfCounter");
            }

            this.MetaDataResolver = metaDataResolver;
            this.Identity         = identity;
            this.Source           = source;
            this.Ctx         = ctx;
            this.IftFactory  = iftFactory;
            this.perfCounter = perfCounter;
        }
Example #3
0
        public ZetboxContextQuery(ZetboxContextImpl ctx, InterfaceType type, ZetboxContextProvider provider, Expression expression, IPerfCounter perfCounter)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            // if (type == null) throw new ArgumentNullException("type");
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }
            if (perfCounter == null)
            {
                throw new ArgumentNullException("perfCounter");
            }

            _type        = type;
            _context     = ctx;
            _expression  = expression;
            _provider    = provider;
            _perfCounter = perfCounter;
        }
Example #4
0
        internal NHibernateContext(
            IMetaDataResolver metaDataResolver,
            Identity identity,
            ZetboxConfig config,
            Func <IFrozenContext> lazyCtx,
            InterfaceType.Factory iftFactory,
            NHibernateImplementationType.Factory implTypeFactory,
            global::NHibernate.ISession nhSession,
            INHibernateImplementationTypeChecker implChecker,
            IPerfCounter perfCounter)
            : base(metaDataResolver, identity, config, lazyCtx, iftFactory)
        {
            if (perfCounter == null)
            {
                throw new ArgumentNullException("perfCounter");
            }
            _implTypeFactory = implTypeFactory;
            _nhSession       = nhSession;
            _implChecker     = implChecker;

            _attachedObjects        = new ContextCache <int>(this, item => item.ID);
            _attachedObjectsByProxy = new ContextCache <IProxyObject>(this, item => ((NHibernatePersistenceObject)item).NHibernateProxy);

            _perfCounter = perfCounter;
        }
Example #5
0
 public Launcher(Func <ClientIsolationLevel, IZetboxContext> ctxFactory, IViewModelFactory mdlFactory, IFrozenContext frozenCtx, ZetboxConfig cfg, IPerfCounter perfCounter)
 {
     this.frozenCtx   = frozenCtx;
     this.ctxFactory  = ctxFactory;
     this.mdlFactory  = mdlFactory;
     this.cfg         = cfg;
     this.perfCounter = perfCounter;
 }
 internal void AddCounter(IPerfCounter pcb)
 {
     if (_counters.ContainsKey(pcb.Name))
     {
         throw new Exception("Already defined: " + pcb.Name);
     }
     _counters[pcb.Name] = pcb;
 }
Example #7
0
 public ViewModelCache(IPerfCounter perfCounter)
 {
     if (perfCounter == null)
     {
         throw new ArgumentNullException("perfCounter");
     }
     _perfCounter = perfCounter;
 }
Example #8
0
 public Launcher(Func<ContextIsolationLevel, IZetboxContext> ctxFactory, IViewModelFactory mdlFactory, IFrozenContext frozenCtx, ZetboxConfig cfg, IPerfCounter perfCounter)
 {
     this.frozenCtx = frozenCtx;
     this.ctxFactory = ctxFactory;
     this.mdlFactory = mdlFactory;
     this.cfg = cfg;
     this.perfCounter = perfCounter;
 }
Example #9
0
        private static void WriteLineDuration(string text, IPerfCounter counter)
        {
            Console.Write(text);

            var prevColor = Console.ForegroundColor;

            Console.ForegroundColor = (counter.AverageDuration.TotalSeconds < 1) ? ConsoleColor.Green : ConsoleColor.Yellow;
            Console.WriteLine($"{Math.Round(counter.AverageDuration.TotalSeconds, 3)} seconds");

            Console.ForegroundColor = prevColor;
        }
Example #10
0
 /// <summary>
 /// Internal Constructor
 /// </summary>
 public EfDataContext(IMetaDataResolver metaDataResolver, Identity identity, ZetboxConfig config, Func <IFrozenContext> lazyCtx, InterfaceType.Factory iftFactory, EfImplementationType.EfFactory implTypeFactory, IPerfCounter perfCounter)
     : base(metaDataResolver, identity, config, lazyCtx, iftFactory)
 {
     if (perfCounter == null)
     {
         throw new ArgumentNullException("perfCounter");
     }
     _ctx             = new EfObjectContext(config);
     _implTypeFactory = implTypeFactory;
     _perfCounter     = perfCounter;
 }
Example #11
0
        public static ViewModelCache GetViewModelCache(this IZetboxContext ctx, IPerfCounter perfCounter)
        {
            if (ctx == null) throw new ArgumentNullException("ctx");

            object result;
            if (!ctx.TransientState.TryGetValue(CacheKey, out result))
            {
                result = new ViewModelCache(perfCounter);
                ctx.TransientState[CacheKey] = result;
            }

            return (ViewModelCache)result;
        }
Example #12
0
        public ZetboxService(IServerObjectHandlerFactory sohFactory, Func<IZetboxContext> ctxFactory, InterfaceType.Factory iftFactory, IPerfCounter perfCounter, ZetboxStreamReader.Factory readerFactory, ZetboxStreamWriter.Factory writerFactory)
        {
            if (readerFactory == null) throw new ArgumentNullException("readerFactory");
            if (writerFactory == null) throw new ArgumentNullException("writerFactory");

            Logging.Facade.Debug("Creating new ZetboxService instance");

            _sohFactory = sohFactory;
            _ctxFactory = ctxFactory;
            _iftFactory = iftFactory;
            _perfCounter = perfCounter;
            _readerFactory = readerFactory;
            _writerFactory = writerFactory;
        }
Example #13
0
        public ZetboxContextQuery(ZetboxContextImpl ctx, InterfaceType type, IProxy proxy, IPerfCounter perfCounter)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            // if (type == null) throw new ArgumentNullException("type");

            _perfCounter = perfCounter;
            _type        = type;
            _context     = ctx;
            _expression  = System.Linq.Expressions.Expression.Constant(this);
            _provider    = new ZetboxContextProvider(_context, _type, proxy, _perfCounter);
        }
Example #14
0
        public static ViewModelCache GetViewModelCache(this IZetboxContext ctx, IPerfCounter perfCounter)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }

            object result;

            if (!ctx.TransientState.TryGetValue(CacheKey, out result))
            {
                result = new ViewModelCache(perfCounter);
                ctx.TransientState[CacheKey] = result;
            }

            return((ViewModelCache)result);
        }
Example #15
0
        public override void Run(RuntimeContext context, IChannel channel)
        {
            IPerfCounter    mainPoolCounter = PerfCounterFactory.Create(PerfCounterImplType.AutoPilot, "iperf_ex", "tds1", PerfCounterType.Number);
            IPerfCounter    extraCouter     = PerfCounterFactory.Create(PerfCounterImplType.Automatic, "iperf_ex", "tds2", PerfCounterType.Number);
            ProAndConsModel server          = new ProAndConsModel();
            Thread          serverThread    = new Thread(() => server.run(2, 2));

            serverThread.Start();
            while (true)
            {
                String workingDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                InstrumentationHelper.Info("location", workingDir);

                mainPoolCounter.Set(server.getPoolValue());
                extraCouter.Set(server.getThreadNum());
                Thread.Sleep(500);
            }
        }
Example #16
0
    public static IServiceCollection AddPerfCounterManager(this IServiceCollection services, IConfiguration configuration)
    {
        IPerfCounter.Init();
        switch (configuration["PerfCounterStorage"])
        {
        case "database":
            services.AddScoped <IPerfCounter, PerfCounterInDatabase>();
            services.TryAddScoped <PerfCounterInDatabase>();
            break;

        default:
            services.AddSingleton <IPerfCounter, DefaultPerfCounter>();
            break;
        }

        services.Configure <HostOptions>(options => options.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.Ignore);
        services.AddHostedService <PerfCounterBackService>();
        return(services);
    }
Example #17
0
        public ZetboxContextImpl(ClientIsolationLevel il, ZetboxConfig config, IProxy proxy, string clientImplementationAssembly, Func <IFrozenContext> lazyCtx, InterfaceType.Factory iftFactory, ClientImplementationType.ClientFactory implTypeFactory, IPerfCounter perfCounter, IIdentityResolver identityResolver)
        {
            if (perfCounter == null)
            {
                throw new ArgumentNullException("perfCounter");
            }
            this._clientIsolationLevel = il;
            this.config = config;
            this.proxy  = proxy;
            this._ClientImplementationAssembly = clientImplementationAssembly;
            this._objects          = new ContextCache <int>(this, item => item.ID);
            this._lazyCtx          = lazyCtx;
            this._iftFactory       = iftFactory;
            this._implTypeFactory  = implTypeFactory;
            this._perfCounter      = perfCounter;
            this._identityResolver = identityResolver;

            CreatedAt = new StackTrace(true);
            ZetboxContextDebuggerSingleton.Created(this);
        }
Example #18
0
        public ZetboxService(IServerObjectHandlerFactory sohFactory, Func <IZetboxContext> ctxFactory, InterfaceType.Factory iftFactory, IPerfCounter perfCounter, ZetboxStreamReader.Factory readerFactory, ZetboxStreamWriter.Factory writerFactory)
        {
            if (readerFactory == null)
            {
                throw new ArgumentNullException("readerFactory");
            }
            if (writerFactory == null)
            {
                throw new ArgumentNullException("writerFactory");
            }

            Logging.Facade.Debug("Creating new ZetboxService instance");

            _sohFactory    = sohFactory;
            _ctxFactory    = ctxFactory;
            _iftFactory    = iftFactory;
            _perfCounter   = perfCounter;
            _readerFactory = readerFactory;
            _writerFactory = writerFactory;
        }
Example #19
0
        public ProxyImplementation(InterfaceType.Factory iftFactory, Zetbox.API.Client.ZetboxService.IZetboxService service, IPerfCounter perfCounter, ZetboxStreamReader.Factory readerFactory, ZetboxStreamWriter.Factory writerFactory)
        {
            if (perfCounter == null)
            {
                throw new ArgumentNullException("perfCounter");
            }
            if (readerFactory == null)
            {
                throw new ArgumentNullException("readerFactory");
            }
            if (writerFactory == null)
            {
                throw new ArgumentNullException("writerFactory");
            }

            _iftFactory    = iftFactory;
            _service       = service;
            _perfCounter   = perfCounter;
            _readerFactory = readerFactory;
            _writerFactory = writerFactory;
        }
Example #20
0
        protected ViewModelFactory(Autofac.ILifetimeScope container, IFrozenContext frozenCtx, ZetboxConfig cfg, IPerfCounter perfCounter, Func <DialogCreator> dialogFactory)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }
            if (cfg == null)
            {
                throw new ArgumentNullException("cfg");
            }
            if (dialogFactory == null)
            {
                throw new ArgumentNullException("dialogFactory");
            }

            this.Container              = container;
            this.FrozenContext          = frozenCtx;
            this.Configuration          = cfg;
            this.Managers               = new Dictionary <IZetboxContext, IMultipleInstancesManager>();
            this._viewModelFactoryCache = new Dictionary <VMCacheKey, object>();
            this.PerfCounter            = perfCounter;
            this.DialogFactory          = dialogFactory;
        }
Example #21
0
 public WpfModelFactory(ILifetimeScopeFactory scopeFactory, Autofac.ILifetimeScope scope, IFrozenContext frozenCtx, ZetboxConfig cfg, IPerfCounter perfCounter, DialogCreator.Factory dialogFactory)
     : base(scopeFactory, scope, frozenCtx, cfg, perfCounter, dialogFactory)
 {
 }
 internal void AddCounter(IPerfCounter pcb)
 {
     if (_counters.ContainsKey(pcb.Name)) throw new Exception("Already defined: " + pcb.Name);
     _counters[pcb.Name] = pcb;
 }
Example #23
0
 public ViewModelCache(IPerfCounter perfCounter)
 {
     if (perfCounter == null) throw new ArgumentNullException("perfCounter");
     _perfCounter = perfCounter;
 }
Example #24
0
 public bool CounterExists(IPerfCounter counter)
 {
     return(GetCounters(counter.CategoryName, counter.InstanceName).Any(c => c.Name.Equals(counter.Name)));
 }
Example #25
0
        public async Task DoRefresh()
        {
            if (!NeedsRefresh)
            {
                return;
            }

            PDH_FMT_COUNTERVALUE value = default(PDH_FMT_COUNTERVALUE);

            uint result = Pdh.PdhCollectQueryData(_query);

            if (result == Pdh.PDH_NO_DATA)
            {
                throw new MissingCountersException(_counters.Keys);
            }
            if (result != 0)
            {
                throw new Win32Exception((int)result);
            }

            bool multiSample = false;
            List <IPerfCounter> missingCounters = new List <IPerfCounter>();

            foreach (KeyValuePair <IPerfCounter, PdhCounterHandle> counterInstance in _counters)
            {
                IPerfCounter     counter = counterInstance.Key;
                PdhCounterHandle handle  = counterInstance.Value;

                result = Pdh.PdhGetFormattedCounterValue(handle, PdhFormat.PDH_FMT_LARGE, IntPtr.Zero, out value);

                if (result == Pdh.PDH_INVALID_DATA && value.CStatus == Pdh.PDH_CSTATUS_INVALID_DATA && !multiSample)
                {
                    multiSample = true;

                    result = Pdh.PdhCollectQueryData(_query);
                    if (result != 0)
                    {
                        throw new Win32Exception((int)result);
                    }

                    result = Pdh.PdhGetFormattedCounterValue(handle, PdhFormat.PDH_FMT_LARGE, IntPtr.Zero, out value);
                }

                if ((result != 0 && value.CStatus == Pdh.PDH_CSTATUS_NO_INSTANCE) ||
                    result == Pdh.PDH_INVALID_HANDLE ||
                    result == Pdh.PDH_CALC_NEGATIVE_VALUE ||
                    result == Pdh.PDH_CALC_NEGATIVE_DENOMINATOR ||
                    (result == Pdh.PDH_INVALID_DATA && value.CStatus == Pdh.PDH_INVALID_DATA))
                {
                    missingCounters.Add(counter);
                    continue;
                }
                else if (result != 0)
                {
                    if (!_counterFinder.CounterExists(counter))
                    {
                        missingCounters.Add(counter);
                        continue;
                    }

                    throw new Win32Exception((int)result);
                }
                else if (value.CStatus != 0)
                {
                    throw new Win32Exception((int)value.CStatus);
                }

                counter.Value = value.longLongValue;
            }

            if (missingCounters.Count > 0)
            {
                throw new MissingCountersException(missingCounters);
            }

            TimeSpan calculationDelta = DateTime.UtcNow - _lastCalculatedTime;

            _lastCalculatedTime = DateTime.UtcNow;
        }
Example #26
0
 public WpfModelFactory(Autofac.ILifetimeScope container, IUiThreadManager uiThread, IFrozenContext frozenCtx, ZetboxConfig cfg, IPerfCounter perfCounter, Func<DialogCreator> dialogFactory)
     : base(container, frozenCtx, cfg, perfCounter, dialogFactory)
 {
     this.uiThread = uiThread;
 }
Example #27
0
 public ViewModelDependencies(IViewModelFactory f, IFrozenContext frozenCtx, IPrincipalResolver principalResolver, IIconConverter iconConverter, IAssetsManager assetMgr, IValidationManager validationManager, IPerfCounter perfCounter)
 {
     Factory = f;
     FrozenContext = frozenCtx;
     PrincipalResolver = principalResolver;
     IconConverter = iconConverter;
     Assets = assetMgr;
     ValidationManager = validationManager;
     PerfCounter = perfCounter;
 }
Example #28
0
 public WpfModelFactory(Autofac.ILifetimeScope container, IUiThreadManager uiThread, IFrozenContext frozenCtx, ZetboxConfig cfg, IPerfCounter perfCounter, Func <DialogCreator> dialogFactory)
     : base(container, frozenCtx, cfg, perfCounter, dialogFactory)
 {
     this.uiThread = uiThread;
 }
Example #29
0
 public FormsModelFactory(Autofac.ILifetimeScope container, IFrozenContext metaCtx, ZetboxConfig cfg, IPerfCounter perfCounter, Func<DialogCreator> dialogFactory)
     : base(container, metaCtx, cfg, perfCounter, dialogFactory)
 {
 }
Example #30
0
 internal EfQueryTranslatorProvider(IMetaDataResolver metaDataResolver, Identity identity, IQueryable source, IZetboxContext ctx, InterfaceType.Factory iftFactory, IPerfCounter perfCounter)
     : base(metaDataResolver, identity, source, ctx, iftFactory, perfCounter)
 {
 }
Example #31
0
 public TestViewModelFactory(Autofac.ILifetimeScope container,
                             IFrozenContext frozenCtx,
                             ZetboxConfig cfg, IPerfCounter perfCounter, Func <DialogCreator> dialogFactory)
     : base(container, frozenCtx, cfg, perfCounter, dialogFactory)
 {
 }
Example #32
0
 internal NHibernateQueryTranslatorProvider(IMetaDataResolver metaDataResolver, Identity identity, IQueryable source, NHibernateContext ctx, InterfaceType.Factory iftFactory, INHibernateImplementationTypeChecker implChecker, IPerfCounter perfCounter)
     : base(metaDataResolver, identity, source, ctx, iftFactory, perfCounter)
 {
     _ctx         = ctx;
     _implChecker = implChecker;
 }
Example #33
0
 public AttachmentUploadMonitor()
 {
     avgTime               = PerfCounter.GetCounter(PerfCounter.AVG_TIME_PER_ATTACHMENT_UPLOAD);
     avgTimeBase           = PerfCounter.GetCounter(PerfCounter.AVG_TIME_PER_ATTACHMENT_UPLOAD_BASE);
     thumbnailUpstreamRate = PerfCounter.GetCounter(PerfCounter.THUMBNAIL_UPSTREAM_RATE);
 }