Exemple #1
0
 public void AfterConfigurationAssigned()
 {
     IndexCommand.ResetQueryCache();
     Indexes = new List <IIndexProvider>();
     ValidateConfiguration();
     IdGenerator = new LinearBlockIdGenerator(Configuration.ConnectionFactory, 20, Configuration.TablePrefix);
 }
Exemple #2
0
        static void Main1(string[] args)
        {
            Person p2 = new Person();

            p2.Id   = 3;
            p2.Age  = 10;
            p2.Name = "handsome person";
            p2.Desc = "handsome look, ugly heart";

            //Person p1 = new Person();
            //p1.Id = 4;
            //p1.Age = 8;
            //p1.Name = "ugly person";
            //p1.Desc = "ugly look, nice heart";

            ElasticConnection client = new ElasticConnection("localhost", 9200);
            var serializer           = new JsonNetSerializer();
            //第一个参数相当于“数据库”,第二个参数相当于“表”,第三个参数相当于“主键”
            IndexCommand cmd = new IndexCommand("zsz", "persons", p2.Id.ToString());
            //Put()第二个参数是要插入的数据
            OperationResult result      = client.Put(cmd, serializer.Serialize(p2));
            var             indexResult = serializer.ToIndexResult(result.Result);

            if (indexResult.created)
            {
                Console.WriteLine("created");
            }
            else
            {
                Console.WriteLine("faled: " + indexResult.error);
            }
            Console.ReadKey();
        }
Exemple #3
0
        public IndexResult Index(IndexCommand indexCommand, object document = null)
        {
            string data   = Serializer.ToJson(document);
            var    result = connection.Put(indexCommand, data);

            return(Serializer.ToIndexResult(result));
        }
Exemple #4
0
        private bool VisitIndexAddCommand(IndexCommand command, EntityId entityId)
        {
            try
            {
                CommitContext context = CommitContext(command);
                string        key     = _definitions.getKey(command.KeyId);
                object        value   = command.Value;

                // Below is a check for a null value where such a value is ignored. This may look strange, but the
                // reason is that there was this bug where adding a null value to an index would be fine and written
                // into the log as a command, to later fail during application of that command, i.e. here.
                // There was a fix introduced to throw IllegalArgumentException out to user right away if passing in
                // null or object that had toString() produce null. Although databases already affected by this would
                // not be able to recover, which is why this check is here.
                if (value != null)
                {
                    context.EnsureWriterInstantiated();
                    context.IndexType.addToDocument(context.GetDocument(entityId, true).Document, key, value);
                }
            }
            catch (ExplicitIndexNotFoundKernelException)
            {
                // Pretend the index never existed.
            }
            return(false);
        }
Exemple #5
0
        internal async Task InitializeAsync()
        {
            IndexCommand.ResetQueryCache();
            Indexes       = new List <IIndexProvider>();
            ScopedIndexes = new List <Type>();
            ValidateConfiguration();

            _sessionPool = new ObjectPool <Session>(MakeSession, Configuration.SessionPoolSize);
            Dialect      = SqlDialectFactory.For(Configuration.ConnectionFactory.DbConnectionType);
            TypeNames    = new TypeService();

            using (var connection = Configuration.ConnectionFactory.CreateConnection())
            {
                await connection.OpenAsync();

                using (var transaction = connection.BeginTransaction())
                {
                    var builder = new SchemaBuilder(Configuration, transaction);
                    await Configuration.IdGenerator.InitializeAsync(this, builder);

                    transaction.Commit();
                }
                //)FIXME : in Oracle it's forbidden to index an already indexed column and PK/UK is already indexed
                //.AlterTable(LinearBlockIdGenerator.TableName, table => table
                //    .CreateIndex("IX_Dimension", "dimension")
            }

            // Pee-initialize the default collection
            await InitializeCollectionAsync(Dialect.NullString);
        }
Exemple #6
0
        static void Main1()
        {
            Person p1 = new Person();

            p1.Id   = 1;
            p1.Age  = 8;
            p1.Name = "ll";
            p1.Desc = "最美丽的女孩";

            ElasticConnection client = new ElasticConnection("localhost", 9200);
            var serializer           = new JsonNetSerializer();
            //第一个参数相当于“数据库”,第二个参数相当于“表”,第三个参数相当于“主键”
            IndexCommand cmd = new IndexCommand("Hlxzsz", "persons", p1.Id.ToString());
            //Put()第二个参数是要插入的数据
            OperationResult result      = client.Put(cmd, serializer.Serialize(p1));
            var             indexResult = serializer.ToIndexResult(result.Result);

            if (indexResult.created)
            {
                Console.WriteLine("创建了");
            }
            else
            {
                Console.WriteLine("没创建" + indexResult.error);
            }
            Console.ReadKey();
        }
Exemple #7
0
        internal async Task InitializeAsync()
        {
            IndexCommand.ResetQueryCache();
            Indexes       = new List <IIndexProvider>();
            ScopedIndexes = new List <Type>();
            ValidateConfiguration();

            _sessionPool = new ObjectPool <Session>(MakeSession, Configuration.SessionPoolSize);
            Dialect      = SqlDialectFactory.For(Configuration.ConnectionFactory.DbConnectionType);
            TypeNames    = new TypeService();

            using (var connection = Configuration.ConnectionFactory.CreateConnection())
            {
                await connection.OpenAsync();

                using (var transaction = connection.BeginTransaction(Configuration.IsolationLevel))
                {
                    var builder = new SchemaBuilder(Configuration, transaction);
                    await Configuration.IdGenerator.InitializeAsync(this, builder);

                    transaction.Commit();
                }
            }

            // Pre-initialize the default collection
            await InitializeCollectionAsync("");
        }
Exemple #8
0
        /// <summary>
        /// Get an applier suitable for the specified IndexCommand.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private TransactionApplier applier(org.neo4j.kernel.impl.index.IndexCommand command) throws java.io.IOException
        private TransactionApplier Applier(IndexCommand command)
        {
            // Have we got an applier for this index?
            string indexName = _defineCommand.getIndexName(command.IndexNameId);
            IDictionary <string, TransactionApplier> applierByIndex = ApplierByIndexMap(command);
            TransactionApplier applier = applierByIndex[indexName];

            if (applier == null)
            {
                // We don't. Have we got an applier for the provider of this index?
                IndexEntityType entityType          = IndexEntityType.byId(command.EntityType);
                IDictionary <string, string> config = _indexConfigStore.get(entityType.entityClass(), indexName);
                if (config == null)
                {
                    // This provider doesn't even exist, return an EMPTY handler, i.e. ignore these changes.
                    // Could be that the index provider is temporarily unavailable?
                    return(TransactionApplier_Fields.Empty);
                }
                string providerName = config[PROVIDER];
                applier = ApplierByProvider[providerName];
                if (applier == null)
                {
                    // We don't, so create the applier
                    applier = _applierLookup.newApplier(providerName, _mode.needsIdempotencyChecks());
                    applier.VisitIndexDefineCommand(_defineCommand);
                    ApplierByProvider[providerName] = applier;
                }

                // Also cache this applier for this index
                applierByIndex[indexName] = applier;
            }
            return(applier);
        }
Exemple #9
0
        static void Main1(string[] args)
        {
            /*
             * Person p1 = new Person();
             * p1.Id = 1;
             * p1.Age = 10;
             * p1.Name = "欧阳帅帅";
             * p1.Desc = "欧阳锋家的帅哥公子,人送外号‘小杨中科’";*/

            Person p1 = new Person();

            p1.Id   = 2;
            p1.Age  = 8;
            p1.Name = "丑娘娘";
            p1.Desc = "二丑家的姑娘,是最美丽的女孩";

            ElasticConnection client = new ElasticConnection("localhost", 9200);
            var serializer           = new JsonNetSerializer();
            //第一个参数相当于“数据库”,第二个参数相当于“表”,第三个参数相当于“主键”
            IndexCommand cmd = new IndexCommand("zsz", "persons", p1.Id.ToString());
            //Put()第二个参数是要插入的数据
            OperationResult result      = client.Put(cmd, serializer.Serialize(p1));
            var             indexResult = serializer.ToIndexResult(result.Result);

            if (indexResult.created)
            {
                Console.WriteLine("创建了");
            }
            else
            {
                Console.WriteLine("没创建" + indexResult.error);
            }
            Console.ReadKey();
        }
Exemple #10
0
        private static CommandLineBuilder BuildCommandLine()
        {
            var root = new RootCommand();

            root.AddCommand(IndexCommand.Create());
            root.AddCommand(SearchCommand.Create());
            return(new CommandLineBuilder(root));
        }
        /// <summary>
        /// 数据索引
        /// </summary>
        /// <param name="indexName">索引名称</param>
        /// <param name="indexType">索引类型</param>
        /// <param name="id">索引文档id,不能重复,如果重复则覆盖原先的</param>
        /// <param name="jsonDocument">要索引的文档,json格式</param>
        /// <returns>索引结果</returns>
        public IndexResult Index(string indexName, string indexType, string id, string jsonDocument)
        {
            var             serializer  = new JsonNetSerializer();
            string          cmd         = new IndexCommand(indexName, indexType, id);
            OperationResult result      = Client.Put(cmd, jsonDocument);
            var             indexResult = serializer.ToIndexResult(result.Result);

            return(indexResult);
        }
Exemple #12
0
        public void AfterConfigurationAssigned()
        {
            IndexCommand.ResetQueryCache();
            Indexes = new List <IIndexProvider>();
            ValidateConfiguration();
            IdGenerator = new LinearBlockIdGenerator(Configuration.ConnectionFactory, Configuration.LinearBlockSize, Configuration.TablePrefix);

            _sessionPool = new ObjectPool <Session>(MakeSession, Configuration.SessionPoolSize);
        }
Exemple #13
0
        public Store(Configuration configuration)
        {
            IndexCommand.ResetQueryCache();

            Configuration = configuration;
            Indexes       = new List <IIndexProvider>();
            ValidateConfiguration();
            IdGenerator = new LinearBlockIdGenerator(Configuration.ConnectionFactory, 20, Configuration.TablePrefix);
        }
        public ActionResult Add(HouseAddModel model)
        {
            long?userId = AdminHelper.GetUserId(HttpContext);
            long?cityId = userSerivce.GetById(userId.Value).CityId;

            if (cityId == null)
            {
                return(View("Error", (object)"总部不能进行房源管理"));
            }
            HouseAddnewDTO dto = new HouseAddnewDTO();

            dto.Address          = model.address;
            dto.Area             = model.area;
            dto.AttachmentIds    = model.attachmentIds;
            dto.CheckInDateTime  = model.checkInDateTime;
            dto.CommunityId      = model.CommunityId;
            dto.DecorateStatusId = model.DecorateStatusId;
            dto.Description      = model.description;
            dto.Direction        = model.direction;
            dto.FloorIndex       = model.floorIndex;
            dto.LookableDateTime = model.lookableDateTime;
            dto.MonthRent        = model.monthRent;
            dto.OwnerName        = model.ownerName;
            dto.OwnerPhoneNum    = model.ownerPhoneNum;
            dto.RoomTypeId       = model.RoomTypeId;
            dto.StatusId         = model.StatusId;
            dto.TotalFloorCount  = model.totalFloor;
            dto.TypeId           = model.TypeId;

            long houseId = houseService.AddNew(dto);

            //生成房源查看的html文件
            CreateStaticPage(houseId);



            //把房源信息写入ElasticSearch
            //创建与SQLLite的连接
            ElasticConnection client = new ElasticConnection("localhost", 9200);
            var serializer           = new JsonNetSerializer();
            //写入数据
            //第一个参数相当于“数据库”,第二个参数相当于“表”,第三个参数相当于“主键”
            IndexCommand indexcmd = new IndexCommand("ZSZHouse", "House", houseId.ToString());
            //不用手动创建数据库,es会自动分配空间用zsz命名
            //Put()第二个参数是要插入的数据
            OperationResult result = client.Put(indexcmd, serializer.Serialize(dto));//把对象序列化成json放入Elastic中返回结果



            return(Json(new AjaxResult {
                Status = "ok"
            }));
        }
Exemple #15
0
        /// <summary>
        /// 添加一条记录
        /// </summary>
        /// <param name="id"></param>
        /// <param name="jsonDocument"></param>
        /// <returns></returns>
        public bool Index(string id, string jsonDocument)
        {
            if (_indexInfo == null)
            {
                throw new ArgumentNullException();
            }
            string          cmd         = new IndexCommand(_indexInfo.IndexName, _indexInfo.IndexType, id);
            OperationResult result      = Client.Put(cmd, jsonDocument);
            var             indexResult = serializer.ToIndexResult(result.Result);

            return(indexResult.created);
        }
        /// <summary>
        /// Add a new command to the collection of page selector commands.
        /// </summary>
        /// <param name="pageName">
        /// Name of the page the new command represents.
        /// </param>
        private void PopulatePageSelector(string pageName)
        {
            if (this.PageSelector == null)
            {
                this.PageSelector = new List <IIndexCommand <string> >();
            }

            IIndexCommand <string> showEventDetails =
                new IndexCommand <string>(
                    pageName,
                    this.NewPage);

            this.PageSelector.Add(showEventDetails);
        }
 /// <summary>
 /// 数据索引
 /// </summary>
 /// <param name="indexName">索引名称</param>
 /// <param name="indexType">索引类型</param>
 /// <param name="id">索引文档id,不能重复,如果重复则覆盖原先的</param>
 /// <param name="jsonDocument">要索引的文档,json格式</param>
 /// <returns>索引结果</returns>
 public IndexResult Delete(string indexName, string indexType, string id)
 {
     try
     {
         var             serializer  = new JsonNetSerializer();
         string          cmd         = new IndexCommand(indexName, indexType, id);
         OperationResult result      = Client.Delete(cmd);
         var             indexResult = serializer.ToIndexResult(result.Result);
         return(indexResult);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Exemple #18
0
        public void CreateCommands(IndexCommand command, List <WriteModel <MongoTextIndexEntity <T> > > writes)
        {
            switch (command)
            {
            case DeleteIndexEntry delete:
                DeleteEntry(delete, writes);
                break;

            case UpsertIndexEntry upsert:
                UpsertEntry(upsert, writes);
                break;

            case UpdateIndexEntry update:
                UpdateEntry(update, writes);
                break;
            }
        }
Exemple #19
0
        public static void CreateCommands(IndexCommand command, IList <IndexDocumentsAction <SearchDocument> > batch)
        {
            switch (command)
            {
            case UpsertIndexEntry upsert:
                UpsertTextEntry(upsert, batch);
                break;

            case UpdateIndexEntry update:
                UpdateEntry(update, batch);
                break;

            case DeleteIndexEntry delete:
                DeleteEntry(delete, batch);
                break;
            }
        }
Exemple #20
0
        public static void CreateCommands(IndexCommand command, List <object> args, string indexName)
        {
            switch (command)
            {
            case UpsertIndexEntry upsert:
                UpsertEntry(upsert, args, indexName);
                break;

            case UpdateIndexEntry update:
                UpdateEntry(update, args, indexName);
                break;

            case DeleteIndexEntry delete:
                DeleteEntry(delete, args, indexName);
                break;
            }
        }
Exemple #21
0
        public IndexModule(IRepeater repeater, ICommandBus commandBus)
        {
            this.RequiresAuthentication();
            this.RequiresClaims(AccessRights.Access);

            _repeater         = repeater;
            _commandBus       = commandBus;
            Get["/"]          = parameters => "Its working!!!";
            Get["/{value}"]   = parameters => _repeater.Repeat(parameters.value);
            Get["/oopserror"] = _ => throw new ArgumentException("message");
            Post["/{value}"]  = parameters =>
            {
                var command = new IndexCommand(parameters.value);
                return(_commandBus.Handle(command));
            };
            OnError += HandleException;
        }
Exemple #22
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private CommitContext commitContext(org.neo4j.kernel.impl.index.IndexCommand command) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
        private CommitContext CommitContext(IndexCommand command)
        {
            IDictionary <string, CommitContext> contextMap = CommitContextMap(command.EntityType);
            string        indexName = _definitions.getIndexName(command.IndexNameId);
            CommitContext context   = contextMap[indexName];

            if (context == null)
            {
                IndexIdentifier identifier = new IndexIdentifier(IndexEntityType.byId(command.EntityType), indexName);

                // TODO the fact that we look up index type from config here using the index store
                // directly should be avoided. But how can we do it in, say recovery?
                // The `dataSource.getType()` call can throw an exception if the index is concurrently deleted.
                // To avoid bubbling an exception during commit, we instead ignore the commands related to that index,
                // and proceed as if the index never existed, and thus cannot accept any modifications.
                IndexType type = _dataSource.getType(identifier, _recovery);
                context = new CommitContext(_dataSource, identifier, type, _recovery);
                contextMap[indexName] = context;
            }
            return(context);
        }
Exemple #23
0
        private async Task IndexAndSearchAsync(IIndexStorage storage)
        {
            var schemaId = NamedId.Of(Guid.NewGuid(), "my-schema");

            var factory = new IndexManager(storage, new NoopLog());

            var grain = new LuceneTextIndexGrain(factory);

            await grain.ActivateAsync(Guid.NewGuid());

            for (var i = 0; i < M; i++)
            {
                var ids = new Guid[N];

                for (var j = 0; j < ids.Length; j++)
                {
                    ids[j] = Guid.NewGuid();
                }

                foreach (var id in ids)
                {
                    var commands = new IndexCommand[]
                    {
                        new UpsertIndexEntry
                        {
                            ContentId      = id,
                            DocId          = id.ToString(),
                            ServeAll       = true,
                            ServePublished = true,
                            Texts          = texts
                        }
                    };

                    await grain.IndexAsync(schemaId, commands.AsImmutable());
                }

                await grain.CommitAsync();
            }
        }
Exemple #24
0
 // Some lazy creation of Maps for holding appliers per provider and index
 private IDictionary <string, TransactionApplier> ApplierByIndexMap(IndexCommand command)
 {
     if (command.EntityType == IndexEntityType.Node.id())
     {
         if (_applierByNodeIndex.Count == 0)
         {
             _applierByNodeIndex = new Dictionary <string, TransactionApplier>();
             LazyCreateApplierByprovider();
         }
         return(_applierByNodeIndex);
     }
     if (command.EntityType == IndexEntityType.Relationship.id())
     {
         if (_applierByRelationshipIndex.Count == 0)
         {
             _applierByRelationshipIndex = new Dictionary <string, TransactionApplier>();
             LazyCreateApplierByprovider();
         }
         return(_applierByRelationshipIndex);
     }
     throw new System.NotSupportedException("Unknown entity type " + command.EntityType);
 }
Exemple #25
0
        public IndexResult Index(object objectToIndex, Action <IndexCommand> commandAction)
        {
            objectToIndex.ValidateNotNullArgument(nameof(objectToIndex));
            IndexCommand indexCommand = this.commands.Index(this.DefaultIndex, this.GetTypeName(objectToIndex), objectToIndex);

            indexCommand.Id         = (DocumentId)this.Conventions.IdConvention.GetId(objectToIndex);
            indexCommand.TimeToLive = this.Conventions.TimeToLiveConvention.GetTimeToLive(objectToIndex);
            if (this.Conventions.LanguageRoutingConvention.HasLanguageRouting(objectToIndex))
            {
                LanguageRouting languageRouting = this.Conventions.LanguageRoutingConvention.GetLanguageRouting(objectToIndex);
                if (languageRouting == null)
                {
                    throw new ArgumentException(string.Format("Language missing for the object with id: {0}.", (object)indexCommand.Id));
                }
                indexCommand.LanguageRouting = this.GetSupportedLanguageRoutingOrDefault(languageRouting);
            }
            if (commandAction.IsNotNull())
            {
                commandAction(indexCommand);
            }
            this.PrepareSerializerUsingConventions(indexCommand.CommandContext.Serializer);
            return(indexCommand.Execute());
        }
Exemple #26
0
        static void Main1(string[] args)
        {
            Person p1 = new Person {
                Id = 2, Age = 11, Name = "独孤求败", Desc = "剑客"
            };
            ElasticConnection client = new ElasticConnection("127.0.0.1", 9200);
            var serializer           = new JsonNetSerializer();
            //第一个相当于"数据库",第二个相当于表,第三个相当于主键
            IndexCommand    cmd         = new IndexCommand("MyTest", "persons", p1.Id.ToString()); //数据区域
            OperationResult result      = client.Put(cmd, serializer.Serialize(p1));               //放进去
            var             indexResult = serializer.ToIndexResult(result.Result);

            if (indexResult.created)
            {
                Console.WriteLine("创建了");
            }
            else
            {
                Console.WriteLine("创建失败" + indexResult.error);
            }

            Console.ReadKey();
        }
Exemple #27
0
        public async Task InitializeAsync()
        {
            IndexCommand.ResetQueryCache();
            ValidateConfiguration();

            _sessionPool = new ObjectPool <Session>(MakeSession, Configuration.SessionPoolSize);
            TypeNames    = new TypeService();

#if SUPPORTS_ASYNC_TRANSACTIONS
            await using (var connection = Configuration.ConnectionFactory.CreateConnection())
            {
                await connection.OpenAsync();

                await using (var transaction = connection.BeginTransaction(Configuration.IsolationLevel))
#else
            using (var connection = Configuration.ConnectionFactory.CreateConnection())
            {
                await connection.OpenAsync();

                using (var transaction = connection.BeginTransaction(Configuration.IsolationLevel))
#endif
                {
                    var builder = new SchemaBuilder(Configuration, transaction);
                    await Configuration.IdGenerator.InitializeAsync(this, builder);

#if SUPPORTS_ASYNC_TRANSACTIONS
                    await transaction.CommitAsync();
#else
                    transaction.Commit();
#endif
                }
            }

            // Pre-initialize the default collection
            await InitializeCollectionAsync("");
        }
        private void AddCommand(string indexName, IndexCommand command, bool clearFirst)
        {
            IList <IndexCommand> commands;

            if (command.EntityType == IndexEntityType.Node.id())
            {
                commands = _nodeCommands.computeIfAbsent(indexName, k => new List <>());
            }
            else if (command.EntityType == IndexEntityType.Relationship.id())
            {
                commands = _relationshipCommands.computeIfAbsent(indexName, k => new List <>());
            }
            else
            {
                throw new System.ArgumentException("" + command.EntityType);
            }

            if (clearFirst)
            {
                commands.Clear();
            }

            commands.Add(command);
        }
Exemple #29
0
        static void Main1(string[] args)
        {
            using (SQLiteConnection conn = new SQLiteConnection(@"Data Source=d:/verycd.sqlite3.db"))                
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "select * from verycd";
                    using (var reader = cmd.ExecuteReader())
                    {
                        ElasticConnection client = new ElasticConnection("localhost", 9200);
                        
                        var serializer = new JsonNetSerializer();                        
                        while(reader.Read())
                        {                            
                            long verycdid =reader.GetInt64(reader.GetOrdinal("verycdid"));
                            string title = reader.GetString(reader.GetOrdinal("title"));
                            string status = reader.GetString(reader.GetOrdinal("status"));
                            string brief = reader.GetString(reader.GetOrdinal("brief"));
                            string pubtime = reader.GetString(reader.GetOrdinal("pubtime"));
                            string updtime = reader.GetString(reader.GetOrdinal("updtime"));
                            string category1 = reader.GetString(reader.GetOrdinal("category1"));
                            string category2 = reader.GetString(reader.GetOrdinal("category2"));
                            string ed2k = reader.GetString(reader.GetOrdinal("ed2k"));
                            string content = reader.GetString(reader.GetOrdinal("content"));
                            string related = reader.GetString(reader.GetOrdinal("related"));

                            VerycdItem item = new VerycdItem();
                            item.verycdid = verycdid;
                            item.title = title;
                            item.status = status;
                            item.brief = brief;
                            item.pubtime = pubtime;
                            item.updtime = updtime;
                            item.category1 = category1;
                            item.category2 = category2;
                            item.ed2k = ed2k;
                            item.content = content;
                            item.related = related;
                            try
                            {
                                //第一个参数相当于“数据库”,第二个参数相当于“表”,第三个参数相当于“主键”
                                IndexCommand Indexcmd = new IndexCommand("verycd", "items", item.verycdid.ToString());
                                //Put()第二个参数是要插入的数据
                                OperationResult result = client.Put(Indexcmd, serializer.Serialize(item));
                                var indexResult = serializer.ToIndexResult(result.Result);
                                if (indexResult.created)
                                {
                                    Console.WriteLine(verycdid + "创建了");
                                }
                                else
                                {
                                    Console.WriteLine(verycdid + "没创建" + indexResult.error);
                                }
                            }
                            catch(Exception ex)
                            {
                                continue;
                            }
                        }
                        Console.ReadKey();                
                    }
                }
            }
        }
Exemple #30
0
        private static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Not enough arguments !");
                return;
            }

            Config.Model = args[0].ToLower().UppercaseFirst();
            var command = "";

            if (args.Length > 1)
            {
                command = args[1].ToLower();
            }

            if (args.Length > 2)
            {
                Config.Area = args[2].ToLower().UppercaseFirst();
            }

            Config.ModelsPath     = Environment.CurrentDirectory + "\\";
            Config.ViewModelsPath = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.FullName + "\\ViewModels\\";
            Config.RepositoryPath = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.Parent.FullName + "\\Repository\\";
            Config.ServicePath    = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.Parent.FullName + "\\Service\\";

            if (string.IsNullOrEmpty(Config.Area))
            {
                Config.ControllerPath = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.Parent.Parent.FullName + "\\Portal.Web\\Controllers\\";
                Config.ViewsPath      = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.Parent.Parent.FullName + "\\Portal.Web\\Views\\" + Config.Model + "\\";
            }
            else
            {
                Config.ControllerPath = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.Parent.Parent.FullName + "\\Portal.Web\\Areas\\" + Config.Area + "\\Controllers\\";
                Config.ViewsPath      = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.Parent.Parent.FullName + "\\Portal.Web\\Areas\\" + Config.Area + "\\Views\\" + Config.Model + "\\";
            }

            var viewsDir = new System.IO.DirectoryInfo(Config.ViewsPath);

            if (!viewsDir.Exists)
            {
                viewsDir.Create();
            }

            Config.PropertyNames        = ClassHelper.GetPropertyNames(Config.ModelsPath + Config.Model + ".cs");
            Config.PropertyTypes        = ClassHelper.GetPropertyTypes(Config.ModelsPath + Config.Model + ".cs");
            Config.PropertyDeclarations = ClassHelper.GetPropertyDeclarations(Config.ModelsPath + Config.Model + ".cs");

            switch (command)
            {
            case "sr":
            case "service":
                var iserviceCommand = new IServiceCommand();
                var serviceCommand  = new ServiceCommand();
                iserviceCommand.Execute();
                serviceCommand.Execute();
                break;

            case "rp":
            case "repository":
                var irepositoryCommand = new IRepositoryCommand();
                var repositoryCommand  = new RepositoryCommand();
                irepositoryCommand.Execute();
                repositoryCommand.Execute();
                break;

            case "vm":
            case "viewmodel":
                var viewModelCommand = new ViewModelCommand();
                viewModelCommand.Execute();
                break;

            case "ad":
            case "addmodel":
                var addModel = new AddModelCommand();
                addModel.Execute();
                break;

            case "vi":
            case "views":
                var indexCommand   = new IndexCommand();
                var createCommand  = new CreateCommand();
                var editCommand    = new EditCommand();
                var deleteCommand  = new DeleteCommand();
                var detailsCommand = new DetailsCommand();

                indexCommand.Execute();
                createCommand.Execute();
                editCommand.Execute();
                deleteCommand.Execute();
                detailsCommand.Execute();

                break;

            case "cr":
            case "controller":
                var controllerCommand = new ControllerCommand();
                controllerCommand.Execute();
                break;

            case "go":
            default:
                var goCommand = new GoCommand();
                goCommand.Execute();


                break;
            }
        }