Example #1
0
        public void Parse(string sql, int dotIndex,out DataViewDB dvDB, out List<ParseErrorInfo> errors, out ContextMenu contextMenu)
        {
            errors = new List<ParseErrorInfo>();
            contextMenu = new ContextMenu();
            dvDB = null;

            try
            {
                var parseInfo = new ParseInfo();
                parseInfo.Type = ParseType.DataView;
                parseInfo.Index = dotIndex;
                parseInfo.Content = sql;
                var parseInfo_json = Newtonsoft.Json.JsonConvert.SerializeObject(parseInfo);
                string json = null;

                if (!ConnectProxy.Instance().Send(parseInfo_json))
                {
                    return;
                }
                json = ConnectProxy.Instance().Read();
                //if (string.IsNullOrWhiteSpace(json))//repeat call if retrive empty text
                //{
                //    if (!ConnectProxy.Instance().Send(parseInfo_json))
                //    {
                //        return;
                //    }
                //    json = ConnectProxy.Instance().Read();
                //}
                try
                {
                    var dvModel = JsonConvert.DeserializeObject<DataViewDB>(json);
                    dvDB = dvModel;
                    errors = dvModel.Errors;
                    dvModel.Parse();

                    foreach (var error in errors)
                    {
                        this.Errors.Add(error);
                    }
                    //
                }
                catch (Exception e)
                {
                    this.Errors.Add(new CodeHelper.Core.Error.ParseErrorInfo()
                    {
                        FileId = Guid.Empty,
                        File = "",
                        ErrorType = CodeHelper.Core.Error.ErrorType.Error,
                        Message = "模块解析错误: " + e.Message
                    });
                    Console.Out.WriteLine(e.StackTrace);
                }
            }
            catch
            {
            }
        }
Example #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
                        {
                        }
                    }
                });
            }
Example #3
0
        public void Parse(IModel model, InputCharInfo inputChar, System.Action callback)
        {
            var text = model.Content;

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

                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);
                        //XmModelDB.Current.InputChar = inputChar;
                    }
                    else if (model.ParseType == CodeHelper.Core.Parser.ParseType.DataModel)
                    {
                        module = JsonConvert.DeserializeObject<DmModelDB>(json);
                        //DmModelDB.Current.InputChar = inputChar;
                    }
                    else if (model.ParseType == Core.Parser.ParseType.DataView)
                    {
                        module = JsonConvert.DeserializeObject<DataViewDB>(json);
                        //DataViewDB.Current.InputChar = inputChar;
                    }
                    else if (model.ParseType == Core.Parser.ParseType.ViewModel)
                    {
                        module = JsonConvert.DeserializeObject<ViewModelDB>(json);
                        ViewModelDB.Current = module as ViewModelDB;
                        ViewModelDB.Current.InputChar = inputChar;
                    }
                    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;
                        WorkflowDB.Current.InputChar = inputChar;
                        module.Name = System.IO.Path.GetFileNameWithoutExtension(model.File);

                    }
                }
                catch (Exception e)
                {
                    this.Errors.Add(new Core.Error.ParseErrorInfo()
                    {
                        FileId = model.FileId,
                        File = model.File,
                        ErrorType = Core.Error.ErrorType.Error,
                        Message = "模块解析错误: " + e.Message
                    });
                }
                if (module == null)
                {
                    model.SetParsed(false);

                    return;
                }

                module.File = model.File;
                module.FileId = model.FileId;

                module.Initialize();

                module.Wise();

                module.FileId = model.FileId;

                model.SetParsed(true);

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

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

            }
            catch (Exception e)
            {
                this.Errors.Add(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();
                }
            }
        }