public void IncorrectCommandSignatureDiagnostic()
        {
            var                sourceCode       = @"using DevExpress.Mvvm.CodeGenerators;

namespace Test {
    [GenerateViewModel]
    partial class WithCommand {
        [GenerateCommand]
        public int Command1() {}

        [GenerateCommand]
        public void Command2(int a, int b) {}
    }

    public class Program {
        public static void Main(string[] args) { }
    }
}
";
            Compilation        inputCompilation = Helper.CreateCompilation(sourceCode);
            ViewModelGenerator generator        = new ViewModelGenerator();

            GeneratorDriver driver = CSharpGeneratorDriver.Create(generator);

            _ = driver.RunGeneratorsAndUpdateCompilation(inputCompilation, out var outputCompilation, out var diagnostics);

            Assert.AreEqual(3, outputCompilation.SyntaxTrees.Count());

            Assert.AreEqual(2, diagnostics.Count());
            Assert.AreEqual(GeneratorDiagnostics.IncorrectCommandSignature.Id, diagnostics[0].Id);
            Assert.AreEqual(GeneratorDiagnostics.IncorrectCommandSignature.Id, diagnostics[1].Id);
        }
Example #2
0
        public void Init()
        {
            this.ReadModelRepository = new GenericReadModelRepositoryFake();
            var viewModelGenerator = new ViewModelGenerator(this.ReadModelRepository);

            var eventBus = new EventBus();

            eventBus.Register <ItemCreated>(viewModelGenerator);
            eventBus.Register <ItemRenamed>(viewModelGenerator);
            eventBus.Register <UnitsAdded>(viewModelGenerator);
            eventBus.Register <UnitsRemoved>(viewModelGenerator);
            eventBus.Register <ItemDisabled>(viewModelGenerator);
            eventBus.Register <ItemEnabled>(viewModelGenerator);
            this.EventStore = new EventStoreFake(eventBus);

            var commandBus = new CommandBus();

            commandBus.RegisterHandler(new CreateItemHandler(this.EventStore));
            commandBus.RegisterHandler(new RenameItemHandler(this.EventStore));
            commandBus.RegisterHandler(new AddUnitsHandler(this.EventStore));
            commandBus.RegisterHandler(new RemoveUnitsHandler(this.EventStore));
            commandBus.RegisterHandler(new DisableItemHandler(this.EventStore));
            commandBus.RegisterHandler(new EnableItemHandler(this.EventStore));
            this.CommandBus = commandBus;
        }
        public async Task <IActionResult> Filter([FromForm] FilterModel model)
        {
            try
            {
                if (this.ValidRoleForAction(_context, _auth, new string[] { "Student", "Teacher", "Editor", "Admin" }))
                {
                    int _facultyId = this.GetLoggedUser(_auth, _context).FacultyId ?? default(int);

                    string PostType   = model.PostType ?? String.Empty;
                    int    LanguageId = model.LanguageId ?? default(int);
                    int    TagId      = model.TagId ?? default(int);
                    int    FacultyId  = model.FacultyId ?? _facultyId;

                    if (model.LanguageId != null)
                    {
                        List <Book> books = await _context.FilterBooks(FacultyId, LanguageId, TagId);

                        return(Ok(books.Select(x => new BookViewModel(x))));
                    }

                    List <Post> posts = await _context.FilterPosts(FacultyId, TagId, PostType);

                    List <PostViewModel> result = new ViewModelGenerator(_context, _auth).CreatePostListViewModel(posts);
                    return(Ok(result.OrderByDescending(x => x.LikeCount).ToList()));
                }
                return(Forbid());
            }
            catch (Exception ex)
            {
                var arguments = this.GetBaseData(_context, _auth);
                _logger.LogException(ex, arguments.Email, arguments.Path);
                return(BadRequest($"{ex.GetType().Name} was thrown."));
            }
        }
        private static IViewModelTypeProvider GetViewModelTypeProvider()
        {
            IViewModelGenerator    viewModelGenerator    = new ViewModelGenerator(new ViewModelPropertyGenerator());
            IViewModelTypeProvider viewModelTypeProvider = new ViewModelTypeProvider(viewModelGenerator);

            return(viewModelTypeProvider);
        }
        private void GenerateFiles(object sender, RoutedEventArgs e)
        {
            //Hlöðum inn grunngildum fyrir DatabaseMockup-ið, þetta er til þess að forritið viti hvar gagnagrunnsskilgreiningarnar eru
            DatabaseMockup.InitializeDatabaseMockup(baseFolderPath.Text);

            //Skilgreinum viðvörunina sem á að birtast í öllum auto generated file-um
            string fileAutoGenerationWarningText = "Autogenerated File - Warning: All modifications will be overwritten. File generated at: " + DateTime.UtcNow;

            //Setjum upp background worker til að sjá um að keyra löngu skipunina sem generate-ar kóðann
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += (o, ea) =>
            {
                //no direct interaction with the UI is allowed from this method
                this.Dispatcher.Invoke(() =>
                {
                    //Hreinsum möppur og útbúum file-a
                    ViewGenerator.GenerateViews(baseFolderPath.Text + pathToViews.Text, fileAutoGenerationWarningText);
                    ViewModelGenerator.GenerateViewModels(baseFolderPath.Text + pathToViewModels.Text, fileAutoGenerationWarningText);
                    ControllerGenerator.GenerateControllers(baseFolderPath.Text + pathToControllers.Text, fileAutoGenerationWarningText);
                });
            };
            worker.RunWorkerCompleted += (o, ea) =>
            {
                //work has completed. you can now interact with the UI
                busyIndicator.IsBusy = false;
            };
            //TODO: Þetta er nóg til þess að gera view-ið greyed out á meðan við erum að vinna, en sýnir ekki loading bar-ið sem er þarna á bakvið. Vil finna út af hverju ekki, hefur sennilega eitthvað að gera með þræði
            busyIndicator.IsBusy = true;

            //Setjum worker-inn í gang sem keyrir langa process-ið
            worker.RunWorkerAsync();
        }
 private void DeleteFiles(object sender, RoutedEventArgs e)
 {
     //Hreinsum möppur án þess að generate-a file-a
     ViewGenerator.DeleteViews(baseFolderPath.Text + pathToViews.Text);
     ViewModelGenerator.DeleteViewModels(baseFolderPath.Text + pathToViewModels.Text);
     ControllerGenerator.DeleteControllers(baseFolderPath.Text + pathToControllers.Text);
 }
Example #7
0
        public static void Init(
            IEventStoreRegistration eventStore,
            IReadModelRepository readModelRepository)
        {
            if (ReadModelRepository != null)
            {
                throw new InvalidOperationException("Bootstrapper is already initialized.");
            }

            ReadModelRepository = readModelRepository;

            var eventBus = new EventBus();

            eventStore.SetEventBusToPublish(eventBus);
            var viewModelGenerator = new ViewModelGenerator(readModelRepository);

            eventBus.Register <ItemCreated>(viewModelGenerator);
            eventBus.Register <ItemRenamed>(viewModelGenerator);
            eventBus.Register <UnitsAdded>(viewModelGenerator);
            eventBus.Register <UnitsRemoved>(viewModelGenerator);
            eventBus.Register <ItemDisabled>(viewModelGenerator);
            eventBus.Register <ItemEnabled>(viewModelGenerator);

            var commandBus = new CommandBus();

            commandBus.RegisterHandler(new CreateItemHandler(eventStore));
            commandBus.RegisterHandler(new RenameItemHandler(eventStore));
            commandBus.RegisterHandler(new AddUnitsHandler(eventStore));
            commandBus.RegisterHandler(new RemoveUnitsHandler(eventStore));
            commandBus.RegisterHandler(new DisableItemHandler(eventStore));
            commandBus.RegisterHandler(new EnableItemHandler(eventStore));
            CommandBus = commandBus;
        }
        public void OnChangedMethodNotFoundDiagnostic()
        {
            var                sourceCode       = @"using DevExpress.Mvvm.CodeGenerators;

namespace Test {
    [GenerateViewModel]
    partial class OnChangedMethodNotFound {
        [GenerateProperty(OnChangedMethod = ""NotCreatedChangedMethod"", OnChangingMethod = ""NotCreatedChangingMethod"")]
        int value1;
        [GenerateProperty(OnChangedMethod = ""IncorrectSignatureChangedMethod"", OnChangingMethod = ""IncorrectSignatureChangingMethod"")]
        int value2;

        public int IncorrectSignatureChangedMethod() { return 1; }
        public void IncorrectSignatureChangingMethod(int arg1, int arg2) { }
    }

    public class Program {
        public static void Main(string[] args) { }
    }
}
";
            Compilation        inputCompilation = Helper.CreateCompilation(sourceCode);
            ViewModelGenerator generator        = new ViewModelGenerator();

            GeneratorDriver driver = CSharpGeneratorDriver.Create(generator);

            _ = driver.RunGeneratorsAndUpdateCompilation(inputCompilation, out var outputCompilation, out var diagnostics);

            Assert.AreEqual(3, outputCompilation.SyntaxTrees.Count());
            Assert.AreEqual(4, diagnostics.Count());
            foreach (var diagnostic in diagnostics)
            {
                Assert.AreEqual(GeneratorDiagnostics.OnChangedMethodNotFound.Id, diagnostic.Id);
            }
        }
        public void ClassWithinClassDiagnostic()
        {
            var                sourceCode       = @"using DevExpress.Mvvm.CodeGenerators;

namespace Test {
    [GenerateViewModel]
    partial class OuterClass {
        [GenerateViewModel]
        partial class InnerClass { }
}

    public class Program {
        public static void Main(string[] args) { }
    }
}
";
            Compilation        inputCompilation = Helper.CreateCompilation(sourceCode);
            ViewModelGenerator generator        = new ViewModelGenerator();

            GeneratorDriver driver = CSharpGeneratorDriver.Create(generator);

            _ = driver.RunGeneratorsAndUpdateCompilation(inputCompilation, out var outputCompilation, out var diagnostics);

            Assert.AreEqual(3, outputCompilation.SyntaxTrees.Count());
            Assert.AreEqual(GeneratorDiagnostics.ClassWithinClass.Id, diagnostics[0].Id);
        }
        public void RaiseMethodNotFoundDiagnostic()
        {
            var                sourceCode       = @"using DevExpress.Mvvm.CodeGenerators;
using System.ComponentModel;

namespace Test {
    class ParentWithoutRaiseMethod : INotifyPropertyChanged, INotifyPropertyChanging {
        public event PropertyChangedEventHandler PropertyChanged;
        public event PropertyChangingEventHandler PropertyChanging;
    }
    [GenerateViewModel(ImplementINotifyPropertyChanging = true)]
    partial class ChildWithoutRaiseMethod : ParentWithoutRaiseMethod {
        [GenerateProperty]
        int value;
    }

    public class Program {
        public static void Main(string[] args) { }
    }
}
";
            Compilation        inputCompilation = Helper.CreateCompilation(sourceCode);
            ViewModelGenerator generator        = new ViewModelGenerator();

            GeneratorDriver driver = CSharpGeneratorDriver.Create(generator);

            _ = driver.RunGeneratorsAndUpdateCompilation(inputCompilation, out var outputCompilation, out var diagnostics);

            Assert.AreEqual(3, outputCompilation.SyntaxTrees.Count());
            Assert.AreEqual(2, diagnostics.Count());
            foreach (var diagnostic in diagnostics)
            {
                Assert.AreEqual(GeneratorDiagnostics.RaiseMethodNotFound.Id, diagnostic.Id);
            }
        }
Example #11
0
        public virtual void RefreshFromDataSource()
        {
            ViewModel = _dataSource != null?ViewModelGenerator.Convert(_dataSource, TimePeriodStart, TimePeriodType, ColumnFilter) : null;

            if (_selectedAppointment != null)
            {
                _selectedAppointment = ViewModel.FindAppointmentByDataObject(_selectedAppointment.AppointmentDataObject);
                if (_selectedAppointment != null)
                {
                    SelectAppointmentInternal(_selectedAppointment.AppointmentDataObject, false);
                }
            }
        }
        public void CanExecuteMethodNotFoundDiagnostic()
        {
            var                sourceCode       = @"using DevExpress.Mvvm.CodeGenerators;
using System.Threading.Tasks;

namespace Test {
    [GenerateViewModel]
    partial class CanExecuteMethodNotFound {
        [GenerateCommand(CanExecuteMethod = ""WrongParameter"")]
        public void Command1(int arg) { }
        [GenerateCommand(CanExecuteMethod = ""NoCreated"")]
        public void Command2(int arg) { }
        [GenerateCommand(CanExecuteMethod = ""ReturnNoBool"")]
        public void Command3(int arg) { }

        [GenerateCommand(CanExecuteMethod = ""WrongParameter"")]
        public Task AsyncCommand1(int arg) => Task.CompletedTask;
        [GenerateCommand(CanExecuteMethod = ""NoCreated"")]
        public Task AsyncCommand2(int arg) => Task.CompletedTask;
        [GenerateCommand(CanExecuteMethod = ""ReturnNoBool"")]
        public Task AsyncCommand3(int arg) => Task.CompletedTask;

        public bool WrongParameter() => true;
        public bool WrongParameter(int? arg) => arg.HasValue;
        public bool WrongParameter(string arg) => arg.Length > 0;
        public bool WrongParameter(int arg1, int arg2) => arg1 > arg2

        public int ReturnNoBool(int arg) => arg;
    }

    public class Program {
        public static void Main(string[] args) { }
    }
}
";
            Compilation        inputCompilation = Helper.CreateCompilation(sourceCode);
            ViewModelGenerator generator        = new ViewModelGenerator();

            GeneratorDriver driver = CSharpGeneratorDriver.Create(generator);

            _ = driver.RunGeneratorsAndUpdateCompilation(inputCompilation, out var outputCompilation, out var diagnostics);

            Assert.AreEqual(3, outputCompilation.SyntaxTrees.Count());
            Assert.AreEqual(6, diagnostics.Count());
            foreach (var diagnostic in diagnostics)
            {
                Assert.AreEqual(GeneratorDiagnostics.CanExecuteMethodNotFound.Id, diagnostic.Id);
            }
        }
Example #13
0
        // ------------------------------------------------ ViewModels Layer
        protected override void CreateViewModelsLayer()
        {
            TableNameInfo tableName = null;
            string        singleTableName = string.Empty, tablePluralName = string.Empty;


            foreach (var tableInfo in GeneratorSettingsManager.TARGET_DATABASE_TABLES_INFORMATIONS)
            {
                // گرفتن اسم جمع و مفرد جدول
                GetSingleAndPluralTableName(ref tableName, ref singleTableName, ref tablePluralName, tableInfo);

                // ساخت فایل های کلاس لایه ویـــو-مـــدل
                var    vmGenerator     = new ViewModelGenerator();
                string nameSpaceDesign = vmGenerator.Create(tableInfo, singleTableName, GeneratorSettingsManager.DESTINATION_PATH, GeneratorSettingsManager.TARGET_DATABASE_CONNECTION_STRING);
            }
        }
        public void MVVMNotAvailableDiagnostic()
        {
            var         sourceCode       = @"using DevExpress.Mvvm.CodeGenerators;
using System.Threading.Tasks;

namespace Test {
    [GenerateViewModel(ImplementIDataErrorInfo = true)]
    partial class WithIDataErrorInfo { }

    [GenerateViewModel]
    partial class WithCommand {
        [GenerateCommand]
        public void Command() { }
    }
    
    [GenerateViewModel]
    partial class WithAsyncCommand {
        [GenerateCommand]
        public Task AsyncCommand() { }
    }

    public class Program {
        public static void Main(string[] args) { }
    }
}
";
            Compilation inputCompilation = CSharpCompilation.Create("MyCompilation",
                                                                    new[] { CSharpSyntaxTree.ParseText(sourceCode) },
                                                                    new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location) },
                                                                    new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
            ViewModelGenerator generator = new ViewModelGenerator();

            GeneratorDriver driver = CSharpGeneratorDriver.Create(generator);

            _ = driver.RunGeneratorsAndUpdateCompilation(inputCompilation, out var outputCompilation, out var diagnostics);

            Assert.AreEqual(5, outputCompilation.SyntaxTrees.Count());

            Assert.AreEqual(3, diagnostics.Count());
            Assert.AreEqual(GeneratorDiagnostics.MVVMNotAvailable.Id, diagnostics[0].Id);
            Assert.AreEqual(GeneratorDiagnostics.MVVMNotAvailable.Id, diagnostics[1].Id);
            Assert.AreEqual(GeneratorDiagnostics.MVVMNotAvailable.Id, diagnostics[2].Id);
        }
Example #15
0
        static void Main(string[] args)
        {
            ConfigValues.Assembly = Assembly.GetExecutingAssembly();
            Console.WriteLine("Ingrese el nombre de la solucion: ");
            ConfigValues.SolutionName = Console.ReadLine();
            Console.WriteLine("Ingrese la ruta del Archivo: ");
            string originPath = Console.ReadLine();

            Console.WriteLine("Ingrese donde desea guardar los archivos generados: ");
            string destinyPath = Console.ReadLine();

            StateMachine stateMachine = new StateMachine(originPath);

            stateMachine.Run();

            PageGeneretor.GeneretePages(stateMachine, destinyPath);
            BasePageGenerator.CreateBasePage(stateMachine, destinyPath);
            ViewContainerGenerator.CreateViewContainer(stateMachine, destinyPath);
            PageManagerGenerator.CreatePageManager(stateMachine, destinyPath);
            ContentViewGenerator.GenereteContentsViews(stateMachine, destinyPath);
            ViewModelGenerator.GenereteViewModels(stateMachine, destinyPath);
            PageContainerGenerator.CreatePageContainer(stateMachine, destinyPath);
        }
        public void TwoSuitableMethodsDiagnostic()
        {
            var                sourceCode       = @"using DevExpress.Mvvm.CodeGenerators;
using System.Threading.Tasks;

namespace Test {
    [GenerateViewModel]
    partial class TwoSuitableMethods {
        [GenerateProperty(OnChangedMethod = ""TwoChangedMethods"", OnChangingMethod = ""TwoChangingMethods"")]
        int value;

        public void TwoChangedMethods() { }
        public void TwoChangedMethods(int arg) { }

        public void TwoChangingMethods() { }
        public void TwoChangingMethods(int arg) { }
    }

    public class Program {
        public static void Main(string[] args) { }
    }
}
";
            Compilation        inputCompilation = Helper.CreateCompilation(sourceCode);
            ViewModelGenerator generator        = new ViewModelGenerator();

            GeneratorDriver driver = CSharpGeneratorDriver.Create(generator);

            _ = driver.RunGeneratorsAndUpdateCompilation(inputCompilation, out var outputCompilation, out var diagnostics);

            Assert.AreEqual(3, outputCompilation.SyntaxTrees.Count());
            Assert.AreEqual(2, diagnostics.Count());
            foreach (var diagnostic in diagnostics)
            {
                Assert.AreEqual(GeneratorDiagnostics.TwoSuitableMethods.Id, diagnostic.Id);
            }
        }
 public void Init()
 {
     this.repositoryMock     = new Mock <IReadModelRepository>();
     this.viewModelGenerator = new ViewModelGenerator(this.repositoryMock.Object);
 }
Example #18
0
        public void GenerationFormat()
        {
            var         source           = @"using DevExpress.Mvvm.CodeGenerators;

namespace Test {
    [GenerateViewModel(ImplementINotifyPropertyChanging = true, ImplementIDataErrorInfo = true, ImplementISupportServices = true)]
    partial class Example {
        [GenerateProperty]
        [System.ComponentModel.DataAnnotations.Range(0,
                                                     1)]
        int property;
        
        [GenerateCommand]
        public void Method(int arg) { }
    }

    public class Program {
        public static void Main(string[] args) { }
    }
}
";
            Compilation inputCompilation = CSharpCompilation.Create("MyCompilation",
                                                                    new[] { CSharpSyntaxTree.ParseText(source) },
                                                                    new[] {
                MetadataReference.CreateFromFile(typeof(DelegateCommand).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(System.ComponentModel.DataAnnotations.RangeAttribute).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(System.Windows.Input.ICommand).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
            },
                                                                    new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
            ViewModelGenerator generator = new ViewModelGenerator();

            GeneratorDriver driver = CSharpGeneratorDriver.Create(generator);

            driver = driver.RunGeneratorsAndUpdateCompilation(inputCompilation, out var outputCompilation, out var diagnostics);

            GeneratorDriverRunResult runResult       = driver.GetRunResult();
            GeneratorRunResult       generatorResult = runResult.Results[0];

            var generatedCode = generatorResult.GeneratedSources[1].SourceText.ToString();
            var tabs          = 0;

            foreach (var str in generatedCode.Split(new[] { Environment.NewLine }, StringSplitOptions.None))
            {
                if (string.IsNullOrEmpty(str))
                {
                    continue;
                }

                if (str.Contains("}") && !str.Contains("{"))
                {
                    if (str.EndsWith("}"))
                    {
                        tabs--;
                    }
                    else
                    {
                        Assert.Fail();
                    }
                }

                var expectedLeadingWhitespaceCount = tabs * 4;
                var leadingWhitespaceCount         = str.Length - str.TrimStart().Length;
                Assert.AreEqual(expectedLeadingWhitespaceCount, leadingWhitespaceCount);

                if (str.EndsWith("{"))
                {
                    tabs++;
                }
            }
        }