Пример #1
0
        public void GetTargetLanguageIdentifierTest()
        {
            /* GetTargetLanguageIdentifier should throw an Exception if called prior to initializing the IdentifierHelper class. */
            Assert.Throws <Exception>(() => IdentifierHelper.GetTargetLanguageIdentifier("valid_identifier"));

            var configuration =
                new Utilities.Sql.SqlServer.Configuration()
            {
                Connection            = null, /* Not needed for these unit tests. */
                XmlSystem             = XmlSystem.NonLinq_XmlDocument,
                TargetLanguage        = TargetLanguage.CSharp_4_0,
                XmlValidationLocation = XmlValidationLocation.PropertySetter
            };

            IdentifierHelper.Init(configuration);

            /* After initialization, bad inputs should throw these exceptions... */

            Assert.Throws <ArgumentNullException>(() => IdentifierHelper.GetTargetLanguageIdentifier(null));
            Assert.Throws <ArgumentException>(() => IdentifierHelper.GetTargetLanguageIdentifier(""));
            Assert.Throws <ArgumentException>(() => IdentifierHelper.GetTargetLanguageIdentifier(" "));

            Action <String, String> areEqual = (expected, actual) => Assert.AreEqual(expected, IdentifierHelper.GetTargetLanguageIdentifier(actual));

            /* ...and good inputs should pass these tests. */

            areEqual("valid_identifier", "valid_identifier");      // Already a valid identifier.
            areEqual("valid_identifier", "valid identifier");      // Spaces converted to underscores.
            areEqual("valid_identifier", "valid.identifier");      // Dots converted to underscores.
            areEqual("_42valid_identifier", "42valid identifier"); // Spaces converted to underscores, and starts with a number.
            areEqual("_delegate", "delegate");                     // Keyword.
            areEqual("_delegate", "_delegate");                    // Already starts with an underscore.
            areEqual("___delegate", "__delegate");                 // C# specific: Starts with two underscores, so prepend a third one.
            areEqual("_42delegate", "42delegate");                 // Starts with a number.
        }
Пример #2
0
 public HistoryController(StatefulControllerDependencies dependencies,
                          IdentifierHelper idHelper,
                          Lazy <AppManager> appManagerLazy) : base(dependencies)
 {
     _idHelper       = idHelper;
     _appManagerLazy = appManagerLazy;
 }
        public ProviderPluginSaveTask RunWithResult(SyneryParser.ProviderPluginSaveStatementContext context)
        {
            ProviderPluginSaveTask saveTask = new ProviderPluginSaveTask();

            // get the full path consisting of the connection identifier, the provider plugin endpoint path and the endpoint name.

            saveTask.FullSyneryPath = context.providerPluginResourceIdentifier().GetText();
            saveTask.FullPath       = IdentifierHelper.ParsePathIdentifier(saveTask.FullSyneryPath);

            if (context.fromCommand() != null)
            {
                saveTask.SourceTableName = Controller.Interpret <SyneryParser.FromCommandContext, string>(context.fromCommand());
            }

            if (context.setCommand() != null)
            {
                IDictionary <string[], IValue> setParameters = Controller.Interpret <SyneryParser.SetCommandContext, IDictionary <string[], IValue> >(context.setCommand());

                foreach (var param in setParameters)
                {
                    // add the pramater with the key and the value (not IValue !)
                    saveTask.Parameters.Add(param.Key, param.Value.Value);
                }
            }

            return(saveTask);
        }
Пример #4
0
        private ValueSetConcept Convert(ValueSetMember member)
        {
            ValueSetConcept concept = new ValueSetConcept()
            {
                code           = member.Code,
                codeSystemName = member.CodeSystem.Name,
                displayName    = member.DisplayName,
                type           = VocabType.L,
                level          = "1"
            };

            if (IdentifierHelper.IsIdentifierOID(member.CodeSystem.Oid))
            {
                string oid;
                IdentifierHelper.GetIdentifierOID(member.CodeSystem.Oid, out oid);
                concept.codeSystem = oid;
            }
            else if (IdentifierHelper.IsIdentifierII(member.CodeSystem.Oid))
            {
                string oid, ext;
                IdentifierHelper.GetIdentifierII(member.CodeSystem.Oid, out oid, out ext);
                concept.codeSystem = oid;
            }

            return(concept);
        }
Пример #5
0
        /// <summary>
        /// Interprets a connect statement that instructs the Interface Booster to open a connection of a Provider Plugin.
        /// </summary>
        /// <param name="context"></param>
        public ProviderPluginConnectTask RunWithResult(SyneryParser.ProviderPluginConnectStatementContext context)
        {
            // get the instance reference name and the connection identifier from the Synery code
            // prepare the ConnectTask for the ProviderPluginManager

            ProviderPluginConnectTask connectTask = new ProviderPluginConnectTask();

            connectTask.SyneryConnectionPath = context.ExternalPathIdentifier().GetText();                             // e.g. \\csv\articleFile
            connectTask.ConnectionPath       = IdentifierHelper.ParsePathIdentifier(connectTask.SyneryConnectionPath); // e.g. new string[] { "csv", "articleFile" }
            connectTask.InstanceReferenceSyneryIdentifier = LiteralHelper.ParseStringLiteral(context.providerPluginConnectStatementProviderPluginInstance().StringLiteral());

            if (context.setCommand() != null)
            {
                // get all connection parameters from the synery code and append them to the ConnectCommand

                IDictionary <string[], IValue> listOfKeyValues = Controller.Interpret <SyneryParser.SetCommandContext, IDictionary <string[], IValue> >(context.setCommand());

                foreach (var keyValue in listOfKeyValues)
                {
                    connectTask.Parameters.Add(keyValue.Key, keyValue.Value.Value);
                }
            }

            return(connectTask);
        }
Пример #6
0
        private string GenerateDocumentTemplateIdentifierXpath(string templateIdentifier)
        {
            string oid;
            string root;
            string extension;
            string urn;

            if (IdentifierHelper.GetIdentifierOID(templateIdentifier, out oid))
            {
                return(string.Format(this.igTypePlugin.TemplateIdentifierXpath, this.schemaPrefix, oid));
            }
            else if (IdentifierHelper.GetIdentifierII(templateIdentifier, out root, out extension))
            {
                if (string.IsNullOrEmpty(extension))
                {
                    return(string.Format(this.igTypePlugin.TemplateIdentifierXpath, this.schemaPrefix, root));
                }
                else
                {
                    return(string.Format(this.igTypePlugin.TemplateVersionIdentifierXpath, this.schemaPrefix, root, extension));
                }
            }
            else if (IdentifierHelper.GetIdentifierURL(templateIdentifier, out urn))
            {
                return(string.Format(this.igTypePlugin.TemplateIdentifierXpath, this.schemaPrefix, urn));
            }
            else
            {
                throw new Exception("Unexpected/invalid identifier for template found when processing template reference for closed template identifier xpath");
            }
        }
Пример #7
0
        public void GetNormalizedSqlIdentifierTest()
        {
            Assert.Throws <ArgumentNullException>(() => IdentifierHelper.GetBracketedSqlIdentifier(null));
            Assert.Throws <ArgumentException>(() => IdentifierHelper.GetBracketedSqlIdentifier(""));
            Assert.Throws <ArgumentException>(() => IdentifierHelper.GetBracketedSqlIdentifier(" "));

            Action <String, String> areEqual = (expected, actual) => Assert.AreEqual(expected, IdentifierHelper.GetBracketedSqlIdentifier(actual));

            areEqual(".", ".");
            areEqual("..", "..");

            areEqual("[a]", "a");
            areEqual("[a]", "[a");
            areEqual("[a]", "a]");
            areEqual("[a]", "[a]");
            areEqual("[a]", "[[a]]");

            areEqual("[a].[b]", "[a].b");
            areEqual("[a].[b]", "a.[b]");
            areEqual("[a].[b]", "[a].[b]");

            areEqual("[a]..[b]", "[a]..b");
            areEqual("[a]..[b]", "a..[b]");
            areEqual("[a]..[b]", "[a]..[b]");
        }
        private void InterpretAssignment(SyneryParser.VariableAssignmentContext context)
        {
            if (context.variableInitializer() != null)
            {
                if (context.variableReference() != null)
                {
                    string name  = context.variableReference().GetText();
                    IValue value = Controller.Interpret <SyneryParser.ExpressionContext, IValue>(context.variableInitializer().expression());

                    Memory.CurrentScope.AssignVariable(name, value.Value);
                }
                else if (context.complexReference() != null)
                {
                    IValue value = Controller.Interpret <SyneryParser.ExpressionContext, IValue>(context.variableInitializer().expression());

                    string   complexReference = context.complexReference().GetText();
                    string[] parts            = IdentifierHelper.ParseComplexIdentifier(complexReference);
                    string[] recordPath       = parts.Take(parts.Count() - 1).ToArray();
                    string   fieldName        = parts.Last();

                    IValue recordValue = Controller.Interpret <SyneryParser.ComplexReferenceContext, IValue, string[]>(context.complexReference(), recordPath);

                    if (recordValue.Type.UnterlyingDotNetType == typeof(IRecord))
                    {
                        IRecord record = ((IRecord)recordValue.Value);
                        record.SetFieldValue(fieldName, value);
                    }
                }
            }
        }
        public IValue RunWithResult(SyneryParser.ComplexReferenceContext context)
        {
            string complexReference = context.GetText();

            string[] parts = IdentifierHelper.ParseComplexIdentifier(complexReference);

            return(RunWithResult(context, parts));
        }
Пример #10
0
        public static string BuildContextString(string aPrefix, string templateIdentifierXpath, string templateVersionIdentifierXpath, Template aTemplate)
        {
            string schemaPrefix = aPrefix;

            if (!string.IsNullOrEmpty(schemaPrefix) && !schemaPrefix.EndsWith(":"))
            {
                schemaPrefix += ":";
            }

            StringBuilder context         = new StringBuilder();
            string        templateContext = aTemplate.PrimaryContext;

            if (string.IsNullOrEmpty(templateContext))
            {
                templateContext = aTemplate.TemplateType.RootContext;
            }

            if (!string.IsNullOrEmpty(templateContext) && templateContext.IndexOf(':') < 0)
            {
                templateContext = schemaPrefix + templateContext;
            }

            context.Append(templateContext);

            string oid;
            string root;
            string extension;
            string urn;

            string identifierFormat        = "[" + templateIdentifierXpath + "]";
            string versionIdentifierFormat = "[" + templateVersionIdentifierXpath + "]";

            if (IdentifierHelper.GetIdentifierOID(aTemplate.Oid, out oid))
            {
                context.Append(string.Format(identifierFormat, schemaPrefix, oid));
            }
            else if (IdentifierHelper.GetIdentifierII(aTemplate.Oid, out root, out extension))
            {
                if (string.IsNullOrEmpty(extension))
                {
                    context.Append(string.Format(identifierFormat, schemaPrefix, root));
                }
                else
                {
                    context.Append(string.Format(versionIdentifierFormat, schemaPrefix, root, extension));
                }
            }
            else if (IdentifierHelper.GetIdentifierURL(aTemplate.Oid, out urn))
            {
                context.Append(string.Format(identifierFormat, schemaPrefix, urn));
            }
            else
            {
                throw new Exception("Unexpected/invalid identifier for template found when processing template reference for closed template identifier xpath");
            }

            return(context.ToString());
        }
        public void Splitting_Short_ComplexIdentifier_Works()
        {
            string complexIdentifier = @"p.PersonId";

            string[] path = IdentifierHelper.ParseComplexIdentifier(complexIdentifier);

            Assert.AreEqual(2, path.Count());
            Assert.AreEqual("p", path[0]);
            Assert.AreEqual("PersonId", path[1]);
        }
        public void Splitting_Short_ExternalPathIdentifier_Works()
        {
            string externalPathIdentifier = @"\\myConnection\someRecordSet\";

            string[] path = IdentifierHelper.ParsePathIdentifier(externalPathIdentifier);

            Assert.AreEqual(2, path.Count());
            Assert.AreEqual("myConnection", path[0]);
            Assert.AreEqual("someRecordSet", path[1]);
        }
        public void Splitting_Short_InternalPathIdentifier_Works()
        {
            string internalPathIdentifier = @"\tableGroup\myTable\";

            string[] path = IdentifierHelper.ParsePathIdentifier(internalPathIdentifier);

            Assert.AreEqual(2, path.Count());
            Assert.AreEqual("tableGroup", path[0]);
            Assert.AreEqual("myTable", path[1]);
        }
        public void Splitting_Long_ComplexIdentifier_Works()
        {
            string complexIdentifier = @"r.Person.Id";

            string[] path = IdentifierHelper.ParseComplexIdentifier(complexIdentifier);

            Assert.AreEqual(3, path.Count());
            Assert.AreEqual("r", path[0]);
            Assert.AreEqual("Person", path[1]);
            Assert.AreEqual("Id", path[2]);
        }
        public void Splitting_Long_ExternalPathIdentifier_Works()
        {
            string externalPathIdentifier = @"\\myConnection\recodSetGroup\subGroup\someRecordSet";

            string[] path = IdentifierHelper.ParsePathIdentifier(externalPathIdentifier);

            Assert.AreEqual(4, path.Count());
            Assert.AreEqual("myConnection", path[0]);
            Assert.AreEqual("recodSetGroup", path[1]);
            Assert.AreEqual("subGroup", path[2]);
            Assert.AreEqual("someRecordSet", path[3]);
        }
Пример #16
0
        private void CreateAndPopulateElementAssertionString(StringBuilder sb)
        {
            //generate the element assertion
            var elementAssert = _element.GetAssertionStringIdentifier();

            if (!string.IsNullOrEmpty(elementAssert))
            {
                elementAssert = this.GetFormattedPrefix() + elementAssert;
            }
            else if (string.IsNullOrEmpty(elementAssert) && !string.IsNullOrEmpty(this._containedTemplateOid))
            {
                elementAssert = "*";
            }

            //do we have a template id?
            if (!string.IsNullOrEmpty(_containedTemplateOid))
            {
                string oid;
                string root;
                string extension;
                string urn;

                if (IdentifierHelper.GetIdentifierOID(_containedTemplateOid, out oid))
                {
                    string format = "[" + this._templateIdentifierXpath + "]";
                    elementAssert = elementAssert + string.Format(format, this.GetFormattedPrefix(), oid);
                }
                else if (IdentifierHelper.GetIdentifierII(_containedTemplateOid, out root, out extension))
                {
                    if (string.IsNullOrEmpty(extension))
                    {
                        string format = "[" + this._templateIdentifierXpath + "]";
                        elementAssert = elementAssert + string.Format(format, this.GetFormattedPrefix(), root);
                    }
                    else
                    {
                        string format = "[" + this._templateVersionIdentifierXpath + "]";
                        elementAssert = elementAssert + string.Format(format, this.GetFormattedPrefix(), root, extension);
                    }
                }
                else if (IdentifierHelper.GetIdentifierURL(_containedTemplateOid, out urn))
                {
                    string format = "[" + this._templateIdentifierXpath + "]";
                    elementAssert = elementAssert + string.Format(format, this.GetFormattedPrefix(), urn);
                }
                else
                {
                    throw new Exception("Unexpected/invalid identifier for template found when processing contained template reference");
                }
            }

            sb.Replace(Sentinels.ELEMENT_TOKEN, elementAssert);
        }
 public override void  Up()
 {
     Database.Insert(
         "Product",
         new string[]
     {
         "Id",
         "Code",
         "Name",
         "Taxes"
     },
         new string[]
     {
         IdentifierHelper.GenerateComb().ToString(),
         "CODIGOPRODUCTO",
         "Prueba",
         "15"
     }
         );
 }
        public ProviderPluginExecuteTask RunWithResult(SyneryParser.ProviderPluginExecuteStatementContext context)
        {
            ProviderPluginExecuteTask executeTask = new ProviderPluginExecuteTask();

            // get the full path consisting of the connection identifier, the provider plugin endpoint path and the endpoint name.

            executeTask.FullSyneryPath = context.providerPluginResourceIdentifier().GetText();
            executeTask.FullPath       = IdentifierHelper.ParsePathIdentifier(executeTask.FullSyneryPath);

            if (context.setCommand() != null)
            {
                IDictionary <string[], IValue> setParameters = Controller.Interpret <SyneryParser.SetCommandContext, IDictionary <string[], IValue> >(context.setCommand());

                foreach (var param in setParameters)
                {
                    // add the pramater with the key and the value (not IValue !)
                    executeTask.Parameters.Add(param.Key, param.Value.Value);
                }
            }

            if (context.getCommand() != null)
            {
                executeTask.GetValues = Controller.Interpret <SyneryParser.GetCommandContext, IList <ProviderPluginGetValue> >(context.getCommand());

                // check whether variables with the specified names exists
                // this prevents errors after sending the request to the provider plugin

                foreach (var getValue in executeTask.GetValues)
                {
                    if (!Memory.CurrentScope.DoesVariableExists(getValue.SyneryVariableName))
                    {
                        throw new SyneryInterpretationException(context, string.Format(
                                                                    "Local variable with name '{0}' was not found.", getValue.SyneryVariableName));
                    }
                }
            }

            executeTask.OnFinishedSuccessfully += ExecuteTask_OnFinishedSuccessfully;

            return(executeTask);
        }
        public KeyValuePair <SyneryType, IRecordType> RunWithResult(SyneryParser.RecordTypeContext context)
        {
            string recordTypeName = RecordHelper.ParseRecordTypeName(context.GetText());

            recordTypeName = IdentifierHelper.GetIdentifierBasedOnFunctionScope(Memory, recordTypeName);

            KeyValuePair <SyneryType, IRecordType> recordTypeDefinition = (from r in Memory.RecordTypes
                                                                           where r.Value.FullName == recordTypeName
                                                                           select r).FirstOrDefault();

            // check record type is known

            if (recordTypeDefinition.Key == null)
            {
                throw new SyneryInterpretationException(context, String.Format(
                                                            "A record type with name='{0}' wasn't found.",
                                                            recordTypeName));
            }

            return(recordTypeDefinition);
        }
        public ProviderPluginReadTask RunWithResult(SyneryParser.ProviderPluginReadStatementContext context)
        {
            ProviderPluginReadTask readTask = new ProviderPluginReadTask();

            // get the full path consisting of the connection identifier, the provider plugin endpoint path and the endpoint name.

            readTask.FullSyneryPath = context.providerPluginResourceIdentifier().GetText();
            readTask.FullPath       = IdentifierHelper.ParsePathIdentifier(readTask.FullSyneryPath);

            if (context.toCommand() != null)
            {
                readTask.TargetTableName = Controller.Interpret <SyneryParser.ToCommandContext, string>(context.toCommand());
            }

            if (context.setCommand() != null)
            {
                IDictionary <string[], IValue> setParameters = Controller.Interpret <SyneryParser.SetCommandContext, IDictionary <string[], IValue> >(context.setCommand());

                foreach (var param in setParameters)
                {
                    // add the pramater with the key and the value (not IValue !)
                    readTask.Parameters.Add(param.Key, param.Value.Value);
                }
            }

            if (context.fieldsCommand() != null)
            {
                readTask.FieldNames = Controller.Interpret <SyneryParser.FieldsCommandContext, IList <string> >(context.fieldsCommand());
            }

            if (context.filterCommand() != null)
            {
                readTask.Filter = Controller.Interpret <SyneryParser.FilterCommandContext, IFilter>(context.filterCommand());
            }

            return(readTask);
        }
Пример #21
0
        private IReadOnlyList <FileInfo> RunCore(
            DirectoryInfo projectDirectory, DirectoryInfo workingDirectory,
            string rootNamespace, IEnumerable <FileInfo> yamlFiles)
        {
            const string methodName     = "AsDictionary";
            const string interfaceName  = "IYamlCSharpDictionary";
            var          convertedFiles = new List <FileInfo>();

            workingDirectory.Create();

            // 生成接口。
            var interfaceCreator = new ShapeInterfaceCreator(
                rootNamespace, interfaceName,
                $"System.Collections.Generic.Dictionary<string, string> {methodName}()");
            var interfaceFile = new FileInfo(Path.Combine(workingDirectory.FullName, $"{interfaceName}.cs"));
            var @interface    = interfaceCreator.Create();

            File.WriteAllText(interfaceFile.FullName, @interface);
            convertedFiles.Add(interfaceFile);

            // 生成实现类。
            var yamlFileToCSharpFile = new YamlFileToCSharpFile();

            foreach (var yamlFile in yamlFiles)
            {
                var(@namespace, @class) = IdentifierHelper.MakeNamespaceAndClassName(projectDirectory, yamlFile, rootNamespace);
                var csharpFile = new FileInfo(Path.Combine(workingDirectory.FullName, $"{@namespace}.{@class}.cs"));

                yamlFileToCSharpFile.ParseToCSharpFile(yamlFile, csharpFile,
                                                       @namespace, $"{RootNamespace}.{interfaceName}", @class, methodName,
                                                       Assembly.GetExecutingAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>()?.InformationalVersion);

                convertedFiles.Add(csharpFile);
            }

            return(convertedFiles);
        }
Пример #22
0
        private object[] ExportConstraints(TemplateConstraint parentConstraint = null, bool isAttribute = false)
        {
            List <object> constraintRules = new List <object>();

            if (parentConstraint != null)
            {
                if (parentConstraint.ValueSet != null || parentConstraint.CodeSystem != null || !string.IsNullOrEmpty(parentConstraint.Value))
                {
                    vocabulary vocabConstraint = new vocabulary();

                    if (parentConstraint.ValueSet != null)
                    {
                        vocabConstraint.valueSet = parentConstraint.ValueSet.Oid;

                        string oid, ext;

                        if (IdentifierHelper.IsIdentifierOID(parentConstraint.ValueSet.Oid))
                        {
                            IdentifierHelper.GetIdentifierOID(parentConstraint.ValueSet.Oid, out oid);
                            vocabConstraint.valueSet = oid;
                        }
                        else if (IdentifierHelper.IsIdentifierII(parentConstraint.ValueSet.Oid))
                        {
                            IdentifierHelper.GetIdentifierII(parentConstraint.ValueSet.Oid, out oid, out ext);
                            vocabConstraint.valueSet = oid;
                        }
                    }

                    if (parentConstraint.CodeSystem != null)
                    {
                        vocabConstraint.codeSystem     = parentConstraint.CodeSystem.Oid;
                        vocabConstraint.codeSystemName = parentConstraint.CodeSystem.Name;

                        string oid, ext;

                        if (IdentifierHelper.IsIdentifierOID(parentConstraint.CodeSystem.Oid))
                        {
                            IdentifierHelper.GetIdentifierOID(parentConstraint.CodeSystem.Oid, out oid);
                            vocabConstraint.codeSystem = oid;
                        }
                        else if (IdentifierHelper.IsIdentifierII(parentConstraint.CodeSystem.Oid))
                        {
                            IdentifierHelper.GetIdentifierII(parentConstraint.CodeSystem.Oid, out oid, out ext);
                            vocabConstraint.codeSystem = oid;
                        }
                    }

                    if (!string.IsNullOrEmpty(parentConstraint.Value))
                    {
                        vocabConstraint.code = parentConstraint.Value;
                    }

                    if (!string.IsNullOrEmpty(parentConstraint.DisplayName))
                    {
                        vocabConstraint.displayName = parentConstraint.DisplayName;
                    }

                    if (parentConstraint.IsStatic == true && parentConstraint.ValueSetDate != null)
                    {
                        vocabConstraint.flexibility = parentConstraint.ValueSetDate.Value.ToString("yyyy-MM-ddThh:mm:ss");
                    }
                    else if (parentConstraint.IsStatic == false)
                    {
                        vocabConstraint.flexibility = "dynamic";
                    }

                    constraintRules.Add(vocabConstraint);
                }
            }

            foreach (var constraint in this.template.ChildConstraints.Where(y => y.ParentConstraintId == (parentConstraint != null ? parentConstraint.Id : (int?)null)))
            {
                if (!constraint.IsPrimitive)
                {
                    if (isAttribute)
                    {
                        continue;       // Can't export child elements/attributes of an attribute constraint
                    }
                    if (constraint.Context.StartsWith("@"))
                    {
                        constraintRules.Add(this.ExportAttribute(constraint));
                    }
                    else
                    {
                        constraintRules.Add(this.ExportElement(constraint));
                    }
                }
                else
                {
                    IFormattedConstraint formattedConstraint = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.igSettings, constraint, null, null, false, false, false, false);

                    XmlNode[] anyField = new XmlNode[] { this.dom.CreateTextNode(formattedConstraint.GetPlainText(false, false, false)) };
                    constraintRules.Add(new FreeFormMarkupWithLanguage()
                    {
                        Any = anyField
                    });
                }
            }

            return(constraintRules.ToArray());
        }
Пример #23
0
 /// <summary>
 /// Determines if the identifier for the template is a "urn:" identifier
 /// </summary>
 public static bool IsIdentifierURL(this Template template)
 {
     return(IdentifierHelper.IsIdentifierURL(template.Oid));
 }
Пример #24
0
 public static bool GetIdentifierURL(this Template template, out string uri)
 {
     return(IdentifierHelper.GetIdentifierURL(template.Oid, out uri));
 }
Пример #25
0
 public void TestInit()
 {
     _Newid = IdentifierHelper.NewAccountId();
 }
Пример #26
0
 public void Helpers_IncrementingNewId_Test()
 {
     Assert.IsTrue(IdentifierHelper.NewAccountId() == _Newid + 1);
     Assert.IsTrue(IdentifierHelper.NewAccountId() == _Newid + 2);
     Assert.IsFalse(IdentifierHelper.NewAccountId() == _Newid + 4);
 }
Пример #27
0
        /// <summary>
        /// Creates a rule context for a template where the template DOES have an identifier element
        /// </summary>
        /// <remarks>
        /// Example: Where "ClinicalDocument" has a "templateId" element
        /// Example: Where a FHIR element DOES have "meta/profile"
        /// </remarks>
        /// <param name="templateIdentifier"></param>
        /// <param name="primaryContext"></param>
        /// <param name="templateIdentifierElementName"></param>
        /// <returns></returns>
        private string BuildContextWithIdentifierElement(string templateIdentifier, string primaryContext = null, string templateIdentifierElementName = null)
        {
            string contextFormat = "{0}";
            string root          = null;
            string extension     = null;

            if (string.IsNullOrEmpty(templateIdentifierElementName))
            {
                templateIdentifierElementName = this.GetTemplateIdentifierElementName();
            }

            if (templateIdentifierElementName.IndexOf(":") < 0)
            {
                templateIdentifierElementName = this.prefix + ":" + templateIdentifierElementName;
            }

            if (!string.IsNullOrEmpty(primaryContext))
            {
                if (primaryContext.Contains(":"))       // primaryContext already contains prefix
                {
                    contextFormat = string.Format("{0}[{{0}}]", primaryContext);
                }
                else
                {
                    contextFormat = string.Format("{0}:{1}[{{0}}]", this.prefix, primaryContext);
                }
            }

            if (string.IsNullOrEmpty(this.plugin.TemplateIdentifierElementName))
            {
                throw new Exception("Plugin for implementation guide type is not configured properly: Does not specify a TemplateIdentifierElementName");
            }

            if (string.IsNullOrEmpty(this.plugin.TemplateIdentifierRootName))
            {
                throw new Exception("Plugin for implementation guide type is not configured properly: Does not specify a TemplateIdentifierRootName");
            }

            if (IdentifierHelper.IsIdentifierOID(templateIdentifier))
            {
                IdentifierHelper.GetIdentifierOID(templateIdentifier, out root);
            }
            else if (IdentifierHelper.IsIdentifierII(templateIdentifier))
            {
                IdentifierHelper.GetIdentifierII(templateIdentifier, out root, out extension);
            }
            else if (IdentifierHelper.IsIdentifierURL(templateIdentifier))
            {
                IdentifierHelper.GetIdentifierURL(templateIdentifier, out root);
            }
            else
            {
                throw new Exception("Unexpected/invalid identifier for template found when processing template reference for template identifier xpath");
            }

            if (!string.IsNullOrEmpty(extension) && !string.IsNullOrEmpty(this.plugin.TemplateIdentifierExtensionName))
            {
                string predicate = string.Format("{0}[{1}='{3}' and {2}='{4}']",
                                                 templateIdentifierElementName,
                                                 this.plugin.TemplateIdentifierRootName,
                                                 this.plugin.TemplateIdentifierExtensionName,
                                                 root,
                                                 extension);
                return(string.Format(contextFormat, predicate));
            }
            else
            {
                string predicate = string.Format("{0}[{1}='{2}']",
                                                 templateIdentifierElementName,
                                                 this.plugin.TemplateIdentifierRootName,
                                                 root);
                return(string.Format(contextFormat, predicate));
            }
        }
        private KeyValuePair <string, IExpressionValue> InterpretComplexReference(SyneryParser.ComplexReferenceContext context, QueryMemory queryMemory)
        {
            // get the future fieldname from it's old name by removing the alias
            string complexIdentifier = context.GetText();

            string[] path      = IdentifierHelper.ParseComplexIdentifier(complexIdentifier);
            string   fieldName = path[path.Length - 1];

            // get the LINQ expression for the field reference
            IField schemaField   = queryMemory.CurrentTable.Schema.GetField(complexIdentifier);
            int    fieldPosition = queryMemory.CurrentTable.Schema.GetFieldPosition(complexIdentifier);

            if (fieldPosition != -1)
            {
                // the field was found - create an array index Expression to access the field value

                Expression arraySelectorExpression = Expression.ArrayIndex(queryMemory.RowExpression, Expression.Constant(fieldPosition));

                ExpressionValue expressionValue = new ExpressionValue(
                    expression: arraySelectorExpression,
                    resultType: TypeHelper.GetSyneryType(schemaField.Type)
                    );

                return(new KeyValuePair <string, IExpressionValue>(fieldName, expressionValue));
            }

            // search for an other kind of complex references

            IValue value = Controller.Interpret <SyneryParser.ComplexReferenceContext, IValue>(context);

            if (value != null)
            {
                // the value could be resolved
                // create a constant LINQ expression for the value

                // check whether it's a primitive type

                if (value.Type != typeof(IRecord))
                {
                    Expression expression;

                    if (value.Type != null)
                    {
                        expression = Expression.Constant(value.Value, value.Type.UnterlyingDotNetType);
                    }
                    else
                    {
                        expression = Expression.Constant(null);
                    }

                    ExpressionValue expressionValue = new ExpressionValue(
                        expression: expression,
                        resultType: value.Type
                        );

                    return(new KeyValuePair <string, IExpressionValue>(fieldName, expressionValue));
                }
                else
                {
                    throw new SyneryInterpretationException(context, String.Format(
                                                                "Cannot use the reference to the record (name='{0}') inside of a query. Only primitve types are allowed."
                                                                , fieldName));
                }
            }

            throw new SyneryInterpretationException(context, String.Format("A field or variable with the name '{0}' wan't found.", complexIdentifier));
        }
Пример #29
0
        public void Setup()
        {
            var identifierHelper = new IdentifierHelper();

            _result = identifierHelper.ParseIdentifier("ThisIsATestIdentifier");
        }
        public override void  Up()
        {
            string IdContableConfigurationSample = IdentifierHelper.GenerateComb().ToString();
            string IdAccountTreeSample           = IdentifierHelper.GenerateComb().ToString();
            string IdDefaultAccountSample        = IdentifierHelper.GenerateComb().ToString();
            string IdParentAccountSample         = IdentifierHelper.GenerateComb().ToString();

            Database.Insert(
                "AccountTree",
                new string[]
            {
                "Id",
                "Code",
                "Name",
                "Description"
            },
                new string[]
            {
                IdAccountTreeSample,
                "CODIGOTREE",
                "PruebaTree",
                "Arbol de cuentas de prueba"
            }
                );


            Database.Insert(
                "ContableAccount",
                new string[]
            {
                "Id",
                "Code",
                "Name",
                "Description",
                "Imputable",
                "IdAccountTree"
            },
                new string[]
            {
                IdDefaultAccountSample,
                "CODIGODEFAULT",
                "PruebaDefault",
                "Cuenta por defecto",
                "True",
                IdAccountTreeSample
            }
                );

            Database.Insert(
                "ContableAccount",
                new string[]
            {
                "Id",
                "Code",
                "Name",
                "Description",
                "Imputable",
                "IdAccountTree"
            },
                new string[]
            {
                IdentifierHelper.GenerateComb().ToString(),
                "CODIGO1",
                "Prueba1",
                "Cuenta1",
                "True",
                IdAccountTreeSample
            }
                );

            Database.Insert(
                "ContableAccount",
                new string[]
            {
                "Id",
                "Code",
                "Name",
                "Description",
                "Imputable",
                "IdAccountTree"
            },
                new string[]
            {
                IdParentAccountSample,
                "CODIGOPADRE",
                "PruebaPadre",
                "CuentaPadre",
                "False",
                IdAccountTreeSample
            }
                );

            Database.Insert(
                "ContableAccount",
                new string[]
            {
                "Id",
                "Code",
                "Name",
                "Description",
                "Imputable",
                "IdAccountTree",
                "IdParentAccount"
            },
                new string[]
            {
                IdentifierHelper.GenerateComb().ToString(),
                "CODIGOHIJO1",
                "PruebaHijo1",
                "CuentaHijo1",
                "False",
                IdAccountTreeSample,
                IdParentAccountSample
            }
                );

            Database.Insert(
                "ContableAccount",
                new string[]
            {
                "Id",
                "Code",
                "Name",
                "Description",
                "Imputable",
                "IdAccountTree",
                "IdParentAccount"
            },
                new string[]
            {
                IdentifierHelper.GenerateComb().ToString(),
                "CODIGOHIJO2",
                "PruebaHijo2",
                "CuentaHijo2",
                "False",
                IdAccountTreeSample,
                IdParentAccountSample
            }
                );


            Database.Insert(
                "ContableConfiguration",
                new string[]
            {
                "Id",
                "Code",
                "Name",
                "Description",
                "IdAccountTree",
                "IdDefaultAccount",
            },
                new string[]
            {
                IdContableConfigurationSample,
                "CODIGOCONFIGURACION",
                "PruebaConfiguracion",
                "Configuración contable de prueba",
                IdAccountTreeSample,
                IdDefaultAccountSample
            }
                );
        }