Ejemplo n.º 1
0
        public void Parse(DmModelDB db)
        {
            db.UsingNameSpaces.AddRange(this.UsingNameSpaces);
            db.NameSpace = this.NameSpace;

            foreach (var m in this.Models.Values)
            {
                db.Models.Add(m.Name, m.Parse());
            }

            foreach (var map in this.Mapings)
            {
                db.Mapings.Add(map.Parse());
            }

            db.Errors.AddRange(this.Errors);
        }
Ejemplo n.º 2
0
            void Parse(IModel model, int charIndex, System.Action callback)
            {
                var text = model.Content;

                ThreadPool.QueueUserWorkItem(o =>
                {
                    try
                    {
                        var parseInfo = new ParseInfo();
                        parseInfo.Content = text;
                        parseInfo.Index = charIndex;
                        parseInfo.Type = model.ParseType;
                        var parseInfo_json = Newtonsoft.Json.JsonConvert.SerializeObject(parseInfo);
                        string json = null;

                        lock (this.syncObj)
                        {
                            if (!ConnectProxy.Instance().Send(parseInfo_json))
                            {
                                model.SetParsed(false);
                                return;
                            }
                            json = ConnectProxy.Instance().Read();
                        }

                        if (json == null)
                        {
                            model.SetParsed(false);
                            return;
                        }
                        IParseModule module = null;
                        try
                        {
                            if (model.ParseType == CodeHelper.Core.Parser.ParseType.XmlModel)
                            {
                                module = JsonConvert.DeserializeObject<XmModelDB>(json);
                            }
                            else if (model.ParseType == CodeHelper.Core.Parser.ParseType.DataModel)
                            {
                                var program = JsonConvert.DeserializeObject<DbProgram>(json);
                                module = new DmModelDB();
                                ((DmModelDB)module).Program = program;
                                module.Name = System.IO.Path.GetFileNameWithoutExtension(model.File);
                            }
                            else if (model.ParseType == Core.Parser.ParseType.DataView)
                            {
                                module = JsonConvert.DeserializeObject<DataViewDB>(json);
                            }
                            else if (model.ParseType == Core.Parser.ParseType.ViewModel)
                            {
                                module = JsonConvert.DeserializeObject<ViewModelDB>(json);
                                ViewModelDB.Current = module as ViewModelDB;
                            }
                            else if (model.ParseType == Core.Parser.ParseType.WorkFlow)
                            {
                                var program = JsonConvert.DeserializeObject<Program>(json);
                                module = new WorkflowDB();
                                ((WorkflowDB)module).Program = program;
                                WorkflowDB.Current = module as WorkflowDB;
                                module.Name = System.IO.Path.GetFileNameWithoutExtension(model.File);
                            }
                        }
                        catch (Exception e)
                        {
                            this.AddError(new Core.Error.ParseErrorInfo()
                            {
                                FileId = model.FileId,
                                File = model.File,
                                ErrorType = Core.Error.ErrorType.Error,
                                Message = "模块解析错误: " + e.Message
                            });
                        }
                        if (module == null)
                        {
                            //this.IsWiseCompleted = true;
                            model.SetParsed(false);
                            OnRemoveModule(model.FileId);
                            return;
                        }

                        module.Initialize();

                        module.FileId = model.FileId;

                        model.SetParsed(true);

                        module.Errors.ForEach(x => { x.File = model.File; x.FileId = model.FileId; });

                        //OnUpdateModule(model.FileId, module);

                        this.waitingWiseModules.Add(module);

                        if (module.Errors != null)
                        {
                            module.Errors.ForEach(x => AddError(x));
                        }

                    }
                    catch (Exception e)
                    {
                        this.AddError(new Core.Error.ParseErrorInfo()
                        {
                            FileId = model.FileId,
                            File = model.File,
                            ErrorType = Core.Error.ErrorType.Error,
                            Message = "模块解析错误: " + e.Message
                        });
                        Console.Out.WriteLine(e.StackTrace);
                    }
                    finally
                    {

                        if (callback != null)
                        {
                            callback();
                        }

                        this.waitingParseModels.Take();

                        if (this.waitingParseModels.Count == 0)
                        {
                            parseEvent.Set();
                        }
                        else
                        {
                        }
                    }
                });
            }