Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new reporting host
        /// </summary>
        /// <param name="overrideTemplateNamespace">null or empty, if default templates should be used, else a assembly with templates.</param>
        /// <param name="overrideTemplateAssembly">null, if default templates should be used, else a assembly with templates.</param>
        /// <param name="fileOpener"></param>
        /// <param name="tempFileService"></param>
        /// <param name="errorReporter"></param>
        public AbstractReportingHost(string overrideTemplateNamespace, Assembly overrideTemplateAssembly, IFileOpener fileOpener, ITempFileService tempFileService, IReportingErrorReporter errorReporter)
        {
            if (fileOpener == null) throw new ArgumentNullException("fileOpener");
            if (tempFileService == null) throw new ArgumentNullException("tempFileService");
            if (errorReporter == null) throw new ArgumentNullException("errorReporter");

            _fileOpener = fileOpener;
            _tempFileService = tempFileService;
            _errorReporter = errorReporter;

            var settings = new NameValueCollection();
            settings["overrideReportTemplateNamespace"] = overrideTemplateNamespace;
            settings["overrideReportTemplateAssembly"] = overrideTemplateAssembly != null ? overrideTemplateAssembly.FullName : null;

            // use this.GetType() to prepare a change:
            // This class is abstract. Anyone who provides report templates should derive from this class (empty implementation).
            // This will distinguish between different reports.
            settings["baseReportTemplateNamespace"] = this.GetType().Namespace;
            settings["baseReportTemplateAssembly"] = this.GetType().Assembly.FullName;

            // Default Inititalization
            Initialize(settings);

            ErrorsAreFatal = false;
        }
Ejemplo n.º 2
0
        // TODO: Move that class into a common reporting assembly and create a own derived class with configuration
        /// <summary>
        /// Creates a new reporting host
        /// </summary>
        /// <param name="overrideTemplateNamespace">null or empty, if default templates should be used, else a assembly with templates.</param>
        /// <param name="overrideTemplateAssembly">null, if default templates should be used, else a assembly with templates.</param>
        /// <param name="fileOpener"></param>
        /// <param name="tmpService"></param>
        public AbstractReportingHost(string overrideTemplateNamespace, Assembly overrideTemplateAssembly, IFileOpener fileOpener, ITempFileService tmpService)
        {
            if (fileOpener == null)
            {
                throw new ArgumentNullException("fileOpener");
            }
            if (tmpService == null)
            {
                throw new ArgumentNullException("tmpService");
            }

            _fileOpener = fileOpener;
            _tmpService = tmpService;

            var settings = new NameValueCollection();

            settings["overrideReportTemplateNamespace"] = overrideTemplateNamespace;
            settings["overrideReportTemplateAssembly"]  = overrideTemplateAssembly != null ? overrideTemplateAssembly.FullName : null;

            // use this.GetType() to prepare a change:
            // This class should be abstract. Anyone who provides report templates should derive from this class (empty implementation).
            // This will distinguish between different reports.
            settings["baseReportTemplateNamespace"] = this.GetType().Namespace;
            settings["baseReportTemplateAssembly"]  = this.GetType().Assembly.FullName;

            // Default Inititalization
            Initialize(settings);

            ErrorsAreFatal = false;
        }
 public OpenProjectMenuItem(IFileOpener<IProject> projectFileOpener, IOpenFileDialog<IProject> openFileDialog,
     IProjectLoader projectLoader)
 {
     this.projectFileOpener = projectFileOpener;
     this.openFileDialog = openFileDialog;
     this.projectLoader = projectLoader;
 }
Ejemplo n.º 4
0
        public DtoPrinter(IFileOpener fileOpener, ITempFileService tmpService)
        {
            if (fileOpener == null) throw new ArgumentNullException("fileOpener");
            if (tmpService == null) throw new ArgumentNullException("tmpService");

            _fileOpener = fileOpener;
            _tmpService = tmpService;
        }
Ejemplo n.º 5
0
 public NavigationReportScreenViewModel(IViewModelDependencies appCtx,
     IZetboxContext dataCtx, ViewModel parent, NavigationScreen screen, IFileOpener fileOpener, ITempFileService tmpService)
     : base(appCtx, dataCtx, parent, screen)
 {
     _appCtx = appCtx;
     _fileOpener = fileOpener;
     _tmpService = tmpService;
 }
 public NavigationReportScreenViewModel(IViewModelDependencies appCtx,
     IZetboxContext dataCtx, ViewModel parent, NavigationScreen screen, IFileOpener fileOpener, ITempFileService tmpService)
     : base(appCtx, dataCtx, parent, screen)
 {
     _appCtx = appCtx;
     _fileOpener = fileOpener;
     _tmpService = tmpService;
 }
Ejemplo n.º 7
0
        public DocumentView OpenFile(string filePath, bool restoreView)
        {
            string extension = Path.GetExtension(filePath);

            // is it a project?
            if (extension.ToUpper() == ".SSPROJ")
            {
                OpenProject(filePath);
                return(null);
            }

            // if the file is already open, just switch to it
            DocumentTab tab = GetDocument(filePath);

            if (tab != null)
            {
                tab.Activate();
                return(tab.View);
            }

            // the IDE will look for a file opener explicitly declaring the file extension.
            // if that fails, then use the default opener (if any).
            DocumentView view = null;

            try
            {
                string fileExtension = Path.GetExtension(filePath);
                if (fileExtension.StartsWith("."))  // remove dot from extension
                {
                    fileExtension = fileExtension.Substring(1);
                }
                var plugins = from name in PluginManager.GetNames <IFileOpener>()
                              let plugin = PluginManager.Get <IFileOpener>(name)
                                           where plugin.FileExtensions.Contains(fileExtension)
                                           select plugin;
                IFileOpener defaultOpener = PluginManager.Get <IFileOpener>(Core.Settings.FileOpener);
                IFileOpener opener        = plugins.FirstOrDefault() ?? defaultOpener;
                if (opener != null)
                {
                    view = opener.Open(filePath);
                }
                else
                {
                    MessageBox.Show(string.Format("Sphere Studio doesn't know how to open that type of file and no default file opener is available.  Tip: Open Configuration Manager and check your plugins.\n\nFile Type: {0}\n\nPath to File:\n{1}", fileExtension.ToLower(), filePath),
                                    @"Unable to Open File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (IOException)
            {
                return(null);
            }

            if (view != null)
            {
                AddDocument(view, filePath, restoreView);
            }
            return(view);
        }
Ejemplo n.º 8
0
 public DtoCellViewModel(IViewModelDependencies dependencies, IZetboxContext dataCtx, DtoTableViewModel parent, IFileOpener fileOpener, ITempFileService tmpService, DtoRowViewModel row, DtoColumnViewModel column, GuiGridLocationAttribute location, ViewModel value, object debugInfo)
     : base(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
 {
     this.Parent = parent;
     this.Row = row;
     this.Column = column;
     this._location = location;
     this._value = value;
 }
Ejemplo n.º 9
0
    private void OpenMyFile()
    {
        IFileOpener opener = FileOpenerFactory.CreateFileOpener();

        if (opener.PresentFileOpenDialogToUser())
        {
            //do something with opener.RequestedFilePath;
        }
    }
Ejemplo n.º 10
0
 public TreeItemInstanceListViewModel(
     IViewModelDependencies appCtx,
     ZetboxConfig config,
     IFileOpener fileOpener,
     ITempFileService tmpService,
     IZetboxContext dataCtx, ViewModel parent,
     Func <IZetboxContext> workingCtxFactory,
     ObjectClass type,
     Func <IQueryable> qry)
     : base(appCtx, config, fileOpener, tmpService, dataCtx, parent, workingCtxFactory, type, qry)
 {
 }
 public TreeItemInstanceListViewModel(
     IViewModelDependencies appCtx,
     ZetboxConfig config,
     IFileOpener fileOpener,
     ITempFileService tmpService,
     IZetboxContext dataCtx, ViewModel parent,
     Func<IZetboxContext> workingCtxFactory,
     ObjectClass type,
     Func<IQueryable> qry)
     : base(appCtx, config, fileOpener, tmpService, dataCtx, parent, workingCtxFactory, type, qry)
 {
 }
Ejemplo n.º 12
0
 public TreeItemInstanceListViewModel(
     IViewModelDependencies appCtx,
     ZetboxConfig config,
     IFileOpener fileOpener,
     ITempFileService tmpService,
     Lazy<IUIExceptionReporter> errorReporter,
     IZetboxContext dataCtx, ViewModel parent,
     ObjectClass type,
     Func<IQueryable> qry)
     : base(appCtx, config, fileOpener, tmpService, errorReporter, dataCtx, parent, type, qry)
 {
 }
Ejemplo n.º 13
0
 public DtoBaseViewModel(IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService, object debugInfo)
     : base(dependencies, dataCtx, parent)
 {
     var dtoParent = parent as DtoBaseViewModel;
     if (dtoParent != null)
     {
         _background = dtoParent.Background;
     }
     _fileOpener = fileOpener;
     _tmpService = tmpService;
     this._debugInfo = debugInfo;
 }
Ejemplo n.º 14
0
        public DtoBaseViewModel(IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService, object debugInfo)
            : base(dependencies, dataCtx, parent)
        {
            var dtoParent = parent as DtoBaseViewModel;

            if (dtoParent != null)
            {
                _background = dtoParent.Background;
            }
            _fileOpener     = fileOpener;
            _tmpService     = tmpService;
            this._debugInfo = debugInfo;
        }
        public StartupWindowViewModel(ISettingsSerializer settingsSerializer,
            IProjectLoader projectLoader,
            IFileOpener<IProject> projectOpener)
        {
            Check.IfIsNull(settingsSerializer).Throw<ArgumentNullException>(() => settingsSerializer);
            Check.IfIsNull(projectLoader).Throw<ArgumentNullException>(() => projectLoader);
            Check.IfIsNull(projectOpener).Throw<ArgumentNullException>(() => projectOpener);

            this.projectLoader = projectLoader;
            this.projectOpener = projectOpener;
            var settings = settingsSerializer.Read();
            recentProjects = settings.RecentProjects;
        }
Ejemplo n.º 16
0
        public DtoPrinter(IFileOpener fileOpener, ITempFileService tmpService)
        {
            if (fileOpener == null)
            {
                throw new ArgumentNullException("fileOpener");
            }
            if (tmpService == null)
            {
                throw new ArgumentNullException("tmpService");
            }

            _fileOpener = fileOpener;
            _tmpService = tmpService;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IFileOpener fileOpener)
        {
            Workspace.Workspace.Init();
            FileOpener = fileOpener;

            InitiateDicomPanelModels();

            SubscribeToMessages();

            Workspace.Workspace.Current.Axial    = AxialPanelModel;
            Workspace.Workspace.Current.Coronal  = CoronalPanelModel;
            Workspace.Workspace.Current.Sagittal = SagittalPanelModel;

            SimpleIoc.Default.GetInstance <IProgressView>().DataContext = SimpleIoc.Default.GetInstance <IProgressService>();
        }
        public StartupWindowViewModel Setup(ISettingsSerializer settingsSerializer = null, IProjectLoader projectLoader = null, IFileOpener<IProject> fileOpener = null)
        {
            projectLoader = projectLoader ?? new StubIProjectLoader();
            fileOpener = fileOpener ?? new StubIFileOpener<IProject>();

            settingsSerializer = settingsSerializer ?? new StubISettingsSerializer
            {
                Read = () => new StubIEditorSettings
                {
                    RecentProjectsGet = () => recentProjects
                }
            };

            return new StartupWindowViewModel(settingsSerializer, projectLoader, fileOpener);
            ;
        }
Ejemplo n.º 19
0
        //private List<string> _tempDirs = new List<string>();

        /// <summary>
        /// Creates a new reporting host
        /// </summary>
        /// <param name="fileOpener"></param>
        /// <param name="tmpService"></param>
        public AbstractReportingHost(IFileOpener fileOpener, ITempFileService tmpService)
            : this(null, null, fileOpener, tmpService)
        {
        }
Ejemplo n.º 20
0
 public BlobActions(IFileOpener fileOpener)
 {
     _fileOpener = fileOpener;
 }
Ejemplo n.º 21
0
 public MigrationProjectActions(IViewModelFactory mdlFactory, IFileOpener fileOpener)
 {
     _mdlFactory = mdlFactory;
     _fileOpener = fileOpener;
 }
Ejemplo n.º 22
0
 public DtoTabbedViewModel(IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService, object debugInfo)
     : base(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
 {
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Creates a new reporting host
 /// </summary>
 /// <param name="fileOpener"></param>
 /// <param name="tmpService"></param>
 public ReportingHost(IFileOpener fileOpener, ITempFileService tmpService)
     : base(null, null, fileOpener, tmpService)
 {
 }
Ejemplo n.º 24
0
 public ReportingHost(IFileOpener fileOpener, ITempFileService tempFileService, IReportingErrorReporter errorReporter)
     : base(fileOpener, tempFileService, errorReporter)
 {
 }
Ejemplo n.º 25
0
 public DtoRowViewModel(IViewModelDependencies dependencies, IZetboxContext dataCtx, DtoTableViewModel parent, IFileOpener fileOpener, ITempFileService tmpService, int rowIdx, object debugInfo)
     : base(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
 {
     this.Parent = parent;
     this._row   = rowIdx;
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Creates a new reporting host
 /// </summary>
 public AbstractReportingHost(IFileOpener fileOpener, ITempFileService tempFileService, IReportingErrorReporter errorReporter)
     : this(null, null, fileOpener, tempFileService, errorReporter)
 {
 }
Ejemplo n.º 27
0
 public ReportScreenViewModel(IViewModelDependencies appCtx,
                              IZetboxContext dataCtx, ViewModel parent, NavigationScreen screen, IFileOpener fileOpener, ITempFileService tmpService)
     : base(appCtx, dataCtx, parent, screen, fileOpener, tmpService)
 {
 }
Ejemplo n.º 28
0
 public DtoRowViewModel(IViewModelDependencies dependencies, IZetboxContext dataCtx, DtoTableViewModel parent, IFileOpener fileOpener, ITempFileService tmpService, int rowIdx, object debugInfo)
     : base(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
 {
     this.Parent = parent;
     this._row = rowIdx;
 }
Ejemplo n.º 29
0
        private static DtoBaseViewModel BuildEmptyFrom(object root, PropertyInfo parentProp, object dto, IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService)
        {
            if (dto == null)
            {
                // cannot inspect runtime type on null reference
                return(null);
            }
            var isPrintableRoot = ExtractIsPrintableRoot(parentProp, dto);

            var dataProps    = new List <PropertyInfo>();
            var percentProps = new Dictionary <string, PropertyInfo>();

            ExtractProps(dto.GetType(), dataProps, percentProps);

            var items = new List <DtoBaseViewModel>();

            foreach (var prop in dataProps)
            {
                var value     = dto.GetPropertyValue <object>(prop.Name);
                var viewModel = BuildFrom(root, prop, value, dependencies, dataCtx, parent, fileOpener, tmpService);
                if (viewModel == null)
                {
                    continue;                    // do not add without content
                }
                var valueModel = viewModel as DtoValueViewModel;
                if (valueModel != null && percentProps.ContainsKey(prop.Name))
                {
                    valueModel.AlternateRepresentation          = string.Format("{0:0.00} %", 100 * Convert.ToDouble(dto.GetPropertyValue <object>(percentProps[prop.Name].Name)));
                    valueModel.AlternateRepresentationAlignment = ContentAlignment.MiddleRight;
                }

                items.Add(viewModel);
            }

            var result = parent as DtoGroupedViewModel;

            if (result != null)
            {
                items.ForEach(result.Items.Add);
                result.IsPrintableRoot = isPrintableRoot;
                return(result);
            }
            else if (items.Count == 1)
            {
                items[0].IsPrintableRoot = isPrintableRoot;
                return(items[0]);
            }
            else
            {
                throw new NotSupportedException(string.Format("Cannot GuiSkipViewModel on multi-property class [{0}], when having a non-grouped parent [{1}]", dto.GetType(), parent.GetType()));
            }
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Creates a new reporting host
 /// </summary>
 /// <param name="overrideTemplateNamespace">null or empty, if default templates should be used, else a assembly with templates.</param>
 /// <param name="overrideTemplateAssembly">null, if default templates should be used, else a assembly with templates.</param>
 /// <param name="fileOpener"></param>
 /// <param name="tmpService"></param>
 public ReportingHost(string overrideTemplateNamespace, System.Reflection.Assembly overrideTemplateAssembly, IFileOpener fileOpener, ITempFileService tmpService)
     : base(overrideTemplateNamespace, overrideTemplateAssembly, fileOpener, tmpService)
 {
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Creates a new reporting host
 /// </summary>
 /// <param name="fileOpener"></param>
 /// <param name="tmpService"></param>
 public ReportingHost(IFileOpener fileOpener, ITempFileService tmpService)
     : base(null, null, fileOpener, tmpService)
 {
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Creates a new reporting host
 /// </summary>
 public ReportingHost(IFileOpener fileOpener, ITempFileService tempFileService, IReportingErrorReporter errorReporter)
     : base(null, null, fileOpener, tempFileService, errorReporter)
 {
 }
Ejemplo n.º 33
0
 public DtoTableViewModel(IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService, object debugInfo)
     : base(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
 {
     Rows    = new ObservableCollection <DtoRowViewModel>();
     Columns = new ObservableCollection <DtoColumnViewModel>();
     Cells   = new ObservableCollection <DtoCellViewModel>();
 }
Ejemplo n.º 34
0
 public ReportScreenViewModel(IViewModelDependencies appCtx, 
     IZetboxContext dataCtx, ViewModel parent, NavigationScreen screen, IFileOpener fileOpener, ITempFileService tmpService)
     : base(appCtx, dataCtx, parent, screen, fileOpener, tmpService)
 {
 }
Ejemplo n.º 35
0
 public DtoCellViewModel(IViewModelDependencies dependencies, IZetboxContext dataCtx, DtoTableViewModel parent, IFileOpener fileOpener, ITempFileService tmpService, DtoRowViewModel row, DtoColumnViewModel column, GuiGridLocationAttribute location, ViewModel value, object debugInfo)
     : base(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
 {
     this.Parent    = parent;
     this.Row       = row;
     this.Column    = column;
     this._location = location;
     this._value    = value;
 }
Ejemplo n.º 36
0
 public ReportingHost(string overrideTemplateNamespace, Assembly overrideTemplateAssembly, IFileOpener fileOpener, ITempFileService tempFileService, IReportingErrorReporter errorReporter)
     : base(overrideTemplateNamespace, overrideTemplateAssembly, fileOpener, tempFileService, errorReporter)
 {
 }
Ejemplo n.º 37
0
 public SourceTableActions(IViewModelFactory mdlFactory, IFileOpener fileOpener)
 {
     _mdlFactory = mdlFactory;
     _fileOpener = fileOpener;
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Creates a new reporting host
 /// </summary>
 /// <param name="overrideTemplateNamespace">null or empty, if default templates should be used, else a assembly with templates.</param>
 /// <param name="overrideTemplateAssembly">null, if default templates should be used, else a assembly with templates.</param>
 /// <param name="fileOpener"></param>
 /// <param name="tmpService"></param>
 public ReportingHost(string overrideTemplateNamespace, System.Reflection.Assembly overrideTemplateAssembly, IFileOpener fileOpener, ITempFileService tmpService)
     : base(overrideTemplateNamespace, overrideTemplateAssembly, fileOpener, tmpService)
 {
 }
Ejemplo n.º 39
0
 public MigrationProjectActions(IViewModelFactory mdlFactory, IFileOpener fileOpener)
 {
     _mdlFactory = mdlFactory;
     _fileOpener = fileOpener;
 }
Ejemplo n.º 40
0
 public DtoGroupedViewModel(IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService, object debugInfo)
     : base(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
 {
     Items = new ObservableCollection <DtoBaseViewModel>();
 }
Ejemplo n.º 41
0
 public DtoGroupedViewModel(IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService, object debugInfo)
     : base(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
 {
     Items = new ObservableCollection<DtoBaseViewModel>();
 }
Ejemplo n.º 42
0
        private static DtoBaseViewModel BuildFrom(object root, PropertyInfo parentProp, object dto, IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService)
        {
            if (dto == null)
            {
                return(null);
            }

            // avoid using the prop's attributes or type if the dto is not assignable to the property, e.g. when working on a list's elements
            if (parentProp != null && parentProp.PropertyType.IsAssignableFrom(dto.GetType()))
            {
                var propertyType = dto.GetType();
                if (typeof(byte).IsAssignableFrom(propertyType) ||
                    typeof(int).IsAssignableFrom(propertyType) ||
                    typeof(uint).IsAssignableFrom(propertyType) ||
                    typeof(long).IsAssignableFrom(propertyType) ||
                    typeof(ulong).IsAssignableFrom(propertyType) ||
                    typeof(double).IsAssignableFrom(propertyType) ||
                    typeof(float).IsAssignableFrom(propertyType) ||
                    typeof(decimal).IsAssignableFrom(propertyType) ||
                    typeof(DateTime).IsAssignableFrom(propertyType)

                    || typeof(byte?).IsAssignableFrom(propertyType) ||
                    typeof(int?).IsAssignableFrom(propertyType) ||
                    typeof(uint?).IsAssignableFrom(propertyType) ||
                    typeof(long?).IsAssignableFrom(propertyType) ||
                    typeof(ulong?).IsAssignableFrom(propertyType) ||
                    typeof(double?).IsAssignableFrom(propertyType) ||
                    typeof(float?).IsAssignableFrom(propertyType) ||
                    typeof(decimal?).IsAssignableFrom(propertyType) ||
                    typeof(DateTime?).IsAssignableFrom(propertyType)

                    || typeof(string).IsAssignableFrom(propertyType))
                {
                    return(FormatValue(root, parentProp, dto, dependencies, dataCtx, parent, fileOpener, tmpService));
                }
                else
                {
                    var propAttrs = parentProp.GetCustomAttributes(false);
                    foreach (var attr in propAttrs)
                    {
                        if (attr is GuiTabbedAttribute)
                        {
                            return(BuildTabbedFrom(root, parentProp, dto, dependencies, dataCtx, parent, fileOpener, tmpService));
                        }
                        else if (attr is GuiGridAttribute)
                        {
                            return(BuildGridFrom(root, parentProp, dto, dependencies, dataCtx, parent, fileOpener, tmpService));
                        }
                        else if (attr is GuiTableAttribute)
                        {
                            return(BuildTableFrom(root, parentProp, dto, dependencies, dataCtx, parent, fileOpener, tmpService));
                        }
                    }
                }
            }

            var type     = dto.GetType();
            var skipAttr = type.GetCustomAttributes(typeof(GuiSkipViewModelAttribute), false);

            if (skipAttr.Length > 0)
            {
                return(BuildEmptyFrom(root, parentProp, dto, dependencies, dataCtx, parent, fileOpener, tmpService));
            }

            var attrs = type.GetCustomAttributes(false);

            foreach (var attr in attrs)
            {
                if (attr is GuiTabbedAttribute)
                {
                    return(BuildTabbedFrom(root, parentProp, dto, dependencies, dataCtx, parent, fileOpener, tmpService));
                }
                else if (attr is GuiGridAttribute)
                {
                    return(BuildGridFrom(root, parentProp, dto, dependencies, dataCtx, parent, fileOpener, tmpService));
                }
                else if (attr is GuiTableAttribute)
                {
                    return(BuildTableFrom(root, parentProp, dto, dependencies, dataCtx, parent, fileOpener, tmpService));
                }
            }

            if (dto.GetType().HasGenericDefinition(typeof(XmlDictionary <,>)))
            {
                return(BuildTabbedFrom(root, parentProp, dto, dependencies, dataCtx, parent, fileOpener, tmpService));
            }
            else if (typeof(IEnumerable).IsAssignableFrom(dto.GetType()))
            {
                return(BuildTableFrom(root, parentProp, dto, dependencies, dataCtx, parent, fileOpener, tmpService));
            }
            else
            {
                return(BuildGroupFrom(root, parentProp, dto, dependencies, dataCtx, parent, fileOpener, tmpService));
            }
        }
Ejemplo n.º 43
0
        /// <summary>
        /// Build a tabbed interface from the specified object. Page oriented output might create new pages for each tab or similar.
        /// </summary>
        public static DtoTabbedViewModel BuildTabbedFrom(object root, PropertyInfo parentProp, object dto, IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService)
        {
            if (dto == null)
            {
                return(null);
            }

            var debugInfo = parentProp == null
                ? string.Format("topTabbed:{0}", dto.GetType())
                : string.Format("tabbed:{0}.{1} = {2}", parentProp.DeclaringType, parentProp.Name, dto.GetType());

            var result = new DtoTabbedViewModel(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
            {
                Title           = ExtractTitle(parentProp, dto),
                Description     = ExtractDescription(parentProp, dto),
                Background      = ExtractBackground(parentProp, dto),
                Formatting      = ExtractFormatting(parentProp, dto),
                IsPrintableRoot = ExtractIsPrintableRoot(parentProp, dto),
                Root            = root,
                Data            = dto,
            };

            // need to extract value from XmlDictionaries
            var dtoData = dto as IXmlDictionaryDtoData;

            if (dtoData != null)
            {
                foreach (var kvp in dtoData.DtoData.OrderBy(e => e.Key))
                {
                    var item = BuildFrom(root, parentProp, kvp.Value, dependencies, dataCtx, result, fileOpener, tmpService);
                    if (item != null)
                    {
                        result.Items.Add(item);
                    }
                }
            }
            else if (typeof(IEnumerable).IsAssignableFrom(dto.GetType()))
            {
                foreach (var element in ((IEnumerable)dto))
                {
                    var item = BuildFrom(root, parentProp, element, dependencies, dataCtx, result, fileOpener, tmpService);
                    if (item != null)
                    {
                        result.Items.Add(item);
                    }
                }
            }
            else
            {
                var dataProps    = new List <PropertyInfo>();
                var percentProps = new Dictionary <string, PropertyInfo>();
                ExtractProps(dto.GetType(), dataProps, percentProps);

                if (percentProps.Count != 0)
                {
                    // TODO: fail: cannot display in grid?
                }

                foreach (var prop in dataProps)
                {
                    var val  = dto.GetPropertyValue <object>(prop.Name);
                    var item = BuildFrom(root, prop, val, dependencies, dataCtx, result, fileOpener, tmpService);
                    if (item != null)
                    {
                        result.Items.Add(item);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 44
0
 public SourceTableActions(IViewModelFactory mdlFactory, IFileOpener fileOpener)
 {
     _mdlFactory = mdlFactory;
     _fileOpener = fileOpener;
 }
Ejemplo n.º 45
0
        private static DtoBaseViewModel FormatValue(object root, PropertyInfo parentProp, object dto, IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService)
        {
            if (dto == null)
            {
                throw new ArgumentNullException("dto");
            }
            if (parentProp == null)
            {
                throw new ArgumentNullException("parentProp");
            }

            DtoBaseViewModel valueModel = null;
            var propertyType            = dto.GetType();
            var title        = ExtractTitle(parentProp, dto);
            var description  = ExtractDescription(parentProp, dto);
            var background   = ExtractBackground(parentProp, dto);
            var asPercent    = parentProp.GetCustomAttributes(typeof(GuiFormatAsPercentAttribute), true).Length > 0;
            var formatString = parentProp.GetCustomAttributes(typeof(GuiFormatStringAttribute), true).OfType <GuiFormatStringAttribute>().Select(gfsa => gfsa.FormatString).SingleOrDefault();

            if (typeof(long).IsAssignableFrom(propertyType) || typeof(int).IsAssignableFrom(propertyType) || typeof(short).IsAssignableFrom(propertyType))
            {
                valueModel = new DtoValueViewModel(dependencies, dataCtx, parent, fileOpener, tmpService, string.Format("value:{0}.{1} = {2}", parentProp.DeclaringType, parentProp.Name, dto))
                {
                    Value           = asPercent ? string.Format("{0} %", 100 * Convert.ToInt64(dto)) : string.Format(formatString ?? "{0}", dto),
                    ValueAlignment  = ContentAlignment.MiddleRight,
                    Title           = title,
                    Description     = description,
                    Formatting      = ExtractFormatting(parentProp, dto),
                    IsPrintableRoot = ExtractIsPrintableRoot(parentProp, dto),
                    Root            = root,
                    Data            = dto,
                };
                if (!string.IsNullOrEmpty(background))
                {
                    valueModel.Background = background;
                }
            }
            else if (typeof(double).IsAssignableFrom(propertyType) || typeof(decimal).IsAssignableFrom(propertyType) || typeof(float).IsAssignableFrom(propertyType))
            {
                valueModel = new DtoValueViewModel(dependencies, dataCtx, parent, fileOpener, tmpService, string.Format("value:{0}.{1} = {2}", parentProp.DeclaringType, parentProp.Name, dto))
                {
                    Value           = asPercent ? string.Format("{0:0.00} %", 100 * Convert.ToDouble(dto)) : string.Format(formatString ?? "{0:0.00}", dto),
                    ValueAlignment  = ContentAlignment.MiddleRight,
                    Title           = title,
                    Description     = description,
                    Formatting      = ExtractFormatting(parentProp, dto),
                    IsPrintableRoot = ExtractIsPrintableRoot(parentProp, dto),
                    Root            = root,
                    Data            = dto,
                };
                if (!string.IsNullOrEmpty(background))
                {
                    valueModel.Background = background;
                }
            }
            else if (typeof(string).IsAssignableFrom(propertyType))
            {
                valueModel = new DtoValueViewModel(dependencies, dataCtx, parent, fileOpener, tmpService, string.Format("value:{0}.{1} = {2}", parentProp.DeclaringType, parentProp.Name, dto))
                {
                    Value           = (dto ?? string.Empty).ToString(),
                    Title           = title,
                    Description     = description,
                    Formatting      = ExtractFormatting(parentProp, dto),
                    IsPrintableRoot = ExtractIsPrintableRoot(parentProp, dto),
                    Root            = root,
                    Data            = dto,
                };
                if (!string.IsNullOrEmpty(background))
                {
                    valueModel.Background = background;
                }
            }
            else if (typeof(DateTime).IsAssignableFrom(propertyType))
            {
                valueModel = new DtoValueViewModel(dependencies, dataCtx, parent, fileOpener, tmpService, string.Format("value:{0}.{1} = {2}", parentProp.DeclaringType, parentProp.Name, dto))
                {
                    Value           = dto != null ? ((DateTime)dto).ToShortDateString() : string.Empty,
                    Title           = title,
                    Description     = description,
                    Formatting      = ExtractFormatting(parentProp, dto),
                    IsPrintableRoot = ExtractIsPrintableRoot(parentProp, dto),
                    Root            = root,
                    Data            = dto,
                };
                if (!string.IsNullOrEmpty(background))
                {
                    valueModel.Background = background;
                }
            }
            else
            {
                valueModel = BuildFrom(root, parentProp, dto, dependencies, dataCtx, parent, fileOpener, tmpService);
            }

            if (valueModel == null)
            {
                Logging.Client.WarnFormat("Unable to format a value from dto '{0}' of type '{1}' contained in property {2}",
                                          dto,
                                          dto.GetType().Name,
                                          string.Format("{0}.{1}", parentProp.DeclaringType.Name, parentProp.Name));
            }

            return(valueModel);
        }
Ejemplo n.º 46
0
        /// <summary>
        /// Creates a descriptive grouping of the specified object
        /// </summary>
        public static DtoGroupedViewModel BuildGroupFrom(object root, PropertyInfo parentProp, object dto, IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService)
        {
            if (dto == null)
            {
                // cannot inspect runtime type on null reference
                return(null);
            }
            var debugInfo = parentProp == null
                ? string.Format("topgroup:{0}", dto.GetType())
                : string.Format("group:{0}.{1} = {2}", parentProp.DeclaringType, parentProp.Name, dto.GetType());

            var result = new DtoGroupedViewModel(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
            {
                Title           = ExtractTitle(parentProp, dto),
                Description     = ExtractDescription(parentProp, dto),
                Background      = ExtractBackground(parentProp, dto),
                Formatting      = ExtractFormatting(parentProp, dto),
                IsPrintableRoot = ExtractIsPrintableRoot(parentProp, dto),
                Root            = root,
                Data            = dto,
            };

            var dataProps    = new List <PropertyInfo>();
            var percentProps = new Dictionary <string, PropertyInfo>();

            ExtractProps(dto.GetType(), dataProps, percentProps);

            foreach (var prop in dataProps)
            {
                var value     = dto.GetPropertyValue <object>(prop.Name);
                var viewModel = BuildFrom(root, prop, value, dependencies, dataCtx, parent, fileOpener, tmpService);
                if (viewModel == null)
                {
                    continue;                    // do not add without content
                }
                var valueModel = viewModel as DtoValueViewModel;
                if (valueModel != null && percentProps.ContainsKey(prop.Name))
                {
                    valueModel.AlternateRepresentation          = string.Format("{0:0.00} %", 100 * Convert.ToDouble(dto.GetPropertyValue <object>(percentProps[prop.Name].Name)));
                    valueModel.AlternateRepresentationAlignment = ContentAlignment.MiddleRight;
                }

                result.Items.Add(viewModel);
            }

            return(result);
        }
Ejemplo n.º 47
0
 public BlobActions(IFileOpener fileOpener)
 {
     _fileOpener = fileOpener;
 }
Ejemplo n.º 48
0
 public DtoTabbedViewModel(IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService, object debugInfo)
     : base(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
 {
 }
Ejemplo n.º 49
0
        /// <summary>
        /// Creates a table out of a list of DTOs
        /// </summary>
        public static DtoTableViewModel BuildTableFrom(object root, PropertyInfo parentProp, object dto, IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService)
        {
            if (dto == null)
            {
                return(null);
            }

            // skip XmlDictionary to its values
            if (dto.GetType().HasGenericDefinition(typeof(XmlDictionary <,>)))
            {
                dto = dto.GetPropertyValue <object>("Values");
            }

            var debugInfo = parentProp == null
                ? string.Format("topTable: {0}", dto.GetType())
                : string.Format("table:{0}.{1} = {2}", parentProp.DeclaringType, parentProp.Name, dto.GetType());

            var result = new DtoTableViewModel(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
            {
                IsDataTable         = true,
                Title               = ExtractTitle(parentProp, dto),
                Description         = ExtractDescription(parentProp, dto),
                Background          = ExtractBackground(parentProp, dto),
                AlternateBackground = ExtractAlternateBackground(parentProp, dto),
                Formatting          = ExtractFormatting(parentProp, dto),
                IsPrintableRoot     = ExtractIsPrintableRoot(parentProp, dto),
                Root = root,
                Data = dto,
            };

            var dataProps    = new List <PropertyInfo>();
            var percentProps = new Dictionary <string, PropertyInfo>();

            ExtractProps(dto.GetType().FindElementTypes().SingleOrDefault(t => t != typeof(object)) ?? dto.GetType(),
                         dataProps, percentProps);

            var allColumns = new Dictionary <PropertyInfo, DtoColumnViewModel>();
            int columnIdx  = 0;

            foreach (var prop in dataProps)
            {
                var column = new DtoColumnViewModel(dependencies, dataCtx, result, fileOpener, tmpService, columnIdx, string.Format("column:{0}.{1}", dto.GetType(), prop.Name))
                {
                    Title       = ExtractTitle(prop, null),
                    Description = ExtractDescription(prop, null),
                    Background  = ExtractBackground(prop, null)
                };
                allColumns[prop] = column;
                columnIdx       += 1;
                result.Columns.Add(column);
            }

            int rowIdx = 0;

            foreach (var line in (IEnumerable)dto)
            {
                var row = new DtoRowViewModel(dependencies, dataCtx, result, fileOpener, tmpService, rowIdx, string.Format("row:{0}[{1}]", dto.GetType(), rowIdx));
                if (rowIdx % 2 == 0)
                {
                    row.Background = result.AlternateBackground;
                }

                result.Rows.Add(row);

                columnIdx = -1;
                foreach (var prop in dataProps)
                {
                    var propName = prop.Name;
                    columnIdx += 1;
                    var viewModel = BuildFrom(root, prop, line.GetPropertyValue <object>(propName), dependencies, dataCtx, row, fileOpener, tmpService);
                    if (viewModel == null)
                    {
                        continue;           // do not add cell without content
                    }
                    viewModel.Title = null; // do not display title in table
                    var valueModel = viewModel as DtoValueViewModel;
                    if (valueModel != null && percentProps.ContainsKey(propName))
                    {
                        valueModel.AlternateRepresentation          = string.Format("{0:0.00} %", 100 * Convert.ToDouble(dto.GetPropertyValue <object>(percentProps[propName].Name)));
                        valueModel.AlternateRepresentationAlignment = ContentAlignment.MiddleRight;
                    }

                    var cellDebugInfo = parentProp == null
                        ? string.Format("topCell:[{0}].{1}", rowIdx, propName)
                        : string.Format("cell:{0}.{1}[{2}].{3}", parentProp.DeclaringType, parentProp.Name, rowIdx, propName);

                    var cell = new DtoCellViewModel(dependencies, dataCtx, result, fileOpener, tmpService, row, allColumns[prop], new GuiGridLocationAttribute(rowIdx, columnIdx), viewModel, cellDebugInfo);
                    result.Cells.Add(cell);
                }

                rowIdx += 1;
            }

            return(result);
        }
Ejemplo n.º 50
0
 public DtoTableViewModel(IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService, object debugInfo)
     : base(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
 {
     Rows = new ObservableCollection<DtoRowViewModel>();
     Columns = new ObservableCollection<DtoColumnViewModel>();
     Cells = new ObservableCollection<DtoCellViewModel>();
 }
Ejemplo n.º 51
0
 // looks, sounds and smells like fetch?
 public static DtoBaseViewModel BuildFrom(object root, IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService)
 {
     return(BuildFrom(root, null, root, dependencies, dataCtx, parent, fileOpener, tmpService));
 }
Ejemplo n.º 52
0
        /// <summary>
        /// Arranges the contained Objects in a grid. Use GridLocation to specify where
        /// </summary>
        public static DtoTableViewModel BuildGridFrom(object root, PropertyInfo parentProp, object dto, IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService)
        {
            if (dto == null)
            {
                return(null);
            }

            var debugInfo = parentProp == null
                ? string.Format("topGrid:{0}", dto.GetType())
                : string.Format("grid:{0}.{1} = {2}", parentProp.DeclaringType, parentProp.Name, dto.GetType());

            var result = new DtoTableViewModel(dependencies, dataCtx, parent, fileOpener, tmpService, debugInfo)
            {
                IsDataTable     = false,
                Title           = ExtractTitle(parentProp, dto),
                Description     = ExtractDescription(parentProp, dto),
                Background      = ExtractBackground(parentProp, dto),
                Formatting      = ExtractFormatting(parentProp, dto),
                IsPrintableRoot = ExtractIsPrintableRoot(parentProp, dto),
                Root            = root,
                Data            = dto,
            };

            // TODO: add description

            var cells = new Dictionary <GuiGridLocationAttribute, ViewModel>();

            if (typeof(IEnumerable).IsAssignableFrom(dto.GetType()))
            {
                var propertyMsg = parentProp == null
                    ? string.Empty
                    : string.Format(" contained in property {0}.{1}", parentProp.DeclaringType.Name, parentProp.Name);
                Logging.Client.WarnFormat("Unable to format a list from dto '{0}' of type '{1}'{2}",
                                          dto,
                                          dto.GetType().Name,
                                          propertyMsg);
            }
            else
            {
                var dataProps    = new List <PropertyInfo>();
                var percentProps = new Dictionary <string, PropertyInfo>();
                ExtractProps(dto.GetType(), dataProps, percentProps);

                if (percentProps.Count != 0)
                {
                    // TODO: fail: cannot display in grid?
                }

                foreach (var prop in dataProps)
                {
                    var value = BuildFrom(root, prop, dto.GetPropertyValue <object>(prop.Name), dependencies, dataCtx, result, fileOpener, tmpService);
                    if (value == null)
                    {
                        continue;                // do not add without content
                    }
                    // struct initialises to (0,0) by default
                    var gridLocation = prop.GetCustomAttributes(false)
                                       .OfType <GuiGridLocationAttribute>()
                                       .Single();

                    // TODO: avoid silent overwriting

                    /*
                     * TODO: might want to consider automatic appending?
                     * That is, given a class with five properties that should be arranged
                     *
                     *    A | B | C
                     *    D | E | -
                     *
                     * specify
                     *
                     *    [GridRow(0)]
                     *    int A { get; set; }
                     *    int B { get; set; }
                     *    int C { get; set; }
                     *    [GridRow(1)]
                     *    int D { get; set; }
                     *    int E { get; set; }
                     *
                     * or even only [GridRowBreak] on D?
                     */
                    cells[gridLocation] = value;
                }
            }

            var allRows = new Dictionary <int, DtoRowViewModel>();

            for (int i = cells.Keys.Select(k => k.Row).Max(); i >= 0; i--)
            {
                allRows[i] = new DtoRowViewModel(dependencies, dataCtx, result, fileOpener, tmpService, i, string.Format("gridrow:{0}.[{1}]", dto.GetType(), i));
            }

            var allColumns = new Dictionary <int, DtoColumnViewModel>();

            for (int i = cells.Keys.Select(k => k.Column).Max(); i >= 0; i--)
            {
                allColumns[i] = new DtoColumnViewModel(dependencies, dataCtx, result, fileOpener, tmpService, i, string.Format("gridcolum:{0}.[][{1}]", dto.GetType(), i));
            }

            foreach (var kvp in cells)
            {
                result.Cells.Add(new DtoCellViewModel(dependencies, dataCtx, result, fileOpener, tmpService, allRows[kvp.Key.Row], allColumns[kvp.Key.Column], kvp.Key, kvp.Value, string.Format("gridcell[{0}][{1}]", kvp.Key.Row, kvp.Key.Column)));
            }

            allRows.Values.ForEach(result.Rows.Add);
            allColumns.Values.ForEach(result.Columns.Add);

            return(result);
        }
Ejemplo n.º 53
0
        //private List<string> _tempDirs = new List<string>();

        /// <summary>
        /// Creates a new reporting host
        /// </summary>
        /// <param name="fileOpener"></param>
        /// <param name="tmpService"></param>
        public AbstractReportingHost(IFileOpener fileOpener, ITempFileService tmpService)
            : this(null, null, fileOpener, tmpService)
        {
        }