Exemple #1
0
        static void testListOfRemove(ListOf lof, SBase s)
        {
            string ename = s.getElementName();

            lof.append(s);
            SBase c = lof.get(0);

            if (c is CompartmentType)
            {
                CompartmentType x = (lof as ListOfCompartmentTypes).remove(0); c = x;
            }
            else if (c is Compartment)
            {
                Compartment x = (lof as ListOfCompartments).remove(0); c = x;
            }
            else if (c is Constraint)
            {
                Constraint x = (lof as ListOfConstraints).remove(0); c = x;
            }
            else if (c is EventAssignment)
            {
                EventAssignment x = (lof as ListOfEventAssignments).remove(0); c = x;
            }
            else if (c is Event)
            {
                Event x = (lof as ListOfEvents).remove(0); c = x;
            }
            else if (c is FunctionDefinition)
            {
                FunctionDefinition x = (lof as ListOfFunctionDefinitions).remove(0); c = x;
            }
            else if (c is InitialAssignment)
            {
                InitialAssignment x = (lof as ListOfInitialAssignments).remove(0); c = x;
            }
            else if (c is Parameter)
            {
                Parameter x = (lof as ListOfParameters).remove(0); c = x;
            }
            else if (c is Reaction)
            {
                Reaction x = (lof as ListOfReactions).remove(0); c = x;
            }
            else if (c is Rule)
            {
                Rule x = (lof as ListOfRules).remove(0); c = x;
            }
            else if (c is Species)
            {
                Species x = (lof as ListOfSpecies).remove(0); c = x;
            }
            else if (c is SpeciesReference)
            {
                SimpleSpeciesReference x = (lof as ListOfSpeciesReferences).remove(0); c = x;
            }
            else if (c is SpeciesType)
            {
                SpeciesType x = (lof as ListOfSpeciesTypes).remove(0); c = x;
            }
            else if (c is UnitDefinition)
            {
                UnitDefinition x = (lof as ListOfUnitDefinitions).remove(0); c = x;
            }
            else if (c is Unit)
            {
                Unit x = (lof as ListOfUnits).remove(0); c = x;
            }
            else
            {
                ERR("[testListOfRemove] Error: (" + ename + ") : ListOfXXX::remove() failed.");
                return;
            }

            if (c == null)
            {
                ERR("[testListOfRemove] Error: (" + ename + ") : ListOfXXX::remove() failed.");
                return;
            }

            string enameGet = c.getElementName();

            if (ename == enameGet)
            {
                //Console.Out.WriteLine("[testListOfRemove] OK: (" + ename + ") remove(" + enameGet + ") : type match.");
                OK();
            }
            else
            {
                ERR("[testListOfRemove] Error: (" + ename + ") remove(" + enameGet + ") : type mismatch.");
            }
        }
 public override string ToString()
 {
     return(ListOf.ToString() + "[]");
 }
Exemple #3
0
        public bool LoadConfig()
        {
            string value   = Str.Empty;
            string dataTag = Str.Empty;

            Sys.Log2(20, "----------------------------------------------------");
            Sys.Log2(20, "Load configuration");
            Sys.Log2(20, "----------------------------------------------------");

            if (_XMLConf == null)
            {
                Sys.LogError("Cannot read configuration");
                return(false);
            }

            //index list
            dataTag = "CMD_INDEX_LIST";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            listIndexes = CC.Current.Indexes.CleanAliasList(_XMLConf.Value(dataTag, Str.Empty));
            if (String.IsNullOrEmpty(listIndexes))
            {
                Sys.LogError("Invalid configuration property: index list is empty");
                return(false);
            }

            //list columns
            dataTag = "CMD_SELECT";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            value = _XMLConf.Value(dataTag, "*");

            //if only one index and index type is audit => do not resolve column aliases
            CCIndex idx = CC.Current.Indexes.Get(listIndexes);

            isAuditIndex = idx != null && (idx.IndexType == CCIndexType.Audit || idx.IndexType == CCIndexType.AuditReplicated) ? true : false;
            ListStr lcolunmOrColumnAlias = ListStr.ListFromStr(value, ',');

            foreach (string s in lcolunmOrColumnAlias)
            {
                string colunmOrColumnAlias = s.Trim();
                if (!isAuditIndex)
                {
                    dColumnColumnAlias.Add(colunmOrColumnAlias, CC.Current.Global.ResolveColumn(colunmOrColumnAlias));
                }
                else
                {
                    dColumnColumnAlias.Add(colunmOrColumnAlias, colunmOrColumnAlias);
                }
            }

            //where clause
            dataTag = "CMD_WHERE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            whereCluase = _XMLConf.Value(dataTag, "");
            whereCluase = IDocHelper.GetValuePattern(_ctxt, whereCluase);

            //group by
            dataTag = "CMD_GROUPBY";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            grouBy = _XMLConf.Value(dataTag, "");

            //order by
            dataTag = "CMD_ORDERBY";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            orderBy = _XMLConf.Value(dataTag, "");

            //count
            dataTag = "CMD_COUNT";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            count = _XMLConf.ValueInt(dataTag, -1);

            //Engine
            dataTag = "CMD_ENGINE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            engine = CC.Current.Engines.CleanAlias(_XMLConf.Value(dataTag, ""));

            //add headers
            dataTag = "CMD_HEADERS";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            addHeaders = _XMLConf.ValueBoo(dataTag, false);

            //Field separator
            dataTag = "CMD_SEPARATOR";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            separator = _XMLConf.ValueChar(dataTag, ',');

            //override headers
            dataTag = "CMD_HEADERS_OVERRIDE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            overrideHeaders = _XMLConf.ValueBoo(dataTag, false);

            //custom headers
            dataTag = "CMD_HEADERS_CUSTOM";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            string sCustomHeaders = _XMLConf.Value(dataTag, "");

            if (addHeaders && overrideHeaders) //check override header has same number of elements than select statement
            {
                lCustomHeaders = ListStr.ListFromStr2(sCustomHeaders, separator);
                if (lCustomHeaders.Count != dColumnColumnAlias.Count)
                {
                    Sys.LogError("Override headers does not have the same number of elements as select statement");
                    return(false);
                }
            }

            //use replace separator
            dataTag = "CMD_USE_REPLACE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            useReplaceSeparator = _XMLConf.ValueBoo(dataTag, false);

            //Replace separator in values
            dataTag = "CMD_SEPARATOR_REPLACE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            replaceSeparator = _XMLConf.ValueChar(dataTag, '/');

            //Enclose fields in double quote
            dataTag = "CMD_DBL_QUOTES";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            useDblQuote = _XMLConf.ValueBoo(dataTag, false);

            //Destination file path
            dataTag = "CMD_FILE_PATH";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            destinationFilePath = CC.Current.EnvVars.Resolve(_XMLConf.Value(dataTag, ""));
            destinationFilePath = IDocHelper.GetValuePattern(_ctxt, destinationFilePath);
            if (Str.IsEmpty(destinationFilePath))
            {
                Sys.LogError("Export file path is empty");
                return(false);
            }

            //Remove duplicate lines
            dataTag = "CMD_DEDUPLICATE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            removeDuplicates = _XMLConf.ValueBoo(dataTag, false);

            //Remove empty lines
            dataTag = "CMD_REMOVE_EMPTY_LINES";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            removeEmptyLines = _XMLConf.ValueBoo(dataTag, false);

            //Enable simulate mode
            dataTag = "CMD_SIMULATE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            simulate = _XMLConf.ValueBoo(dataTag, false);

            //Simulate count
            dataTag = "CMD_NB_LINE_SIMULATE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            simulateCount = _XMLConf.ValueInt(dataTag, 1000);

            //Mapping Grid - do not check if DatatagExist - grid is optionnal
            dataTag = "CMD_MAPPING";
            ListOf <XDoc> mappingGridElts = _XMLConf.EltList("CMD_MAPPING");

            for (int i = 0; i < mappingGridElts.Count; i++)
            {
                XDoc   mappingElt          = mappingGridElts.Get(i);
                string columnOrAliasColumn = mappingElt.Value("Column");
                if (String.IsNullOrEmpty(columnOrAliasColumn) || String.IsNullOrWhiteSpace(columnOrAliasColumn))
                {
                    Sys.LogError("Column Mapping - Column cannot be empty");
                    return(false);
                }

                string val = mappingElt.Value("Value");
                if (String.IsNullOrEmpty(val) || String.IsNullOrWhiteSpace(val))
                {
                    Sys.LogError("Column Mapping - Value Pattern cannot be empty for column [" + columnOrAliasColumn + "]");
                    return(false);
                }

                string         squery         = mappingElt.Value("SelectionQuery");
                SelectionQuery selectionQuery = SelectionQuery.FromStr(squery, out string errorMessage);
                if (!Str.IsEmpty(errorMessage))
                {
                    Sys.LogError("Column Mapping - Invalid selection query [" + squery + "] for column [" + columnOrAliasColumn + "] - ", errorMessage);
                    return(false);
                }

                if (!dColumnColumnAlias.TryGetValue(columnOrAliasColumn, out string columnName))
                {
                    columnName = null;
                }
                ColumnMapping columnMapping = new ColumnMapping(columnName, columnOrAliasColumn, val, selectionQuery);
                lColumnMapping.AddUnique(columnMapping);
            }

            Sys.Log2(20, "Load configuration OK");
            LogConfig();

            return(true);
        }