Search Results

Search found 26126 results on 1046 pages for 'generic service contract'.

Page 92/1046 | < Previous Page | 88 89 90 91 92 93 94 95 96 97 98 99  | Next Page >

  • Multi- authentication scenario for a public internet service using Kerberos

    - by StrangeLoop
    I have a public web server which has users coming from internet (via HTTPS) and from a corporate intranet. I wish to use Kerberos authentication for the intranet users so that they would be automatically logged in the web application without the need to provide any login/password (assuming they are already logged to the Windows domain). For the users coming from internet I want to provide traditional basic/form- based authentication. User/password data for these users would be stored internally in a database used by the application. Web application will be configured to use Kerberos authentication for users coming from specific intranet ip networks and basic/form- based authentication will be used for the rest of the users. From a security perspective, are there some risks involved in this kind of setup or is this a generally accepted solution? My understanding is that server doesn't need access to KDC (see Kerberos authentication, service host and access to KDC) and it can be completely isolated from AD and corporate intranet. The server has a keytab file stored locally that is used to decrypt tickets sent by the users coming from intranet. The tickets only contain username and domain of the incoming user. Server never sees the passwords of authenticated users. If the server would be hacked and the keytab file compromised, it would mean that attacker could forge tickets for any domain user and get access to the web application as any user. But typically this is the case anyway if hacker gains access to the keytab file on the local filesystem. The encryption key contained in the keytab file is based on the service account password in AD and is in hashed form, I guess it is very difficult to brute force this password if strong Kerberos encryption like AES-256-SHA1 is used. As the server has no network access to intranet, even the compromised service account couldn't be directly used for anything.

    Read the article

  • Opscenter repair service times out. ERROR: Requested range intersects a local range [...]

    - by jlemire-zs
    My production cluster had the repair service enabled since april 16th with the default 9 days time to completion and repairs would complete properly. However, since may 22nd, it is being disabled automatically by Opscenter: From /var/log/opscenter/opscenterd.log: [...] 2014-06-03 21:13:47-0400 [zs_prod] ERROR: Repair task (<Node 10.1.0.22='6417880425364517165'>, (-4019838962446882275L, -4006140687792135587L), set(['zs_logging', 'OpsCenter'])) timed out after 3600 seconds. 2014-06-03 22:16:44-0400 [zs_prod] ERROR: Repair task (<Node 10.1.0.22='6417880425364517165'>, (-4006140687792135587L, -4006140687792135586L), set(['zs_logging', 'OpsCenter'])) timed out after 3600 seconds. 2014-06-03 22:16:44-0400 [zs_prod] ERROR: More than 100 errors during repair service, shutting down repair service 2014-06-03 22:16:44-0400 [zs_prod] INFO: Stopping repair service [...] From /var/log/opscenter/repair_service/zs_prod.log: [...] 2014-06-03 22:16:44-0400 [zs_prod] ERROR: Repair task (<Node 10.1.0.22='6417880425364517165'>, (-4006140687792135587L, -4006140687792135586L), set(['zs_logging', 'OpsCenter'])) timed out after 3600 seconds. 2014-06-03 22:16:44-0400 [zs_prod] ERROR: Task (<Node 10.1.0.22='6417880425364517165'>, (-4006140687792135587L, -4006140687792135586L), set(['zs_logging', 'OpsCenter'])) has failed 1 times. 2014-06-03 22:16:44-0400 [zs_prod] ERROR: 101 errors have ocurred out of 100 allowed. 2014-06-03 22:16:44-0400 [zs_prod] ERROR: More than 100 errors during repair service, shutting down repair service 2014-06-03 22:16:44-0400 [zs_prod] INFO: Stopping repair service On the nodes on which the repair fails, from /var/log/cassandra/system.log: ERROR [RMI TCP Connection(93502)-10.1.0.22] 2014-06-03 20:12:28,858 StorageService.java (line 2560) Repair session failed: java.lang.IllegalArgumentException: Requested range intersects a local range but is not fully contained in one; this would lead to i mprecise repair at org.apache.cassandra.service.ActiveRepairService.getNeighbors(ActiveRepairService.java:164) at org.apache.cassandra.repair.RepairSession.<init>(RepairSession.java:128) at org.apache.cassandra.repair.RepairSession.<init>(RepairSession.java:117) at org.apache.cassandra.service.ActiveRepairService.submitRepairSession(ActiveRepairService.java:97) at org.apache.cassandra.service.StorageService.forceKeyspaceRepair(StorageService.java:2620) at org.apache.cassandra.service.StorageService$5.runMayThrow(StorageService.java:2556) at org.apache.cassandra.utils.WrappedRunnable.run(WrappedRunnable.java:28) These errors, which only occurs if the repair service is running, are the only errors these nodes experience. Outside of the repair task, the Cassandra cluster works perfectly. I am running Opscenter 4.1.2 with a 6 nodes DSE 4.0.2 cluster installed on linux virtual machines. The nodes run a vanilla installation of Ubuntu Server 12.04 64-bit and DSE was installed and secured according to the provided installation documentation. I have been experiencing that problem on my development cluster for a while too (with DSE 4.0.0, 4.0.1 and 4.0.2), but I thought this was because of some configuration error on my part. The problem has appeared spontaneously at some point too. The Cassandra cluster has been working very smoothly with a good write throughput. It is very stable and has enough resources to work with. We did not notice any problems with the applications that depend on it.

    Read the article

  • A server which uses 2 IPs and is needed to give service (under NAT)

    - by user6004
    I have an internal server, which uses a certain service. This service listens on a port, and speaks on a different port. The problem with the service is that it can't listen and speak on the same IP address, so I have configured 2 IP addresses for that NIC, and so I "solved" the problem with the listening and speaking. I have a problem though... I need that server to be NATed, with a public IP address, and that server needs to be available from the outside (and as only one IP)... The question is, how do I solve the situation here? If I do a NAT for one IP address (the listening port), then he will be able to get requests from the outside, but won't be able to send out traffic (because the other IP won't have NAT). If I do NAT on both of the IPs, then when traffic comes in for the listening port, it won't necessarily arrive to the listening IP, but rather to the speaking one. I hope I made myself clear and that there is a sensible solution here that I am missing.

    Read the article

  • Protocol (or service publish/discovery) to detect devices in network

    - by Gobliins
    we connect some embedded devices in a network. What i am looking for now, is a way to find the devices IP and identify them. We work with Windows PC´s and i am about to write a C# tool that should do this. I thought about send a udp broadcast and in the ack i.e. is the device´s ip, which would mean the device needs a daemon runnig to assign an ip itself. Running a service (like a printer) on the device, and on the PC just lookup for the service. I read about some things like apipa, zeroconf, ipv4 local link, bonjour, dns-sd, mdns, bonjour; They can automatically assign ip´s and publish services in a network. My Question is, can someone recommend me what would be good for my task? -The protocol or Service should be low on ressource (memory/cpu usage) use. -Are there some standard protocolls to use? -Is DNS a good idea or would it be to ressource consumpting just for finding a device´s IP? -Should also work when no dhcp servers are around. edit: To clarify a bit: The IP configuration is automatic. The problem to focus is how to tell the PC which IP in the network (or a direct connection in this vase there would only be one) belongs to the device (identity).

    Read the article

  • iTextSharp error - cannot convert type 'Collections.Generic.List' to 'iTextSharp.text.Element'

    - by mike
    I am trying to export pdf file using aspx and c#. I got the following error. Cannot implicitly convert type 'System.Collections.Generic.List'' to 'iTextSharp.text.Element' I have the following code using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.html.simpleparser; StringBuilder strB = new StringBuilder(); document.Open(); if (text.Length.Equals(0))//export the text { GridView1.DataBind(); using (StringWriter sWriter = new StringWriter(strB)) { using (HtmlTextWriter htWriter = new HtmlTextWriter(sWriter)) { GridView1.RenderControl(htWriter); } } } else //export the grid { strB.Append(text); } using (TextReader sReader = new StringReader(strB.ToString())) { StyleSheet styles = new StyleSheet(); List<Element> list = new List<Element>(); list = HTMLWorker.ParseToList(sReader, styles); foreach (IElement elm in list) { document.Add(elm); } } I got the error in this line: list = HTMLWorker.ParseToList(sReader, styles); It's the first time that I am trying to export pdf files. I tried to cast the list element , however this did not solve my error. Any advice would be helpful!!!

    Read the article

  • WCF Web Service Gives 404 error in Azure

    - by landyman
    I'm new to using WCF and Azure, but I have a WCF Web Service that works correctly when debugging in Visual Studio. I set the startup project to Azure, and I get 404 errors for any URL I try related to the service. Here is what I think is relavant code: From IWebService.cs [OperationContract] [WebGet(UriTemplate = "GetData/Xml?value={value}", ResponseFormat=WebMessageFormat.Xml)] string GetDataXml(string value); and from Web.config: <system.serviceModel> <services> <service name="WebService" behaviorConfiguration="WebServiceBehavior"> <!-- Service Endpoints --> <endpoint address="" binding="webHttpBinding" contract="IWebService" behaviorConfiguration="WebEndpointBehavior"></endpoint> <endpoint address="ws" binding="wsHttpBinding" contract="IWebService"/> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="WebServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="WebEndpointBehavior"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> </system.serviceModel> I have tried changing the binding to 'basicHttpBinding', but that had no luck. Thanks in advance for any help!

    Read the article

  • Spring 3 DI using generic DAO interface

    - by Peders
    I'm trying to use @Autowired annotation with my generic Dao interface like this: public interface DaoContainer<E extends DomainObject> { public int numberOfItems(); // Other methods omitted for brevity } I use this interface in my Controller in following fashion: @Configurable public class HelloWorld { @Autowired private DaoContainer<Notification> notificationContainer; @Autowired private DaoContainer<User> userContainer; // Implementation omitted for brevity } I've configured my application context with following configuration <context:spring-configured /> <context:component-scan base-package="com.organization.sample"> <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation" /> </context:component-scan> <tx:annotation-driven /> This works only partially, since Spring creates and injects only one instance of my DaoContainer, namely DaoContainer. In other words, if I ask userContainer.numberOfItems(); I get the number of notificationContainer.numberOfItems() I've tried to use strongly typed interfaces to mark the correct implementation like this: public interface NotificationContainer extends DaoContainer<Notification> { } public interface UserContainer extends DaoContainer<User> { } And then used these interfaces like this: @Configurable public class HelloWorld { @Autowired private NotificationContainer notificationContainer; @Autowired private UserContainer userContainer; // Implementation omitted... } Sadly this fails to BeanCreationException: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.organization.sample.dao.NotificationContainer com.organization.sample.HelloWorld.notificationContainer; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.organization.sample.NotificationContainer] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} Now, I'm a little confused how should I proceed or is using multiple Dao's even possible. Any help would be greatly appreciated :)

    Read the article

  • Help me understand these generic method warnings

    - by Raj
    Folks, I have a base class, say: public class BaseType { private String id; ... } and then three subclasses: public class TypeA extends BaseType { ... } public class TypeB extends BaseType { ... } public class TypeC extends BaseType { ... } I have a container class that maintains lists of objects of these types: public class Container { private List<TypeA> aList; private List<TypeB> bList; private List<TypeC> cList; // finder method goes here } And now I want to add a finder method to container that will find an object from one of the lists. The finder method is written as follows: public <T extends BaseType> T find( String id, Class<T> clazz ) { final List<T> collection; if( clazz == TypeA.class ) { collection = (List<T>)aList; } else if( clazz == TypeB.class ) { collection = (List<T>)bList; } else if( clazz == TypeC.class ) { collection = (List<T>)cList; } else return null; for( final BaseType value : collection ) { if( value.getId().equals( id ) ) { return (T)value; } } return null; } My question is this: If I don't add all the casts to T in my finder above, I get compile errors. I think the compile should be able to infer the types based on parametrization of the generic method (). Can anyone explain this? Thanks. -Raj

    Read the article

  • Performance penalty of typecasting and boxing/unboxing types in C# when storing generic values

    - by kitsune
    I have a set-up similar to WPF's DependencyProperty and DependencyObject system. My properties however are generic. A BucketProperty has a static GlobalIndex (defined in BucketPropertyBase) which tracks all BucketProperties. A Bucket can have many BucketProperties of any type. A Bucket saves and gets the actual values of these BucketProperties... now my question is, how to deal with the storage of these values, and what is the penalty of using a typecasting when retrieving them? I currently use an array of BucketEntries that save the property values as simple objects. Is there any better way of saving and returning these values? Beneath is a simpliefied version: public class BucketProperty<T> : BucketPropertyBase { } public class Bucket { private BucketEntry[] _bucketEntries; public void SaveValue<T>(BucketProperty<T> property, T value) { SaveBucketEntry(property.GlobalIndex, value) } public T GetValue<T>(BucketProperty<T> property) { return (T)FindBucketEntry(property.GlobalIndex).Value; } } public class BucketEntry { private object _value; private uint _index; public BucketEntry(uint globalIndex, object value) { ... } }

    Read the article

  • Structuremap and generic types

    - by James D
    Hi I have a situation which seems a bit different from others I've seen. For clarrification, this isn't the normal question eg; something like IAClass maps to AClass etc - that involves using basically a single concrete classes per interface. This involves having a single generic class, but I want to be able to load ALL possible usages of it. Eg - the main class is of public class MyClass<TDomainObject> : IMyClass<TDomainObject> where TDomainObject : DomainObject So example usages would be IMyClass<Person> p = new MyClass<Person>; IMyClass<Employer> p = new MyClass<Employer>; I.e. for all DomainObjects I would like to be able to load a MyClass< for. So you can see I don't use a specific class for each declaration, they all use the same one. How would I get this loaded into StructureMap?

    Read the article

  • A generic error in GDI+ with ToolStrip in ManagerRenderMode

    - by volody
    I have a vb.net form with ToolStrip menu RenderMode - ManagerRenderMode LayoutStyle - HorizontalStackWithOverflow My development environment is .net 4.0, VS2010, windows 7 x64; but occasionally I am getting next error A generic error occurred in GDI+. Stacktrace: at System.Drawing.Graphics.CheckErrorStatus(Int32 status) at System.Drawing.Graphics.FillRectangle(Brush brush, Int32 x, Int32 y, Int32 width, Int32 height) at System.Drawing.Graphics.FillRectangle(Brush brush, Rectangle rect) at System.Windows.Forms.ToolStripProfessionalRenderer.FillWithDoubleGradient(Color beginColor, Color middleColor, Color endColor, Graphics g, Rectangle bounds, Int32 firstGradientWidth, Int32 secondGradientWidth, LinearGradientMode mode, Boolean flipHorizontal) at System.Windows.Forms.ToolStripProfessionalRenderer.RenderToolStripBackgroundInternal(ToolStripRenderEventArgs e) at System.Windows.Forms.ToolStripProfessionalRenderer.OnRenderToolStripBackground(ToolStripRenderEventArgs e) at System.Windows.Forms.ToolStripRenderer.DrawToolStripBackground(ToolStripRenderEventArgs e) at System.Windows.Forms.ToolStrip.OnPaintBackground(PaintEventArgs e) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    Read the article

  • Formula parsing / evaluation routine or library with generic DLookup functionality

    - by tbone
    I am writing a .Net application where I must support user-defined formulas that can perform basic mathematics, as well as accessing data from any arbitrary table in the database. I have the math part working, using JScript Eval(). What I haven't decided on is what a nice way is to do the generic table lookups. For example, I may have a formula something like: Column: BonusAmount Formula: {CurrentSalary} * 1.5 * {[SystemSettings][Value][SettingName=CorpBonus AND Year={Year}]} So, in this example I would replace {xxx} and {Year} with the value of Column xxx from the current table, and I would replace the second part with the value of (select Value from SystemSettings WHERE SettingName='CorpBonus' AND Year=2008) So, basically, I am looking for something very much like the MS Access DLookup function: DLookup ( expression, domain, [criteria] ) DLookup("[UnitPrice]", "Order Details", "OrderID = 10248") But, I also need to overall parsing routine that can tell whether to just look up in the current row, or to look into another table. Would also be nice to support aggregate functions (ie: DAvg, DMax, etc), as well as all the weird edge cases handled. So I wonder if anyone knows of any sort of an existing library, or has a nice routine that can handle this formula parsing and database lookup / aggregate function resolution requirements.

    Read the article

  • Generic allocator class without variadic templates?

    - by rainer
    I am trying to write a generic allocator class that does not really release an object's memory when it is free()'d but holds it in a queue and returns a previously allocated object if a new one is requested. Now, what I can't wrap my head around is how to pass arguments to the object's constructor when using my allocator (at least without resorting to variadic templates, that is). The alloc() function i came up with looks like this: template <typename... T> inline T *alloc(const &T... args) { T *p; if (_free.empty()) { p = new T(args...); } else { p = _free.front(); _free.pop(); // to call the ctor of T, we need to first call its DTor p->~T(); p = new( p ) T(args...); } return p; } Still, I need the code to be compatible with today's C++ (and older versions of GCC that do not support variadic templates). Is there any other way to go about passing an arbitrary amount of arguments to the objects constructor?

    Read the article

  • WPF Designer has bug with parsing generic control with overrided property

    - by Ivan Laktyunkin
    I've created a generic lookless control with virtual property: public abstract class TestControlBase<TValue> : Control { public static readonly DependencyProperty ValueProperty; static TestControlBase() { ValueProperty = DependencyProperty.Register("Value", typeof(TValue), typeof(TestControlBase<TValue>)); } protected TestControlBase() { Focusable = false; Value = default(TValue); } public virtual TValue Value { get { return (TValue)GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } } } Then I've made a control derived from it and overrided Value property: public class TestControl : TestControlBase<int> { public override int Value { get { return base.Value; } set { base.Value = value; } } } So I use it in a Window XAML: <TestControls:TestControl /> When I open window in designer all is OK, but when I put mouse cursor to this line, or to this control in designer I receive exception: Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Delegate.DynamicInvokeImpl(Object[] args) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) Ambiguous match found. at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) at System.Type.GetProperty(String name) at MS.Internal.ComponentModel.DependencyPropertyKind.get_IsDirect() at MS.Internal.ComponentModel.DependencyPropertyKind.get_IsAttached() at MS.Internal.ComponentModel.APCustomTypeDescriptor.GetProperties(Attribute[] attributes) at MS.Internal.ComponentModel.APCustomTypeDescriptor.GetProperties() at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultExtendedTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties() at System.ComponentModel.TypeDescriptor.GetPropertiesImpl(Object component, Attribute[] attributes, Boolean noCustomTypeDesc, Boolean noAttributes) at System.ComponentModel.TypeDescriptor.GetProperties(Object component) at MS.Internal.Model.ModelPropertyCollectionImpl.GetProperties(String propertyNameHint) at MS.Internal.Model.ModelPropertyCollectionImpl.<GetEnumerator>d__0.MoveNext() at MS.Internal.Designer.PropertyEditing.Model.ModelPropertyMerger.<GetFirstProperties>d__0.MoveNext() at MS.Internal.Designer.PropertyEditing.PropertyInspector.UpdateCategories(Selection selection) at MS.Internal.Designer.PropertyEditing.PropertyInspector.OnSelectionChangedIdle() Who know this problem? Please explain :) I have no ideas except that WPF Designer doesn't like generics. If I replace generics by Object all is OK.

    Read the article

  • Using LINQ in generic collections

    - by Hugo S Ferreira
    Hi, Please consider the following snippet from an implementation of the Interpreter pattern: public override object Execute(Interpreter interpreter, object ctx) { var list = ctx as IEnumerable<string>; return (list != null) ? list.FirstOrDefault() : null; } What about if I want to use the same function for integers? public override object Execute(Interpreter interpreter, object ctx) { var list = ctx as IEnumerable<string>; if (list != null) return list.FirstOrDefault(); var list = ctx as IEnumerable<int>; return (list != null) ? list.FirstOrDefault() : null; } What I wanted was something like: public override object Execute(Interpreter interpreter, object ctx) { var list = ctx as IEnumerable; return (list != null) ? list.FirstOrDefault() : null; } But Linq doesn't act on IEnumerables. Instead, to get to this solution, I would be forced to write something like: public override object Execute(Interpreter interpreter, object ctx) { var list = ctx as IEnumerable; if (list != null) foreach(var i in list) { yield return i; return; } return null; } Or use a generic method: public override T Execute<T>(Interpreter interpreter, object ctx) { var list = ctx as IEnumerable<T>; return (list != null) ? list.FirstOrDefault() : null; } Which would break the Interpreter pattern (as it was implemented in this system). Covariance would also fail (at least in C#3), though would it work, it would be the exact behavior I wanted: public override object Execute(Interpreter interpreter, object ctx) { var list = ctx as IEnumerable<object>; return (list != null) ? list.FirstOrDefault() : null; } So, my question is: what's the best way to achieve the intended behavior? Thanks :-)

    Read the article

  • Create Generic method constraining T to an Enum

    - by johnc
    I'm building a function to extend the Enum.Parse concept that allows a default value to be parsed in case that an Enum value is not found Is case insensitive So I wrote the following public static T GetEnumFromString<T>(string value, T defaultValue) where T : Enum { if (string.IsNullOrEmpty(value)) return defaultValue; foreach (T item in Enum.GetValues(typeof(T))) { if (item.ToString().ToLower().Equals(value.Trim().ToLower())) return item; } return defaultValue; } I am getting a Error Constraint cannot be special class 'System.Enum' Fair enough, but is there a workaround to allow a Generic Enum, or am I going to have to mimic the Parse function and pass a type as an attribute, which forces the ugly boxing requirement to your code. EDIT All suggestions below have been greatly appreciated, thanks Have settled on (I've left the loop to maintain case insensitivity - I am usng this when parsing XML) public static class EnumUtils { public static T ParseEnum<T>(string value, T defaultValue) where T : struct, IConvertible { if (!typeof(T).IsEnum) throw new ArgumentException("T must be an enumerated type"); if (string.IsNullOrEmpty(value)) return defaultValue; foreach (T item in Enum.GetValues(typeof(T))) { if (item.ToString().ToLower().Equals(value.Trim().ToLower())) return item; } return defaultValue; } }

    Read the article

  • How to simply a foreach iteration using reflection

    - by Priya
    Consider that I have to get the overall performance of X. X has Y elements and Y in turn has Z elements which inturn has some N elements. To get the performance of X I do this: List<double> XQ = new List<double>(); foreach (Elem Y in X.Y){ List<double> YQ = new List<double>(); foreach (Elem Z in Y.Z){ List<double> ZQ = new List<double>(); foreach (Elem N in Z.N){ ZQ.Add(GetPerformance(N)); } YQ.Add(AVG(ZQ)); } XQ.Add(AVG(YQ)); } AVG of XQ list gives the performance of X. The performance can be calculated for either X or Y or for Z. X, Y and Z share the same base class. So depending on the item given the foreach loop has to be executed. Currently I have a switch case to determine each item (X or Y or Z) and the foreach loop is repeated in the code pertaining to the item (eg. If Y foreach starts from Y.Z). Is is possible to convert this whole code generic using reflection instead of having to repeat it in each switch case? Thanks

    Read the article

  • How to access a method on a generic datacontext which is only created at runtime

    - by Jeremy Holt
    I'm creating my generic DataContext using only the connectionString in the ctor. I have no issues in retrieving the table using DataContext.GetTable(). However, I need to also be able to retrieve entities of inline table functions. The dbml designer generates public IQueryable<testFunctionResult> testFunction() { return this.CreateMethodCallQuery<testFunctionResult>(this, ((MethodInfo)(MethodInfo.GetCurrentMethod()))); } The question is how do I get the MethodInfo.GetCurrentMethod() when the DataContext has no method called "testFunction", i.e.typeof(DataContext).GetMethod("testFunction") returns null? What I'm trying to achieve is something like: public class UnitofWork<T> { public UnitofWork(string connectionString) { this.DataContext = new DataContext(connectionString); } public UnitofWork(IQueryable<T> tableEntity) { _tableEntity = tableEntity; } public IQueryable<T> TableEntity { get { if (DataContext == null) return _tableEntity; var metaType = DataContext.Mapping.GetMetaType(typeof (T)); if (metaType.IsEntity) _tableEntity = DataContext.GetTable<T>(); else { var s = typeof(T).Name; string methodName = s.Substring(0, s.IndexOf("Result")) + "()"; // the designer automatically affixes "Result" to the type name // Make a method from methodName // _tableEntity = DataContext.CreateMethodCallQuery(DataContext, method, new object[]{}); } return _tableEntity; } set { _tableEntity = value; } } ) Thanks in advance for any insight Jeremy

    Read the article

  • setcontext and makecontext to call a generic function pointer

    - by Simone Margaritelli
    In another question i had the problem to port the code unsigned long stack[] = { 1, 23, 33, 43 }; /* save all the registers and the stack pointer */ unsigned long esp; asm __volatile__ ( "pusha" ); asm __volatile__ ( "mov %%esp, %0" :"=m" (esp)); for( i = 0; i < sizeof(stack); i++ ){ unsigned long val = stack[i]; asm __volatile__ ( "push %0" :: "m"(val) ); } unsigned long ret = function_pointer(); /* restore registers and stack pointer */ asm __volatile__ ( "mov %0, %%esp" :: "m" (esp) ); asm __volatile__ ( "popa" ); To a 64bit platform and many guys told me i should use the setcontext and makecontext functions set instead due to the calling conversion differences between 32 and 64 bits and portability issues. Well, i really can't find any useful documentation online, or at least not the kind i need to implement this, so, how can i use those functions to push arguments onto the stack, call a generic function pointer, obtain the return value and then restore the registers?

    Read the article

  • Generic unit test scheduling

    - by Raphink
    Hello, I'm (re)writing a program that does generic unit test scheduling. The current program is a mono-threaded Perl program, but I'm willing to modularize it and parallelize the tests. I'm also considering rewriting it in Python. Here is what I need to do: I have a list of tests, with the following attributes: uri: a URI to test (could be HTTP/HTTPS/SSH/local) ; depends: an associative array of tests/values that this test depends on ; join: a list of DB joints to be added when selecting items to process in this test ; depends_db: additional conditions to add to the DB request when selecting items to process in this test. The program builds a dependency tree, beginning with the tests that have no dependencies ; for each test: a list of items is selected from the database using the conditions (results of depending tests, joints and depends_db) ; the list of items is sent to the URI (using POST or stdin) ; the result is retrived as a YAML file listing the state and comments for the test for each tested item ; the results are stored in the DB ; the test returns, allowing depending tests to be performed. the program generates reports (CSV, DB, graphviz) of the performed tests. The primary use of this program currently is to test a fleet of machines against services such as backup, DNS, etc. The tests can then be: - backup: hosted on the backup machine(s), called through HTTP, checks if the machines' backup went well ; - DNS: hosted on the local machine, called via stdin, checks if the machines' fqdn have a valid DNS entry. Does such a tool/module already exist? What would be the best implementation to achieve this (using Perl or Python)?

    Read the article

  • Fluent NHibernate automap a HasManyToMany using a generic type

    - by zulkamal
    I have a bunch of domain entities that can be keyword tagged (a Tag is also an entity.) I want to do a normal many-to-many (Tag - TagReview <- Review) table relationship but I don't want to have to create a new concrete relationship on both the Entity and Tag every single time I add a new entity. I was hoping to do a generic based Tag and do this: // Tag public class Tag<T> { public virtual int Id { get; private set; } public virtual string Name { get; set; } public virtual IList<T> Entities { get; set; } public Tag() { Entities = new List<T>(); } } // Review public class Review { public virtual string Id { get; private set; } public virtual string Title { get; set; } public virtual string Content { get; set; } public virtual IList<Tag<Review>> Tags { get; set; } public Review() { Tags = new List<Tag<Review>>(); } } Unfortunately I get an exception: ----> System.ArgumentException : Cannot create an instance of FluentNHibernate.Automapping.AutoMapping`1[Example.Entities.Tag`1[T]] because Type.ContainsGenericParameters is true. I anticipate there will be maybe 5-10 entities so mapping normally would be ok but is there a way to do something like this?

    Read the article

  • How to refactor these generic methods?

    - by Steve Crane
    I have written two nearly identical generic extension methods and am trying to figure out how I might refactor them into a single method. They differ only in that one operates on List and the other on List, and the properties I'm interested in are AssetID for AssetDocument and PersonID for PersonDocument. Although AssetDocument and PersonDocument have the same base class the properties are defined in each class so I don't think that helps. I have tried public static string ToCSVList<T>(this T list) where T : List<PersonDocument>, List<AssetDocument> thinking I might then be able to test the type and act accordingly but this results in the syntax error Type parameter 'T' inherits conflicting constraints These are the methods that I would like to refactor into a single method but perhaps I am simply going overboard and they would besat be left as they are. I'd like to hear what you think. public static string ToCSVList<T>(this T list) where T : List<AssetDocument> { var sb = new StringBuilder(list.Count * 36 + list.Count); string delimiter = String.Empty; foreach (var document in list) { sb.Append(delimiter + document.AssetID.ToString()); delimiter = ","; } return sb.ToString(); } public static string ToCSVList<T>(this T list) where T : List<PersonDocument> { var sb = new StringBuilder(list.Count * 36 + list.Count); string delimiter = String.Empty; foreach (var document in list) { sb.Append(delimiter + document.PersonID.ToString()); delimiter = ","; } return sb.ToString(); }

    Read the article

  • Java generic Comparable where subclasses can't compare to eachother

    - by dege
    public abstract class MyAbs implements Comparable<MyAbs> This would work but then I would be able to compare class A and B with each other if they both extend MyAbs. What I want to accomplish however is the exact opposite. So does anyone know a way to get the generic type to be the own class? Seemed like such a simple thing at first... Edit: To explain it a little further with an example. Say you have an abstract class animals, then you extend it with Dogs and ants. I wouldn't want to compare ants with Dogs but I however would want to compare one dog with another. The dog might have a variable saying what color it is and that is what I want to use in the compareTo method. However when it comes to ants I would rather want to compare ant's size than their color. Hope that clears it up. Could possibly be a design flaw however.

    Read the article

  • jQuery ajax call failing with undefined error

    - by Groo
    My jQuery ajax call is failing with an undefined error. My js code looks like this: $.ajax({ type: "POST", url: "Data/RealTime.ashx", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", timeout: 15000, dataFilter: function(data, type) { alert("RAW DATA: " + data + ", TYPE: "+ type); return data; }, error: function(xhr, textStatus, errorThrown) { alert("FAIL: " + xhr + " " + textStatus + " " + errorThrown); }, success: function(data) { alert("SUCCESS"); } }); My ajax source is a generic ASP.NET handler: [WebService(Namespace = "http://my.website.com")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class RealTime : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; context.Response.Write("{ data: [1,2,3] }"); context.Response.End(); } public bool IsReusable { get { return false; } } } Now, if I return an empty object ("{ }") in my handler, the call will succeed. But when I return any other JSON object, the call fails. The dataFilter handler shows that I am receiving a correct object. Firebug shows the response as expected, and the JSON tab shows that the object is parsed correctly. So what could be the cause?

    Read the article

  • Log 2 N generic comparison tree

    - by Morano88
    Hey! I'm working on an algorithm for Redundant Binary Representation (RBR) where every two bits represent a digit. I designed the comparator that takes 4 bits and gives out 2 bits. I want to make the comparison in log 2 n so If I have X and Y .. I compare every 2 bits of X with every 2 bits of Y. This is smooth if the number of bits of X or Y equals n where (n = 2^X) i.e n = 2,4,8,16,32,... etc. Like this : However, If my input let us say is 6 or 10 .. then it becomes not smooth and I have to take into account some odd situations like this : I have a shallow experience in algorithms .. is there a generic way to do it .. so at the end I get only 2 bits no matter what the input is ? I just need hints or pseudo-code. If my question is not appropriate here .. so feel free to flag it or tell me to remove it. I'm using VHDL by the way!

    Read the article

< Previous Page | 88 89 90 91 92 93 94 95 96 97 98 99  | Next Page >