public MesNewFileCommandHandler(
     IMesManager shell,
     [ImportMany] IMesEditorProvider[] editorProviders)
 {
     _shell           = shell;
     _editorProviders = editorProviders;
 }
        public void Initialize(IMesManager mesManager)
        {
#if DEBUG
            Debugger.Launch();
#endif
            this._MesManager = mesManager;
            this._Logger     = this._MesManager.ApplicationMainLogger;
        }
Esempio n. 3
0
        /// <summary>
        /// Inizializzazione estensione e collegamento all'oggetto principale PowerMES
        /// (eseguito al caricamento in memoria dell'estensione)
        /// </summary>
        /// <param name="mesManager">Riferimento all'oggetto principale PowerMES</param>
        public void Initialize(IMesManager mesManager)
        {
#if DEBUG
            Debugger.Launch();
#endif
            //memorizzo il riferimento all'oggetto principale di PowerMES
            this._MesManager = mesManager;
            this._Logger     = this._MesManager.ApplicationMainLogger;
        }
        public MesManagerView()
        {
            InitializeComponent();

            try
            {
                IMesManager manager = Mvx.IoCProvider.Resolve <IMesManager>();
                manager.ManagerView = this;
                DataContext         = manager;
            } catch { }
        }
Esempio n. 5
0
        /// <inheritdoc />
        public void Initialize(IMesManager mesManager)
        {
#if DEBUG
            Debugger.Launch();
#endif
            //memorizzo il riferimento all'oggetto principale di PowerMES
            _MesManager = mesManager;

            //strumenti per messaggi di DIAGNOSTICA:
            _MesLogger = _MesManager.ApplicationMainLogger;
            _MesLogger.WriteMessage(MessageLevel.Info, true, LOGGERSOURCE, "Estensione creata!");
        }
Esempio n. 6
0
        protected override async Task <Boolean> ShowContentView(FrameworkElement element, MvxContentPresentationAttribute attribute, MvxViewModelRequest request)
        {
            try
            {
                // Everything that passes here should be a view
                IMvxView    view    = element as IMvxView;
                IMesManager manager = Mvx.IoCProvider.Resolve <IMesManager>();

                // from which we can now get the view model.
                switch (view.ViewModel)
                {
                case IMesDocument document:

                    // Try to set view, this is needed for DocumentManager
                    IMesDocument docViewModel = (IMesDocument)view.ViewModel;
                    docViewModel.View = view;     // Needed for Binding with AvalonDock
                    docViewModel.ViewAppearing();
                    docViewModel.ViewAppeared();

                    // Add to manager model
                    manager.Documents.Add(docViewModel);
                    _log.Trace($"Add {document.ToString()} to IManager.Documents");
                    return(true);

                case IMesTool tool:
                    // Try to set view, this is needed for DocumentManager
                    IMesTool toolViewModel = (IMesTool)view.ViewModel;
                    toolViewModel.View = view;     // Needed for Binding with AvalonDock
                    toolViewModel.ViewAppearing();
                    toolViewModel.ViewAppeared();

                    // Add to manager model
                    manager.Tools.Add(toolViewModel);
                    _log.Trace($"Add {tool.ToString()} to IManager.Tools");
                    return(true);

                default:
                    _log.Trace($"Passing to parent {view.ViewModel.ToString()}");
                    return(await base.ShowContentView(element, attribute, request));
                }
            }
            catch (Exception exception)
            {
                if (_log == null)
                {
                    _log = Mvx.IoCProvider.Resolve <IMvxLog>();
                }
                _log.ErrorException("Error seen during navigation request to {0} - error {1}",
                                    exception, request.ViewModelType.Name, exception.ToLongString());
                return(false);
            }
        }
        private IMesManager _MesManager = null; //riferimento a PowerMES

        #endregion

        #region IMesExtension implementation

        /// <summary>
        /// Inizializzazione estensione e collegamento all'oggetto principale PowerMES
        /// (eseguito al caricamento in memoria dell'estensione)
        /// </summary>
        /// <param name="mesManager">Riferimento all'oggetto principale PowerMES</param>
        public void Initialize(IMesManager mesManager)
        {
            //memorizzo il riferimento all'oggetto principale di PowerMES
            this._MesManager = mesManager;

            //strumenti per messaggi di DIAGNOSTICA:
            this._Logger = this._MesManager.ApplicationMainLogger;

            //questa istruzione inserisce un messaggio nel file di log di PowerMES
            this._MesManager.AppendMessageToLog(MessageLevel.Diagnostics, "FileTranslatorExtension", "Estensione creata!");
            //mentre la successiva invia un messaggio ai Clients
            this._MesManager.SendMessageToUI(MessageLevel.Diagnostics, "FileTranslatorExtension", "Estensione creata!");
        }
Esempio n. 8
0
        /// <summary>
        /// Inizializzazione estensione e collegamento all'oggetto principale PowerMES
        /// (eseguito al caricamento in memoria dell'estensione)
        /// </summary>
        /// <param name="mesManager">Riferimento all'oggetto principale PowerMES</param>
        public void Initialize(IMesManager mesManager)
        {
#if DEBUG
            Debugger.Launch();
#endif
            //memorizzo il riferimento all'oggetto principale di PowerMES
            this._MesManager = mesManager;
            this._Logger     = this._MesManager.ApplicationMainLogger;

            /*
             * Your custom implementation here...
             * --
             * Fornire di seguito l'implementazione del metodo...
             */
        }
 public MesViewHistoryCommandHandler(IMesManager shell)
 {
     _shell = shell;
 }
 public MesCloseFileCommandHandler(IMesManager shell) => _shell = shell;
        public Boolean LoadState(IMesManager shell, IMesManagerView shellView, String fileName)
        {
            Dictionary <String, IMesLayoutItem> layoutItems = new Dictionary <String, IMesLayoutItem>();

            if (!File.Exists(fileName))
            {
                return(false);
            }

            try
            {
                using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open, FileAccess.Read)))
                {
                    Int32 count = reader.ReadInt32();

                    for (Int32 i = 0; i < count; i++)
                    {
                        String typeName         = reader.ReadString();
                        String contentId        = reader.ReadString();
                        Int64  stateEndPosition = reader.ReadInt64();
                        stateEndPosition += reader.BaseStream.Position;

                        Type    contentType   = Type.GetType(typeName);
                        Boolean skipStateData = true;

#warning LoadState
#if false
                        if (contentType != null)
                        {
                            var contentInstance = IoC.GetInstance(contentType, null) as ILayoutItem;

                            if (contentInstance != null)
                            {
                                layoutItems.Add(contentId, contentInstance);

                                try
                                {
                                    contentInstance.LoadState(reader);
                                    skipStateData = false;
                                }
                                catch
                                {
                                    skipStateData = true;
                                }
                            }
                        }
#endif

                        // Skip state data block if we couldn't read it.
                        if (skipStateData)
                        {
                            reader.BaseStream.Seek(stateEndPosition, SeekOrigin.Begin);
                        }
                    }

                    shellView.LoadLayout(reader.BaseStream, shell.ShowTool, shell.OpenDocument, layoutItems);
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
 public MesViewToolboxCommandHandler(IMesManager shell)
 {
     _shell = shell;
 }
Esempio n. 13
0
 public MesSaveAllFilesCommandHandler(IMesManager shell) => _shell = shell;
 public MesSwitchToDocumentListCommandHandler(IMesManager shell)
 {
     _shell = shell;
 }
Esempio n. 15
0
 public MesAppService(IMesManager iMesManager)
 {
     this.iMesManager = iMesManager;
 }
 public MesExitCommandHandler(IMesManager shell) => _shell = shell;
        public Boolean SaveState(IMesManager shell, IMesManagerView shellView, String fileName)
        {
            try
            {
                using (BinaryWriter writer = new BinaryWriter(new FileStream(fileName, FileMode.Create, FileAccess.Write)))
                {
                    IEnumerable <IMesLayoutItem> itemStates = shell.Documents.Concat(shell.Tools.Cast <IMesLayoutItem>());

                    Int32 itemCount = 0;
                    // reserve some space for items count, it'll be updated later
                    writer.Write(itemCount);

                    foreach (IMesLayoutItem item in itemStates)
                    {
                        if (!item.ShouldReopenOnStart)
                        {
                            continue;
                        }

                        Type itemType = item.GetType();
                        List <ExportAttribute> exportAttributes = itemType
                                                                  .GetCustomAttributes(typeof(ExportAttribute), false)
                                                                  .Cast <ExportAttribute>().ToList();

                        // get exports with explicit types or names that inherit from ILayoutItem
                        List <Type> exportTypes         = new List <Type>();
                        Boolean     foundExportContract = false;
                        foreach (ExportAttribute att in exportAttributes)
                        {
                            // select the contract type if it is of type ILayoutitem.
                            Type type = att.ContractType;
                            if (LayoutBaseType.IsAssignableFrom(type))
                            {
                                exportTypes.Add(type);
                                foundExportContract = true;
                                continue;
                            }

                            // select the contract name if it is of type ILayoutItem.
                            type = GetTypeFromContractNameAsILayoutItem(att);
                            if (LayoutBaseType.IsAssignableFrom(type))
                            {
                                exportTypes.Add(type);
                                foundExportContract = true;
                            }
                        }
                        // select the viewmodel type if it is of type ILayoutItem.
                        if (!foundExportContract && LayoutBaseType.IsAssignableFrom(itemType))
                        {
                            exportTypes.Add(itemType);
                        }

                        // throw exceptions here, instead of failing silently. These are design time errors.
                        Type firstExport = exportTypes.FirstOrDefault();
                        if (firstExport == null)
                        {
                            throw new InvalidOperationException(String.Format(
                                                                    "A ViewModel that participates in LayoutItem.ShouldReopenOnStart must be decorated with an ExportAttribute who's ContractType that inherits from ILayoutItem, infringing type is {0}.", itemType));
                        }

                        if (exportTypes.Count > 1)
                        {
                            throw new InvalidOperationException(String.Format(
                                                                    "A ViewModel that participates in LayoutItem.ShouldReopenOnStart can't be decorated with more than one ExportAttribute which inherits from ILayoutItem. infringing type is {0}.", itemType));
                        }

                        String selectedTypeName = firstExport.AssemblyQualifiedName;

                        if (String.IsNullOrEmpty(selectedTypeName))
                        {
                            throw new InvalidOperationException(String.Format(
                                                                    "Could not retrieve the assembly qualified type name for {0}, most likely because the type is generic.", firstExport));
                        }
                        // TODO: it is possible to save generic types. It requires that every generic parameter is saved, along with its position in the generic tree... A lot of work.

                        writer.Write(selectedTypeName);
                        writer.Write(item.ContentId);

                        // Here's the tricky part. Because some items might fail to save their state, or they might be removed (a plug-in assembly deleted and etc.)
                        // we need to save the item's state size to be able to skip the data during deserialization.
                        // Save current stream position. We'll need it later.
                        Int64 stateSizePosition = writer.BaseStream.Position;

                        // Reserve some space for item state size
                        writer.Write(0L);

                        Int64 stateSize;

                        try
                        {
                            Int64 stateStartPosition = writer.BaseStream.Position;
                            item.SaveState(writer);
                            stateSize = writer.BaseStream.Position - stateStartPosition;
                        }
                        catch
                        {
                            stateSize = 0;
                        }

                        // Go back to the position before item's state and write the actual value.
                        writer.BaseStream.Seek(stateSizePosition, SeekOrigin.Begin);
                        writer.Write(stateSize);

                        if (stateSize > 0)
                        {
                            // Got to the end of the stream
                            writer.BaseStream.Seek(0, SeekOrigin.End);
                        }

                        itemCount++;
                    }

                    writer.BaseStream.Seek(0, SeekOrigin.Begin);
                    writer.Write(itemCount);
                    writer.BaseStream.Seek(0, SeekOrigin.End);

                    shellView.SaveLayout(writer.BaseStream);
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }