static void Main(string[] args) { int sum = new GenericInvoker <UserManager>().Call(x => x.Sum(2, 3)); new GenericInvoker <UserManager>().CallVoid(x => x.Message(sum.ToString())); System.Console.ReadLine(); }
public GenericInvokerInfo(Type t, string m, Type[] gens, Type[] parms ) { this.Type = t; this.MethodName = m; this.GenericTypeParams = gens; this.ParameterTypes = parms; this.IsValid = false; this.Invoker = null; }
public void TestAs() { var obj1 = new GenericInvoker(); obj1.As <IInvokable>(s => s.Invoke()); var obj2 = new NoGenericInvoker(); obj2.As <IInvokable>(s => s.Invoke(), () => Console.WriteLine("obj2不是 IInvokable 类型")); }
static InterceptedQueryProvider() { createLazySource = GenericInvoker .Instance <InterceptedQueryProvider>() .CreateFunc1 <Func <Type, IQueryable>, IQueryable>(x => x.CreateLazySource <object>(null)); queryableExecuteGenericMethod = GenericInvoker .Instance <IQueryProvider>() .CreateFunc1 <Expression, object>(x => x.Execute <object>(null)); }
static RestQueryProvider() { executeGenericMethod = GenericInvoker .Instance <RestQueryProvider>() .CreateFunc1 <RestQueryableTreeParser, bool, object>(x => x.Execute <object>(null, false)); executeWithClientSelectPart = GenericInvoker .Instance <RestQueryProvider>() .CreateFunc2 <string, RestQueryableTreeParser.QueryProjection, LambdaExpression, RequestOptions, bool, object>( x => x.ExecuteWithClientSelectPart <int, bool>(null, default(RestQueryableTreeParser.QueryProjection), null, null, false)); }
private object InvokeGenericMethod(object obj, Type genericType, string methodName, Type[] argTypes, object[] args) { object obj2 = null; GenericInvoker invoker = ReflectionUtils.GenericMethodInvokerMethod(obj.GetType(), methodName, new Type[] { genericType }, argTypes); try { obj2 = invoker(obj, args); } catch (Exception exception) { if (exception.InnerException != null) { throw exception.InnerException; } throw exception; } return(obj2); }
static QueryProviderBase() { createQueryGeneric = GenericInvoker .Instance <QueryProviderBase>() .CreateFunc1 <Expression, IQueryable>(x => x.CreateQuery <object>(null)); }
private void SetPropertyValue <TType>(PropertyInfo propInfo, TType obj, ListItem item) where TType : SharePointDomainModel { // Don't map ignored properties var ignoredPropertyAttribute = propInfo.GetCustomAttribute <IgnoredPropertyAttribute>(); if (ignoredPropertyAttribute != null) { return; } var attribute = propInfo.GetCustomAttribute <LookupListNameAttribute>(); if (attribute == null) { var underlyingType = Nullable.GetUnderlyingType(propInfo.PropertyType) ?? propInfo.PropertyType; if (underlyingType.FullName == "Amt.SharePoint.Integration.Models.User") { var fieldUserValue = (FieldUserValue)item[propInfo.PropertyName()]; var user = _ctx.Web.SiteUsers.GetById(fieldUserValue.LookupId); _ctx.Load(user); _ctx.ExecuteQuery(); var sharePointUser = new Models.User { Email = user.Email, ID = user.Id, LoginName = user.LoginName, Title = user.Title }; propInfo.SetValue(obj, sharePointUser, null); } if (underlyingType.FullName == "Amt.SharePoint.Integration.Models.Hyperlink") { var fieldUrlValue = (FieldUrlValue)item[propInfo.PropertyName()]; if (fieldUrlValue == null) { propInfo.SetValue(obj, null, null); return; } //TODO: Downlaod content if downloadable. var url = fieldUrlValue.Url; var downloadableContent = propInfo.GetCustomAttribute <DownloadableContentAttribute>(); if (downloadableContent != null) { var rootUrl = string.Join("/", _sharepointUrl.Split('/').Take(3).ToArray()); url = url.Replace(rootUrl + "/:i:/r", ""); url = url.Replace(rootUrl, ""); url = url.Split('?')[0]; DownloadImage(url); } var hyperlink = new Hyperlink { Url = url, Description = fieldUrlValue.Description, TypeId = fieldUrlValue.TypeId }; propInfo.SetValue(obj, hyperlink, null); } if (underlyingType.FullName == "Amt.SharePoint.Integration.Models.PublishingImage") { var fieldUrlValue = (string)item[propInfo.PropertyName()]; if (fieldUrlValue == null) { propInfo.SetValue(obj, null, null); return; } Match matches = Regex.Match(fieldUrlValue, "alt=\"(?<AltTag>.*?)\".* src=\"(?<SrcTag>.*?)\""); DownloadImage(matches.Groups["SrcTag"].Value); var image = new PublishingImage { Alt = matches.Groups["AltTag"].Value, Src = matches.Groups["SrcTag"].Value }; propInfo.SetValue(obj, image, null); } else { propInfo.SetValue(obj, Convert.ChangeType(item[propInfo.PropertyName()], underlyingType), null); } } else { if (item[propInfo.PropertyName()] == null) { return; } if (propInfo.PropertyType.IsArray) { Type arrayType = propInfo.PropertyType.GetElementType(); var array = Array.CreateInstance(arrayType, ((FieldLookupValue[])(item[propInfo.PropertyName()])).Count()); for (var index = 0; index < ((FieldLookupValue[])(item[propInfo.PropertyName()])).Length; index++) { var lookupId = ((FieldLookupValue[])(item[propInfo.PropertyName()]))[index].LookupId; GenericInvoker invoker = DynamicMethods. GenericMethodInvokerMethod(typeof(SharePointRepository <T>), "GetById", new[] { arrayType }, new[] { arrayType }); var lookupItem = invoker(this, lookupId); array.SetValue(lookupItem, index); } propInfo.SetValue(obj, array, null); } else { var lookupId = ((FieldLookupValue)(item[propInfo.PropertyName()])).LookupId; GenericInvoker invoker = DynamicMethods. GenericMethodInvokerMethod(typeof(SharePointRepository <T>), "GetById", new[] { propInfo.PropertyType }, new[] { propInfo.PropertyType }); var lookupItem = invoker(this, lookupId); propInfo.SetValue(obj, Convert.ChangeType(lookupItem, propInfo.PropertyType), null); } } }
public void SetUp() { _sut = new GenericInvoker <Foo>(); }
public void Copy(string provider1, string server1, string catalog1, string login1, string cred1, string provider2, string server2, string catalog2, string login2, string cred2, string table_cue_after, string single_table, bool no_utc) { string bintablename = new doc02Binary().TableName.ToLower(); /* 0. define exclusions */ var exclusions = new List <string>() { new sys02Installation().TableName, new doc02FT().TableName, /* [dlatikay 20110920] now the table name will resolve properly, was before: "doc02FT"; -!- until better solution, currently not included in schema! */ new doc02Binary().TableName, new doc02BinaryL().TableName, new log02OrgSync().TableName, new log02OrgSyncItem().TableName, new msg02EventA().TableName, new nav02PickupStorage().TableName, /* it fails with a strange error in the RAW field (SessionID). we just omit it as it is transient and therefore not needed in systemcopy anyway */ new nav02Menu().TableName, /* [dlatikay 20101012] added */ new nav02MenuL().TableName, /* [dlatikay 20101012] added */ new nav02MenuLocation().TableName, /* [dlatikay 20151002] added */ new nav02MenuLocationL().TableName, /* [dlatikay 20151002] added */ new per02TaskA().TableName, new rpt02Link().TableName, new rpt02LinkL().TableName, new rpt02Destination().TableName, /* [dlatikay 20101012] added */ new sys02Computer().TableName, new sys02GroupAccount().TableName, new sys02JobA().TableName, new sys02Useraccount().TableName, new tpi02CredentialStore().TableName, new tpi02FunclocImp().TableName, new tpi02HRImpAcceptor().TableName }; /* except the single table from the exception */ if (!String.IsNullOrWhiteSpace(single_table)) { string exex = exclusions.Find((x) => { return(x.ToLower().Equals(single_table.ToLower())); }); /* [dlatikay 20090824] for genuine case insensitivity */ if (!String.IsNullOrWhiteSpace(exex)) { exclusions.Remove(exex); } } /* 1. open both connections */ ddl db1 = new ddlfactory((DbProvider)Enum.Parse(typeof(DbProvider), provider1)).Generate; ddl db2 = new ddlfactory((DbProvider)Enum.Parse(typeof(DbProvider), provider2)).Generate; try { db1.Connect(server1, catalog1, login1, cred1, null, no_utc); db2.Connect(server2, catalog2, login2, cred2, null, no_utc); /* 2. enumerate the tables in source and target */ List <string> tables1 = db1.ListAllTables(); List <string> tables2 = db2.ListAllTables(); /* 3. for each table in the source, attempt to truncate * the table in the destination and re-fill it using bulk insert * approach */ /* 3a. for each table */ bool keep_skipping = (table_cue_after != null && table_cue_after.Length > 0) || (single_table != null && single_table.Length > 0); bool stop_after_single_table = false; Assembly assy = Assembly.GetExecutingAssembly(); foreach (string table in tables1) { string tablename = table.ToLower(); if (single_table == null || single_table.Length <= 0) { log(864, tablename); /* Transferring table \"{0}\"... */ } if (keep_skipping) { if (table_cue_after != null && table_cue_after.Length > 0) { log(1173, table_cue_after); /* --> skipped, precedes continuation point "{0}" */ keep_skipping = tablename != table_cue_after.ToLower(); } else if (single_table != null && single_table.Length > 0) { keep_skipping = (!single_table.ToLower().Equals(tablename)); if (!keep_skipping) { log(864, tablename); /* Transferring table \"{0}\"... */ stop_after_single_table = true; } } } /* take this one? */ if (!keep_skipping) { /* must not be in the exclusion list. if the single table is in the exclusion list, we excluded it from the exclusion list already :) */ if (!exclusions.Exists(delegate(string x) { return(x.ToLower().Equals(tablename)); })) { /* must exist in source and target (otherwise installations do not match in schema version probably) */ if (tables2.Exists(delegate(string x) { return(x.ToLower().Equals(tablename)); })) { //if (tablename.StartsWith(bintablename)) // /* the "doc02Binary" table gets special treatment because it contains huge binary chunks. so does the doc02BinaryL. */ // CopyBinRowwise(db1, db2, tablename); //else //{ /* got the singular, need the plural */ TableDef element = (TableDef)assy.CreateInstance("dal.schema." + tablename, true); string plural = db1.ObtainPlural(assy, tablename); ITableList list = (ITableList)assy.CreateInstance("dal.schema." + plural, true); /* generic-dynamically invoke the dbselectall statement on the source */ GenericInvoker invoker = clsDynamicGenerics.GenericMethodInvokerMethod( element.GetType(), "DbSelectAll", new Type[] { list.GetType(), element.GetType() }, new Type[] { typeof(ddl) } ); list = invoker(element, db1) as ITableList; /* truncate the target */ element.DbTruncate(db2); if (list.Rowcount > 0) { log(1157, list.Rowcount.ToString()); /* --> number of records to be transferred: {0} */ /* now for the dbinsertall statement on the target - who's able to fully understand this, must be drugged */ try { element.InsertAllGeneric(db2, list); } catch (Exception ex) { throw new DALException(String.Format("Failed to copy table \"{0}\".", element.TableName), ex); } log(870, list.Rowcount.ToString()); /* --> number of records transferred: {0} */ } else { log(869); /* --> deletion only, no data in source table */ } } else { /* table does not exist in destination */ log(866); /* --> skipped because not existing in target database. */ } } else { /* table skipped because of exclusion rule */ log(865); /* --> skipped because in exclusion list. */ } } /* if we wanted only a single table we might now abort */ if (stop_after_single_table) { break; } } /* succeeded */ } finally { /* cleanup */ if (db2 != null) { db2.Disconnect(); } if (db1 != null) { db1.Disconnect(); } } }