Ejemplo n.º 1
0
        private async Task <IAssemblyMetadata> LoadRootAssembly(string target)
        {
            if (IsTracingEnabled)
            {
                Tracer.LogLoadingModel(target);
                Tracer.Flush();
            }

            AssemblyMetadata graph = null;

            try
            {
                graph = await AssemblyMetadata.Load(Persister, target);
            }
            catch (Exception e)
            {
                string errorMessage = $"Error during retrieval of elements from repository. {e.Message}";
                ErrorMessageTarget.SendMessage("Loading error", errorMessage);
                if (IsTracingEnabled)
                {
                    Tracer.LogFailure($"{target}; {errorMessage}");
                    Tracer.Flush();
                }
                return(null);
            }
            finally
            {
                Persister.Dispose();
            }

            return(graph);
        }
Ejemplo n.º 2
0
        private async Task Save(ISourceProvider targetPathProvider)
        {
            if (targetPathProvider == null)
            {
                throw new ArgumentNullException(nameof(targetPathProvider), "SourceProvider can't be null.");
            }

            if (Persister.FileSystemDependency == FileSystemDependency.Independent)
            {
                targetPathProvider = new NullSourceProvider();
            }

            if (targetPathProvider.GetAccess())
            {
                try
                {
                    string target = targetPathProvider.GetPath();
                    await Task.Run(async() =>
                    {
                        if (IsTracingEnabled)
                        {
                            Tracer.LogSavingModel(target);
                            Tracer.Flush();
                        }

                        Persister.Access(target);
                        await(ObjectsList?.FirstOrDefault().ModelObject as AssemblyMetadata)?.Save(Persister, target);
                        Persister.Dispose();
                        InformationMessageTarget.SendMessage("Saving completed", "Model was successfully saved.");

                        if (IsTracingEnabled)
                        {
                            Tracer.LogModelSaved(target);
                            Tracer.Flush();
                        }
                    });
                }
                catch (Exception ex)
                {
                    ErrorMessageTarget.SendMessage("Saving error", ex.Message);
                    if (IsTracingEnabled)
                    {
                        Tracer.LogFailure(
                            $"Exception caught when trying to open a file for writing {Environment.NewLine}{ex.Message}");
                        Tracer.Flush();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void ImportTracer()
        {
            tracingProvider = new TracingProvider(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            try
            {
                if (Tracer is null)
                {
                    Tracer = tracingProvider.ProvideTracer();
                }
            }
            catch (MEFLoaderException ex)
            {
                ErrorMessageTarget.SendMessage("MEF composition error", ex.Message);
                ErrorMessageTarget.CloseApp();
                IsTracingEnabled = false;
            }
        }
Ejemplo n.º 4
0
        private void LoadAssembly()
        {
            if (IsTracingEnabled)
            {
                Tracer.LogLoadingModel(LoadedAssembly);
                Tracer.Flush();
            }
            try
            {
                Reflector reflector = new Reflector(LoadedAssembly);
                LoadedAssemblyRepresentation = reflector.AssemblyModel;

                if (IsTracingEnabled)
                {
                    Tracer.LogModelLoaded(LoadedAssembly);
                    Tracer.Flush();
                }
            }
            catch (BadImageFormatException ex)
            {
                if (IsTracingEnabled)
                {
                    Tracer.LogFailure($"Failed when reading assembly {ex.Message}");
                    Tracer.Flush();
                }
                ErrorMessageTarget.SendMessage("Assembly reading error", ex.Message);
                LoadedAssemblyRepresentation = null;
            } catch (Exception ex)
            {
                if (IsTracingEnabled)
                {
                    Tracer.LogFailure($"Failed when reading assembly {ex.Message}");
                    Tracer.Flush();
                }
                ErrorMessageTarget.SendMessage("Unknown assembly reading error", ex.Message);
                LoadedAssemblyRepresentation = null;
            }
        }
Ejemplo n.º 5
0
        private void ImportPersister()
        {
            persistenceProvider = new PersistenceProvider(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            try
            {
                if (Persister is null)
                {
                    Persister = persistenceProvider.ProvidePersister();
                }
            }
            catch (MEFLoaderException ex)
            {
                if (IsTracingEnabled)
                {
                    Tracer.LogFailure("Persister loading failure. " +
                                      $"{ex.Message}  {ex.StackTrace} " +
                                      $"{ex.InnerException?.Message} {ex.InnerException?.StackTrace}");
                }
                ErrorMessageTarget.SendMessage("MEF composition error", ex.Message);
                ErrorMessageTarget.CloseApp();
            }
        }
Ejemplo n.º 6
0
        private async Task Load(ISourceProvider targetPathProvider)
        {
            if (targetPathProvider == null)
            {
                throw new ArgumentNullException(nameof(targetPathProvider), "SourceProvider can't be null.");
            }

            if (Persister.FileSystemDependency == FileSystemDependency.Independent)
            {
                targetPathProvider = new NullSourceProvider();
            }

            if (targetPathProvider.GetAccess())
            {
                try
                {
                    string            target = targetPathProvider.GetPath();
                    IAssemblyMetadata result = await Task.Run(
                        async() => await LoadRootAssembly(target));

                    if (result is null)
                    {
                        const string errorMessage = "Repository doesn't contain any elements";
                        ErrorMessageTarget.SendMessage("Loading error", errorMessage);
                        if (IsTracingEnabled)
                        {
                            Tracer.LogFailure($"{target}; {errorMessage}");
                            Tracer.Flush();
                        }
                    }
                    else
                    {
                        ObjectsList.Clear();
                        ObjectsList.Add(new AssemblyItem(result as AssemblyMetadata));
                        LoadedAssembly = "Model deserialized";
                        SaveModel.RaiseCanExecuteChanged();
                        InformationMessageTarget?.SendMessage("Loading completed", "Model was successfully loaded.");

                        if (IsTracingEnabled)
                        {
                            Tracer.LogModelLoaded(target);
                            Tracer.Flush();
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorMessageTarget.SendMessage("Loading error", ex.Message);
                    if (IsTracingEnabled)
                    {
                        Tracer.LogFailure(
                            $"Exception caught when trying to open a file for reading {Environment.NewLine}{ex.Message}");
                        Tracer.Flush();
                    }
                }
            }
            else
            {
                ErrorMessageTarget.SendMessage("Target in use", "File you tried to open is currently in use by another program");
            }
        }