/// <summary>
        /// Instantiates a new instance of Configuration class from a xml file.
        /// </summary>
        /// <param name="filePath">The file path to consider.</param>
        /// <param name="scope">The scope to consider.</param>
        /// <param name="scriptVariableSet">The set of script variables to consider.</param>
        /// <param name="log">The log to consider.</param>
        /// <param name="xmlSchemaSet">The XML schema set to consider for checking.</param>
        /// <param name="mustFileExist">Indicates whether the file must exist.</param>
        /// <param name="isRuntimeUpdated">Indicates whether the runtime is updated.</param>
        /// <returns>The Xml operation project defined in the Xml file.</returns>
        public static T Load <T>(
            string filePath,
            IBdoScope scope = null,
            IScriptVariableSet scriptVariableSet = null,
            IBdoLog log = null,
            XmlSchemaSet xmlSchemaSet = null,
            bool mustFileExist        = true,
            bool isRuntimeUpdated     = true) where T : class, IBdoBaseConfiguration, new()
        {
            T unionConfiguration = new T();

            if (XmlHelper.Load <T>(filePath, scope, scriptVariableSet, log, xmlSchemaSet, mustFileExist, isRuntimeUpdated) is T topConfiguration)
            {
                unionConfiguration.Update(topConfiguration);

                if (topConfiguration is BdoUsableConfiguration topUsableConfiguration)
                {
                    foreach (string usingFilePath in topUsableConfiguration.UsingFilePaths)
                    {
                        string completeUsingFilePath = (usingFilePath.Contains(":") ?
                                                        usingFilePath :
                                                        Path.GetDirectoryName(filePath).EndingWith(@"\") + usingFilePath).ToPath();
                        if (Load <T>(completeUsingFilePath, scope, scriptVariableSet, log, xmlSchemaSet, mustFileExist) is T usingConfiguration)
                        {
                            unionConfiguration.Update(usingConfiguration);
                        }
                    }
                }
            }

            unionConfiguration.CurrentFilePath = filePath;

            return(unionConfiguration);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="q"></param>
 /// <param name="orderBy"></param>
 /// <param name="pageSize"></param>
 /// <param name="pageToken"></param>
 /// <param name="log"></param>
 /// <returns></returns>
 internal IDbQuery QuerySelectCommunities(
     string q, string orderBy, int?pageSize = null, string pageToken = null,
     IBdoLog log = null)
 {
     return(this.UseQuery("GetCommunityWithCode", p =>
                          DbFluent.SelectQuery(Table <DbCommunity>("community"))
                          .From(
                              DbFluent.TableAsJoin(DbQueryJoinKind.Left, Table("RegionalDirectorate"),
                                                   JoinCondition("Community_RegionalDirectorate")))
                          .WithFields(Tuple("SelectCommunity"))
                          .Filter(
                              q,
                              DbApiFluent.CreateFilterDefinition(
                                  DbApiFluent.CreateFilterClause("startDate", Field <DbCommunity>(p => p.CreationDate), DataOperators.GreaterOrEqual),
                                  DbApiFluent.CreateFilterClause("endDate", Field <DbCommunity>(p => p.LastModificationDate), DataOperators.LesserOrEqual),
                                  DbApiFluent.CreateFilterClause("code", Field <DbCommunity>(p => p.Code), DataOperators.Equal)),
                              log)
                          .Sort(
                              orderBy,
                              DbApiFluent.CreateSortDefinition(
                                  DbApiFluent.CreateSortClause("startDate", Field <DbCommunity>(p => p.CreationDate)),
                                  DbApiFluent.CreateSortClause("endDate", Field <DbCommunity>(p => p.LastModificationDate)),
                                  DbApiFluent.CreateSortClause("code", Field <DbCommunity>(p => p.Code))),
                              log)));
 }
Ejemplo n.º 3
0
        // Extensions

        /// <summary>
        /// Adds filters to the specified database query considering the specified filter query string.
        /// </summary>
        /// <param name="dbQuery">The database query to consider.</param>
        /// <param name="filterQuery">The filter query string to consider.</param>
        /// <param name="definition">The clause statement to consider.</param>
        /// <param name="log">The log to consider.</param>
        /// <returns>The built query.</returns>
        public static IDbSingleQuery Filter(
            this IDbSingleQuery dbQuery,
            string filterQuery,
            DbApiFilterDefinition definition = null,
            IBdoLog log = null)
        {
            if (dbQuery != null && !string.IsNullOrEmpty(filterQuery))
            {
                string scriptText = filterQuery.ConvertToExtensionScript(log, definition);

                if (scriptText?.Length > 0)
                {
                    if (dbQuery.WhereClause?.Expression != null && !string.IsNullOrEmpty(dbQuery.WhereClause?.Expression?.Text))
                    {
                        dbQuery.WhereClause.Expression.Text = "$sqlAnd(" + dbQuery.WhereClause.Expression.Text + "," + scriptText + ")";
                    }
                    else
                    {
                        if (dbQuery.WhereClause == null)
                        {
                            dbQuery.WhereClause = new DbQueryWhereClause();
                        }

                        dbQuery.WhereClause.Expression = scriptText.CreateExpAsScript();
                    }
                }
            }

            return(dbQuery);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads the carrier dictionary from the specified assembly.
        /// </summary>
        /// <param name="assembly">The assembly to consider.</param>
        /// <param name="extensionDefinition">The extension definition to consider.</param>
        /// <param name="log">The log to consider.</param>
        /// <returns></returns>
        private int LoadCarrierDictionaryFromAssembly(
            Assembly assembly,
            IBdoExtensionDefinition extensionDefinition,
            IBdoLog log = null)
        {
            if (assembly == null)
            {
                return(-1);
            }

            // we load the carrier dictionary from the assembly

            IBdoCarrierDictionaryDto dictionaryDto = (IBdoCarrierDictionaryDto)ExtractDictionaryFromAssembly <BdoCarrierDefinitionDto>(assembly, log);

            // we feach carrier classes

            var types = assembly.GetTypes().Where(p => typeof(IBdoCarrier).IsAssignableFrom(p) && !p.IsAbstract);
            int count = 0;

            foreach (Type type in types)
            {
                IBdoCarrierDefinitionDto definitionDto = new BdoCarrierDefinitionDto();

                // we update definition from carrier attribute

                if (type.GetCustomAttribute(typeof(BdoCarrierAttribute)) is BdoCarrierAttribute carrierAttribute)
                {
                    UpdateDictionary(definitionDto, carrierAttribute);
                }
                definitionDto.ItemClass = type.FullName;
                definitionDto.LibraryId = extensionDefinition?.Dto?.Id;

                // we create the detail specification from detail property attributes

                foreach (PropertyInfo property in type.GetProperties().Where(p => p.GetCustomAttributes(typeof(DetailPropertyAttribute)).Any()))
                {
                    definitionDto.DetailSpec.Add(ElementSpecFactory.Create(property.Name, property.PropertyType));
                }

                // we build the runtime definition

                IBdoCarrierDefinition itemDefinition = new BdoCarrierDefinition(extensionDefinition, definitionDto)
                {
                    RuntimeType = type
                };

                if (dictionaryDto != null)
                {
                    // retrieve the definition index

                    // update definition with index
                }

                _store.Add <IBdoCarrierDefinition>(itemDefinition);

                count++;
            }

            return(count);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads the specified extensions into the specified scope.
        /// </summary>
        /// <param name="references">The library references to consider.</param>
        public IBdoLog LoadExtensionsInStore(params IBdoAssemblyReference[] references)
        {
            var log = new BdoLog();

            if (_store == null)
            {
                return(log);
            }

            // we load libraries

            foreach (IBdoAssemblyReference reference in references)
            {
                if (reference != null)
                {
                    IBdoLog subLog = LoadLibrary(reference);

                    if (subLog.HasErrorsOrExceptionsOrWarnings())
                    {
                        log.AddSubLog(subLog, title: "Loading extension '" + (reference?.Name ?? "?") + "'");
                    }
                    else
                    {
                        log.AddMessage("Extension '" + (reference?.Name ?? "?") + "' loaded");
                    }
                }
            }

            return(log);
        }
Ejemplo n.º 6
0
        // Create -------------------------------------

        /// <summary>
        /// Creates a connector.
        /// </summary>
        /// <param name="scope">The scope to consider.</param>
        /// <param name="dataSource">The data source to consider.</param>
        /// <param name="connectorDefinitionUniqueId">The connector definition name to consider.</param>
        /// <param name="log">The log of execution to consider.</param>
        /// <returns>Returns True if the connector has been opened. False otherwise.</returns>
        public static T Open <T>(
            this IBdoScope scope,
            IDatasource dataSource,
            string connectorDefinitionUniqueId,
            IBdoLog log = null)
            where T : class, IBdoConnection
        {
            if (log == null)
            {
                log = new BdoLog();
            }

            if (dataSource == null)
            {
                log.AddError("Data source missing");
            }
            else if (!string.IsNullOrEmpty(connectorDefinitionUniqueId) && dataSource.HasConfiguration(connectorDefinitionUniqueId))
            {
                log.AddError("Connection not defined in data source", description: "No connector is defined in the specified data source.");
            }
            else if (!string.IsNullOrEmpty(connectorDefinitionUniqueId))
            {
                return(scope.Open <T>(dataSource.GetConfiguration(connectorDefinitionUniqueId), log));
            }
            else if (dataSource.Configurations.Count > 0)
            {
                return(scope.Open <T>(dataSource.Configurations[0], log));
            }

            return(default);
Ejemplo n.º 7
0
        /// <summary>
        /// Converts the specified log to string.
        /// </summary>
        /// <param name="log">The log to consider.</param>
        /// <returns>The string corresponding to the specified log using the specified formater.</returns>
        public static string ToString <T>(this IBdoLog log)
            where T : IBdoLoggerFormat, new()
        {
            var formater = new T();

            return(formater.ToString(log));
        }
        // GroupBy -------------------------------------

        private string GetSqlText_GroupByClause(
            IDbQueryGroupByClause clause,
            IDbSingleQuery query                 = null,
            IDataElementSet parameterSet         = null,
            IScriptVariableSet scriptVariableSet = null,
            IBdoLog log = null)
        {
            string queryString = "";

            if (clause != null)
            {
                if (clause?.Expression != null)
                {
                    string expression = Scope?.Interpreter.Evaluate(clause.Expression, scriptVariableSet, log)?.ToString() ?? "";
                    queryString += expression;
                }
                else if (clause.Fields?.Count > 0)
                {
                    foreach (DbField field in clause.Fields)
                    {
                        if (!string.IsNullOrEmpty(queryString))
                        {
                            queryString += ", ";
                        }
                        queryString += GetSqlText_Field(
                            field, query, parameterSet, DbQueryFieldMode.CompleteNameOrValueAsAlias,
                            query.DataModule, query.Schema, query.DataTable,
                            scriptVariableSet: scriptVariableSet, log: log);
                    }
                }
                queryString = queryString.If(!string.IsNullOrEmpty(queryString), " group by " + queryString);
            }

            return(queryString);
        }
Ejemplo n.º 9
0
        // ------------------------------------------
        // ACCESSORS
        // ------------------------------------------

        #region Accessors

        // SQL commands

        /// <summary>
        /// Gets the SQL text of the specified query.
        /// </summary>
        /// <param name="query">The query to consider.</param>
        /// <param name="parameterMode">Indicates whether parameters are replaced.</param>
        /// <param name="parameterSet">The parameter set to consider.</param>
        /// <param name="scriptVariableSet">The script variable set to consider.</param>
        /// <param name="log">The log to consider.</param>
        /// <returns>Returns the SQL text of the specified query.</returns>
        public string CreateCommandText(
            IDbQuery query,
            DbQueryParameterMode parameterMode   = DbQueryParameterMode.ValueInjected,
            IDataElementSet parameterSet         = null,
            IScriptVariableSet scriptVariableSet = null,
            IBdoLog log = null)
        {
            string sqlText = "";

            if (QueryBuilder == null)
            {
                log?.AddError("Data builder missing");
            }
            else
            {
                var subLog = new BdoLog();
                sqlText = QueryBuilder.BuildQuery(query, parameterMode, parameterSet, scriptVariableSet, subLog);
                log?.AddEvents(subLog);

                if (subLog.HasErrorsOrExceptions())
                {
                    return(StringHelper.__NoneString);
                }
            }

            return(sqlText);
        }
Ejemplo n.º 10
0
        // ------------------------------------------
        // EVALUATION
        // ------------------------------------------

        #region Evaluation

        // Expression

        /// <summary>
        /// Evaluates the specified data expression.
        /// </summary>
        /// <param name="expression">The data expression to consider.</param>
        /// <param name="scriptVariableSet">The script variable set to consider.</param>
        /// <param name="log">The log to consider.</param>
        /// <returns>Literal or script value according to the specified default mode.</returns>
        public object Evaluate(
            IDataExpression expression,
            IScriptVariableSet scriptVariableSet = null,
            IBdoLog log = null)
        {
            int index;
            int scriptwordBeginIndex;

            var script = expression?.Text ?? string.Empty;

            switch (expression?.Kind)
            {
            case DataExpressionKind.Auto:
                if (!string.IsNullOrEmpty(script))
                {
                    var resultScript = script;

                    scriptwordBeginIndex = script.IndexOf("{{");
                    while (scriptwordBeginIndex > -1)
                    {
                        index = script.IndexOfNextString("}}", scriptwordBeginIndex + 1);

                        if ((scriptwordBeginIndex > -1) && (index > -1))
                        {
                            var subScript = script.Substring(2)[0..^ 2];
        // Load ------------------------------------------------

        /// <summary>
        /// Creates the instance of the specified definition.
        /// </summary>
        /// <param name="scope">The scope to consider.</param>
        /// <param name="xmlstring">The XML string to consider.</param>
        /// <param name="scriptVariableSet">The set of script variables to consider.</param>
        /// <param name="log">The log to consider.</param>
        public static ITBdoExtensionItemConfiguration <T> LoadConfiguration <T>(
            this IBdoScope scope,
            string xmlstring,
            IScriptVariableSet scriptVariableSet = null,
            IBdoLog log = null) where T : IBdoExtensionItemDefinition
        {
            BdoExtensionItemKind extensionItemKind = typeof(T).GetExtensionItemKind();

            ITBdoExtensionItemConfiguration <T> configuration = default;

            switch (extensionItemKind)
            {
            case BdoExtensionItemKind.Carrier:
                configuration = XmlHelper.LoadFromString <BdoCarrierConfiguration>(xmlstring, scope, scriptVariableSet, log) as ITBdoExtensionItemConfiguration <T>;
                break;

            case BdoExtensionItemKind.Connector:
                configuration = XmlHelper.LoadFromString <BdoConnectorConfiguration>(xmlstring, scope, scriptVariableSet, log) as ITBdoExtensionItemConfiguration <T>;
                break;

            case BdoExtensionItemKind.Entity:
                configuration = XmlHelper.LoadFromString <BdoEntityConfiguration>(xmlstring, scope, scriptVariableSet, log) as ITBdoExtensionItemConfiguration <T>;
                break;

            case BdoExtensionItemKind.Format:
                configuration = XmlHelper.LoadFromString <BdoFormatConfiguration>(xmlstring, scope, scriptVariableSet, log) as ITBdoExtensionItemConfiguration <T>;
                break;

            case BdoExtensionItemKind.Task:
                configuration = XmlHelper.LoadFromString <BdoTaskConfiguration>(xmlstring, scope, scriptVariableSet, log) as ITBdoExtensionItemConfiguration <T>;
                break;
            }

            return(configuration);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Pulls a remote files in folder to a local URI.
 /// </summary>
 /// <param name="remoteFileUri">The URI of the remote file to consider.</param>
 /// <param name="remoteFilter">The remote filter to consider.</param>
 /// <param name="localFolderUri">The URI of the local folder to consider.</param>
 /// <param name="log">The log to consider.</param>
 /// <param name="canOverwrite">Indicates whether the local files can be overwritten.</param>
 /// <param name="isRecursive">Indicates whether the search is folder recursive.</param>
 public abstract void Pull(
     string remoteFileUri,
     string remoteFilter,
     string localFolderUri,
     bool canOverwrite,
     IBdoLog log      = null,
     bool isRecursive = false);
Ejemplo n.º 13
0
 /// <summary>
 /// Creates the instance of the specified definition.
 /// </summary>
 /// <param name="scope">The scope to consider.</param>
 /// <param name="configuration">The configuration to consider.</param>
 /// <param name="name">The name to consider.</param>
 /// <param name="log">The log to consider.</param>
 /// <param name="scriptVariableSet">The script variable set to use.</param>
 /// <typeparam name="T">The connector class to return.</typeparam>
 /// <returns>Returns the created connector.</returns>
 public static T CreateDbConnector <T>(
     this IBdoScope scope,
     IBdoConnectorConfiguration configuration,
     string name = null,
     IBdoLog log = null,
     IScriptVariableSet scriptVariableSet = null) where T : class, IBdoDbConnector, new()
 => scope.CreateConnector <T>(configuration, name, log, scriptVariableSet).WithScope(scope) as T;
Ejemplo n.º 14
0
        // Open -------------------------------------

        /// <summary>
        /// Creates a connector.
        /// </summary>
        /// <param name="scope">The scope to consider.</param>
        /// <param name="depot">The data source depot to consider.</param>
        /// <param name="dataSourceName">The data source name to consider.</param>
        /// <param name="connectorDefinitionUniqueId">The connector definition name to consider.</param>
        /// <param name="log">The log of execution to consider.</param>
        /// <returns>Returns True if the connector has been opened. False otherwise.</returns>
        public static T Open <T>(
            this IBdoScope scope,
            IBdoDatasourceDepot depot,
            string dataSourceName,
            string connectorDefinitionUniqueId,
            IBdoLog log = null)
            where T : class, IBdoConnection
        {
            if (log == null)
            {
                log = new BdoLog();
            }

            if (depot == null)
            {
                depot = scope?.DataStore?.Get <IBdoDatasourceDepot>();
            }

            if (depot == null)
            {
                log.AddError("Data source depot missing");
            }
            else if (!depot.HasItem(dataSourceName))
            {
                log.AddError("Data source '" + dataSourceName + "' missing in depot");
            }
            else
            {
                return(scope.Open <T>(depot.Get(dataSourceName), connectorDefinitionUniqueId, log));
            }

            return(default);
Ejemplo n.º 15
0
        // -----------------------------------------------
        // FILE MANAGEMENT
        // -----------------------------------------------

        #region File_Management

        // Pull ---------------------------------------

        /// <summary>
        /// Pulls a remote file to a local Uri.
        /// </summary>
        /// <param name="remoteFileUri">The remote Uri to consider.</param>
        /// <param name="localPathUri">The Uri of the local path to consider.</param>
        /// <param name="log">The log to consider.</param>
        /// <param name="canOverwrite">Indicates whether the local file can be overwritten.</param>
        public virtual void Pull(
            string remoteFileUri,
            string localPathUri,
            Boolean canOverwrite,
            IBdoLog log = null)
        {
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Deletes the items.
 /// </summary>
 /// <param name="folderUri">The Uri of the folder path to consider.</param>
 /// <param name="filter">The filter to consider.</param>
 /// <param name="log">The log to consider.</param>
 /// <param name="timeLimit">The date time limit to consider.</param>
 /// <param name="isRecursive">Indicates whether the search is folder recursive.</param>
 /// <param name="fileKind">The kind of elements to consider.</param>
 public override void DeleteItems(
     string folderUri,
     string filter,
     DateTime timeLimit,
     bool isRecursive,
     IBdoLog log = null,
     CarrierKind_standard fileKind = CarrierKind_standard.Any)
 {
     foreach (RepositoryItem item in GetFiles(
                  folderUri, filter, isRecursive, log, fileKind))
     {
         if (item.LastWriteDate != null)
         {
             if ((timeLimit == null) ||
                 ((DateTime.TryParse(item.LastWriteDate, out DateTime lastWriteDateTime)) &&
                  (DateTime.Now.Subtract(lastWriteDateTime).Ticks > timeLimit.Ticks)))
             {
                 if (item is RepositoryFolder)
                 {
                     BdoNFSConnection.DeleteFolder(item.Path, log);
                 }
                 else if (item is RepositoryFile)
                 {
                     BdoNFSConnection.DeleteFile(item.Path, log);
                 }
             }
         }
     }
 }
Ejemplo n.º 17
0
        // ------------------------------------------
        // STATIC
        // ------------------------------------------

        #region Static

        // Serialization ----------------------------

        /// <summary>
        /// Saves the xml string of this instance.
        /// </summary>
        /// <param name="object1">The object1 to save.</param>
        /// <param name="log">The saving log to consider.</param>
        /// <returns>The Xml string of this instance.</returns>
        public static string ToXml(this Object object1, IBdoLog log = null)
        {
            if (object1 == null)
            {
                return(string.Empty);
            }

            string       st           = string.Empty;
            StringWriter streamWriter = null;

            try
            {
                // if the object is a data item then we update the storage info
                if (object1 is DataItem dataItem)
                {
                    dataItem?.UpdateStorageInfo(log);
                }

                XmlSerializer xmlSerializer = new XmlSerializer(object1.GetType());
                streamWriter = new StringWriter();
                xmlSerializer.Serialize(streamWriter, object1);
                st = streamWriter.ToString();
            }
            catch (Exception ex)
            {
                log?.AddException(ex);
            }
            finally
            {
                streamWriter?.Close();
            }

            return(st);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Creates the instance of the specified definition.
 /// </summary>
 /// <param name="scope">The scope to consider.</param>
 /// <param name="configuration">The configuration to consider.</param>
 /// <param name="name">The name to consider.</param>
 /// <param name="log">The log to consider.</param>
 /// <param name="scriptVariableSet">The script variable set to use.</param>
 /// <returns>Returns the created connector.</returns>
 public static BdoDbConnector CreateDbConnector(
     this IBdoScope scope,
     IBdoConnectorConfiguration configuration = null,
     string name = null,
     IBdoLog log = null,
     IScriptVariableSet scriptVariableSet = null)
 => scope.CreateConnector(configuration, name, log, scriptVariableSet).WithScope(scope) as BdoDbConnector;
Ejemplo n.º 19
0
 /// <summary>
 /// Deletes the items.
 /// </summary>
 /// <param name="folderUri">The URI of the folder path to consider.</param>
 /// <param name="filter">The filter to consider.</param>
 /// <param name="log">The log to consider.</param>
 /// <param name="timeLimit">The date time limit to consider.</param>
 /// <param name="isRecursive">Indicates whether the search is folder recursive.</param>
 /// <param name="fileKind">The kind of elements to consider.</param>
 public abstract void DeleteItems(
     string folderUri,
     string filter,
     DateTime timeLimit,
     bool isRecursive,
     IBdoLog log = null,
     CarrierKind_standard fileKind = CarrierKind_standard.Any);
Ejemplo n.º 20
0
        // Browser ---------------------------------------

        /// <summary>
        /// Waits for the specified file to be accessible.
        /// </summary>
        /// <param name="path">The path of the file to consider.</param>
        /// <param name="aSecondNumber">The number of seconds to consider.</param>
        /// <param name="log">The log to consider.</param>
        /// <returns>Returns true if the file is available. False otherwise.</returns>
        public static bool WaitForFile(
            string path,
            int aSecondNumber = 4,
            IBdoLog log       = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }

            DateTime dateTime         = DateTime.Now.AddSeconds(aSecondNumber);
            bool     isFileAccessible = !File.Exists(path);

            while ((DateTime.Now <= dateTime) && (!isFileAccessible))
            {
                FileStream fileStream = null;
                try
                {
                    FileInfo fileInfo = new FileInfo(path);
                    fileStream       = fileInfo.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
                    isFileAccessible = true;
                }
                catch
                {
                    isFileAccessible = false;
                }
                finally
                {
                    fileStream?.Close();
                }
            }

            return(isFileAccessible);
        }
Ejemplo n.º 21
0
        public static void Process(IBdoHost host, IBdoLog log)
        {
            _ = host.DataStore.GetDatasourceDepot()?.GetConnectorConfiguration("db.test", "database.mssqlserver$client");

            //var repo = new TestDbRepository(host?.GetModel<MyDbModel>(), host.CreatePostgreSqlConnector(string.Empty));
            //repo.Test();
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Pushes local files to a remote URI.
 /// </summary>
 /// <param name="localFileUris">The local URIs to consider.</param>
 /// <param name="remoteFolderUri">The URI of the remote folder to consider.</param>
 /// <param name="log">The log to consider.</param>
 /// <param name="canOverwrite">Indicates whether the remote files can be overwritten.</param>
 public override void Push(
     List <string> localFileUris,
     string remoteFolderUri,
     bool canOverwrite,
     IBdoLog log = null)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 23
0
 private void Test(IBdoLog log)
 {
     Assert.That(log.Errors.Count == _testData.itemNumber, "Bad insertion of errors ({0} expected; {1} found)", _testData.itemNumber, _log.Errors.Count);
     Assert.That(log.Exceptions.Count == _testData.itemNumber, "Bad insertion of exceptions ({0} expected; {1} found)", _testData.itemNumber, _log.Exceptions.Count);
     Assert.That(log.Messages.Count == _testData.itemNumber, "Bad insertion of messages ({0} expected; {1} found)", _testData.itemNumber, _log.Messages.Count);
     Assert.That(log.Warnings.Count == _testData.itemNumber, "Bad insertion of warnings ({0} expected; {1} found)", _testData.itemNumber, _log.Warnings.Count);
     Assert.That(log.SubLogs.Count == _testData.itemNumber, "Bad insertion of sub logs ({0} expected; {1} found)", _testData.itemNumber, _log.SubLogs.Count);
 }
Ejemplo n.º 24
0
        // Deserialiaze ----------------------------

        /// <summary>
        /// Loads a data item from the specified file path.
        /// </summary>
        /// <param name="filePath">The path of the Xml file to load.</param>
        /// <param name="scope">The scope to consider.</param>
        /// <param name="scriptVariableSet">The set of script variables to consider.</param>
        /// <param name="log">The output log of the method.</param>
        /// <param name="xmlSchemaSet">The XML schema set to consider for checking.</param>
        /// <param name="mustFileExist">Indicates whether the file must exist.</param>
        /// <param name="isRuntimeUpdated">Indicates whether it is updated in runtime.</param>
        /// <returns>The loaded log.</returns>
        /// <remarks>If the XML schema set is null then the schema is not checked.</remarks>
        public static T Load <T>(
            String filePath,
            IBdoScope scope = null,
            IScriptVariableSet scriptVariableSet = null,
            IBdoLog log = null,
            XmlSchemaSet xmlSchemaSet = null,
            bool mustFileExist        = true,
            bool isRuntimeUpdated     = true) where T : class, IDataItem
        {
            T dataItem = default;

            StreamReader streamReader = null;

            if (!File.Exists(filePath))
            {
                if (mustFileExist)
                {
                    log?.AddError("File not found ('" + filePath + "'). Could not load '" + typeof(T).Name + "' object");
                }
            }
            else
            {
                try
                {
                    IBdoLog checkLog = new BdoLog();

                    if (xmlSchemaSet != null)
                    {
                        XDocument xDocument = XDocument.Load(filePath);
                        xDocument.Validate(xmlSchemaSet, (o, e) => checkLog.AddError("File not valid ('" + filePath + "'). Could not load '" + typeof(T).Name + "' object"));
                        log?.AddEvents(checkLog);
                    }

                    if (!checkLog.HasErrorsOrExceptions())
                    {
                        // then we load
                        XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
                        streamReader = new StreamReader(filePath);
                        dataItem     = xmlSerializer.Deserialize(XmlReader.Create(streamReader)) as T;

                        if (isRuntimeUpdated)
                        {
                            dataItem?.UpdateRuntimeInfo(scope, scriptVariableSet, log);
                        }
                    }
                }
                catch (Exception ex)
                {
                    log?.AddException(ex);
                }
                finally
                {
                    streamReader?.Close();
                }
            }

            return(dataItem);
        }
        private void BuildScriptwordTree(
            IBdoScriptwordDictionaryDto dictionaryDto,
            List <BdoScriptwordDefinition> allDefinitions,
            IBdoLog log = null,
            IBdoScriptwordDefinition parentDefinition = null)
        {
            if (dictionaryDto == null)
            {
                return;
            }

            List <BdoScriptwordDefinitionDto> scriptWordDefinitionDtos = parentDefinition == null ? dictionaryDto.Definitions : parentDefinition?.Dto.Children;

            // we recursively retrieve the sub script words
            foreach (IBdoScriptwordDefinitionDto definitionDto in scriptWordDefinitionDtos)
            {
                // if the current script word is a reference then
                if (!string.IsNullOrEmpty(definitionDto.ReferenceUniqueName))
                {
                    // we retrieve the reference script word
                    IBdoScriptwordDefinition referenceScriptwordDefinition = allDefinitions.Find(p => p.KeyEquals(definitionDto.ReferenceUniqueName) == true);

                    if (referenceScriptwordDefinition == null)
                    {
                        log?.AddError(
                            title: "Child reference '" + definitionDto.ReferenceUniqueName + "' not found in index for script word '" + definitionDto.Key() + "'");
                    }
                    else
                    {
                        parentDefinition?.Children?.Add(referenceScriptwordDefinition.UniqueId?.ToUpper(), referenceScriptwordDefinition);
                    }
                }
                else
                {
                    IBdoScriptwordDefinition definition = allDefinitions.Find(p => p.Dto?.KeyEquals(definitionDto) == true);

                    if (definition == null)
                    {
                        log?.AddError(title: "Script word '" + definitionDto.Key() + "' not found in code");
                    }
                    else
                    {
                        if (parentDefinition != null)
                        {
                            parentDefinition.Children.Add(definition.UniqueId?.ToUpper(), definition);
                            definition.Parent = parentDefinition;
                        }
                        else
                        {
                            _store.Add <IBdoScriptwordDefinition>(definition);
                        }

                        BuildScriptwordTree(dictionaryDto, allDefinitions, log, definition);
                    }
                }
            }
        }
Ejemplo n.º 26
0
        // Browser ---------------------------------------

        /// <summary>
        /// Gets the list of elements of the remote folder.
        /// </summary>
        /// <param name="folderUri">The Uri of the folder path to consider.</param>
        /// <param name="filter">The filter to consider.</param>
        /// <param name="log">The log to consider.</param>
        /// <param name="isRecursive">Indicates whether the search is folder recursive.</param>
        /// <param name="fileKind">The kind of elements to consider.</param>
        /// <returns>Lists of elements of the remote folder.</returns>
        public virtual List <RepositoryItem> GetFiles(
            string folderUri,
            string filter,
            Boolean isRecursive,
            IBdoLog log = null,
            CarrierKind_standard fileKind = CarrierKind_standard.Any)
        {
            return(new List <RepositoryItem>());
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Creates the instance of the specified definition.
 /// </summary>
 /// <param name="scope">The scope to consider.</param>
 /// <param name="configuration">The configuration to consider.</param>
 /// <param name="name">The name to consider.</param>
 /// <param name="log">The log to consider.</param>
 /// <param name="scriptVariableSet">The script variable set to use.</param>
 /// <typeparam name="T">The connector class to return.</typeparam>
 /// <returns>Returns the created connector.</returns>
 public static T CreateConnector <T>(
     this IBdoScope scope,
     IBdoConnectorConfiguration configuration,
     string name = null,
     IBdoLog log = null,
     IScriptVariableSet scriptVariableSet = null) where T : class, IBdoConnector, new()
 {
     return(scope.CreateConnector(configuration, name, log, scriptVariableSet) as T);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Deletes the items.
 /// </summary>
 /// <param name="folderUri">The Uri of the folder path to consider.</param>
 /// <param name="filter">The filter to consider.</param>
 /// <param name="log">The log to consider.</param>
 /// <param name="timeLimit">The date time limit to consider.</param>
 /// <param name="isRecursive">Indicates whether the search is folder recursive.</param>
 /// <param name="fileKind">The kind of elements to consider.</param>
 public virtual void DeleteItems(
     string folderUri,
     string filter,
     DateTime timeLimit,
     Boolean isRecursive,
     IBdoLog log = null,
     CarrierKind_standard fileKind = CarrierKind_standard.Any)
 {
 }
Ejemplo n.º 29
0
        // Carriers ------------------------------------------------

        /// <summary>
        /// Creates the instance of the specified definition.
        /// </summary>
        /// <param name="scope">The scope to consider.</param>
        /// <param name="configuration">The configuration to consider.</param>
        /// <param name="name">The name to consider.</param>
        /// <param name="log">The log to consider.</param>
        /// <param name="scriptVariableSet">The script variable set to use.</param>
        /// <typeparam name="T">The carrier class to return.</typeparam>
        /// <returns>Returns the created carrier.</returns>
        public static T CreateCarrier <T>(
            this IBdoScope scope,
            IBdoCarrierConfiguration configuration = null,
            string name = null,
            IBdoLog log = null,
            IScriptVariableSet scriptVariableSet = null) where T : BdoCarrier
        {
            return(scope.CreateCarrier(configuration, name, log, scriptVariableSet) as T);
        }
Ejemplo n.º 30
0
        // ------------------------------------------
        // MUTATORS
        // ------------------------------------------

        #region Mutators

        /// <summary>
        /// Add the items from all the assemblies.
        /// </summary>
        /// <param name="log">The log to append.</param>
        public IBdoDepot AddFromAllAssemblies(IBdoLog log = null)
        {
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                AddFromAssembly(assembly.FullName, log);
            }

            return(this);
        }