Exemplo n.º 1
0
        private void CreateOptionSetField(JToken field)
        {
            CreateAttributeRequest req = new CreateAttributeRequest();

            req.EntityName = field["entity"].ToString();

            var am = new PicklistAttributeMetadata();

            am.SchemaName    = field["schemaname"].ToString();
            am.RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None);
            am.DisplayName   = new Label(field["displayname"].ToString(), 1033);
            am.Description   = new Label("", 1033);

            OptionSetMetadata os = new OptionSetMetadata();

            os.IsGlobal = false;
            foreach (var option in field["options"])
            {
                Label label = new Label(option["displayname"].ToString(), 1033);
                int?  value = JSONUtil.GetInt32(option, "value");
                os.Options.Add(new OptionMetadata(label, value));
            }
            am.OptionSet = os;

            req.Attribute = am;

            this._cdsConnection.Execute(req);
        }
Exemplo n.º 2
0
        private void CreateTextField(JToken field)
        {
            var entitySchemaName = JSONUtil.GetText(field, "entity");
            var displayName      = JSONUtil.GetText(field, "displayname");
            var fieldSchemaName  = JSONUtil.GetText(field, "schemaname");

            var req = new CreateAttributeRequest();

            req.EntityName = entitySchemaName;

            var format = JSONUtil.GetText(field, "format");

            if (format == null)
            {
                format = "single";
            }

            int?maxlength = JSONUtil.GetInt32(field, "maxlength");

            if (format == "single")
            {
                var am = new StringAttributeMetadata();
                am.SchemaName    = field["schemaname"].ToString();
                am.RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None);

                maxlength    = maxlength == null ? 100 : maxlength;
                am.MaxLength = maxlength;

                am.FormatName  = StringFormatName.Text;
                am.DisplayName = new Label(displayName, 1033);
                am.Description = new Label("", 1033);
                req.Attribute  = am;
            }
            else if (format == "multi")
            {
                var am = new MemoAttributeMetadata();
                am.SchemaName    = fieldSchemaName;
                am.RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None);

                maxlength    = maxlength == null ? 2000 : maxlength;
                am.MaxLength = maxlength;

                am.DisplayName = new Label(displayName, 1033);
                am.Description = new Label("", 1033);
                req.Attribute  = am;
            }

            this._cdsConnection.Execute(req);
        }
Exemplo n.º 3
0
        public void Process(JObject command, Context context)
        {
            // get default property
            var item = JSONUtil.GetToken(command, "communicate");

            if (item == null)
            {
                item = JSONUtil.GetToken(command, "#communicate");
            }
            if (item == null)
            {
                item = JSONUtil.GetToken(command, "#say");
            }

            // get all other properties
            var select = JSONUtil.GetText(command, "select");
            var rate   = JSONUtil.GetInt32(command, "rate");

            item = context.ReplaceVariables(item);

            if (select != null)
            {
                item = item.SelectToken(select);
            }

            if (rate != null)
            {
                var iRate = (int)rate; // get it? :)
                foreach (char c in item.ToString())
                {
                    Console.Write(c);
                    System.Threading.Thread.Sleep(iRate);
                }
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine(item);
            }
        }
Exemplo n.º 4
0
        private JArray RunSequenceRule(JToken query, JObject rule, Context context)
        {
            var results = new JArray();

            var whenSequence = rule["when-sequence"];

            if (whenSequence != null)
            {
                // get the object at the current sequence position
                int?pos = JSONUtil.GetInt32(rule, "#seq-pos");
                if (pos == null)
                {
                    pos = 0; rule.Add("#seq-pos", 0);
                }
                var jaWhenSequence = (JArray)whenSequence;
                var currentItem    = jaWhenSequence[pos];

                context.Trace($"Examining {JSONUtil.SingleLine(query)} against {JSONUtil.SingleLine(jaWhenSequence)} at pos = {pos} ({JSONUtil.SingleLine(currentItem)})");

                // try the unification at the current position - will return null if not able to unify
                var unification = Unification.Unify(currentItem, query);

                // if able to unify, instantiate constituent at that position
                if (unification != null)
                {
                    context.Trace($"Unified {JSONUtil.SingleLine(currentItem)} with {JSONUtil.SingleLine(query)}");

                    currentItem         = Unification.ApplyUnification(currentItem, unification);
                    jaWhenSequence[pos] = currentItem;
                    pos++;
                    rule["#seq-pos"] = pos;

                    // if sequence is complete, then return unification for the "then" portion to fire
                    if (pos == jaWhenSequence.Count)
                    {
                        context.Trace($"Detected completed sequence {JSONUtil.SingleLine(jaWhenSequence)}");

                        //var clonedRule = (JObject)rule.DeepClone();
                        rule.Add("#unification", unification); // include the unification information
                        results.Add(rule);
                    }
                    // if sequence is not complete, then throw a new arc on the open arcs for next round
                    else
                    {
                        context.Trace($"Adding extended sequence {JSONUtil.SingleLine(jaWhenSequence)} [{pos}] to open arcs");

                        var     arcSet   = context.Fetch("#seq-arcs");
                        JObject joArcSet = null;
                        JArray  arcs     = null;
                        if (arcSet == null)
                        {
                            joArcSet = new JObject();
                            arcs     = new JArray();
                            joArcSet.Add("rules", arcs);
                            context.Store("#seq-arcs", joArcSet);
                        }
                        else
                        {
                            joArcSet = (JObject)arcSet;
                            arcs     = (JArray)joArcSet["rules"];
                        }

                        arcs.Add(rule);
                        //context.Store("#seq-arcs", joArcSet);
                    }
                }
            }

            if (results.Count == 0)
            {
                return(null);
            }
            return(results);
        }