Esempio n. 1
0
        public void CreateEventsTest()
        {
            _log = new BdoLog();

            for (int i = 0; i < _testData.itemNumber; i++)
            {
                _log.AddError("Error" + i);
                _log.AddException("Exception" + i);
                _log.AddMessage("Message" + i);
                _log.AddWarning("Warning" + i);
                _log.AddSubLog(new BdoLog());
            }

            Test(_log);
        }
Esempio n. 2
0
 /// <summary>
 /// Deletes a local folder.
 /// </summary>
 /// <param name="localfolderUri">The local Uri to consider.</param>
 /// <param name="log">The log to consider.</param>
 public static void DeleteFolder(
     string localfolderUri,
     IBdoLog log = null)
 {
     try
     {
         if (Directory.Exists(localfolderUri))
         {
             Directory.Delete(localfolderUri, true);
             log?.AddMessage("Folder '" + localfolderUri + "' deleted");
         }
         else
         {
             log?.AddError("Could not delete folder '" + localfolderUri + "'");
         }
     }
     catch (IOException exception)
     {
         log?.AddException("Could not delete folder '" + localfolderUri + "'", description: exception.ToString());
     }
 }
Esempio n. 3
0
        // -----------------------------------------------
        // OTHER METHODS
        // -----------------------------------------------

        #region Other_Methods


        // Delete ---------------------------------------------------

        /// <summary>
        /// Deletes a local file.
        /// </summary>
        /// <param name="localFileUri">The local Uri to consider.</param>
        /// <param name="log">The log to consider.</param>
        public static void DeleteFile(
            string localFileUri,
            IBdoLog log = null)
        {
            try
            {
                if (File.Exists(localFileUri))
                {
                    Directory.Delete(localFileUri, true);
                    log?.AddMessage("File '" + localFileUri + "' deleted");
                }
                else
                {
                    log?.AddError("Could not delete file '" + localFileUri + "'");
                }
            }
            catch (IOException exception)
            {
                log?.AddException(exception);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Loads the specified library.
        /// </summary>
        /// <param name="libraryReference">The library reference to consider.</param>
        /// <returns>Returns the loaded library.</returns>
        private IBdoLog LoadLibrary(IBdoAssemblyReference libraryReference)
        {
            var log = new BdoLog();

            if (libraryReference != null && _loadOptions?.SourceKinds != null)
            {
                try
                {
                    Assembly assembly = null;

                    // first we load the assembly

                    IBdoLog firstLog = new BdoLog()
                    {
                        DisplayName = "Loading library '" + libraryReference.Name + "'"
                    };

                    foreach (DatasourceKind dataSourceKind in _loadOptions?.SourceKinds)
                    {
                        IBdoLog subLog = firstLog.AddSubLog(title: "Loading assembly from '" + dataSourceKind.ToString() + "'", eventKind: EventKinds.Message);

                        switch (dataSourceKind)
                        {
                        case DatasourceKind.Memory:
                            if (!string.IsNullOrEmpty(libraryReference.Name))
                            {
                                assembly = AppDomainPool.LoadAssembly(_appDomain, libraryReference.Name, subLog);
                            }
                            else
                            {
                                subLog?.AddWarning("File name missing");
                            }
                            break;

                        case DatasourceKind.Repository:
                            string fileName = libraryReference.FileName;
                            if (string.IsNullOrEmpty(fileName))
                            {
                                fileName = libraryReference.Name + ".dll";
                            }

                            string filePath = _loadOptions.LibraryFolderPath.EndingWith(@"\").ToPath() + fileName;
                            if (!File.Exists(filePath))
                            {
                                subLog?.AddError("Could not find the assembly file path '" + filePath + "'");
                            }
                            else
                            {
                                assembly = AppDomainPool.LoadAssemblyFromFile(_appDomain, filePath, subLog);

                                if (assembly == null)
                                {
                                    subLog?.AddError("Could not load assembly '" + filePath + "'");
                                }
                                else
                                {
                                    subLog?.AddCheckpoint("Loading assembly from file '" + filePath + "'");
                                    assembly = Assembly.LoadFrom(filePath);
                                }
                            }
                            break;

                        case DatasourceKind.RestApi:
                            break;
                        }

                        if (assembly != null)
                        {
                            subLog?.AddMessage("Assembly loaded");
                            break;
                        }
                    }

                    // if we have an assembly then we index library items

                    if (assembly == null)
                    {
                        log?.AddSubLog(firstLog, p => p.HasErrorsOrExceptionsOrWarnings());
                    }
                    else
                    {
                        firstLog.GetEvents(true, EventKinds.Error, EventKinds.Exception).ForEach(p => p.Kind = EventKinds.Warning);
                        log?.AddSubLog(firstLog);

                        // we get the extension definition

                        IBdoExtensionDefinition extensionDefinition = ExtractExtensionDefinition(assembly, null, log);

                        // we load the using assemblies

                        if (extensionDefinition?.Dto?.UsingAssemblyFileNames != null)
                        {
                            foreach (var st in extensionDefinition.Dto.UsingAssemblyFileNames)
                            {
                                var fileName = st;
                                if (!fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
                                {
                                    fileName += ".dll";
                                }
                                IBdoAssemblyReference reference = BdoAssemblyReferenceFactory.Create(st).WithFileName(fileName);

                                log.AddSubLog(LoadExtensionsInStore(reference), title: "Loading using extensions...");
                            }
                        }

                        // we load the item definition specifiying the extension definition

                        foreach (BdoExtensionItemKind kind in new[] {
                            BdoExtensionItemKind.Carrier,
                            BdoExtensionItemKind.Connector,
                            BdoExtensionItemKind.Entity,
                            BdoExtensionItemKind.Handler,
                            BdoExtensionItemKind.Metrics,
                            BdoExtensionItemKind.Routine,
                            BdoExtensionItemKind.Scriptword,
                            BdoExtensionItemKind.Task
                        })
                        {
                            IBdoLog subSubLog = new BdoLog();
                            int     count     = LoadDictionary(assembly, kind, extensionDefinition, subSubLog);

                            if (subSubLog.HasErrorsOrExceptionsOrWarnings())
                            {
                                log.AddSubLog(
                                    subSubLog,
                                    title: "Dictionary '" + kind.ToString() + "' loaded (" + count.ToString() + " items added)");
                            }
                            else
                            {
                                log.AddMessage("Dictionary '" + kind.ToString() + "' loaded (" + count.ToString() + " items added)");
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    log?.AddException(exception);
                }
            }

            return(log);
        }