Exemple #1
0
        static Backendless()
        {
            Types.AddAbstractTypeMapping(typeof(IList <>), typeof(List <>));
            Types.AddClientClassMapping("flex.messaging.messages.AcknowledgeMessage", typeof(AckMessage));
            Types.AddClientClassMapping("flex.messaging.messages.AsyncMessage", typeof(AsyncMessage));
            Types.AddClientClassMapping("flex.messaging.messages.RemotingMessage", typeof(ReqMessage));
            Types.AddClientClassMapping("flex.messaging.messages.CommandMessage", typeof(CommandMessage));
            Types.AddClientClassMapping("flex.messaging.messages.ErrorMessage", typeof(ErrMessage));
            Types.AddClientClassMapping("flex.messaging.io.ArrayCollection", typeof(ObjectProxy));
            Types.AddClientClassMapping("com.backendless.persistence.GeometryDTO", typeof(GeometryDTO));
            Types.AddClientClassMapping("com.backendless.persistence.Point", typeof(Point));
            Types.AddClientClassMapping("com.backendless.persistence.LineString", typeof(LineString));
            Types.AddClientClassMapping("com.backendless.persistence.Polygon", typeof(Polygon));
            Types.AddClientClassMapping("com.backendless.transaction.UnitOfWork", typeof(UnitOfWork));
            Types.AddClientClassMapping("com.backendless.transaction.Operation", typeof(Operation));
            Types.AddClientClassMapping("com.backendless.transaction.OperationCreate", typeof(OperationCreate));
            Types.AddClientClassMapping("com.backendless.transaction.OperationCreateBulk", typeof(OperationCreateBulk));
            Types.AddClientClassMapping("com.backendless.transaction.OperationDelete", typeof(OperationDelete));
            Types.AddClientClassMapping("com.backendless.transaction.OperationDeleteBulk", typeof(OperationDeleteBulk));
            Types.AddClientClassMapping("com.backendless.transaction.OperationUpdate", typeof(OperationUpdate));
            Types.AddClientClassMapping("com.backendless.transaction.OperationUpdateBulk", typeof(OperationUpdateBulk));
            Types.AddClientClassMapping("com.backendless.transaction.OperationFind", typeof(OperationFind));
            Types.AddClientClassMapping("com.backendless.transaction.OperationAddRelation", typeof(OperationAddRelation));
            Types.AddClientClassMapping("com.backendless.transaction.OperationSetRelation", typeof(OperationSetRelation));
            Types.AddClientClassMapping("com.backendless.transaction.OperationDeleteRelation", typeof(OperationDeleteRelation));

            ORBConfig.GetInstance()
            .getObjectFactories()
            .AddArgumentObjectFactory("Weborb.V3Types.BodyHolder", new BodyHolderFactory());
            Types.AddAbstractTypeMapping(typeof(IDictionary), typeof(Dictionary <object, object>));
        }
Exemple #2
0
 /// <summary>
 /// The register proxy factory.
 /// </summary>
 /// <param name="contractType">
 /// The contract type.
 /// </param>
 /// <param name="serviceType">
 /// The service type.
 /// </param>
 /// <param name="channelFactory">
 /// The channel factory.
 /// </param>
 protected virtual void RegisterProxyFactory(Type contractType, Type serviceType, Type channelFactory)
 {
     lock (this.createdFactories)
     {
         if (!this.createdFactories.Contains(serviceType))
         {
             var factory = (ChannelFactory)Activator.CreateInstance(channelFactory.MakeGenericType(new[] { contractType, serviceType }));
             ORBConfig.GetInstance().getObjectFactories().AddServiceObjectFactory(contractType.FullName, (IServiceObjectFactory)factory);
             this.createdFactories.Add(serviceType);
         }
         else
         {
             var objFactories = ORBConfig.GetInstance().getObjectFactories();
             var soFactory    = (ChannelFactory)objFactories._GetServiceObjectFactory(contractType.FullName);
             if (soFactory.State == CommunicationState.Faulted ||
                 soFactory.State == CommunicationState.Closed ||
                 soFactory.State == CommunicationState.Closing)
             {
                 objFactories.RemoveServiceFactoryFor(contractType.FullName);
                 var factory =
                     (ChannelFactory)Activator.CreateInstance(channelFactory.MakeGenericType(new[] { contractType, serviceType }));
                 ORBConfig.GetInstance().getObjectFactories().AddServiceObjectFactory(contractType.FullName, (IServiceObjectFactory)factory);
             }
         }
     }
 }
Exemple #3
0
        private void CheckIfServerIsRunning()
        {
            lock (_locker)
            {
                if (HttpContext.Current != null)
                {
                    var server = (RTMPServer)HttpContext.Current.Application["WebOrbRTMPServerKey"];
                    if (server == null || !server.IsRunning)
                    {
                        try
                        {
                            if (server != null)
                            {
                                server.shutdown();
                            }
                        }
                        catch (Exception)
                        {
                        }
                        // Initialize WebORB configuration before starting messaging server
                        ORBConfig config = ORBConfig.GetInstance();

                        // Create Messaging server. 2037 is the port number, 500 is connection backlog
                        server = new RTMPServer(typeof(DBChangesNotifier).Name, int.Parse((string)this.settings.RTMPServerPort), 500, config);

                        // Start the messaging server
                        server.start();
                        this.logger.Error("RTMP server was restarted");

                        // Store the server instance in the Application context, so it can be cleared out when application stops
                        HttpContext.Current.Application["WebOrbRTMPServerKey"] = server;
                    }
                }
            }
        }
Exemple #4
0
        public object defaultAdapt(ReferenceCache refCache)
        {
            // server side support for javascript class aliasing
            if (properties.Contains(ORBConstants.CLASS_NAME_FIELD))
            {
                string clientClassName = (string)((IAdaptingType)properties[ORBConstants.CLASS_NAME_FIELD]).defaultAdapt();
                Type   type            = ORBConfig.GetInstance().getTypeMapper()._getServerTypeForClientClass(clientClassName);
                if (type != null)
                {
                    return(adapt(type));
                }
            }

#if (FULL_BUILD)
            Hashtable hashtable = new Hashtable();
#else
            Dictionary <Object, Object> hashtable = new Dictionary <Object, Object>();
#endif

            if (refCache.HasObject(this))
            {
                return(refCache.GetObject(this));
            }
            else
            {
                refCache.AddObject(this, hashtable);
            }

            ICollection keys = properties.Keys;

            foreach (object key in keys)
            {
                object obj = properties[key];

                if (obj != null)
                {
                    if (obj is IAdaptingType && refCache.HasObject((IAdaptingType)obj))
                    {
                        obj = refCache.GetObject((IAdaptingType)obj);
                    }
                    else if (obj is ICacheableAdaptingType)
                    {
                        ICacheableAdaptingType cacheableType = (ICacheableAdaptingType)obj;
                        object result = cacheableType.defaultAdapt(refCache);
                        refCache.AddObject((IAdaptingType)obj, result);
                        obj = result;
                    }
                    else if (obj is IAdaptingType)
                    {
                        obj = ((IAdaptingType)obj).defaultAdapt();
                    }
                }

                hashtable[key] = obj;
            }

            return(hashtable);
        }
Exemple #5
0
        public override V3Message execute(Request message, RequestContext context)
        {
            String       dsId    = (String)this.headers["DSId"];
            String       woId    = (String)this.headers["WebORBClientId"];
            IDestination destObj = ORBConfig.GetInstance().GetDataServices().GetDestinationManager().GetDestination(destination);

            if (Log.isLogging(LoggingConstants.INFO))
            {
                Log.log(LoggingConstants.INFO, "Delivering message to destination " + destination);
            }

            if (messageId == null)
            {
                messageId = Guid.NewGuid().ToString();
            }

            if (destObj == null)
            {
                String error = "Unknown destination - " + destination + ". Make sure the destination is properly configured.";

                if (Log.isLogging(LoggingConstants.ERROR))
                {
                    Log.log(LoggingConstants.ERROR, error);
                }

                return(new ErrMessage(messageId, new Exception(error)));
            }

            Object[] bodyParts = (Object[])this.body.body;

            if (bodyParts != null && bodyParts.Length > 0)
            {
                for (int i = 0; i < bodyParts.Length; i++)
                {
                    if (bodyParts[i] is IAdaptingType)
                    {
                        bodyParts[i] = ((IAdaptingType)bodyParts[i]).defaultAdapt();
                    }
                    else if (bodyParts[i].GetType().IsArray)
                    {
                        Object[] arrayPart = (Object[])bodyParts[i];

                        for (int j = 0; j < arrayPart.Length; j++)
                        {
                            if (arrayPart[j] is IAdaptingType)
                            {
                                arrayPart[j] = ((IAdaptingType)arrayPart[j]).defaultAdapt();
                            }
                        }
                    }
                }
                destObj.messagePublished(woId, bodyParts[0]);
                destObj.GetServiceHandler().AddMessage((Hashtable)this.headers, this);
            }

            return(new AckMessage(messageId, clientId, null, new Hashtable()));
        }
Exemple #6
0
        public static void InitApp(String applicationId, String apiKey)
        {
            if (String.IsNullOrEmpty(applicationId))
            {
                throw new ArgumentNullException(ExceptionMessage.NULL_APPLICATION_ID);
            }

            if (String.IsNullOrEmpty(apiKey))
            {
                throw new ArgumentNullException(ExceptionMessage.NULL_SECRET_KEY);
            }

            Log.addLogger(Log.DEFAULTLOGGER, new ConsoleLogger());
            Log.startLogging(BACKENDLESSLOG);
#if WITHRT
            Quobject.EngineIoClientDotNet.Modules.LogManager.Enabled = !DeviceCheck.IsMobile;
#endif
            AppId  = applicationId;
            APIKey = apiKey;

            Persistence   = new PersistenceService();
            Data          = Persistence;
            Geo           = new GeoService();
            Messaging     = new MessagingService();
            Files         = new FileService();
            UserService   = new UserService();
            Events        = Events.GetInstance();
            Cache         = Cache.GetInstance();
            Counters      = CounterService.GetInstance();
            Logging       = new LoggingService();
            CustomService = new CustomService();

      #if WITHRT
            RT = new RTServiceImpl();
      #endif

            MessageWriter.DefaultWriter = new UnderflowWriter();
            MessageWriter.AddAdditionalTypeWriter(typeof(BackendlessUser), new BackendlessUserWriter());
            MessageWriter.AddAdditionalTypeWriter(typeof(Geometry), new BackendlessGeometryWriter());
            MessageWriter.AddAdditionalTypeWriter(typeof(Point), new BackendlessGeometryWriter());
            MessageWriter.AddAdditionalTypeWriter(typeof(LineString), new BackendlessGeometryWriter());
            MessageWriter.AddAdditionalTypeWriter(typeof(Polygon), new BackendlessGeometryWriter());
            ORBConfig.GetInstance().getObjectFactories().AddArgumentObjectFactory(typeof(BackendlessUser).FullName, new BackendlessUserFactory());
            ORBConfig.GetInstance().getObjectFactories().AddArgumentObjectFactory(typeof(GeometryDTO).FullName, new BackendlessGeometryFactory());
            ORBConfig.GetInstance().getObjectFactories().AddArgumentObjectFactory(typeof(Geometry).FullName, new BackendlessGeometryFactory());
            ORBConfig.GetInstance().getObjectFactories().AddArgumentObjectFactory(typeof(Point).FullName, new BackendlessGeometryFactory());
            ORBConfig.GetInstance().getObjectFactories().AddArgumentObjectFactory(typeof(LineString).FullName, new BackendlessGeometryFactory());
            ORBConfig.GetInstance().getObjectFactories().AddArgumentObjectFactory(typeof(Polygon).FullName, new BackendlessGeometryFactory());

            HeadersManager.CleanHeaders();
            LoginStorage loginStorage = new LoginStorage();

            if (loginStorage.HasData)
            {
                HeadersManager.GetInstance().AddHeader(HeadersEnum.USER_TOKEN_KEY, loginStorage.UserToken);
            }
        }
Exemple #7
0
        //public static ManualResetEvent allDone = new ManualResetEvent( false );

#if !(FULL_BUILD)
        static WeborbClient()
        {
            Types.Types.AddAbstractTypeMapping(typeof(IList <>), typeof(List <>));
            Types.Types.AddClientClassMapping("flex.messaging.messages.AcknowledgeMessage", typeof(AckMessage));
            Types.Types.AddClientClassMapping("flex.messaging.messages.AsyncMessage", typeof(AsyncMessage));
            Types.Types.AddClientClassMapping("flex.messaging.messages.RemotingMessage", typeof(ReqMessage));
            Types.Types.AddClientClassMapping("flex.messaging.messages.CommandMessage", typeof(CommandMessage));
            Types.Types.AddClientClassMapping("flex.messaging.messages.ErrorMessage", typeof(ErrMessage));
            Types.Types.AddClientClassMapping("flex.messaging.io.ArrayCollection", typeof(ObjectProxy));
            ORBConfig.GetInstance().getObjectFactories().AddArgumentObjectFactory("Weborb.V3Types.BodyHolder", new Weborb.V3Types.BodyHolderFactory());
            Types.Types.AddAbstractTypeMapping(typeof(IDictionary), typeof(Dictionary <object, object>));
        }
Exemple #8
0
        public static void InitApp(string applicationId, string apiKey)
        {
            if (string.IsNullOrEmpty(applicationId))
            {
                throw new ArgumentNullException(ExceptionMessage.NULL_APPLICATION_ID);
            }

            if (string.IsNullOrEmpty(apiKey))
            {
                throw new ArgumentNullException(ExceptionMessage.NULL_SECRET_KEY);
            }

            AppId  = applicationId;
            APIKey = apiKey;

            Persistence   = new PersistenceService();
            Data          = Persistence;
            Geo           = new GeoService();
            Messaging     = new MessagingService();
            Files         = new FileService();
            UserService   = new UserService();
            Events        = Events.GetInstance();
            Cache         = Cache.GetInstance();
            Counters      = CounterService.GetInstance();
            Logging       = new LoggingService();
            CustomService = new CustomService();

            MessageWriter.DefaultWriter = new UnderflowWriter();
            MessageWriter.AddAdditionalTypeWriter(typeof(BackendlessUser), new BackendlessUserWriter());
            ORBConfig.GetInstance().getObjectFactories().AddArgumentObjectFactory(typeof(BackendlessUser).FullName, new BackendlessUserFactory());

            HeadersManager.CleanHeaders();
            LoginStorage loginStorage = new LoginStorage();

            if (loginStorage.HasData)
            {
                HeadersManager.GetInstance().AddHeader(HeadersEnum.USER_TOKEN_KEY, loginStorage.UserToken);
            }
        }
Exemple #9
0
 public static object CreateArgumentObject(Type type, IAdaptingType argument)
 {
     return(ORBConfig.GetInstance().getObjectFactories()._CreateArgumentObject(type, argument));
 }
Exemple #10
0
        private void setFieldsDirect(object obj, IDictionary properties, ReferenceCache referenceCache)
        {
            if (ReportUnderflow)
            {
                Dictionary <object, object> propertiesCopy = new Dictionary <object, object>();

                foreach (object key in properties.Keys)
                {
                    propertiesCopy.Add(key, properties[key]);
                }

                properties = propertiesCopy;
            }

            Type type = obj.GetType();



            bool logDebug = Log.isLogging(LoggingConstants.DEBUG);

            while (!Object.ReferenceEquals(type, typeof(object)))
            {
                FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

                foreach (FieldInfo field in fields)
                {
                    if ((field.Attributes & FieldAttributes.Literal) == FieldAttributes.Literal)
                    {
                        continue;
                    }

                    IMemberRenameAttribute[] renamers = (IMemberRenameAttribute[])field.GetCustomAttributes(typeof(IMemberRenameAttribute), true);
                    string memberName = field.Name;

                    if (renamers.Length > 0)
                    {
                        memberName = renamers[0].GetClientName(type, field);
                    }

                    object fieldValue = properties[memberName];

                    if (fieldValue == null)
                    {
#if (FULL_BUILD)
                        SerializationConfigHandler serializationConfig = (SerializationConfigHandler)ORBConfig.GetInstance().GetConfig("weborb/serialization");

                        if (serializationConfig != null && serializationConfig.Keywords.Contains(memberName))
                        {
                            memberName = serializationConfig.PrefixForKeywords + memberName;
                            fieldValue = properties[memberName];

                            if (fieldValue == null)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }
#endif
#if (SILVERLIGHT || PURE_CLIENT_LIB || WINDOWS_PHONE8)
                        continue;
#endif
                    }

                    if (fieldValue is IAdaptingType)
                    {
                        if (logDebug)
                        {
                            Log.log(LoggingConstants.DEBUG, "initializing field " + field.Name);
                            Log.log(LoggingConstants.DEBUG, "field type - " + field.FieldType.FullName);
                        }

                        object val = ObjectFactories.CreateArgumentObject(field.FieldType, (IAdaptingType)fieldValue);

                        if (val != null)
                        {
                            if (logDebug)
                            {
                                Log.log(LoggingConstants.DEBUG, "argument factory created object for the field " + val);
                            }

                            //referenceCache[ fieldValue ] = val;

                            referenceCache.AddObject((IAdaptingType)fieldValue, field.FieldType, val);

                            fieldValue = val;
                        }
                        else
                        {
                            if (logDebug)
                            {
                                Log.log(LoggingConstants.DEBUG, "argument factory is missing or returned no value. will use type adaptation");
                            }

                            if (fieldValue is ICacheableAdaptingType)
                            {
                                fieldValue = ((ICacheableAdaptingType)fieldValue).adapt(field.FieldType, referenceCache);
                            }
                            else
                            {
                                fieldValue = ((IAdaptingType)fieldValue).adapt(field.FieldType);
                            }
                        }
                    }

                    if (ReportUnderflow)
                    {
                        properties.Remove(memberName);
                    }

                    try
                    {
                        field.SetValue(obj, fieldValue);
                    }
                    catch (Exception e)
                    {
                        if (Log.isLogging(LoggingConstants.INFO))
                        {
                            Log.log(LoggingConstants.INFO, "field name - " + field.Name);
                        }
                        throw e;
                    }
                }

                PropertyInfo[] props = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

                foreach (PropertyInfo prop in props)
                {
                    if (!prop.CanWrite)
                    {
                        continue;
                    }

                    IMemberRenameAttribute[] renamers = (IMemberRenameAttribute[])prop.GetCustomAttributes(typeof(IMemberRenameAttribute), true);
                    string memberName = prop.Name;

                    if (renamers.Length > 0)
                    {
                        memberName = renamers[0].GetClientName(type, prop);
                    }

                    object propValue = properties[memberName];

                    if (propValue == null)
                    {
#if (FULL_BUILD)
                        SerializationConfigHandler serializationConfig = (SerializationConfigHandler)ORBConfig.GetInstance().GetConfig("weborb/serialization");

                        if (serializationConfig != null && serializationConfig.Keywords.Contains(memberName))
                        {
                            memberName = serializationConfig.PrefixForKeywords + memberName;
                            propValue  = properties[memberName];

                            if (propValue == null)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }
#endif
#if (SILVERLIGHT || PURE_CLIENT_LIB || WINDOWS_PHONE8)
                        continue;
#endif
                    }

                    if (propValue is IAdaptingType)
                    {
                        if (logDebug)
                        {
                            Log.log(LoggingConstants.DEBUG, "initializing property " + prop.Name);
                            Log.log(LoggingConstants.DEBUG, "property type - " + prop.PropertyType.FullName);
                        }

                        object val = ObjectFactories.CreateArgumentObject(prop.PropertyType, (IAdaptingType)propValue);

                        if (val != null)
                        {
                            if (logDebug)
                            {
                                Log.log(LoggingConstants.DEBUG, "argument factory created object for the field " + val);
                            }

                            //referenceCache[ propValue ] = val;
                            referenceCache.AddObject((IAdaptingType)propValue, prop.PropertyType, val);

                            propValue = val;
                        }
                        else
                        {
                            if (logDebug)
                            {
                                Log.log(LoggingConstants.DEBUG, "argument factory is missing or returned no value. will use type adaptation");
                            }

                            if (propValue is ICacheableAdaptingType)
                            {
                                propValue = ((ICacheableAdaptingType)propValue).adapt(prop.PropertyType, referenceCache);
                            }
                            else
                            {
                                propValue = ((IAdaptingType)propValue).adapt(prop.PropertyType);
                            }
                        }
                    }

                    if (ReportUnderflow)
                    {
                        properties.Remove(memberName);
                    }

                    prop.SetValue(obj, propValue, null);
                }

                type = type.BaseType;
            }

            if (ReportUnderflow && properties.Count > 0)
            {
                ReportObjectUnderflow(obj, properties);
            }
        }
Exemple #11
0
 public static object CreateServiceObject(Type type)
 {
     //return ThreadContext.getORBConfig().getObjectFactories()._CreateServiceObject( type );
     return(ORBConfig.GetInstance().getObjectFactories()._CreateServiceObject(type));
 }
Exemple #12
0
        protected virtual ClassDefinition getClassDefinition(String className, Object obj)
        {
#if (FULL_BUILD)
            SerializationConfigHandler serializationConfig = (SerializationConfigHandler)ORBConfig.GetInstance().GetConfig("weborb/serialization");
#endif

            ClassDefinition classDef = new ClassDefinition();

            Type objectClass = obj.GetType();
            IPropertyExclusionAttribute[] propExclusion = (IPropertyExclusionAttribute[])objectClass.GetCustomAttributes(typeof(IPropertyExclusionAttribute), true);

            while (!Object.ReferenceEquals(objectClass, typeof(object)))
            {
                BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static;

                if (serializePrivate)
                {
                    flags |= BindingFlags.NonPublic;
                }

                PropertyInfo[] props = objectClass.GetProperties(flags);

                for (int i = 0; i < props.Length; i++)
                {
                    if (!props[i].CanRead)
                    {
                        continue;
                    }

                    bool skipProperty = false;
                    IPropertyExclusionAttribute[] propExclusionAttr = (IPropertyExclusionAttribute[])props[i].GetCustomAttributes(typeof(IPropertyExclusionAttribute), false);

                    if (propExclusionAttr.Length > 0)
                    {
                        continue;
                    }

                    foreach (IPropertyExclusionAttribute attr in propExclusion)
                    {
                        if (attr.ExcludeProperty(obj, props[i].Name))
                        {
                            skipProperty = true;
                            break;
                        }
                    }

                    if (skipProperty)
                    {
                        continue;
                    }

                    if (props[i].GetGetMethod().IsStatic)
                    {
                        if (!cacheStaticField(className, props[i].Name))
                        {
                            continue;
                        }
                    }

                    IMemberRenameAttribute[] renamers = (IMemberRenameAttribute[])props[i].GetCustomAttributes(typeof(IMemberRenameAttribute), true);
                    string memberName;

                    if (renamers.Length > 0)
                    {
                        memberName = renamers[0].GetClientName(objectClass, props[i]);
                    }
                    else
                    {
                        memberName = PropertyRenaming.GetRenamingRule(objectClass, props[i].Name);
                    }
#if (FULL_BUILD)
                    if (serializationConfig != null && serializationConfig.Keywords.Contains(memberName))
                    {
                        memberName = serializationConfig.PrefixForKeywords + memberName;
                    }
#endif
                    if (!classDef.ContainsMember(memberName))
                    {
                        //ITypeWriter typeWriter = MessageWriter.getWriter( props[ i ].PropertyType, null, false );
                        classDef.AddMemberInfo(memberName, props[i]);
                    }
                }

                flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static;

                if (serializePrivate)
                {
                    flags |= BindingFlags.NonPublic;
                }

                FieldInfo[] fields = objectClass.GetFields(flags);

                //Log.log( ORBConstants.INFO, "ObjectWriter.write.before writing fields: " + writer.BaseStream.Length );
                //if( Log.isLogging( LoggingConstants.DEBUG ) )
                //   Log.log( LoggingConstants.DEBUG, "number of fields: " + fields.Length );

                for (int i = 0; i < fields.Length; i++)
                {
                    if (fields[i].IsLiteral || fields[i].IsNotSerialized || fields[i].FieldType == typeof(IntPtr))
                    {
                        continue;
                    }

                    string fieldName = fields[i].Name;

                    if (fields[i].IsStatic)
                    {
                        if (!cacheStaticField(className, fieldName))
                        {
                            continue;
                        }
                    }

                    IMemberRenameAttribute[] renamers = (IMemberRenameAttribute[])fields[i].GetCustomAttributes(typeof(IMemberRenameAttribute), true);
                    string memberName;

                    if (renamers.Length > 0)
                    {
                        memberName = renamers[0].GetClientName(objectClass, fields[i]);
                    }
                    else
                    {
                        memberName = fields[i].Name;
                    }
#if (FULL_BUILD)
                    if (serializationConfig != null && serializationConfig.Keywords.Contains(memberName))
                    {
                        memberName = serializationConfig.PrefixForKeywords + memberName;
                    }
#endif
                    if (!classDef.ContainsMember(memberName))
                    {
                        //ITypeWriter typeWriter = MessageWriter.getWriter( fields[ i ].FieldType, null, false );
                        classDef.AddMemberInfo(memberName, fields[i]);
                    }
                }

                objectClass = objectClass.BaseType;
            }

            IDictionary classStaticsCache = ThreadContext.currentWriterCache();

            if (classStaticsCache != null)
            {
                classStaticsCache.Remove(className);
            }

            classDef.ClassName = className;
            return(classDef);
        }
Exemple #13
0
        private bool haveMatchingData(Type formalArgType)
        {
            if (formalArgType.IsArray && canBeArray())
            {
                return(true);
            }
            else
            {
                BindingFlags flags   = BindingFlags.Public | BindingFlags.Instance;
                MemberInfo[] members = formalArgType.GetMembers(flags);

                /*FieldInfo[] fields = formalArgType.GetFields( flags );
                 * PropertyInfo[] props = formalArgType.GetProperties( flags );
                 *
                 * foreach( FieldInfo field in fields )
                 *  if( !properties.Contains( field.Name ) )
                 *      return false;
                 *
                 * foreach( PropertyInfo property in props )
                 *  if( !properties.Contains( property.Name ) )
                 *      return false;
                 */

                foreach (MemberInfo member in members)
                {
                    IMemberRenameAttribute[] renamers = (IMemberRenameAttribute[])member.GetCustomAttributes(typeof(IMemberRenameAttribute), true);
                    string memberName = member.Name;

                    if (renamers.Length > 0)
                    {
                        memberName = renamers[0].GetClientName(formalArgType, member);
                    }

                    if (!properties.Contains(memberName))
                    {
#if ( FULL_BUILD )
                        SerializationConfigHandler serializationConfig = (SerializationConfigHandler)ORBConfig.GetInstance().GetConfig("weborb/serialization");

                        if (serializationConfig != null && serializationConfig.Keywords.Contains(memberName))
                        {
                            memberName = serializationConfig.PrefixForKeywords + memberName;
                            return(properties.Contains(memberName));
                        }
#endif
                        return(false);
                    }
                }

                return(true);
            }
        }
Exemple #14
0
 public static String[] GetMappedArgumentClasses()
 {
     //return ThreadContext.getORBConfig().getObjectFactories()._GetMappedArgumentClasses();
     return(ORBConfig.GetInstance().getObjectFactories()._GetMappedArgumentClasses());
 }
Exemple #15
0
 public static object CreateServiceObject(String className)
 {
     //return ThreadContext.getORBConfig().getObjectFactories()._CreateServiceObject( className );
     return(ORBConfig.GetInstance().getObjectFactories()._CreateServiceObject(className));
 }
Exemple #16
0
 public static void AddClientClassMapping(string clientClass, Type mappedServerType)
 {
     //ThreadContext.getORBConfig().getTypeMapper()._AddClientClassMapping( clientClass, mappedServerType );
     ORBConfig.GetInstance().getTypeMapper()._AddClientClassMapping(clientClass, mappedServerType);
 }
Exemple #17
0
 public static void AddAbstractTypeMapping(Type abstractType, Type mappedType)
 {
     //ThreadContext.getORBConfig().getTypeMapper()._AddAbstractTypeMapping( abstractType, mappedType );
     ORBConfig.GetInstance().getTypeMapper()._AddAbstractTypeMapping(abstractType, mappedType);
 }
Exemple #18
0
 public static string GetReverseMapping(string mappedName)
 {
     //return ThreadContext.getORBConfig().getServiceRegistry()._GetReverseMapping( mappedName );
     return(ORBConfig.GetInstance().GetServiceRegistry()._GetReverseMapping(mappedName));
 }
Exemple #19
0
 public static void AddMapping(string name, string mappedName, IDictionary context)
 {
     //ThreadContext.getORBConfig().getServiceRegistry()._AddMapping( name, mappedName, context );
     ORBConfig.GetInstance().GetServiceRegistry()._AddMapping(name, mappedName, context);
 }
Exemple #20
0
 public static bool ContainsMappingFor(string name)
 {
     return(ORBConfig.GetInstance().GetServiceRegistry()._ContainsMappingFor(name));
 }
Exemple #21
0
 public static Hashtable GetContext(string type)
 {
     //return ThreadContext.getORBConfig().getServiceRegistry()._GetContext( type );
     return(ORBConfig.GetInstance().GetServiceRegistry()._GetContext(type));
 }
Exemple #22
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            //Log.log( ORBConstants.INFO, "ObjectWriter.write.begin: " + writer.BaseStream.Length );
#if (FULL_BUILD)
            if (obj is IRemote)
            {
                remoteReferenceWriter.write(RemoteReferenceObject.createReference(obj), writer);
                return;
            }

            SerializationConfigHandler serializationConfig = (SerializationConfigHandler)ORBConfig.GetInstance().GetConfig("weborb/serialization");

            if (!configured)
            {
                //serializePrivate = ThreadContext.getORBConfig().serializePrivateFields;

                if (serializationConfig != null)
                {
                    serializePrivate = serializationConfig.SerializePrivateFields;
                }

                configured = true;
            }
#endif
            Type objectClass = obj.GetType();

            /*
             * if( obj is IAutoUpdate )
             * {
             *  //if( Weborb.Util.License.LicenseManager.GetInstance().IsStandardLicense() && !NetUtils.RequestIsLocal( ThreadContext.currentRequest() ) )
             *  //    throw new Exception( "auto-update is disabled, this feature is available in WebORB Professional Edition" );
             *
             *  string id = Guid.NewGuid().ToString();
             *  objectFields[ "_orbid_" ] = id;
             *  ThreadContext.currentHttpContext().Cache.Insert( id, new AutoUpdateObjectWrapper( ((IAutoUpdate) obj).GetUpdateHandler(), obj ) );
             * }
             */

            ClassDefinition classDef;

            cachedClassDefs.TryGetValue(objectClass, out classDef);
            Dictionary <String, Object> objectFields = new Dictionary <String, Object>();

            if (classDef == null)
            {
                string className = objectClass.IsGenericType && objectClass.FullName != null
                             ? objectClass.FullName.Substring(0, objectClass.FullName.IndexOf("`"))
                             : objectClass.FullName;

                string clientSideMapping = GetClientClass(className);

                if (clientSideMapping != null)
                {
                    // if( Log.isLogging( LoggingConstants.DEBUG ) )
                    //    Log.log( LoggingConstants.DEBUG, "serializing a named object with client side mapping " + clientSideMapping );

                    className = clientSideMapping;
                }
                // Commented out this code in 4.0.0.4. This code does not make sense anymore
                // For one these mappings exist between ServiceNames (or Destination names) and
                // classes. A service class should not be serialized back to the client.
                // If it is serialized, user should use class mapping for that.
                //else
                //{
                //    className = ServiceRegistry.GetReverseMapping( className );

                //    if( Log.isLogging( LoggingConstants.DEBUG ) )
                //        Log.log( LoggingConstants.DEBUG, "serializing object " + className );
                //}

                classDef = getClassDefinition(className, obj);
                lock (_sync)
                {
                    cachedClassDefs[objectClass] = classDef;
                }

                // TODO: remove this try/catch
                //try
                //{
                //cachedClassDefs[ objectClass ] = classDef;
                // }
                //catch ( Exception e )
                // {
                //if ( Log.isLogging( LoggingConstants.ERROR ) )
                //  Log.log( LoggingConstants.ERROR, e );
                //System.Diagnostics.Debugger.Launch();
                //}
            }
            else
            {
                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    Log.log(LoggingConstants.DEBUG, "serializing using cached Class Def " + classDef.ClassName);
                }
            }

            Dictionary <string, MemberInfo> members = classDef.Members;

            foreach (KeyValuePair <string, MemberInfo> member in members)
            {
                Object val = null;

                if (member.Value is PropertyInfo)
                {
                    try
                    {
                        val = ((PropertyInfo)member.Value).GetValue(obj, null);
                    }
                    catch (Exception exception)
                    {
                        if (Log.isLogging(LoggingConstants.ERROR))
                        {
                            Log.log(LoggingConstants.ERROR, "Unable to retrieve property/field value from an instance of " + classDef.ClassName + ". Value will be set to null. Property name is " + member.Value.Name);
                        }

                        if (Log.isLogging(LoggingConstants.EXCEPTION))
                        {
                            Log.log(LoggingConstants.EXCEPTION, exception);
                        }
                    }
                }
                else
                {
                    val = ((FieldInfo)member.Value).GetValue(obj);
                }

                String memberName = member.Key;

#if (FULL_BUILD)
                if (serializationConfig != null && serializationConfig.Keywords.Contains(memberName))
                {
                    memberName = serializationConfig.PrefixForKeywords + memberName;
                }
#endif

                objectFields[memberName] = val;
            }

            onWriteObject(obj, classDef.ClassName, objectFields, writer);
        }
Exemple #23
0
        public static object CreateArgumentObject(String typeName, IAdaptingType argument)
        {
            Type type = TypeLoader.LoadType(typeName);

            return(ORBConfig.GetInstance().getObjectFactories()._CreateArgumentObject(type, argument));
        }
Exemple #24
0
 public static Type GetAbstractClassMapping(Type type)
 {
     //return ThreadContext.getORBConfig().getTypeMapper()._GetAbstractClassMapping( type );
     return(ORBConfig.GetInstance().getTypeMapper()._GetAbstractClassMapping(type));
 }
Exemple #25
0
 public static IServiceObjectFactory GetServiceObjectFactory(String serviceTypeName)
 {
     //return ThreadContext.getORBConfig().getObjectFactories()._GetServiceObjectFactory( serviceTypeName );
     return(ORBConfig.GetInstance().getObjectFactories()._GetServiceObjectFactory(serviceTypeName));
 }
Exemple #26
0
        public void write(object obj, IProtocolFormatter writer)
        {
            ITypeWriter typeWriter;

            if (obj is IDictionary)
            {
                typeWriter = MessageWriter.getWriter(typeof(IDictionary), writer, false);
                typeWriter.write(obj, writer);
                return;
            }

            /*
             * if( obj is Array )
             * {
             * base.write( obj, writer );
             * return;
             * }*/

            object[] array = null;

#if (FULL_BUILD)
            if (VectorUtils.IsVector(obj))
            {
                Type objectType  = obj.GetType();
                Type elementType = objectType.GetGenericArguments()[0];
                Type vectorType  = typeof(V3VectorWriter <>).MakeGenericType(elementType);
                typeWriter = (ITypeWriter)vectorType.GetConstructor(new Type[0]).Invoke(new object[0]);
                typeWriter.write(obj, writer);
                return;
            }

            if (obj is ICollection)
            {
                ICollection coll = (ICollection)obj;
                SerializationConfigHandler serializationConfig = (SerializationConfigHandler)ORBConfig.GetInstance().GetConfig("weborb/serialization");

                if (!serializationConfig.LegacyCollectionSerialization && !(obj is IWebORBArray))
                {
                    typeWriter = MessageWriter.getWriter(typeof(IWebORBArrayCollection), writer, false);
                    typeWriter.write(new WebORBArrayCollection(coll), writer);
                    return;
                }
                else
                {
                    array = new object[coll.Count];
                    coll.CopyTo(array, 0);
                }
            }
            else
            {
#endif
            IEnumerable collection  = (IEnumerable)obj;
            IEnumerator enumerator  = collection.GetEnumerator();
            List <Object> arrayList = new List <Object>();

            while (enumerator.MoveNext())
            {
                arrayList.Add(enumerator.Current);
            }

            array = arrayList.ToArray();
#if (FULL_BUILD)
        }
#endif

            typeWriter = MessageWriter.getWriter(array.GetType(), writer, false);
            typeWriter.write(array, writer);
            //base.write( array, writer );
        }
Exemple #27
0
 public static IArgumentObjectFactory GetArgumentObjectFactory(String argumentTypeName)
 {
     //return ThreadContext.getORBConfig().getObjectFactories()._GetArgumentObjectFactory( argumentTypeName );
     return(ORBConfig.GetInstance().getObjectFactories()._GetArgumentObjectFactory(argumentTypeName));
 }
Exemple #28
0
 public static string getClientClassForServerType(string serverClassName)
 {
     //return ThreadContext.getORBConfig().getTypeMapper()._getClientClassForServerType( serverClassName );
     return(ORBConfig.GetInstance().getTypeMapper()._getClientClassForServerType(serverClassName));
 }
Exemple #29
0
 public static void RemoveMapping(string name)
 {
     //ThreadContext.getORBConfig().getServiceRegistry()._RemoveMapping( name );
     ORBConfig.GetInstance().GetServiceRegistry()._RemoveMapping(name);
 }
Exemple #30
0
 public static Type getServerTypeForClientClass(string clientClass)
 {
     //return ThreadContext.getORBConfig().getTypeMapper()._getServerTypeForClientClass( clientClass );
     return(ORBConfig.GetInstance().getTypeMapper()._getServerTypeForClientClass(clientClass));
 }