Пример #1
0
        /// <summary>
        /// 创建一个程序集编译类
        /// </summary>
        /// <param name="name">程序集名字</param>
        /// <returns></returns>
        public static NAssembly CreateAssembly(this DomainBase domain, string name = default)
        {
            NAssembly result = new NAssembly(name);

            result.AssemblyBuilder.Compiler.Domain = domain;
            return(result);
        }
Пример #2
0
    public static TDomain RegisterDefault <TDomain>() where TDomain : DomainBase <TDomain>, new()
    {
        if (Default != null)
        {
            if (typeof(TDomain) != Default.GetType())
            {
                Default = (new TDomain()).GetInstance("Default");
            }
        }
        else
        {
            Default = (new TDomain()).GetInstance("Default");
        }


        foreach (var asm in DependencyContext
                 .Default
                 .CompileLibraries
                 .SelectMany(cl => cl.ResolveReferencePaths()))
        {
            Default.AddReferencesFromDllFile(asm);
        }


        return((TDomain)Default);
    }
Пример #3
0
    public static TDomain RegisterDefault <TDomain>(bool initializeReference = true) where TDomain : DomainBase
    {
        DynamicMethod   method = new DynamicMethod("Domain" + Guid.NewGuid().ToString(), typeof(DomainBase), new Type[] { typeof(string) });
        ILGenerator     il     = method.GetILGenerator();
        ConstructorInfo ctor   = typeof(TDomain).GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new Type[] { typeof(string) }, null);

        il.Emit(OpCodes.Ldarg_0);
        il.Emit(OpCodes.Newobj, ctor);
        il.Emit(OpCodes.Ret);
        CreateDomain = (Func <string, DomainBase>)(method.CreateDelegate(typeof(Func <string, DomainBase>)));

        Default = Create("Default");
        if (initializeReference)
        {
            foreach (var asm in DependencyContext
                     .Default
                     .CompileLibraries
                     .SelectMany(cl => cl.ResolveReferencePaths()))
            {
                Default.AddReferencesFromDllFile(asm);
            }
        }



        return((TDomain)Default);
    }
Пример #4
0
        public static T Use(DomainBase domain, Action <AssemblyCSharpBuilder> option = default)
        {
            T instance = new T();

            instance.AssemblyBuilder.Compiler.Domain = domain;
            instance.OptionAction = option;
            option?.Invoke(instance.AssemblyBuilder);
            return(instance);
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            DomainBase domainBase = value as DomainBase;

            if (domainBase != null)
            {
                return(!domainBase.IsDirty);
            }
            return(true);
        }
Пример #6
0
 public static Guid GetIDFromObject(DomainBase<Guid> domain)
 {
     if (domain != null)
       {
     return domain.ID;
       }
       else
       {
     return new Guid();
       }
 }
Пример #7
0
        public static T Delegate(string content, DomainBase domain = default, Action<AssemblyCSharpBuilder> option = default, params NamespaceConverter[] usings)
        {

            var method = typeof(T).GetMethod("Invoke");
            return FakeMethodOperator.Use(domain, option)
                .UseMethod(method)
                .Using(usings)
                .StaticMethodBody(content)
                .Compile<T>();

        }
Пример #8
0
        public static T Delegate(string content, DomainBase domain = default, Action <AssemblyCSharpBuilder> option = default, Func <FakeMethodOperator, FakeMethodOperator> methodAction = null, params NamespaceConverter[] usings)
        {
            var method    = typeof(T).GetMethod("Invoke");
            var @operator = FakeMethodOperator.UseDomain(domain, option);

            @operator
            .UseMethod(method)
            .Using(usings)
            .StaticMethodBody(content);
            methodAction?.Invoke(@operator);
            return(@operator.Compile <T>());
        }
Пример #9
0
    internal static void RegisterDefault(Type type)
    {
        DomainBase domain = (DomainBase)type.Assembly.CreateInstance(type.FullName);

        if (Default == null || (Default != null && Default.GetType() != type))
        {
            if (domain != null)
            {
                Default = domain.GetInstance("Default");
            }
        }
    }
Пример #10
0
        private bool isValidProduct(List <ProductDomain> ListProducts)
        {
            string AvailableProducts = DomainBase.GetAvailableProduct();

            foreach (ProductDomain product in ListProducts)
            {
                if (!AvailableProducts.ToUpper().Contains(product.Name.ToUpper()))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #11
0
 public static void Add(string key, DomainBase domain)
 {
     if (Cache.ContainsKey(key))
     {
         if (!Cache[key].IsAlive)
         {
             Cache[key] = new WeakReference(domain);
         }
     }
     else
     {
         Cache[key] = new WeakReference(domain, trackResurrection: true);
     }
 }
Пример #12
0
 public static T RegisterDefault <T>() where T : DomainBase, new()
 {
     if (Default != null)
     {
         if (typeof(T) != Default.GetType())
         {
             Default = (new T()).GetInstance("Default");
         }
     }
     else
     {
         Default = (new T()).GetInstance("Default");
     }
     return((T)Default);
 }
Пример #13
0
        private void SetToolbaritems()
        {
            ToolbarItems.Clear();
            var infoItem  = new ToolbarItem("Info", "info.png", () => ShowInfo());
            var scoreItem = TabView.SelectedIndex > 1
                ? new ToolbarItem("Score", "todo.png", () => ShowToDo())
                : new ToolbarItem("Score", "score.png", () => ShowScore());
            var finishItem = new ToolbarItem("Finish", "finish.png", async() => await _vm.Finish());

            ToolbarItems.Add(infoItem);
            ToolbarItems.Add(scoreItem);

            if (DomainBase.IsEmpty(_vm.Game.Game.FinishedAt))
            {
                ToolbarItems.Add(finishItem);
            }
        }
Пример #14
0
        public async Task LoadAsync(string gameId)
        {
            var gameDto = await DataService.GetPlayGame(gameId);

            Tees = new ObservableCollection <TeeDto>(gameDto.Tees.OrderBy(x => x.Number));
            foreach (var teeDto in Tees)
            {
                teeDto.Scores = new ObservableCollection <ScoreDto>(gameDto.Scores.Where(x => x.TeeId == teeDto.Id).OrderBy(x => x.PlayerAbbreviation));
            }

            var scores = gameDto.Scores.OrderBy(x => x.PlayerId).ToList();

            foreach (var scoreDto in scores)
            {
                scoreDto.Player    = gameDto.Players.First(x => x.Id == scoreDto.PlayerId);
                scoreDto.TeeNumber = gameDto.Tees.First(x => x.Id == scoreDto.TeeId).Number;
            }

            TotalScores = new ObservableCollection <TotalScoreDto>();
            foreach (var player in gameDto.Players.OrderBy(x => x.Abbreviation))
            {
                TotalScores.Add(new TotalScoreDto
                {
                    PlayerId   = player.Id,
                    TotalPutts = scores.Where(x => x.PlayerId == player.Id).Sum(x => x.Putts),
                });
            }

            Scores = new ObservableCollection <ScoreDto>(scores.OrderBy(x => x.TeeNumber).ThenBy(x => x.PlayerAbbreviation));
            Game   = gameDto;

            CurrentScore = Scores[Game.Game.CurrentTee];
            CurrentScore.ScoreChanged += CurrentScore_ScoreChanged;
            CurrentTee       = Tees.First(x => x.Id == CurrentScore.TeeId);
            IsBackEnabled    = false;
            IsNextEnabled    = true;
            ScoringIsEnabled = DomainBase.IsEmpty(Game.Game.FinishedAt);
            Title            = $"{Game.Game.GameType} @ {Game.Venue.Name}";

            RaisePropertyChanged(nameof(GameStartTime));
            RaisePropertyChanged(nameof(GameFinishedTime));
        }
Пример #15
0
        private async Task <T> SaveAsync <T>(DomainBase entity, bool synchronize = false) where T : DomainBase
        {
#if OFFLINE_SYNC_ENABLED
            var table = App.MobileService.GetSyncTable <T>();
#else
            var table = App.MobileService.GetTable <T>();
#endif
            var action = "init";
            try
            {
                if (entity.IsNew)
                {
                    entity.Id = NewId();
                    action    = "insert";
                    await table.InsertAsync((T)entity).ConfigureAwait(false);
                }
                else
                {
                    action = "update";
                    await table.UpdateAsync((T)entity).ConfigureAwait(false);
                }
                action = "sync";
                if (synchronize)
                {
                    await SyncAsync().ConfigureAwait(false);
                }
                action = "lookup";

                return((T)entity);
            }
            catch (Exception e)
            {
                var msg = $"Error executing {action} operation. Item: {typeof(T).Name} ({entity.Id}). Operation discarded. ";
                ErrorReportingService.ReportError(this, e, msg);
                //Debug.WriteLine($"{msg}. Error: {e.Message}");
                throw;
            }
        }
Пример #16
0
 public static ContextualReflectionScope Lock(DomainBase domain)
 {
     return(domain.EnterContextualReflection());
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ValueNode{T}" /> class.
 /// </summary>
 /// <param name="identifier">The parameter's identifier. Must be unique.</param>
 /// <param name="domain">The parameter's domain.</param>
 public ValueNode(string identifier, DomainBase <T> domain)
     : base(identifier)
 {
     this._domain = domain;
 }
Пример #18
0
 public DomainObjectMustContainIDRule(DomainBase domainBase)
 {
     _domainBase = domainBase;
 }
Пример #19
0
        private bool ExecuteValidation(List <ProductDomain> ListProducts)
        {
            if (MachineDomain.InsertedCoins == null || MachineDomain.InsertedCoins.Count == 0)
            {
                throw new ValidationException("Please Insert some Coins..");
            }
            else if (!isValidProduct(ListProducts))
            {
                throw new ValidationException(String.Format("NO_PRODUCT. Please request only {0}", DomainBase.GetAvailableProduct()));
            }
            else if (!isAvailableQttProduct(ListProducts))
            {
                throw new ValidationException("Unavailable Product. Insufficient Quantity. Sorry!");
            }
            else if (!isEnoughMoney(ListProducts))
            {
                throw new ValidationException("Insufficiente Coins to order the amount of product. Please Insert more Coins.");
            }

            return(true);
        }
Пример #20
0
        public static void Send(IDomainMapper domainMapper, Socket publisher, RuntimeTypeModel typeModel, MemoryStream stream, DomainBase instance)
        {
            var status = publisher.SendMore(domainMapper.Type2Bytes(instance.GetType()));

            if (status != SendStatus.Sent)
            {
                throw new InvalidOperationException("Key not sent!");
            }

            stream.SetLength(0);
            typeModel.Serialize(stream, instance);
            status = publisher.Send(stream.ToArray());
            if (status != SendStatus.Sent)
            {
                throw new InvalidOperationException("Instance not sent!");
            }
        }
Пример #21
0
        /// <summary>
        /// 获取编译所需的引用库
        /// </summary>
        /// <returns></returns>
        public static HashSet <PortableExecutableReference> GetCompileReferences(DomainBase main, DomainBase follow)
        {
            var defaultNode = (NatashaAssemblyDomain)main;

            //如果主从域不一样
            if (follow.Name != "default")
            {
                //去除剩余的部分
                var sets = new HashSet <PortableExecutableReference>(defaultNode.ReferencesFromStream.Values);

                //遍历主域的流引用集合
                foreach (var item in defaultNode.ReferencesFromStream.Keys)
                {
                    //遍历从域的流引用集合
                    foreach (var current in follow.ReferencesFromStream.Keys)
                    {
                        //如果程序集名相同
                        if (item.GetName().Name == current.GetName().Name)
                        {
                            //是否选用最新程序集
                            if (follow.UseNewVersionAssmebly)
                            {
                                //如果主域版本小,移除主域的引用
                                if (item.GetName().Version < current.GetName().Version)
                                {
                                    //使用现有域的程序集版本
                                    sets.Remove(defaultNode.ReferencesFromStream[item]);
                                    break;
                                }
                            }
                            else
                            {
                                sets.Remove(defaultNode.ReferencesFromStream[item]);
                                break;
                            }
                        }
                    }
                }

                //添加从域的流编译的引用
                sets.UnionWith(follow.ReferencesFromStream.Values);
                //添加主域的文件编译引用
                sets.UnionWith(defaultNode.ReferencesFromFile.Values);

                //对比主从域的文件编译引用
                foreach (var item in defaultNode.ReferencesFromFile.Keys)
                {
                    foreach (var current in follow.ReferencesFromFile.Keys)
                    {
                        //如果从域指定了文件编译引用
                        if (item == current)
                        {
                            //移除主域的引用
                            sets.Remove(defaultNode.ReferencesFromFile[item]);
                        }
                    }
                }

                //添加从域的引用
                sets.UnionWith(follow.ReferencesFromFile.Values);
                return(sets);
            }
            else
            {
                //如果是系统域则直接拼接自己的引用库
                var sets = new HashSet <PortableExecutableReference>(defaultNode.ReferencesFromStream.Values);
                sets.UnionWith(defaultNode.ReferencesFromFile.Values);
                return(sets);
            }
        }