Example #1
0
        public async Task <bool> SaveAsync(IProgressEx Progress)
        {
            if ((await ComponentSet.SaveAsync(Progress)) == false)
            {
                return(false);
            }

            if ((await ViewSet.SaveAsync(Progress)) == false)
            {
                return(false);
            }

            try
            {
                XDocument xDoc = new XDocument();

                xDoc.Add(this.Xml);

                xDoc.Save(_projectFilePath);

                _hasChanges = false;
            }
            catch (Exception ex)
            {
                MainLogger.Log(ex);
                return(false);
            }

            return(true);
        }
Example #2
0
        public void Load(IProgressEx Progress)
        {
            try
            {
                if (Plugin.Ident != Ident)
                {
                    throw new ComponentNotFoundException(String.Format("Component '{0}' has a wrong Ident", ComponentType));
                }
            }
            catch (NotImplementedException)
            {
                throw new ComponentNotFoundException(String.Format("Component '{0}' has no Ident", ComponentType));
            }

            _progress = Progress;

            try
            {
                Plugin.PluginHost = this;
                Plugin.LoadPlugin(Progress);
            }
            catch (NotImplementedException)
            {
            }

            _pluginLoaded = true;
        }
Example #3
0
        internal void Load(IProgressEx Progress)
        {
            _progress = Progress;

            try
            {
                if (Plugin.Ident != Ident)
                {
                    throw new ViewNotFoundException(String.Format("View '{0}' has a wrong Ident", Ident));
                }
            }
            catch (NotImplementedException)
            {
                throw new ViewNotFoundException(String.Format("View '{0}' does not implement the Ident property", Ident));
            }

            try
            {
                Plugin.PluginHost = this;
            }
            catch (NotImplementedException)
            {
                throw new ViewNotFoundException(String.Format("View '{0}' does not implement the PluginHost property", Ident));
            }

            try
            {
                Plugin.LoadPlugin(Progress);
            }
            catch (Exception ex)
            {
                Logger.Log(ex, LogReceiver.Console);
                ParentSet.HasExceptions = true;
                _pluginLoaded           = false;
                ViewControl             = null;
                return;
            }

            try
            {
                if (Plugin is UserControl)
                {
                    ViewControl = (UserControl)Plugin;
                }
                else
                {
                    ViewControl = null;
                }
            }
            catch (Exception ex)
            {
                ViewControl = null;
                Logger.Log(ex, LogReceiver.Console);
                ParentSet.HasExceptions = true;
            }

            _pluginLoaded = true;
        }
Example #4
0
 public void Unload(IProgressEx Progress)
 {
     foreach (DynComponent component in this)
     {
         if (component.Plugin != null)
         {
             component.Unload(Progress);
         }
     }
 }
Example #5
0
 public void Save(IProgressEx Progress)
 {
     foreach (DynComponent component in this)
     {
         if (!component.Save(Progress))
         {
             throw new ComponentException(string.Format("Can not save the component '{0}'", component.Ident));
         }
     }
 }
Example #6
0
 public void Save(IProgressEx Progress = null)
 {
     foreach (KeyValuePair <string, DynView> entry in _flattenViewDictionary)
     {
         if (!entry.Value.Save(Progress))
         {
             throw new ComponentException(string.Format(Resources.Messages.CanNotSaveView, entry.Value.Name));
         }
     }
 }
Example #7
0
        public void Unload(IProgressEx Progress = null)
        {
            foreach (DynView view in this)
            {
                view.Unload(Progress);
            }

            _views.Clear();

            _isDisposed = true;
        }
Example #8
0
        public void Load(string FilePath, IProgressEx Progress = null)
        {
            _hasChanges = false;

            _projectFilePath = FilePath;

            ProjectBasePath = Path.GetDirectoryName(_projectFilePath);

            MainLogger.Log(String.Format("Loading Project File '{0}'...", Path.GetFileName(_projectFilePath)), 0,
                           LogMessageType.Information, LogReceiver.Console | LogReceiver.StatusBar);

            XDocument xDoc = XDocument.Load(FilePath);

            // Deserializing the project from XML document
            this.Xml = xDoc.Element("Project");

            // Base directory where the components are stored
            ComponentSet.BaseDir = Path.Combine(ApplicationBasePath, _COMPONENTS_DIR);

            // Optional project directory where the components are stored
            ComponentSet.ProjectDir = Path.Combine(ProjectBasePath, _COMPONENTS_DIR);

            ComponentSet.VerboseLoad = IsVerboseLoad();

            // Loading components
            ComponentSet.Load(Progress);

            CheckComponents();

            // If views are defined, load them
            if (ViewSet != null)
            {
                ViewSet.VerboseLoad    = ComponentSet.VerboseLoad;
                ViewSet.Components     = ComponentSet;
                ViewSet.BaseDir        = Path.Combine(ApplicationBasePath, _VIEWS_DIR);
                ViewSet.ProjectBaseDir = Path.Combine(ProjectBasePath, _VIEWS_DIR);
                ViewSet.Load(Progress);
            }

            if (ComponentSet.HasExceptions || ViewSet.HasExceptions)
            {
                MainLogger.Log(string.Format("Project '{0}' has loaded with problems!", Properties["Title"]), 0,
                               LogMessageType.Exclamation, LogReceiver.Console | LogReceiver.StatusBar | LogReceiver.MessageBox);
            }
            else
            {
                MainLogger.Log(string.Format("Project '{0}' loaded successfully!", Properties["Title"]), 0,
                               LogMessageType.Success, LogReceiver.Console | LogReceiver.StatusBar);
            }

            _target = (ITarget)ComponentSet["Target"].Plugin;

            _loaded = true;
        }
Example #9
0
 public async Task <bool> SaveAsync(IProgressEx Progress)
 {
     return(await Task.Factory.StartNew <bool>(() =>
     {
         try
         {
             Save(Progress);
             return true;
         }
         catch (ComponentException ex)
         {
             Parent.MainLogger.Log(ex);
             return false;
         }
     }));
 }
Example #10
0
        public void Unload(IProgressEx Progress)
        {
            if (_pluginLoaded == true)
            {
                try
                {
                    Plugin.UnloadPlugin(Progress);
                }
                catch (NotImplementedException)
                {
                }

                _pluginLoaded = false;
            }
            _isDisposed = true;
        }
Example #11
0
        public void Unload(IProgressEx Progress)
        {
            if (_pluginLoaded == true)
            {
                Plugin.UnloadPlugin(Progress);

                _pluginLoaded = false;

                foreach (DynViewTimer timer in _viewTimers)
                {
                    timer.Dispose();
                }
            }

            _isDisposed = true;
        }
Example #12
0
        private async Task <bool> GoOfflineAsync(IProgressEx Progress)
        {
            LockUI();

            StopConnectionMonitoring();

            if ((await _project.GoOfflineAsync(Progress) == false))
            {
                _logger.Log(Resources.Messages.ProjectCanNotGoOffline, 0, LogMessageType.Exclamation, LogReceiver.Console);
                UnlockUI();
                StartConnectionMonitoring();
                return(false);
            }

            UnlockUI();

            await UpdateViewsAndUI();

            return(true);
        }
Example #13
0
        private async Task <bool> SaveProjectAsync(IProgressEx Progress)
        {
            bool result;

            try
            {
                LockUI();

                result = await _project.SaveAsync(Progress);

                UnlockUI();
            }
            catch (Exception ex)
            {
                result = false;
                _logger.Log(ex.Message, 0, LogMessageType.Failure, LogReceiver.MessageBox | LogReceiver.Console);
            }

            UpdateUI();

            return(result);
        }
Example #14
0
        public void Load(IProgressEx Progress)
        {
            AssemblyLoader  asmLoader = new AssemblyLoader();
            ProgressExValue pV        = new ProgressExValue();

            // Flatten the tree of views, so it can be iterated
            _flattenViewDictionary = FlattenViewTree(_views);

            foreach (KeyValuePair <string, DynView> entry in _flattenViewDictionary)
            {
                string viewAssembly;
                string className;
                string nameSpace;

                string logMessage = string.Format(Resources.Messages.LoadingViewFile, entry.Value.Name);

                if (Progress != null)
                {
                    pV.MainStatus = logMessage;
                    Progress.Report(pV);
                }

                if (VerboseLoad)
                {
                    Parent.MainLogger.Log(logMessage, 0, LogMessageType.Information, LogReceiver.Console);
                }

                // Search for the View's DLL file
                if (!DiscoverViewAssembly(entry.Value, out viewAssembly, out nameSpace, out className))
                {
                    Parent.MainLogger.Log(new ViewNotFoundException(String.Format(Resources.Messages.CanNotFindView, entry.Value.Ident)),
                                          LogReceiver.Console | LogReceiver.MessageBox);

                    HasExceptions = true;

                    continue;
                }

                string ViewPluginType = String.Format("{0}.{1}", nameSpace, className);

                IView plugin = null;

                try
                {
                    plugin = asmLoader.Load <IView>(viewAssembly, ViewPluginType);
                }
                catch (Exception ex)
                {
                    throw new ViewException(ex.Message);
                }

                if (plugin == null)
                {
                    throw new ViewException(String.Format(Resources.Messages.CanNotLoadView, entry.Value.Ident));
                }

                entry.Value.Plugin = plugin;
            }

            int i = 0;

            // Initializing the views (calling the LoadPlugin method)
            foreach (KeyValuePair <string, DynView> entry in _flattenViewDictionary)
            {
                if (entry.Value.Plugin == null)
                {
                    continue;
                }

                string logMessage = string.Format(Resources.Messages.InitializingView, entry.Value.Name);

                if (Progress != null)
                {
                    pV.MainStatus = logMessage;
                    pV.Percentage = i * 100 / _flattenViewDictionary.Count;
                    Progress.Report(pV);
                }

                if (VerboseLoad)
                {
                    Parent.MainLogger.Log(logMessage, 0, LogMessageType.Information, LogReceiver.Console);
                }

                entry.Value.Load(Progress);

                i++;
            }

            Progress.Report(null);
        }
Example #15
0
        internal bool GoOnline(bool online = true, bool forceAction = false, IProgressEx Progress = null)
        {
            if (online)
            {
                try
                {
                    _target.Connect(Progress);
                }
                catch (Exception ex)
                {
                    MainLogger.Log(ex);
                    return(false);
                }

                if (!forceAction)
                {
                    foreach (DynComponent component in ComponentSet)
                    {
                        if (!component.CanGoOnline())
                        {
                            MainLogger.Log(string.Format("Component '{0}' can not go online", component.Ident), 0,
                                           LogMessageType.Exclamation, LogReceiver.Console);
                            return(false);
                        }
                    }

                    foreach (KeyValuePair <string, DynView> entry in ViewSet.ViewsList)
                    {
                        if (!entry.Value.CanGoOnline())
                        {
                            MainLogger.Log(string.Format("View '{0}' can not go online", entry.Value.Name), 0,
                                           LogMessageType.Exclamation, LogReceiver.Console);
                            return(false);
                        }
                    }
                }
            }
            else
            {
                if (!forceAction)
                {
                    foreach (DynComponent component in ComponentSet)
                    {
                        if (!component.CanGoOffline())
                        {
                            MainLogger.Log(string.Format("Component '{0}' can not go offline", component.Ident), 0,
                                           LogMessageType.Exclamation, LogReceiver.Console);
                            return(false);
                        }
                    }

                    foreach (KeyValuePair <string, DynView> entry in ViewSet.ViewsList)
                    {
                        if (!entry.Value.CanGoOffline())
                        {
                            MainLogger.Log(string.Format("View '{0}' can not go offline", entry.Value.Name), 0,
                                           LogMessageType.Exclamation, LogReceiver.Console);
                            return(false);
                        }
                    }
                }
            }

            foreach (DynComponent component in ComponentSet)
            {
                if (online)
                {
                    if (!component.GoOnline())
                    {
                        GoOffline(Progress);

                        if (!forceAction)
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    component.GoOffline();
                }
            }

            foreach (KeyValuePair <string, DynView> entry in ViewSet.ViewsList)
            {
                if (online)
                {
                    if (!entry.Value.GoOnline())
                    {
                        GoOffline(Progress);

                        if (!forceAction)
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    entry.Value.GoOffline();
                }
            }

            if (!online)
            {
                try
                {
                    _target.Disconnect(Progress);
                }
                catch (Exception)
                {
                }
            }

            _isOnline = online;

            return(true);
        }
Example #16
0
 public bool Save(IProgressEx Progress)
 {
     return(CallHandler(OnSaveProject));
 }
Example #17
0
 public bool GoOffline(IProgressEx Progress, bool forceAction = false)
 {
     return(GoOnline(false, forceAction, Progress));
 }
Example #18
0
 public async Task <bool> GoOnlineAsync(bool forceAction = false, IProgressEx Progress = null)
 {
     return(await Task.Factory.StartNew(() => GoOnline(forceAction : forceAction, Progress : Progress)));
 }
Example #19
0
 public async Task <bool> GoOfflineAsync(IProgressEx Progress, bool forceAction = false)
 {
     return(await Task.Factory.StartNew(() => GoOffline(Progress, forceAction)));
 }
Example #20
0
        public void Load(IProgressEx Progress)
        {
            AssemblyLoader asmLoader = new AssemblyLoader();

            // Loading the assemblies
            foreach (DynComponent component in this)
            {
                string logMessage = string.Format("Loading component '{0}'...", component.Ident);

                if (Progress != null)
                {
                    ProgressExValue pV = new ProgressExValue();
                    pV.MainStatus = logMessage;
                    Progress.Report(pV);
                }

                if (VerboseLoad)
                {
                    Parent.MainLogger.Log(logMessage, 0, LogMessageType.Information, LogReceiver.Console);
                }

                string ComponentAssembly = DiscoverComponentAssembly(component);

                if (string.IsNullOrEmpty(ComponentAssembly))
                {
                    throw new ComponentNotFoundException(String.Format("Can not find the component '{0}' of type '{1}'",
                                                                       component.Ident, component.ComponentType));
                }

                string ComponentType = String.Format("{0}.{1}", component.Ident, component.ComponentType);

                try
                {
                    switch (component.ComponentType)
                    {
                    case "Target":
                        component.Plugin = asmLoader.Load <ITarget>(ComponentAssembly, ComponentType);
                        break;

                    default:
                        component.Plugin = asmLoader.Load <IComponent>(ComponentAssembly, ComponentType);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    throw new ComponentException(ex.Message);
                }

                if (component.Plugin == null)
                {
                    throw new ComponentException(String.Format("Can not load the component '{0}'", component.Ident));
                }
            }

            int i = 0;

            // Loading the components
            foreach (DynComponent component in this)
            {
                string logMessage = string.Format("Initializing component '{0}'...", component.Ident);

                if (Progress != null)
                {
                    ProgressExValue pV = new ProgressExValue();
                    pV.MainStatus = logMessage;
                    pV.Percentage = i * 100 / this._components.Count;
                    Progress.Report(pV);
                }

                if (VerboseLoad)
                {
                    Parent.MainLogger.Log(logMessage, 0, LogMessageType.Information, LogReceiver.Console);
                }

                component.Load(Progress);

                i++;
            }

            Progress.Report(null);
        }
Example #21
0
 public async Task LoadAsync(string FilePath, IProgressEx Progress = null)
 {
     await Task.Factory.StartNew(() => Load(FilePath, Progress));
 }