Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Static Code Analysis

, 15 Mar 2010
A static code analyzer building method call networks + sample applications.
CodeAnalyzerAndToDoSample.zip
Generator
bin
.noclean
Arebis.CodeAnalysis.Static.dll
Arebis.CodeGeneration.dll
Arebis.CodeGeneration.VisualStudio.dll
Arebis.CodeGenerator.dll
Arebis.Common.dll
CGen.exe
Content.cst
Content.cst.gen
COperation.cst
COperation.cst.gen
files
GeneratorMain.cst
GeneratorMain.cst.gen
Index.cst
Index.cst.gen
IndexTop.cst
IndexTop.cst.gen
SOperation.cst
SOperation.cst.gen
UIOperation.cst
UIOperation.cst.gen
Output
SampleApp
LocalTestRun.testrunconfig
ToDoApplication
Infrastructure
Properties
Service References
ToDoContract
Properties
ToDoSample.vsmdi
ToDoService
Entities.edmx
Infrastructure
Properties
ToDoSample.Service.csproj.user
ToDoSampleDb.mdf
ToDoSampleDb_log.ldf
ToDoUnitTests
Properties
Testing
ToDoSample.UnitTests.csproj.user
UnitTests
StaticCodeAnalyzer
Arebis.CodeAnalysis.Static
Arebis.CodeAnalysis.Static.csproj.user
CodeModel.cd
Processors
Rules
Properties
Arebis.Common
Arebis
Collections
Generic
Reflection
Properties
System
Collections
Generic
Net2
Threading
Net2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ToDoSample.Contract;

namespace ToDoSample.Application
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static readonly DependencyProperty AllUsersProperty =
            DependencyProperty.Register("AllUsers", typeof(List<User>), typeof(MainWindow), new UIPropertyMetadata(default(List<User>)));
        public static readonly DependencyProperty CurrentUserProperty =
            DependencyProperty.Register("CurrentUser", typeof(User), typeof(MainWindow), new UIPropertyMetadata(default(User)));
        public static readonly DependencyProperty UserFilterProperty =
            DependencyProperty.Register("UserFilter", typeof(string), typeof(MainWindow), new UIPropertyMetadata(default(string)));
        public static readonly DependencyProperty ToDoItemsProperty =
            DependencyProperty.Register("ToDoItems", typeof(List<ToDoItem>), typeof(MainWindow), new UIPropertyMetadata(default(List<ToDoItem>)));
        public static readonly DependencyProperty CurrentToDoItemProperty =
            DependencyProperty.Register("CurrentToDoItem", typeof(ToDoItem), typeof(MainWindow), new UIPropertyMetadata(default(ToDoItem)));

        /// <summary>
        /// Constructor.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// AllUsers property.
        /// </summary>
        public List<User> AllUsers
        {
            get { return (List<User>)GetValue(AllUsersProperty); }
            set { SetValue(AllUsersProperty, value); }
        }

        /// <summary>
        /// CurrentUser property.
        /// </summary>
        public User CurrentUser
        {
            get { return (User)GetValue(CurrentUserProperty); }
            set { SetValue(CurrentUserProperty, value); }
        }

        /// <summary>
        /// UserFilter property.
        /// </summary>
        public string UserFilter
        {
            get { return (string)GetValue(UserFilterProperty); }
            set { SetValue(UserFilterProperty, value); }
        }

        /// <summary>
        /// ToDoItems property.
        /// </summary>
        public List<ToDoItem> ToDoItems
        {
            get { return (List<ToDoItem>)GetValue(ToDoItemsProperty); }
            set { SetValue(ToDoItemsProperty, value); }
        }

        /// <summary>
        /// CurrentToDoItem property.
        /// </summary>
        public ToDoItem CurrentToDoItem
        {
            get { return (ToDoItem)GetValue(CurrentToDoItemProperty); }
            set { SetValue(CurrentToDoItemProperty, value); }
        }

        public void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // On application startup, load list of users:
            using (var service = new ToDoService())
            {
                this.AllUsers = service.Invoke.ListAllUsers();
            }
        }

        public void UserSelected(object sender, SelectionChangedEventArgs e)
        {
            this.RefreshToDoItems();
        }

        public void ToDoItemSelected(object sender, SelectionChangedEventArgs e)
        {
            if (this.todoListBox.SelectedItem != null)
                this.CurrentToDoItem = ((ToDoItem)this.todoListBox.SelectedItem).WorkingCopy();
        }

        public void MarkDoneClicked(object sender, RoutedEventArgs e)
        {
            using (var service = new ToDoService())
            {
                service.Invoke.MarkToDoItemDone(this.CurrentToDoItem.Id);
            }

            this.RefreshToDoItems();
        }

        public void CreateNewToDoItemClicked(object sender, RoutedEventArgs e)
        {
            this.CurrentToDoItem = null;
            this.CurrentToDoItem = new ToDoItem();
        }

        public void SaveClicked(object sender, RoutedEventArgs e)
        {
            ToDoItem item = null;

            using (var service = new ToDoService())
            {
                if (this.CurrentToDoItem.IsNewInstance())
                {
                    item = service.Invoke.CreateToDoItem(
                        this.CurrentUser.Id,
                        this.CurrentToDoItem.Text,
                        this.CurrentToDoItem.DueDate
                    );
                }
                else
                {
                    item = service.Invoke.UpdateToDoItem(
                        this.CurrentToDoItem.Id,
                        this.CurrentToDoItem.Text,
                        this.CurrentToDoItem.DueDate
                    );
                }
            }

            this.RefreshToDoItems();

            this.todoListBox.SelectedItem = item;
        }

        public void DeleteClicked(object sender, RoutedEventArgs e)
        {
            using (var service = new ToDoService())
            {
                service.Invoke.DeleteToDoItem(this.CurrentToDoItem.Id);
            }

            this.RefreshToDoItems();
        }

        private void RefreshToDoItems()
        {
            // When a user is selected, retrieve it's ToDo items:
            using (var service = new ToDoService())
            {
                this.ToDoItems = service.Invoke.ListToDoItemsForUser(this.CurrentUser.Id);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rudi Breedenraedt
Architect Wolters Kluwer Belgium
Belgium Belgium
Rudi is a Software Architect at Wolters Kluwer Belgium.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 15 Mar 2010
Article Copyright 2010 by Rudi Breedenraedt
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid