Пример #1
0
        /// <summary>
        /// Importe des syntaxes d'objets depuis un dossier
        /// </summary>
        /// <param name="path"></param>
        public void ImportSyntaxDirectory(string path)
        {
            string groupName = Path.GetFileNameWithoutExtension(path);

            // Scan les objets
            if (Directory.Exists(path))
            {
                string[] groupsPaths = Directory.GetFiles(path, "*");
                foreach (var syntaxFile in groupsPaths)
                {
                    using (StreamReader streamReader = new StreamReader(syntaxFile, Encoding.UTF8))
                    {
                        try
                        {
                            ObjectSyntax syntax = new ObjectSyntax();
                            syntax.ObjectType   = Path.GetFileNameWithoutExtension(syntaxFile);
                            syntax.ContentRegEx = streamReader.ReadLine();
                            syntax.ParamRegEx   = streamReader.ReadLine();
                            syntax.ObjectDesc   = String.Empty;
                            syntax.GroupName    = groupName;
                            project.AddObjectSyntax(syntax);
                            Console.WriteLine("Add syntax object " + syntax.ObjectType);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Ignore object file '" + syntaxFile + "'. " + ex.Message);
                        }
                        streamReader.Close();
                    }
                }
            }

            // Scan les groupes
            if (Directory.Exists(path + @"\groups"))
            {
                string[] groupsPaths = Directory.GetFiles(path + @"\groups", "*");
                foreach (var syntaxFile in groupsPaths)
                {
                    using (StreamReader streamReader = new StreamReader(syntaxFile, Encoding.UTF8))
                    {
                        try
                        {
                            ParamSyntax syntax = new ParamSyntax();
                            syntax.ParamType    = Path.GetFileNameWithoutExtension(syntaxFile);
                            syntax.ContentRegEx = streamReader.ReadLine();
                            syntax.ParamRegEx   = streamReader.ReadLine();
                            syntax.GroupName    = groupName;
                            project.AddParamSyntax(syntax);
                            Console.WriteLine("Add syntax param " + syntax.ParamType);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Ignore param file '" + syntaxFile + "'. " + ex.Message);
                        }
                        streamReader.Close();
                    }
                }
            }
        }
Пример #2
0
        //-----------------------------------------------------------------------------------------
        // Evénements
        //-----------------------------------------------------------------------------------------
        #region IEventProcess
        // Traite les événements
        public void ProcessEvent(object from, object _this, IEvent e)
        {
            //
            // Model Change
            // Après le changement du model
            //
            if (e is ModelChangeEvent)
            {
                ModelChangeEvent ev = e as ModelChangeEvent;
                //Actualise l'interface
                UpdateUI();
                // Notifie les vues
                this.NotifyEvent(e);
            }

            //
            // Entity Change
            // Après le changement d'une entité
            //
            if (e is EntityChangeEvent)
            {
                EntityChangeEvent ev = e as EntityChangeEvent;
                //Actualise l'interface
                OnEntityChange(ev.Model, ev.Entity, ev.BaseEvent);
                // Notifie les vues
                this.NotifyEvent(e);
            }

            //
            // Pré-Create
            // Préprare la création d'une nouvelle entité (avant édition des champs)
            //
            if (e is EntityPreCreateEvent)
            {
                EntityPreCreateEvent ev = e as EntityPreCreateEvent;

                // Allocation
                if (ev.Entity == null)
                {
                    ev.Entity = app.appModel.CreateEntity(ev.EntityName);
                }

                // Affecte le status de création
                ev.Entity.EntityState = EntityState.Added;

                // Initialise les données par défaut
                if (ev.Entity is IEntityPersistent)
                {
                    IEntityPersistent p = ev.Entity as IEntityPersistent;
                    //Affecte la source de données à la nouvelle entitée
                    p.Factory = app.appModel.project.Factory;
                }

                if (ev.Entity is ObjectSyntax)
                {
                    ObjectSyntax entity = ev.Entity as ObjectSyntax;
                    // Ajoute au projet en cours
                    app.Project.AddObjectSyntax(entity);
                }


                if (ev.Entity is ParamSyntax)
                {
                    ParamSyntax entity = ev.Entity as ParamSyntax;
                    // Ajoute au projet en cours
                    app.Project.AddParamSyntax(entity);
                }

                if (ev.Entity is ObjectContent)
                {
                    ObjectContent entity = ev.Entity as ObjectContent;
                    // Ajoute au projet en cours
                    app.Project.AddObjectContent(entity);
                    // Génére un identifiant unique
                    entity.Id = Guid.NewGuid().ToString("N");
                    foreach (var p in entity.ParamContent)
                    {
                        p.Id = Guid.NewGuid().ToString("N");
                    }
                }

                if (ev.Entity is ParamContent)
                {
                    ParamContent entity = ev.Entity as ParamContent;
                    CurObjectContent.AddParamContent(entity);
                    // Génére un identifiant unique
                    entity.Id = Guid.NewGuid().ToString("N");
                }

                if (ev.Entity is SearchParams)
                {
                    SearchParams entity = ev.Entity as SearchParams;
                    app.Project.AddSearchParams(entity);
                }

                if (ev.Entity is DatabaseSource)
                {
                    DatabaseSource entity = ev.Entity as DatabaseSource;
                    app.Project.AddDatabaseSource(entity);

                    if (app.States.SelectedDatabaseSourceId == null)
                    {
                        app.States.SelectedDatabaseSourceId = app.Project.DatabaseSource.First().Id;
                    }
                }

                // Ajoute l'instance au model (notifie le controleur)
                app.appModel.Add(ev.Entity);
            }

            // Implémente la gestion du copier coller
            EventProcess.ProcessCopyPasteEvents(app, this, app.appModel, from, _this, e);

            /*
             *
             * //
             * // Change
             * // Action après le changement d'une entité
             * //
             * if (e is EntityChangeEvent)
             * {
             *  EntityChangeEvent ev = e as EntityChangeEvent;
             *  // Concerne ce model ?
             *  if (ev.Model == app.appModel)
             *  {
             *      if (ev.Entity is ObjectContent)
             *      {
             *          OnPropertyChanged("ObjectContentList");
             *      }
             *      if (ev.Entity is ParamContent)
             *      {
             *          CurParamContentList = new ObservableCollection<ParamContent>(curObjectContent.ParamContent);
             *      }
             *      if (ev.Entity is DatabaseSource)
             *      {
             *          OnPropertyChanged("CurDatabaseSource");
             *      }
             *  }
             * }*/
        }