コード例 #1
0
        internal static string Builder(IBase iBase)
        {
            var nomeTabela = iBase.GetType().Name.ToLower();
            var tabela     = iBase.GetType().GetCustomAttribute <TabelaAttribute>();

            if (tabela != null && !string.IsNullOrEmpty(tabela.Nome))
            {
                nomeTabela = tabela.Nome;
            }
            var sql = $"insert into {nomeTabela} ( ";

            var campos       = iBase.GetType().GetProperties();
            var camposTabela = new List <string>();

            foreach (var campo in campos)
            {
                var campoPersistir = campo.GetCustomAttribute <CampoPersisitidoAttribute>();
                if (campoPersistir != null)
                {
                    var nomeCampo = string.IsNullOrEmpty(campoPersistir.NomeColuna) ? campo.Name : campoPersistir.NomeColuna;
                    camposTabela.Add(nomeCampo);
                }
            }

            sql += string.Join(",", camposTabela);
            sql += ")";

            return(sql);
        }
コード例 #2
0
        public static string Builder(IBase iBase)
        {
            var nome   = $"{iBase.GetType().Name.ToLower()}s";
            var tabela = iBase.GetType().GetCustomAttribute <TabelaAttribute>();

            if (tabela != null && !string.IsNullOrEmpty(tabela.Nome))
            {
                nome = tabela.Nome;
            }

            var campos = iBase.GetType().GetProperties();

            var           sql       = $"insert into {nome} values (";
            List <string> colunasDb = new List <string>();

            foreach (var campo in campos)
            {
                var campoPersistir = campo.GetCustomAttribute <CampoPersistidoAttribute>();
                if (campoPersistir != null)
                {
                    var nomeCampo = string.IsNullOrEmpty(campoPersistir.NomeColuna) ? campo.Name : campoPersistir.NomeColuna;

                    colunasDb.Add(nomeCampo);
                }
            }

            sql += string.Join(",", colunasDb.ToArray());

            return(sql);
        }
コード例 #3
0
ファイル: ResourceFileData.cs プロジェクト: ArtStudy/ToE2.0
        public void ReLoad(IBase obj)
        {
            var       typevalue = obj.GetType();
            FileTypes type      = ((TypeDataAttribute)obj.GetType().GetCustomAttributes(typeof(TypeDataAttribute), false)[0]).Type;

            if (this.Data[type].ContainsKey(obj))
            {
                var baseobj = this.Data[type][obj].Find((item) => item.FileType == type);
                var lr      = this.Data[type][obj];
                this.Data[type].Remove(obj);

                switch (type)
                {
                case FileTypes.Level:

                    var Levelresult = ResourceConverter.ResourceToLevel(baseobj, lr);
                    Data[type][Levelresult.Item1] = Levelresult.Item2;
                    break;

                case FileTypes.Boss:
                    var Bossresult = ResourceConverter.ResourceToBoss(baseobj, lr);

                    Data[type][Bossresult.Item1] = Bossresult.Item2;
                    break;

                case FileTypes.Question:

                    var Questionesult = ResourceConverter.ResourceToQuestion(baseobj, lr);

                    Data[type][Questionesult.Item1] = Questionesult.Item2;

                    break;

                case FileTypes.Language:
                    var LanguagePacresult = ResourceConverter.ResourceToLanguagePack(baseobj, lr);

                    Data[type][LanguagePacresult.Item1] = LanguagePacresult.Item2;
                    break;

                case FileTypes.Age:

                    var Ageresult = ResourceConverter.ResourceToAge(baseobj, lr);
                    Data[type][Ageresult.Item1] = Ageresult.Item2;
                    break;

                case FileTypes.InventoryItem:
                    var InventoryItemresult = ResourceConverter.ResourceToInventoryItem(baseobj, lr);

                    Data[type][InventoryItemresult.Item1] = InventoryItemresult.Item2;
                    break;

                case FileTypes.TextStyle:
                    var TextStyleresult = ResourceConverter.ResourceToTextStyle(baseobj, lr);

                    Data[type][TextStyleresult.Item1] = TextStyleresult.Item2;
                    break;
                }
            }
        }
コード例 #4
0
        private static Dictionary <UInt64, T> GetProperty <T>(ISaveData obj, string name)
        {
            var   type  = ((TypeDataAttribute)obj.GetType().GetCustomAttributes(typeof(TypeDataAttribute), false)[0]).Type;
            IBase @base = null;

            switch (type)
            {
            case FileTypes.Level:
                @base = SaveLevelData;
                break;

            case FileTypes.User:
                @base = SaveUserData;
                break;
            }

            var typebase = @base.GetType();
            var property = typebase.GetProperty(name);

            if (property == null)
            {
                throw new Exception("Отсутвует поле сохранения");
            }


            Dictionary <UInt64, T> pairs = (Dictionary <UInt64, T>)property.GetValue(@base);

            return(pairs);
        }
コード例 #5
0
        public static async void DeleteFromVirtualDBAsync(IBase obj)
        {
            await Task.Run(() => {
                switch (obj.GetType().Name)
                {
                case "User":
                    Users.Remove((User)obj);
                    break;

                case "EventModel":
                    Events.Remove((EventModel)obj);
                    break;

                case "ArticleModel":
                    Articles.Remove((ArticleModel)obj);
                    break;

                case "CommentModel":
                    Comments.Remove((CommentModel)obj);
                    break;

                case "MessageModel":
                    Messages.Remove((MessageModel)obj);
                    break;
                }
            });
        }
コード例 #6
0
    public static void Salvar(IBase iBase)
    {
        Console.Write("Salvando carro.");

        var campos = iBase.GetType().GetProperties();

        List <String> colunas = new List <string>();
        string        sql     = $"insert into{iBase.GetType().Name} values(";

        foreach (var campo in campos)
        {
            colunas.Add(campo.Name);
        }
        sql += string.Join(",", colunas.ToArray());
        sql += ")";
    }
コード例 #7
0
    private static void Main(string[] args)
    {
        IService svc1   = new Service1();
        IBase    result = svc1.Call <ReturnType1>();

        Console.WriteLine(result.GetType());
    }
コード例 #8
0
        public void SetRecordId(IBase instance)
        {
            if (instance.RecordState == ERecordState.Added)
            {
                instance.SetRecordId();
            }

            foreach (var property in instance.GetType().GetProperties())
            {
                if (
                    (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(List <>) && property.GetCustomAttribute <NotMappedAttribute>() == null) ||
                    (property.PropertyType.BaseType != null && (
                         property.PropertyType.BaseType.IsGenericType && property.PropertyType.BaseType.GetGenericTypeDefinition() == typeof(List <>) && property.GetCustomAttribute <NotMappedAttribute>() == null))
                    )
                {
                    try
                    {
                        if (property.GetValue(instance, null) != null)
                        {
                            foreach (var baseItem in (IEnumerable)property.GetValue(instance, null))
                            {
                                if (baseItem is Base)
                                {
                                    Base baseItemInstance = (Base)baseItem;

                                    SetRecordId(baseItemInstance);
                                }
                            }
                        }
                    }
                    catch { }
                }
            }
        }
コード例 #9
0
        public static void Salvar(IBase carro)
        {
            var sql = $"insert into {carro.GetType().Name.ToLower()}s ( ";

            var campos       = carro.GetType().GetProperties();
            var camposTabela = new List <string>();

            foreach (var campo in campos)
            {
                camposTabela.Add(campo.Name);
            }

            sql += string.Join(",", camposTabela);
            sql += ")";
            Console.WriteLine(sql);
        }
コード例 #10
0
        /// <summary>
        /// Creates new instance of Ui class.
        /// </summary>
        public Ui()
        {
            this.mouseContentRestorationTimerLock = new object();
            this.previewRegex = new System.Text.RegularExpressions.Regex(@"^\S*\s", System.Text.RegularExpressions.RegexOptions.Compiled);

            Hotkeys.Instance.RegisterHotkey(Settings.Keys.Hotkeys.Menu, new Hotkey((Gdk.ModifierType)Settings.Instance[Settings.Keys.Hotkeys.MenuModifiers].AsInteger(),
                                                                                   (Gdk.Key)Settings.Instance[Settings.Keys.Hotkeys.MenuKey].AsInteger(),
                                                                                   Settings.Instance[Settings.Keys.Hotkeys.Menu].AsBoolean(),
                                                                                   this.ShowMenu));
            Hotkeys.Instance.RegisterHotkey(Settings.Keys.Hotkeys.CopyMouse, new Hotkey((Gdk.ModifierType)Settings.Instance[Settings.Keys.Hotkeys.CopyMouseModifiers].AsInteger(),
                                                                                        (Gdk.Key)Settings.Instance[Settings.Keys.Hotkeys.CopyMouseKey].AsInteger(),
                                                                                        Settings.Instance[Settings.Keys.Hotkeys.CopyMouse].AsBoolean(),
                                                                                        this.SetTemporaryMouseItemAsContent));
            Hotkeys.Instance.Enabled = true;

            this.Plugins = new List <IPlugin>();
            this.Trays   = new List <ITray>();

            Clipboard.Instance.LockMouseClipboard = Settings.Instance[Settings.Keys.Hotkeys.CopyMouse].AsBoolean();
            Clipboard.Instance.ClipboardChanged  += this.OnClipboardChanged;
            Settings.Instance.SettingChanged     += this.OnSettingChanged;
            this.RebuildMenu();

            string[]      plugins        = Settings.Instance[Settings.Keys.Plugins.List].AsString().Split('|');
            List <string> parsed_plugins = new List <string>();

            foreach (string plug in plugins.OrderBy(p => p))
            {
                if (string.IsNullOrWhiteSpace(plug))
                {
                    continue;
                }

                try
                {
                    IBase plugin = Core.Plugins.LoadPlugin(plug);
                    Type  t      = plugin.GetType();

                    if (t.GetInterface(typeof(IPlugin).Name) != null)
                    {
                        ((IPlugin)plugin).Load();
                        this.Plugins.Add((IPlugin)plugin);
                    }
                    else if (t.GetInterface(typeof(ITray).Name) != null)
                    {
                        ((ITray)plugin).Load(this.Menu, this.RebuildMenu);
                        this.Trays.Add((ITray)plugin);
                    }

                    parsed_plugins.Add(plug);
                }
                catch (Exception ex)
                {
                    Tools.PrintInfo(ex, this.GetType());
                }
            }

            Settings.Instance[Settings.Keys.Plugins.List] = string.Join("|", parsed_plugins);
        }
コード例 #11
0
        public static void Salvar(IBase iBase)
        {
            var campos = iBase.GetType().GetProperties();

            ICollection <string> colunas = new HashSet <string>();
            string query = $"insert into {iBase.GetType().Name} values (";

            foreach (var campo in campos)
            {
                colunas.Add(campo.Name);
            }

            query += string.Join(",", colunas);
            query += ")";

            Console.WriteLine(query);
        }
コード例 #12
0
        public static void Salvar(IBase iBase)
        {
            var campos = iBase.GetType().GetProperties();

            var           sql       = $"insert into " + iBase.GetType().Name + " values (";
            List <string> colunasDB = new List <string>();

            foreach (var campo in campos)
            {
                colunasDB.Add(campo.Name);
            }

            sql += string.Join("", colunasDB.ToArray());

            sql += ")";

            Console.WriteLine(sql);
        }
コード例 #13
0
        public static string MakeID(this IBase baseObject, string predicate)
        {
            var id = "/" + baseObject.GetType().Name + "[@" + predicate + "]";

            if (baseObject.Parent != null)
            {
                id = baseObject.Parent.ID + id;
            }

            return(id);
        }
コード例 #14
0
ファイル: RuleManager.cs プロジェクト: keithdv/OOBehave
 void ISetTarget.SetTarget(IBase target)
 {
     if (target is T tt)
     {
         Target = tt;
     }
     else
     {
         throw new InvalidTargetTypeException(target.GetType().FullName);
     }
 }
コード例 #15
0
ファイル: Base.cs プロジェクト: whatanaka/estudos
 private void setProperty(ref IBase obj, SqlDataReader reader)
 {
     foreach (PropertyInfo pi in obj.GetType().GetProperties(BindingFlags.Public))
     {
         OpcoesBase pOpcoesBase = (OpcoesBase)pi.GetCustomAttribute(typeof(OpcoesBase));
         if (pOpcoesBase != null && pOpcoesBase.UsarNoBancoDeDados)
         {
             pi.SetValue(obj, reader[pi.Name].ToString());
         }
     }
 }
コード例 #16
0
        public static void Salvar(IBase iBase)
        {
            var campos = iBase.GetType().GetProperties();

            var sql = $"insert into {iBase.GetType().Name.ToLower()}s values (";

            List <string> colunasDb = new List <string>();

            foreach (var campo in campos)
            {
                if (campo.Name.ToLower() != "id")
                {
                    colunasDb.Add(campo.Name);
                }
            }

            sql += string.Join(",", colunasDb.ToArray());
            sql += ")";

            Console.WriteLine(sql);
        }
コード例 #17
0
ファイル: ResourceFileData.cs プロジェクト: ArtStudy/ToE2.0
        public void Save(IBase obj)
        {
            FileTypes    type = ((TypeDataAttribute)obj.GetType().GetCustomAttributes(typeof(TypeDataAttribute), false)[0]).Type;
            ListResourse lr   = null;

            switch (type)
            {
            case FileTypes.Level:

                lr = ResourceConverter.ToResource((ILevel)obj);
                break;

            case FileTypes.Boss:
                lr = ResourceConverter.ToResource((IBoss)obj);
                break;

            case FileTypes.Question:

                lr = ResourceConverter.ToResource((IQuestion)obj);

                break;

            case FileTypes.Language:
                lr = ResourceConverter.ToResource((ILanguagePack)obj);
                break;

            case FileTypes.Age:

                lr = ResourceConverter.ToResource((IAge)obj);
                break;

            case FileTypes.InventoryItem:

                lr = ResourceConverter.ToResource((IInventoryItem)obj);
                break;

            case FileTypes.TextStyle:

                lr = ResourceConverter.ToResource((ITextStyle)obj);
                break;
            }



            Data[type][obj] = lr;
        }
コード例 #18
0
ファイル: Base.cs プロジェクト: gaginski/MyReview
        private void setProperty(ref IBase obj, SqlDataReader reader)
        {
            Util u = new Util();

            foreach (PropertyInfo pi in obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                OpcoesBase pOpcoesBase = (OpcoesBase)pi.GetCustomAttribute(typeof(OpcoesBase));
                if (pOpcoesBase != null && pOpcoesBase.UsarNoBanco && reader[pi.Name].ToString() != null)
                {
                    if (!pOpcoesBase.Criptografado)
                    {
                        pi.SetValue(obj, reader[pi.Name]);
                    }
                    else
                    {
                        pi.SetValue(obj, u.descriptografa(reader[pi.Name].ToString(), pOpcoesBase.chaveCripto));
                    }
                }
            }
        }
コード例 #19
0
        public ResolveQuery SetIdentifier(IBase item)
        {
            if (item is ReferentialEntity e)
            {
                this.Kind       = ElementEnum.Entity;
                this.TypeName   = e.TypeEntity;
                this.Identifier = "i:" + e.Id;
            }
            else if (item is ReferentialRelationship r)
            {
                this.Kind       = ElementEnum.Relationship;
                this.TypeName   = r.TypeEntity;
                this.Identifier = "i:" + r.Id;
            }
            else if (item is EntityDefinition e1)
            {
                this.Kind     = ElementEnum.EntityDefinition;
                this.TypeName = e1.Name;
            }
            else if (item is RelationshipDefinition r1)
            {
                this.Kind     = ElementEnum.RelationshipDefinition;
                this.TypeName = r1.Name;
            }
            else if (item is RestrictionDefinition r2)
            {
                this.Kind     = ElementEnum.RestrictionDefinition;
                this.TypeName = r2.Name;
            }
            else if (item is ReferentialRelationshipLink l)
            {
                this.Kind       = ElementEnum.Entity;
                this.Identifier = "n:" + l.Name;
            }
            else
            {
                throw new NotImplementedException(item.GetType().Name);
            }

            return(this);
        }
コード例 #20
0
        public string GetOverrideId(IBase baseObject, string predicate, string generatedId)
        {
            var id = generatedId;

            if (baseObject.Name == "Ripley")
            {
                predicate = "Model='HydraDevOps'";
            }
            else if (baseObject.Name == "RipleyEntities")
            {
                predicate = "Container='HydraDevOpsContext'";
            }

            id = "/" + baseObject.GetType().Name + "[@" + predicate + "]";

            if (baseObject.Parent != null)
            {
                id = baseObject.Parent.ID + id;
            }

            return(id);
        }
コード例 #21
0
        public void SetEntityValues(IBase dynamicProxy, IBase poco, IBase parentPoco = null)
        {
            var readonlyFields = new List <string> {
                "RecordId", "CreatedDateTime"
            };

            #region  alt enityleri güncellerken upper record idler güncellenemez.

            if (parentPoco != null)
            {
                var parentProperty = GetPropertiesByAttribute(poco.GetType(), typeof(ForeignKeyAttribute)).Where(p => p.Name == parentPoco.GetType().Name).FirstOrDefault();

                if (parentProperty != null)
                {
                    readonlyFields.Add(parentProperty.GetCustomAttribute <ForeignKeyAttribute>().Name);
                }
            }

            #endregion

            Type pocoType = poco.GetType();

            var headerCurrentValues = _context.Entry(dynamicProxy).CurrentValues;
            var headerProps         = pocoType.GetProperties();

            var modifiedSpecialFields = new string[] { "ModifiedDateTime", "ModifiedUser" };

            foreach (var propertyName in headerCurrentValues.Properties.Where(x => !readonlyFields.Contains(x.Name)))
            {
                headerCurrentValues[propertyName] = headerProps.Where(x => x.Name == propertyName.Name).Single().GetValue(poco);
            }

            foreach (var notMappedProperty in GetMappedProperties(dynamicProxy.GetType()))
            {
                if (notMappedProperty.CanWrite)
                {
                    notMappedProperty.SetValue(dynamicProxy, headerProps.Where(x => x.Name == notMappedProperty.Name).Single().GetValue(poco));
                }
            }

            dynamicProxy.RecordState = poco.RecordState;

            Func <PropertyInfo, bool> listWhere = (PropertyInfo p) => (p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(List <>)
                                                                       ||
                                                                       (p.PropertyType.BaseType != null && (
                                                                            p.PropertyType.BaseType.IsGenericType && p.PropertyType.BaseType.GetGenericTypeDefinition() == typeof(List <>))));


            var listProperties = GetNotMappedProperties(pocoType).Where(listWhere).ToList();

            var notMapProps = GetMappedProperties(pocoType).Where(
                p => (p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() != typeof(List <>)
                      ||
                      (p.PropertyType.BaseType != null && (
                           p.PropertyType.BaseType.IsGenericType && p.PropertyType.BaseType.GetGenericTypeDefinition() != typeof(List <>))))
                ).ToList();

            var dynamicProxyListProperties = GetNotMappedProperties(dynamicProxy.GetType()).Where(listWhere).ToList();

            var listPropertyNames = listProperties.Select(x => x.Name);
            var notMapPropNames   = notMapProps.Select(x => x.Name);


            foreach (var listProperty in listProperties)
            {
                #region Details:


                var listItems = (IList)listProperty.GetValue(poco);

                if (listItems == null)
                {
                    continue;
                }

                foreach (IBase listItem in listItems)
                {
                    if (listItem.RecordState == ERecordState.Unchanged)
                    {
                        continue;
                    }

                    else if (listItem.RecordState == ERecordState.Added)
                    {
                        var propertyOnDynamic = dynamicProxyListProperties.Where(x => x.Name == listProperty.Name).FirstOrDefault();

                        if (propertyOnDynamic == null)
                        {
                            throw new Exception(String.Format("{0} List<> property not found on class:{1}", listProperty.Name, dynamicProxy.GetType()));
                        }

                        var listValueOnDynamic = (IList)propertyOnDynamic.GetValue(dynamicProxy);

                        if (listValueOnDynamic == null)
                        {
                            var listType            = typeof(List <>);
                            var constructedListType = listType.MakeGenericType(listItem.GetType());
                            var instance            = (IList)Activator.CreateInstance(constructedListType);
                            instance.Add(listItem);
                            propertyOnDynamic.SetValue(dynamicProxy, instance);
                        }
                        else if (!listValueOnDynamic.Contains(listItem))
                        {
                            listValueOnDynamic.Add(listItem);
                        }
                    }
                    else
                    {
                        var dbListItem = _context.Set <TEntity>().Find(listItem.RecordId);

                        if (dbListItem != null)
                        {
                            if (listItem.RecordState == ERecordState.Deleted)
                            {
                                _context.Entry(dbListItem).Property("Deleted").CurrentValue = 1;
                                _context.Entry(dbListItem).Property("Deleted").IsModified   = true;
                            }
                            else
                            {
                                SetEntityValues((IBase)dbListItem, listItem, poco);
                            }
                        }
                    }
                }
                #endregion
            }
        }
コード例 #22
0
 public X Apply(IBase data)
 {
     try
     {
         return(ApplyImpl((dynamic)data));
     }
     catch (RuntimeBinderException ex)
     {
         throw new InvalidOperationException(
                   string.Format("{0} is not implemented for type {1}.", typeof(MyAlgorithm).Name, data.GetType().Name),
                   ex);
     }
 }
コード例 #23
0
 public HasInterfaceConstructor(IBase baseClass)
 {
     ParamObject = baseClass;
     ParamType   = baseClass.GetType();
 }