Example #1
0
        /// <summary>
        /// Reads a section of the given type from the stored sections
        /// </summary>
        /// <typeparam name="T">The type of section to deserialize</typeparam>
        /// <param name="encryptionKey">The key to use to decrypt when deserializing</param>
        /// <returns>An configuration section object of type T</returns>
        public object ReadSection(Type sectionType, string encryptionKey)
        {
            // check that there are any sections
            if (SectionSettings != null)
            {
                // get the data for the given section type and deserialize the section
                ConfigurableSettingsData configurationSectionData = SectionSettings.FirstOrDefault(s => s.TypeFullName == sectionType.FullName);
                if (configurationSectionData != null)
                {
                    return(DataContractUtility.Deserialize(sectionType, configurationSectionData.SerializedData, encryptionKey));
                }
            }

            return(null);
        }
Example #2
0
 /// <summary>
 /// Deserializes the operation result to the given type, using the given encryption key
 /// </summary>
 /// <typeparam name="T">The type to which to deserialize the result</typeparam>
 /// <param name="encryptionKey">The key to use to decrypt the serialized object before deserializing</param>
 /// <returns>The deserialized operation result</returns>
 public T GetValue <T>(string encryptionKey)
 {
     // deserialize to the given type
     return(DataContractUtility.Deserialize <T>(OperationResult, encryptionKey));
 }
Example #3
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);
        }