public void CreatedTraceSourceUsesNamespaceFromType()
        {
            var factory = CreateFactory(LogLevel.None,
                                        ("Decos.Diagnostics.Trace.Tests", LogLevel.Information));

            var log = factory.Create <TraceSourceLogFactoryTests>();

            Assert.IsTrue(log.IsEnabled(LogLevel.Information));
        }
        public void CreatedTraceSourceLogUsesInheritedLogLevel()
        {
            var factory = CreateFactory(LogLevel.Information,
                                        ("Decos", LogLevel.Warning));

            var log = factory.Create("Decos.Diagnostics");

            Assert.IsTrue(log.IsEnabled(LogLevel.Warning));
            Assert.IsFalse(log.IsEnabled(LogLevel.Information));
        }
        public void CreatedTraceSourceLogUsesDefaultLogLevelIfNoneMatch()
        {
            var factory = CreateFactory(LogLevel.Information,
                                        ("Decos.Diagnostics.Trace", LogLevel.Debug));

            var log = factory.Create("Decos.Diagnostics");

            Assert.IsTrue(log.IsEnabled(LogLevel.Information));
            Assert.IsFalse(log.IsEnabled(LogLevel.Debug));
        }
        public void CreatedTraceSourceCanBeTurnedOffIndividually()
        {
            var factory = CreateFactory(LogLevel.Information,
                                        ("Decos", LogLevel.None));

            var log = factory.Create("Decos.Diagnostics");

            Assert.IsFalse(log.IsEnabled(LogLevel.Critical));
            Assert.IsFalse(log.IsEnabled(LogLevel.Error));
            Assert.IsFalse(log.IsEnabled(LogLevel.Warning));
            Assert.IsFalse(log.IsEnabled(LogLevel.Information));
            Assert.IsFalse(log.IsEnabled(LogLevel.Debug));
        }
        public void CreatedTraceSourceLogUsesBestMatchingFilter()
        {
            // Test to ensure dictionary is sorted properly

            var factory = CreateFactory(LogLevel.None,
                                        ("Decos", LogLevel.Information),
                                        ("Decos.Diagnostics.Trace.Tests.Something", LogLevel.None),
                                        ("Decos.Diagnostics", LogLevel.Warning),
                                        ("Decos.Diagnostics.Trace.Tests", LogLevel.Debug),
                                        ("Decos.Diagnostics.Trace", LogLevel.Critical));

            var log = factory.Create("Decos.Diagnostics.Trace.Tests");

            Assert.IsTrue(log.IsEnabled(LogLevel.Debug));
        }
Example #6
0
        public InitView(DataManager dataManager, CreateFactory createFactory)
        {
            InitializeComponent();
            DataContext = new InitViewModel(this, dataManager, createFactory);

            LanguageManager.SwitchLanguage(this, DataManager.CurrentCulture);
        }
Example #7
0
        /// <summary>
        /// 生成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButtonCreateCode_Click(object sender, EventArgs e)
        {
            var FocusedNode = this.treeListDataView.FocusedNode;
            int id          = Convert.ToInt32(FocusedNode.GetValue("ParentID"));

            if (id == 0)
            {
                XtraMessageBox.Show(@"请先选择要生成的表名!", @"警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string tableName           = FocusedNode.GetValue("Name").ToString();
            var    TemplateFocusedNode = this.treeListTemplate.FocusedNode;
            int    TemplateID          = Convert.ToInt32(TemplateFocusedNode.GetValue("ID"));
            string TemplateName        = TemplateFocusedNode.GetValue("Name").ToString();

            if (!CreateFactory.Instance().CheckCreateTemplate(TemplateName))
            {
                XtraMessageBox.Show(@"请先选择要生成的模板!", @"警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            this.CurrentTableName = tableName;
            create = CreateFactory.Instance().GetCreateHandle(TemplateID);
            if (create != null)
            {
                string Message = create.CreateMethod(this.CurrentTableName, this.ProjectName);
                this.richTextBoxMessage.Text     = Message;
                this.toolStripButtonSave.Enabled = true;
            }
            else
            {
                XtraMessageBox.Show(@"该模板生成类暂未实现!", @"警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #8
0
        /// <summary>
        /// 开始生成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void simpleButtonCreate_Click(object sender, EventArgs e)
        {
            if (this.listBoxDataViewDes.Items.Count == 0)
            {
                XtraMessageBox.Show(@"请先选择要生成的数据表", @"提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (this.listBoxTemplateDes.Items.Count == 0)
            {
                XtraMessageBox.Show(@"请先选择要生成的模板", @"提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string OutputPath = this.textEditOutputPath.Text;

            if (string.IsNullOrEmpty(OutputPath))
            {
                XtraMessageBox.Show(@"请先选择要输出的目录", @"提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            List <DataViewNode> DvList = this.DataViewNodeList.Where(o => this.listBoxDataViewDes.Items.Contains(o.Name)).ToList();
            List <DataViewNode> TpList = this.ucTemplateTV1.TemplateNodeList.Where(o => this.listBoxTemplateDes.Items.Contains(o.Name)).ToList();

            foreach (var item in TpList)
            {
                ICreate create = CreateFactory.Instance().GetCreateHandle(item.ID);
                foreach (var itemDv in DvList)
                {
                    create.GenerationCode(OutputPath, itemDv.Name, this.ProjectName);
                }
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Example #9
0
 protected virtual void Fired(IFactoryCreate factor)
 {
     CreateFactory?.Invoke(this, new FactoryEventArgs()
     {
         Factory = factor as Factory
     });
 }
Example #10
0
 public ConcurrentCache(SourceProducer sourceProducer, KeyProducer keyProducer, UpdateFactory updateFactory, CreateFactory createFactory, RemovedAction removedAction = null)
 {
     _sourceFactory = sourceProducer;
     _updateFactory = updateFactory;
     _createFactory = createFactory;
     _keyProducer   = keyProducer;
     _removedAction = removedAction;
 }
Example #11
0
 public LoadViewModel(Window view, DataManager dataManager, CreateFactory factory) : base(dataManager)
 {
     _view    = view;
     _factory = factory;
     //_dataManager.LoadGames();
     //Items = new ObservableCollection<LoadedGameViewModel>(_dataManager.LoadedGames.Select((m) => _factory.Create(m)).ToList() );
     LoadCommand   = new RelayCommand((o) => Load(), (o) => CanLoad());
     CancelCommand = new RelayCommand((o) => Exit(), (o) => true);
 }
Example #12
0
        public LoadView(DataManager dataManager, CreateFactory createFactory)
        {
            InitializeComponent();
            var viewModel = new LoadViewModel(this, dataManager, createFactory);

            viewModel.Init();
            DataContext = viewModel;

            LanguageManager.SwitchLanguage(this, DataManager.CurrentCulture);
        }
Example #13
0
 public InitViewModel(Window view, DataManager dataManager, CreateFactory createFactory) : base(dataManager)
 {
     NewCommand            = new RelayCommand((o) => New(false), (o) => true);
     NewOnlineCommand      = new RelayCommand((o) => New(true), (o) => IsOnline);
     PlayCommand           = new RelayCommand((o) => Play(false), (o) => true);
     PlayOnlineCommand     = new RelayCommand((o) => Play(true), (o) => IsOnline);
     ExitCommand           = new RelayCommand((o) => Exit(), (o) => true);
     _view                 = view;
     _creteFactory         = createFactory;
     ServerStatusViewModel = new ServerStatusViewModel();
 }
Example #14
0
        public CreationView(DataManager dataManager, CreateFactory createFactory)
        {
            InitializeComponent();
            var viewModel = new CreationViewModel(dataManager, createFactory);

            viewModel.Init();
            DataContext = viewModel;
            Loaded     += delegate(object sender, RoutedEventArgs args)
            {
                LanguageManager.SwitchLanguage(this, DataManager.CurrentCulture);
            };
        }
        public CreationWeavesViewModel(DataManager dataManager, CreateFactory createFactory)
        {
            SelectTypeCommand = new RelayCommand((o) => SelectType(o), (o) => true);
            AddCommand        = new RelayCommand((o) => Add(), (o) => CanAdd());
            RemoveCommand     = new RelayCommand((o) => Remove(), (o) => CanRemove());
            WeavePoints       = CustomWeavesPoints;
            AllWeaves         = new ObservableCollection <BaseWeaveViewModel>(dataManager.GetWeaves().Select(s => createFactory.Create(s)));
            Weaves            = new ObservableCollection <BaseWeaveViewModel>();
            PlayerWeaves      = new ObservableCollection <PlayerWeaveViewModel>();

            IsValid   = true;
            IsVisible = false;
        }
        public CreationSkillsViewModel(DataManager dataManager, CreateFactory createFactory)
        {
            AddCommand     = new RelayCommand((o) => Add(), (o) => CanAdd());
            RemoveCommand  = new RelayCommand((o) => Remove(), (o) => CanRemove());
            SkillPoints    = CustomSkillPoints;
            FeatPoints     = CustomFeatPoints;
            Skills         = new ObservableCollection <BaseSkillViewModel>(dataManager.GetSkills().Select(s => createFactory.Create(s)));
            Feats          = new ObservableCollection <BaseSkillViewModel>(dataManager.GetFeats().Select(f => createFactory.Create(f)));
            PlayerSkills   = new ObservableCollection <PlayerSkillViewModel>();
            PlayerFeats    = new ObservableCollection <PlayerFeatViewModel>();
            IsSkillChecked = true;

            IsVisible = true;
        }
Example #17
0
        /// <summary>
        /// Begin a read transaction.
        /// There can be more than one.
        /// </summary>
        /// <param name="createFactory"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public Task <IConnectionFactory> BeginRead(CreateFactory createFactory, CancellationToken token)
        {
            // update the counter.
            using (_counterBegin.Start())
            {
                // get out if needed.
                token.ThrowIfCancellationRequested();

                // create the transaction
                var trans = createFactory();

                // return our created factory.
                return(Task.FromResult(trans));
            }
        }
Example #18
0
        /// <summary>
        /// Begin a write transaction.
        /// There can only be one
        /// </summary>
        /// <param name="createFactory"></param>
        /// <param name="token"></param>
        /// <param name="timeoutMs">The max number of ms we want to wait before we return null</param>
        /// <returns></returns>
        public async Task <IConnectionFactory> BeginWrite(CreateFactory createFactory, int timeoutMs, CancellationToken token)
        {
            // update the counter.
            using (_counterBegin.Start())
            {
                for (;;)
                {
                    // wait for the transaction to no longer be null
                    // outside of the lock, (so it can be freed.
                    await helper.Wait.UntilAsync(() => _writeFactory == null, timeoutMs, token).ConfigureAwait(false);

                    // now trans and create the transaction
                    var lockTaken = false;
                    try
                    {
                        Monitor.TryEnter(_lock, ref lockTaken);
                        if (!lockTaken)
                        {
                            token.ThrowIfCancellationRequested();
                            continue;
                        }

                        // oops... we didn't really get it.
                        // go around again to make sure.
                        if (_writeFactory != null)
                        {
                            continue;
                        }

                        // create the connection
                        // we were able to get a null transaction
                        // ... and we are inside the lock
                        _writeFactory = createFactory();
                        return(_writeFactory);
                    }
                    finally
                    {
                        if (lockTaken)
                        {
                            Monitor.Exit(_lock);
                        }
                    }
                }
            }
        }
Example #19
0
        public CreationViewModel(DataManager dataManager, CreateFactory createFactory) : base(dataManager)
        {
            _createFactory = createFactory;

            NextCommand   = new RelayCommand((o) => ChangeSection(true), (o) => CanChangeSection(true));
            PrevCommand   = new RelayCommand((o) => ChangeSection(false), (o) => CanChangeSection(false));
            CancelCommand = new RelayCommand((o) => Cancel(), (o) => true);
            FinishCommand = new RelayCommand((o) => Finish(), (o) => CanFinish);

            //Items = new ObservableCollection<BaseCreationViewModel>()
            //{
            //    new CreationDataViewModel(),
            //    new CreationAttributesViewModel(),
            //    new CreationSkillsViewModel(_dataManager, _createFactory),
            //    new CreationWeavesViewModel()
            //};

            //using (CanChangeDisposable())
            //{
            //    CurrentCreationSection = Items[0];
            //}
        }
Example #20
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Start Program");
            Console.WriteLine("--------------------------------------------------------------------------------------------------");
            Console.WriteLine("CHAIN OF RESPONSIBILITY---------------------------------------------------------------------------");
            Console.WriteLine("--------------------------------------------------------------------------------------------------");
            var chainofResponsilbity = new RunChainofResponsiblity();

            chainofResponsilbity.Run();

            Console.WriteLine("--------------------------------------------------------------------------------------------------");
            Console.WriteLine("SINGLETON NOT ASYNC-------------------------------------------------------------------------------");
            Console.WriteLine("--------------------------------------------------------------------------------------------------");
            var runLoggers = new RunLoggers();
            var stopwatch  = new Stopwatch();

            Console.WriteLine("Singleton");
            stopwatch.Start();
            runLoggers.RunLoggerNonAsync(new Logger(@"log.txt"));
            stopwatch.Stop();
            Console.WriteLine($"TimeElapsed = {stopwatch.Elapsed}");
            Console.WriteLine("--------------------------------------------------------------------------------------------------");
            Console.WriteLine("SINGLETON IN PARALLEL-----------------------------------------------------------------------------");
            Console.WriteLine("--------------------------------------------------------------------------------------------------");
            stopwatch.Restart();
            //await runLoggers.RunLoggerSingletonParallel(new LoggerSingleton(@"log_Singleton.txt"));
            await runLoggers.RunLoggerSingletonParallel(Singleton.Instance);

            stopwatch.Stop();
            Console.WriteLine($"TimeElapsed = {stopwatch.Elapsed}");

            Console.WriteLine("--------------------------------------------------------------------------------------------------");
            Console.WriteLine("NOT SINGLETONIN PARALLEL--------------------------------------------------------------------------");
            Console.WriteLine("--------------------------------------------------------------------------------------------------");
            stopwatch.Restart();
            try
            {
                await runLoggers.RunLoggerNonSingletonParallel(new Logger(@"NotSingleton_log.txt"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            stopwatch.Stop();
            Console.WriteLine($"TimeElapsed = {stopwatch.Elapsed}");

            Console.WriteLine("--------------------------------------------------------------------------------------------------");
            Console.WriteLine("FACTORY PATTERN-----------------------------------------------------------------------------------");
            Console.WriteLine("--------------------------------------------------------------------------------------------------");

            var transactionTypes = new List <string> {
                "CreditCard", "CheckingAccount"
            };

            foreach (var type in transactionTypes)
            {
                var defaultbalanceShouldbe = type == "CreditCard" ? 1000 : 12450.25;
                Console.WriteLine($"Starting Factory {type} wih default balance of {defaultbalanceShouldbe}");
                var factory            = new CreateFactory();
                var transactionFactory = factory.LoadFactory(type);
                Console.WriteLine("CheckBalance: " + transactionFactory.CheckBalance("12345"));
                Console.WriteLine("Deposit of $75.50: " + transactionFactory.Deposit("12345", 75.50));
                Console.WriteLine("CheckBalance: " + transactionFactory.CheckBalance("12345"));
                Console.WriteLine("WithDraw of $50.25: " + transactionFactory.WithDraw("12345", 50.25));
                Console.WriteLine("CheckBalance: " + transactionFactory.CheckBalance("12345"));
                Console.WriteLine("--------------------------------------------------------------------------------------------------");
            }

            Console.WriteLine("-----------------------------------------------------------------------------------------------------");
            Console.WriteLine("REPOSITORY PATTERN-----------------------------------------------------------------------------------");
            Console.WriteLine("-----------------------------------------------------------------------------------------------------");


            var businessRespository = new BusinessRepository(new LoggerFile(), new LoggerDB());

            foreach (var item in businessRespository.getAllLogs())
            {
                Console.WriteLine($"Log record: {item.Source}");
            }

            Console.WriteLine("Adding Records---------------------------------------------------------------------------------------");

            var record = new Log {
                Error = "Error Source", Source = "Adding a Source"
            };

            businessRespository.AddDBLog(record);
            businessRespository.AddFileLog(record);
            businessRespository.AddFileLog(record);
            Console.WriteLine("Listing all Data--------------------------------------------------------------------------------------");
            foreach (var item in businessRespository.getAllLogs())
            {
                Console.WriteLine($"Log record: {item.Source}");
            }



            Console.WriteLine("--------------------------------------------------------------------------------------------------");

            Console.WriteLine("End Program");
        }
Example #21
0
 public static LogContext Create(HttpContext context)
 {
     return(CreateFactory(() => context)());
 }
Example #22
0
 private void Init()
 {
     _dataManager   = new DataManager(new FakeDatabase(), new RepositoryManager());
     _createFactory = new CreateFactory();
 }