Example #1
0
        /// <summary>
        /// Gets configuration from the server and invokes a callback when completed
        /// </summary>
        /// <param name="callback"></param>
        public void LoadConfiguration(Action callback)
        {
            // invoke service call
            base.Channel.BeginGetConfiguration(
                (asyncResult) =>
            {
                // get server configuration by ending async call
                Shared.ServerConfiguration serverConfiguration = base.Channel.EndGetConfiguration(asyncResult);
                if (serverConfiguration != null)
                {
                    // load app settings
                    if (serverConfiguration.AppSettings != null)
                    {
                        serverConfiguration.AppSettings.ForEach(appSetting => AppSettings.Add(appSetting.Key, appSetting.Value));
                    }

                    // load configuration sections
                    if (serverConfiguration.SectionSettings != null)
                    {
                        serverConfiguration.SectionSettings.ForEach(sectionData =>
                        {
                            // check that the type is recognized
                            Type sectionType = DataContractUtility.GetType(sectionData.TypeAssemblyQualifiedName, sectionData.TypeFullName, false);
                            if (sectionType != null)
                            {
                                // deserialize to object and store in configuration section
                                object section = serverConfiguration.ReadSection(sectionType, EncryptionKey);
                                if (section != null)
                                {
                                    ConfigurationSections.Add(sectionData.Name, section);
                                }
                            }
                        });
                    }
                }

                callback();
            },
                null);
        }
Example #2
0
        public InvokeResponse Invoke(InvokeRequest request)
        {
            InvokeResponse response = new InvokeResponse();

            if (!string.IsNullOrEmpty(request.ComponentType))
            {
                IServiceComponentManager componentManager = Container.Resolve <IServiceComponentManager>();
                IServiceComponent        component        = componentManager.ServiceComponents.FirstOrDefault(c => c != null && c.GetType().GetInterface(request.ComponentType) != null);

                if (component != null)
                {
                    MethodInfo operation =
                        component.GetType().GetMethod(request.OperationName,
                                                      request.OperationParameters.Select(op => DataContractUtility.GetType(op.AssemblyQualifiedTypeName, op.TypeName, op.IsEnumerable)).ToArray());
                    if (operation != null)
                    {
                        try
                        {
                            List <object> parameters = new List <object>();
                            foreach (InvokeParameter parameter in request.OperationParameters)
                            {
                                parameters.Add(DataContractUtility.Deserialize(DataContractUtility.GetType(parameter.AssemblyQualifiedTypeName, parameter.TypeName, parameter.IsEnumerable),
                                                                               parameter.SerializedParameter));
                            }

                            object result;

                            try
                            {
                                result = operation.Invoke(component, parameters.ToArray());
                                if (result != null)
                                {
                                    response.OperationResult = DataContractUtility.Serialize(result.GetType(), result);
                                }
                            }
                            catch (Exception ex)
                            {
                                response.Error = new Exception("An exception occurred trying to invoke operation.", ex);
                            }
                        }
                        catch (Exception ex)
                        {
                            response.Error = new InvalidRequestException("An exception occurred trying to deserialize operation parameters.", ex);
                        }
                    }
                    else
                    {
                        response.Error = new InvalidRequestException("Operation not found.");
                    }
                }
                else
                {
                    response.Error = new InvalidRequestException("Component not found.");
                }
            }
            else
            {
                response.Error = new InvalidRequestException("Component type not provided.");
            }

            return(response);
        }