예제 #1
0
        /// <summary>
        /// Costructor of Mongo Repository Base
        /// </summary>
        /// <param name="dataSession">Data Session</param>
        /// <param name="CollectionName">if null use as collectionName the pluralized class name</param>
        protected MongoDbRepositoryBase(IDataSession dataSession, string CollectionName = null)
        {
            //Validazione argomenti
            if (dataSession == null)
            {
                throw new ArgumentNullException(nameof(dataSession));
            }
            //dataSession.
            //var options = new TOptions();
            //Type type = System.Type.GetType();
            //dataSession.

            //Tento il cast della sessione generica a RemoteApiDataSession
            if (!(dataSession is MongoDbDataSession <TOptions> currentSession))
            {
                throw new InvalidCastException(string.Format("Specified session of type '{0}' cannot be converted to type '{1}'.",
                                                             dataSession.GetType().FullName, typeof(MongoDbDataSession <TOptions>).FullName));
            }

            //Imposto la proprietà della sessione
            DataSession = currentSession;

            //DataSession = dataSession;
            //Imposto il nome della Collection
            if (CollectionName == null)
            {
                var pluralize = new PluralizeUtility();
                CollectionName = pluralize.Pluralize(typeof(TEntity));
            }
            _CollectionName = CollectionName;
        }
예제 #2
0
        static void Main(string[] args)
        {
            //var mongo new DevMongoDbOptions { }

            SessionFactory.RegisterDefaultDataSession <MongoDbDataSession <DevMongoDbOptions> >();

            //Inizializzo la session e il dominio
            using (var DataSession = SessionFactory.OpenSession())
            {
                //var a = DataSession.ResolveRepository<ITestClassRepository>();

                using (var Layer = new MainServiceLayer(DataSession))
                {
                    //Console.WriteLine("Hello World!");
                    //MongoTestClassRepository _repo = new MongoTestClassRepository(new MongoDbDataSession());
                    //do
                    //{
                    //    var tmpEntity = new Entities.TestClass
                    //    {
                    //        Property1 = RandomGen.GenericInt(10000),
                    //        Property2 = RandomGen.GenericString(250, 20),
                    //        Property3 = RandomGen.GenericDate(),
                    //        Property4 = null,
                    //        Property5 = RandomGen.GenericNullableDate(60),
                    //        Property6 = null
                    //    };

                    //    Layer.SaveTest(ref tmpEntity);

                    //    Task.Delay(5000).Wait();

                    //} while (true);
                    //var resString = RandomGenerator.GenericOnlyAlfaNumericString(43, 0, false);
                    //// RICERCA SINGOLA ENTITà

                    ////Fetch
                    var respF = Layer.Fetch();

                    //var respFF = Layer.Fetch(c => c.Property1 == 1);

                    //var resS = Layer.GetSingle("de3318bd-d5db-4f1e-8130-cfed77039e93");
                    //Layer.Delete(resS);

                    //var resd = Layer.Count();
                    var TestCollection = Layer.GetClass(1);

                    var myTest = new PluralizeUtility();
                    var resTS  = myTest.Pluralize(typeof(TestClass));

                    //TEST UTILS
                }
            }


            //Console.ReadKey();
        }