Exemplo n.º 1
0
 /// <summary>
 /// Metodo que consulta un objeto por id
 /// </summary>
 /// <param name="oid">identificador del objeto "Llave primaria"</param>
 /// <returns></returns>
 public BusinessObject GetObjectByOid(object oid)
 {
     try
     {
         using (UnitOfWork unit = SessionManager <Persistent> .GetNewUnitOfWork())
         {
             BusinessObject outObjectBO     = Activator.CreateInstance <BusinessObject>();
             Persistent     persistenObject = unit.GetObjectByKey <Persistent>(oid);
             if (persistenObject != null)
             {
                 MapperManager <Persistent, BusinessObject> mapper = TransformerFactory.Create <Persistent, BusinessObject>();
                 outObjectBO = mapper.MapperPersistent2BO(persistenObject);
                 return(outObjectBO);
             }
             else
             {
                 return(default(BusinessObject));
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 2
0
        public void Create_Transformer_From_Factory()
        {
            var transformerFactory = new TransformerFactory();
            var transformer        = transformerFactory.Create("tr");

            Assert.NotNull(transformer);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Metodo que permite consultar un procedimiento almacenado
        /// </summary>
        /// <param name="ProcedureName">nombre del procedimiento almacenado</param>
        /// <param name="list">lista de parametros</param>
        /// <returns></returns>
        public List <BusinessObject> GetProcedure(string procedureName, params object[] list)
        {
            try
            {
                List <BusinessObject> outList = Activator.CreateInstance <List <BusinessObject> >();
                using (UnitOfWork unit = SessionManager <Persistent> .GetNewUnitOfWork())
                {
                    OperandValue[]           parametros = GetOperands(list);
                    ICollection <Persistent> response   = new List <Persistent>();
                    response = unit.GetObjectsFromSproc <Persistent>(procedureName, parametros);
#if DEBUG
                    var tipoRecibido   = typeof(Persistent).GetType().Name;
                    var totalElementos = response.Count;
                    var totalParametrosProcedimiento = list.Count();
#endif

                    MapperManager <Persistent, BusinessObject> mapper = TransformerFactory.Create <Persistent, BusinessObject>();
                    foreach (var item in response.ToList <Persistent>())
                    {
                        outList.Add(mapper.MapperPersistent2BO(item));
                    }
                }
                return(outList);
            }
            catch (Exception)
            {
                throw;
            }
        }
 public void BadSectionTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         factory.Create("Foo");
     }
 }
 public void BadTypeTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(badTypeXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         factory.Create("ApplConfig1");
     }
 }
 public void TypeDoesNotImplementTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         factory.Create("ApplConfig1");
     }
 }
 public void NoTransformerDefinedTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(noTransformerXmlString))
     {
         TransformerFactory factory     = new TransformerFactory(configurationContext);
         ITransformer       transformer = factory.Create("ApplConfig1");
         Assert.AreEqual(typeof(NullTransformer), transformer.GetType());
     }
 }
 public void CreateTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(xmlString))
     {
         TransformerFactory factory     = new TransformerFactory(configurationContext);
         ITransformer       transformer = factory.Create("ApplConfig1");
         Assert.IsNotNull(transformer);
     }
 }
Exemplo n.º 9
0
        public void Convert_Number_ToWords()
        {
            var transformerFactory = new TransformerFactory();
            var transformer        = transformerFactory.Create("tr");
            var result             = transformer.ToWords(123456789);

            CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("tr-TR");

            Assert.Equal("YÜZ YİRMİ ÜÇ MİLYON DÖRT YÜZ ELLİ ALTI BİN YEDİ YÜZ SEKSEN DOKUZ", result.ToUpper());
        }
Exemplo n.º 10
0
        public async Task Validate_ValidName()
        {
            // arrange
            var transformer = TransformerFactory.Create <Generic, Output>();

            // Act
            var result = await transformer.Validate(new Generic { Name = "Krizanac, Matt" });

            // Assert
            Assert.AreEqual(0, result.Count());
        }
Exemplo n.º 11
0
        public async Task Transform_To_String()
        {
            // Arrange
            var transformer = TransformerFactory.Create <Generic, string>();

            // Act
            var result = await transformer.Transform(new Generic { Name = "Krizanac, Matt" });

            // Assert
            StringAssert.AreEqualIgnoringCase("hello world", result);
        }
Exemplo n.º 12
0
 public void CreateTypedTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(typedXmlString))
     {
         TransformerFactory factory     = new TransformerFactory(configurationContext);
         ITransformer       transformer = factory.Create("TypedConfig");
         Assert.IsNotNull(transformer);
         XmlSerializerTransformer xmlTransformer = transformer as XmlSerializerTransformer;
         Assert.IsNotNull(xmlTransformer);
         Assert.AreEqual(1, xmlTransformer.GetTypes().Length);
     }
 }
Exemplo n.º 13
0
        public async Task Transform_To_Output()
        {
            // Arrange
            var transformer = TransformerFactory.Create <Generic, Output>();

            // Act
            var result = await transformer.Transform(new Generic { Name = "Krizanac, Matt" });

            // Assert
            StringAssert.AreEqualIgnoringCase("matt", result.FirstName);
            StringAssert.AreEqualIgnoringCase("krizanac", result.LastName);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Metodo que crea un objeto
 /// </summary>
 /// <param name="oObject">objeto a crear</param>
 public void CreateObject(BusinessObject oObject)
 {
     try
     {
         using (UnitOfWork unit = SessionManager <Persistent> .GetNewUnitOfWork())
         {
             MapperManager <Persistent, BusinessObject> mapper = TransformerFactory.Create <Persistent, BusinessObject>();
             Persistent persistent = mapper.MapperBO2Persistent(oObject, unit);
             unit.CommitChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 15
0
 /// <summary>
 /// Metodo que actualiza un objeto de la base de datos
 /// </summary>
 /// <param name="oObject">información a actulizar</param>
 /// <param name="oid">identificador del registro</param>
 /// <returns></returns>
 public BusinessObject UpdateObject(BusinessObject oObject, object oid)
 {
     try
     {
         using (UnitOfWork unit = SessionManager <Persistent> .GetNewUnitOfWork())
         {
             Persistent destination = unit.GetObjectByKey <Persistent>(oid);
             MapperManager <Persistent, BusinessObject> mapper = TransformerFactory.Create <Persistent, BusinessObject>();
             Persistent persistent = mapper.MapperBO2Persistent(oObject, destination);
             unit.CommitChanges();
             oObject = mapper.MapperPersistent2BO(persistent);
             return(oObject);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 16
0
        private static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Command-line Encryption / Decryption Utility -- using AES");
                Console.WriteLine();
                Console.WriteLine("USAGE: secure enc[rypt] {password} -- encrypts STDIN and writes the result to STDOUT (Base64-encoded).");
                Console.WriteLine("       secure dec[rypt] {password} -- decodes (Base64) and decrypts STDIN and writes the result to STDOUT.");
                Console.WriteLine();
                Console.WriteLine("Note:  if using STDIN for testing, use Ctrl-Z to end the input.");

                return;
            }

            var factory = new TransformerFactory();

            var transformer = factory.Create(args[0]);
            var result      = transformer.Transform(args[1], ReadInput());

            Console.WriteLine(result);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Metodo que permite consultar una colección
 /// </summary>
 /// <returns></returns>
 public List <BusinessObject> GetCollection()
 {
     try
     {
         List <BusinessObject> outList = Activator.CreateInstance <List <BusinessObject> >();
         using (UnitOfWork unit = SessionManager <Persistent> .GetNewUnitOfWork())
         {
             XPCollection <Persistent> objectCollection        = new XPCollection <Persistent>(unit);
             MapperManager <Persistent, BusinessObject> mapper = TransformerFactory.Create <Persistent, BusinessObject>();
             foreach (var item in objectCollection)
             {
                 outList.Add(mapper.MapperPersistent2BO(item));
             }
             return(outList);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 18
0
 /// <summary>
 /// Metodo que permite consultar una coleccion de objetos
 /// </summary>
 /// <param name="filter">filtro</param>
 /// <param name="parameters">paramtros</param>
 /// <returns></returns>
 public List <BusinessObject> GetCollection(string filter, params object[] parameters)
 {
     try
     {
         List <BusinessObject> outList = Activator.CreateInstance <List <BusinessObject> >();
         using (UnitOfWork unit = SessionManager <Persistent> .GetNewUnitOfWork())
         {
             CriteriaOperator          criteriaFilter          = CriteriaOperator.Parse(filter, parameters);
             XPCollection <Persistent> objectCollection        = new XPCollection <Persistent>(unit, criteriaFilter);
             MapperManager <Persistent, BusinessObject> mapper = TransformerFactory.Create <Persistent, BusinessObject>();
             foreach (var item in objectCollection)
             {
                 outList.Add(mapper.MapperPersistent2BO(item));
             }
             return(outList);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 19
0
 /// <summary>
 /// Metodo que consulta un objeto con filtro
 /// </summary>
 /// <param name="filter">filtro</param>
 /// <param name="parameters">parametros</param>
 /// <returns></returns>
 public BusinessObject GetObject(string filter, params object[] parameters)
 {
     try
     {
         BusinessObject outObjectBO = Activator.CreateInstance <BusinessObject>();
         using (UnitOfWork unit = SessionManager <Persistent> .GetNewUnitOfWork())
         {
             CriteriaOperator criteriaFilter   = CriteriaOperator.Parse(filter, parameters);
             Persistent       persistentObject = unit.FindObject <Persistent>(criteriaFilter);
             if (persistentObject != null)
             {
                 MapperManager <Persistent, BusinessObject> mapper = TransformerFactory.Create <Persistent, BusinessObject>();
                 outObjectBO = mapper.MapperPersistent2BO(persistentObject);
             }
             return(outObjectBO);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 20
0
 public void Transform_NoMappings()
 {
     Assert.Throws <ArgumentException>(() => TransformerFactory.Create <long, int>());
 }
Exemplo n.º 21
0
 public void CreateTypedTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(typedXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         ITransformer transformer = factory.Create("TypedConfig");
         Assert.IsNotNull(transformer);
         XmlSerializerTransformer xmlTransformer = transformer as XmlSerializerTransformer;
         Assert.IsNotNull(xmlTransformer);
         Assert.AreEqual(1, xmlTransformer.GetTypes().Length);
     }
 }
Exemplo n.º 22
0
 public void BadSectionTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         factory.Create("Foo");
     }
 }
Exemplo n.º 23
0
 public void BadTypeTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(badTypeXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         factory.Create("ApplConfig1");
     }
 }
Exemplo n.º 24
0
 public void TypeDoesNotImplementTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         factory.Create("ApplConfig1");
     }
 }
Exemplo n.º 25
0
 public void NoTransformerDefinedTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(noTransformerXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         ITransformer transformer = factory.Create("ApplConfig1");
         Assert.AreEqual(typeof(NullTransformer), transformer.GetType());
     }
 }
Exemplo n.º 26
0
        public void ThrowsException_Transformer_From_Factory_With_EmptyParam()
        {
            var transformerFactory = new TransformerFactory();

            Assert.Throws <ArgumentException>(() => transformerFactory.Create(null));
        }
Exemplo n.º 27
0
 public void Transform_MultipleMappings()
 {
     Assert.Throws <ArgumentException>(() => TransformerFactory.Create <int, int>());
 }
Exemplo n.º 28
0
        public void ThrowsException_Transformer_From_Factory_With_NotSupportedParam()
        {
            var transformerFactory = new TransformerFactory();

            Assert.Throws <NotSupportedException>(() => transformerFactory.Create("en"));
        }
Exemplo n.º 29
0
        //Constructor
        /// <summary>
        /// Creates an initialized instance.
        /// </summary>
        /// <param name="inputEncoderCfg">The configuration of the input encoder.</param>
        public InputEncoder(InputEncoderSettings inputEncoderCfg)
        {
            _encoderCfg = (InputEncoderSettings)inputEncoderCfg.DeepClone();
            //Steady fields
            _numOfSteadyFields = 0;
            _routedSteadyFieldIndexCollection = new List <int>();
            if (_encoderCfg.FeedingCfg.FeedingType == InputFeedingType.Patterned)
            {
                FeedingPatternedSettings fps = (FeedingPatternedSettings)_encoderCfg.FeedingCfg;
                if (fps.SteadyFieldsCfg != null)
                {
                    _numOfSteadyFields = fps.SteadyFieldsCfg.FieldCfgCollection.Count;
                    for (int i = 0; i < fps.SteadyFieldsCfg.FieldCfgCollection.Count; i++)
                    {
                        if (fps.SteadyFieldsCfg.FieldCfgCollection[i].RouteToReadout)
                        {
                            _routedSteadyFieldIndexCollection.Add(i);
                        }
                    }
                }
            }
            //Varying fields
            _varyingFields = new List <InputField>(_encoderCfg.VaryingFieldsCfg.TotalNumOfFields);
            int[] coordinates         = _encoderCfg.CoordinatesCfg.GetCoordinates();
            int   fieldIdx            = _numOfSteadyFields;
            int   inputNeuronStartIdx = 0;

            //External fields
            foreach (ExternalFieldSettings fieldCfg in _encoderCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection)
            {
                _varyingFields.Add(new InputField(fieldCfg.Name,
                                                  fieldIdx++,
                                                  coordinates,
                                                  Interval.IntN1P1,
                                                  fieldCfg.FeatureFilterCfg,
                                                  _encoderCfg.VaryingFieldsCfg.InputSpikesCoderCfg,
                                                  (fieldCfg.RouteToReadout && _encoderCfg.VaryingFieldsCfg.RouteToReadout),
                                                  inputNeuronStartIdx
                                                  ));
                inputNeuronStartIdx += _varyingFields[(fieldIdx - _numOfSteadyFields) - 1].NumOfInputNeurons;
            }
            //Internal input transformers and fields
            _internalInputTransformerCollection = new List <ITransformer>();
            if (_encoderCfg.VaryingFieldsCfg.TransformedFieldsCfg != null)
            {
                List <string> names = _encoderCfg.VaryingFieldsCfg.GetNames();
                foreach (TransformedFieldSettings fieldCfg in _encoderCfg.VaryingFieldsCfg.TransformedFieldsCfg.FieldCfgCollection)
                {
                    _internalInputTransformerCollection.Add(TransformerFactory.Create(names, fieldCfg.TransformerCfg));
                    _varyingFields.Add(new InputField(fieldCfg.Name,
                                                      fieldIdx++,
                                                      coordinates,
                                                      Interval.IntN1P1,
                                                      fieldCfg.FeatureFilterCfg,
                                                      _encoderCfg.VaryingFieldsCfg.InputSpikesCoderCfg,
                                                      (fieldCfg.RouteToReadout && _encoderCfg.VaryingFieldsCfg.RouteToReadout),
                                                      inputNeuronStartIdx
                                                      ));
                    inputNeuronStartIdx += _varyingFields[(fieldIdx - _numOfSteadyFields) - 1].NumOfInputNeurons;
                }
            }
            //Internal input generators and fields
            _internalInputGeneratorCollection = new List <IGenerator>();
            if (_encoderCfg.VaryingFieldsCfg.GeneratedFieldsCfg != null)
            {
                foreach (GeneratedFieldSettings fieldCfg in _encoderCfg.VaryingFieldsCfg.GeneratedFieldsCfg.FieldCfgCollection)
                {
                    _internalInputGeneratorCollection.Add(GeneratorFactory.Create(fieldCfg.GeneratorCfg));
                    _varyingFields.Add(new InputField(fieldCfg.Name,
                                                      fieldIdx++,
                                                      coordinates,
                                                      Interval.IntN1P1,
                                                      fieldCfg.FeatureFilterCfg,
                                                      _encoderCfg.VaryingFieldsCfg.InputSpikesCoderCfg,
                                                      (fieldCfg.RouteToReadout && _encoderCfg.VaryingFieldsCfg.RouteToReadout),
                                                      inputNeuronStartIdx
                                                      ));
                    inputNeuronStartIdx += _varyingFields[(fieldIdx - _numOfSteadyFields) - 1].NumOfInputNeurons;
                }
            }
            _routedVaryingFieldCollection = new List <InputField>(_varyingFields.Count);
            foreach (InputField field in _varyingFields)
            {
                if (field.RouteToReadout)
                {
                    _routedVaryingFieldCollection.Add(field);
                }
            }
            _varyingDataVectorLength = NonFixedVaryingDataVectorLength;
            NumOfTimePoints          = VariableNumOfTimePoints;
            NumOfRoutedValues        = 0;
            //Input processing queue
            _inputDataQueue = new List <double[]>();
            ResetInputProcessingQueue();
            return;
        }
Exemplo n.º 30
0
 public void CreateTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(xmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         ITransformer transformer = factory.Create("ApplConfig1");
         Assert.IsNotNull(transformer);
     }
 }