Ejemplo n.º 1
0
        public static ItemReference FromFullItem(IReadOnlyItem elem, bool getKeyedName)
        {
            var result = new ItemReference();

            FillItemRef(result, elem, getKeyedName);
            return(result);
        }
Ejemplo n.º 2
0
        private void EnsureContext()
        {
            if (!_contextLoaded)
            {
                _contextLoaded = true;
                var aml   = Conn.AmlContext;
                var query = aml.Item(aml.Type("Workflow"), aml.Action("get"),
                                     aml.Select("source_type,source_id"), aml.RelatedExpand(false),
                                     aml.RelatedId(
                                         aml.Item(aml.Type("Workflow Process"), aml.Action("get"),
                                                  aml.Relationships(
                                                      aml.Item(aml.Type("Workflow Process Activity"), aml.Action("get"),
                                                               aml.RelatedId(Activity.Id())
                                                               )
                                                      )
                                                  )
                                         )
                                     );
                QueryDefaults?.Invoke(query);
                var workflow = Conn.ItemByQuery(query.ToAml());

                query = aml.Item(aml.TypeId(workflow.Property("source_type").Value),
                                 aml.Id(workflow.SourceId().Value), aml.Action("get"));
                QueryDefaults?.Invoke(query);
                _context = Conn.ItemByQuery(query.ToAml());
                _result.ErrorContext(_context);
            }
        }
Ejemplo n.º 3
0
 private void EnsureExisting()
 {
     if (!_existingLoaded)
     {
         _existingLoaded = true;
         if (!string.IsNullOrEmpty(Item.Id()))
         {
             var aml   = Conn.AmlContext;
             var query = aml.Item(Item.Type(), aml.Id(Item.Id()), aml.Action("get"));
             if (QueryDefaults != null)
             {
                 QueryDefaults.Invoke(query);
             }
             var items = query.Apply(Conn).Items();
             if (items.Any())
             {
                 _existing = items.Single();
             }
             else
             {
                 _existing = Client.Item.GetNullItem <IReadOnlyItem>();
             }
         }
         else
         {
             _existing = Client.Item.GetNullItem <IReadOnlyItem>();
         }
     }
 }
        /// <summary>
        /// Gets the <see cref="Vault" /> object from AML data.
        /// </summary>
        /// <param name="item">The AML item.</param>
        /// <returns>The <see cref="Vault" /> object from AML data.</returns>
        public Vault GetVault(IReadOnlyItem item)
        {
            if (item == null || !item.Exists)
            {
                return(null);
            }

            var vault = LinkedListOps.Find(_last, item.Id());

            if (vault == null)
            {
                lock (_lock)
                {
                    vault = LinkedListOps.Find(_last, item.Id());

                    if (vault == null)
                    {
                        vault = new Vault(item, _client);
                        LinkedListOps.Add(ref _last, vault);
                    }
                }
            }

            return(vault);
        }
Ejemplo n.º 5
0
            public static async Task <ArasProperty> NewProp(IReadOnlyItem item, IAsyncConnection conn)
            {
                var prop = NewProp(item.Id());
                await prop.Initialize(item, conn);

                return(prop);
            }
Ejemplo n.º 6
0
        public StateLink(IReadOnlyItem item, Dictionary <string, StateNode> nodes)
        {
            Id    = item.Id();
            Label = item.Property("label").Value;
            Name  = item.Property("name").Value
                    ?? item.Property("role").KeyedName().Value;
            if (item.Property("segments").HasValue())
            {
                Segments.AddRange(item.Property("segments").Value
                                  .Split('|')
                                  .Select(p => p.Split(','))
                                  .Select(p => new Point(int.Parse(p[0]), int.Parse(p[1]))));
            }

            if (nodes.TryGetValue(item.Property("from_state").Value ?? item.SourceItem().Id() ?? "", out var sourceNode))
            {
                Source = sourceNode;
            }
            if (nodes.TryGetValue(item.Property("to_state").Value ?? item.RelatedId().Value ?? "", out var relatedNode))
            {
                Related = relatedNode;
            }

            IsDefault  = item.Property("is_default").AsBoolean(false);
            IsOverride = item.Property("is_override").AsBoolean(false);
        }
Ejemplo n.º 7
0
        public static Method FromFullItem(IReadOnlyItem elem, bool getKeyedName)
        {
            var result = new Method();

            FillItemRef(result, elem, getKeyedName);
            return(result);
        }
Ejemplo n.º 8
0
            public MapElement(IReadOnlyItem item)
            {
                Type       = item.TypeName();
                Id         = item.Id();
                IsRelative = item.Property("segments").Exists;

                Position = new Point()
                {
                    X = item.Property("x").AsInt(0),
                    Y = item.Property("y").AsInt(0)
                };

                if (item.Property("segments").HasValue())
                {
                    Segments = item.Property("segments").Value
                               .Split('|')
                               .Select(p => p.Split(','))
                               .Select(p => new Point()
                    {
                        X = int.Parse(p[0]),
                        Y = int.Parse(p[1])
                    })
                               .ToArray();
                }
                else
                {
                    Segments = Enumerable.Empty <Point>();
                }

                _context = item.AmlContext.LocalizationContext;
            }
Ejemplo n.º 9
0
        private Vault GetReadVaultForFile(IReadOnlyItem file, IEnumerable <Vault> readPriority)
        {
            var located = file.Relationships("Located").ToList();

            if (located.Count < 1)
            {
                return(null);
            }
            else if (located.Count == 1)
            {
                return(_factory.GetVault(located[0].RelatedId().AsItem()));
            }
            else
            {
                // The maximum file version
                var maxVersion = located.Select(l => l.Property("file_version").AsInt(-1)).Max();
                if (maxVersion < 0)
                {
                    return(_factory.GetVault(located[0].RelatedId().AsItem()));
                }
                located = located.Where(l => l.Property("file_version").AsInt(-1) == maxVersion).ToList();
                if (located.Count == 1)
                {
                    return(_factory.GetVault(located[0].RelatedId().AsItem()));
                }

                // The vault sortOrders
                var vaultSort = new Dictionary <string, int>();
                var vaultList = readPriority.ToList();
                // Looping in reverse order to ensure that the minimum number is stored
                for (int i = vaultList.Count - 1; i >= 0; i--)
                {
                    vaultSort[vaultList[i].Id] = i;
                }

                // Sort based on the vault priorities
                located.Sort((x, y) =>
                {
                    int xSort, ySort;
                    if (!vaultSort.TryGetValue(x.RelatedId().Value, out xSort))
                    {
                        xSort = 999999;
                    }
                    if (!vaultSort.TryGetValue(y.RelatedId().Value, out ySort))
                    {
                        ySort = 999999;
                    }

                    int compare = xSort.CompareTo(ySort);
                    if (compare == 0)
                    {
                        compare = x.Id().CompareTo(y.Id());
                    }
                    return(compare);
                });

                return(_factory.GetVault(located.First(l => l.Property("file_version").AsInt(-1) == maxVersion).RelatedId().AsItem()));
            }
        }
Ejemplo n.º 10
0
        internal Vault(IReadOnlyItem i)
        {
            this.Id             = i.Id();
            this.Url            = i.Property("vault_url").Value;
            this.Authentication = AuthenticationSchemes.None;

            HttpClient = (SyncHttpClient)Factory.DefaultService();
        }
Ejemplo n.º 11
0
 internal Item(IConnection conn, IReadOnlyItem result)
 {
     _conn    = conn;
     _content = new List <IReadOnlyItem>()
     {
         result
     };
 }
Ejemplo n.º 12
0
        internal Vault(IReadOnlyItem i, HttpClient client)
        {
            this.Id             = i.Id();
            this.Url            = i.Property("vault_url").Value;
            this.Authentication = AuthenticationSchemes.None;

            HttpClient = client;
        }
Ejemplo n.º 13
0
 public Method(IReadOnlyItem elem, bool isCore = false)
 {
     FillItemRef(this, elem, false);
     this.KeyedName             = elem.Property("name").AsString("");
     this.IsCore                = elem.Property("core").AsBoolean(isCore);
     this.Documentation         = AmlDocumentation.Parse(this.KeyedName, elem.Property("method_code").AsString(""));
     this.Documentation.Summary = this.Documentation.Summary ?? elem.Property("comments").AsString(null);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VoteContext"/> class.
        /// </summary>
        /// <param name="conn">The connection.</param>
        /// <param name="item">The item.</param>
        public VoteContext(IServerConnection conn, IReadOnlyItem item) : base(conn, item)
        {
            var aml = conn.AmlContext;

            Assignment = aml.Item(aml.Type("Activity Assignment"), aml.Id(item.Property("AssignmentId").Value),
                                  aml.SourceId(aml.KeyedName(item.KeyedName()), aml.Type(item.Type().Value), item.Id()),
                                  aml.Property("id", item.Property("AssignmentId").Value)
                                  );
        }
 private XmlElement CreateDetailElement(IReadOnlyItem item, string report)
 {
   var detail = _faultNode.Elem("detail");
   if (item != null)
   {
     detail.Elem("item").Attr("type", item.Type().Value).Attr("id", item.Id());
   }
   detail.Elem("error_resolution_report", report);
   return detail;
 }
Ejemplo n.º 16
0
        /// <summary>Retrieve the value of the <c>source_id</c> property as an Item</summary>
        public static IReadOnlyItem SourceItem(this IReadOnlyItem parent)
        {
            var par = parent.Parent; // Relationships

            if (par != null && par is Relationships)
            {
                return(par.Parent as IReadOnlyItem);
            }
            return(parent.Property("source_id").AsItem());
        }
Ejemplo n.º 17
0
 public ItemType WithScripts(IReadOnlyItem itemType)
 {
     foreach (var prop in itemType.Relationships("Property")
              .Select(p => Property.FromItem(p, this)))
     {
         _properties[prop.Name] = prop;
     }
     WithExtra(itemType);
     return(this);
 }
Ejemplo n.º 18
0
        internal static void FillItemRef(ItemReference result, IReadOnlyItem elem, bool getKeyedName)
        {
            result.Type = elem.Type().Value;
            if (elem.Attribute("id").Exists)
            {
                result.Unique = elem.Attribute("id").Value;
            }
            else if (elem.Attribute("where").Exists)
            {
                result.Unique = elem.Attribute("where").Value;
            }
            if (getKeyedName)
            {
                if (result.Type == "FileType" && elem.Property("mimetype").HasValue())
                {
                    result.KeyedName = elem.Property("extension").AsString("") + ", "
                                       + elem.Property("mimetype").AsString("");
                }
                else
                {
                    IReadOnlyProperty_Base node = elem.Property("id");
                    if (node.Exists && node.KeyedName().Exists)
                    {
                        result.KeyedName = node.KeyedName().Value;
                    }
                    else
                    {
                        result.KeyedName = node.Attribute("_keyed_name").Value
                                           ?? elem.KeyedName().AsString(null)
                                           ?? elem.Property("name").AsString(null);
                    }

                    node = elem.SourceId();
                    if (node.Exists && node.KeyedName().Exists)
                    {
                        if (result.KeyedName.IsGuid())
                        {
                            var related = elem.RelatedId();
                            if (related.Exists && related.KeyedName().Exists)
                            {
                                result.KeyedName = node.Attribute("keyed_name").Value + " > " + related.Attribute("keyed_name").Value;
                            }
                            else
                            {
                                result.KeyedName = node.Attribute("keyed_name").Value + ": " + result.KeyedName;
                            }
                        }
                        else if (!string.IsNullOrEmpty(node.Attribute("keyed_name").Value))
                        {
                            result.KeyedName += " {" + node.Attribute("keyed_name").Value + "}";
                        }
                    }
                }
            }
        }
Ejemplo n.º 19
0
        internal void AddReadOnly(IReadOnlyItem content)
        {
            var list = _content as IList <IReadOnlyItem>;

            if (list == null)
            {
                list     = new List <IReadOnlyItem>();
                _content = list;
            }
            list.Add(content);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Loads the property metadata for the current type into the schema.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="itemTypeMeta">The properties.</param>
        private void LoadProperties(ItemType type, IReadOnlyItem itemTypeMeta)
        {
            var props = itemTypeMeta.Relationships("Property")
                        .Concat(itemTypeMeta.Relationships("ItemType_xPropertyDefinition").Select(i => i.RelatedItem()));

            foreach (var prop in props)
            {
                var newProp = Property.FromItem(prop, type);
                type.Properties[newProp.Name] = newProp;
            }
        }
Ejemplo n.º 21
0
 public static Vault GetVault(IReadOnlyItem i)
 {
   if (i == null || !i.Exists) return null;
   Vault result;
   if (!_vaults.TryGetValue(i.Id(), out result))
   {
     result = new Vault(i);
     _vaults[i.Id()] = result;
   }
   return result;
 }
Ejemplo n.º 22
0
        private IPromise <IHttpResponse> DownloadFileFromVault(IReadOnlyItem fileItem, Vault vault, bool async, Command request)
        {
            var url = vault.Url;

            if (string.IsNullOrEmpty(url))
            {
                return(null);
            }

            var urlPromise = url.IndexOf("$[") < 0 ?
                             Promises.Resolved(url) :
                             _conn.Process(new Command("<url>@0</url>", url)
                                           .WithAction(CommandAction.TransformVaultServerURL), async)
                             .Convert(s => s.AsString());

            return(urlPromise.Continue(u =>
            {
                if (u != vault.Url)
                {
                    vault.Url = u;
                }
                var uri = new Uri(string.Format("{0}?dbName={1}&fileId={2}&fileName={3}&vaultId={4}",
                                                u, _conn.Database, fileItem.Id(),
                                                Uri.EscapeDataString(fileItem.Property("filename").Value),
                                                vault.Id));

                var req = new HttpRequest();
                _conn.SetDefaultHeaders(req.SetHeader);
                req.SetHeader("VAULTID", vault.Id);
                foreach (var a in _conn.DefaultSettings)
                {
                    a.Invoke(req);
                }
                request.Settings?.Invoke(req);

                var trace = new LogData(4
                                        , "Innovator: Download file from vault"
                                        , request.LogListener ?? Factory.LogListener
                                        , request.Parameters)
                {
                    { "aras_url", _conn.MapClientUrl("../../Server") },
                    { "database", _conn.Database },
                    { "file_id", fileItem.Id() },
                    { "filename", fileItem.Property("filename").Value },
                    { "query", request.Aml },
                    { "url", uri },
                    { "user_id", _conn.UserId },
                    { "vault_id", vault.Id },
                    { "version", _conn.Version }
                };
                return vault.HttpClient.GetPromise(uri, async, trace, req).Always(trace.Dispose);
            }));
        }
Ejemplo n.º 23
0
        public void NullItemForInterface()
        {
            var nullItem = Item.GetNullItem <IReadOnlyItem>();

            Assert.AreNotEqual(null, nullItem);
            nullItem = Item.GetNullItem <IItem>();
            Assert.AreNotEqual(null, nullItem);
            nullItem = new IReadOnlyItem[] { }.FirstOrNullItem();
            Assert.AreNotEqual(null, nullItem);
            nullItem = new IItem[] { }.FirstOrNullItem();
            Assert.AreNotEqual(null, nullItem);
        }
Ejemplo n.º 24
0
        public ServerEvent(IReadOnlyItem serverEvent)
        {
            Event = serverEvent.Property("server_event").Value;
            var related = serverEvent.RelatedId();

            Method = related.AsItem().Exists
        ? ItemReference.FromFullItem(related.AsItem(), true)
        : new ItemReference(related.Type().Value, related.Value)
            {
                KeyedName = related.KeyedName().Value
            };
            SortOrder = serverEvent.Property("sort_order").AsInt(0);
        }
Ejemplo n.º 25
0
 public DelegateContext(IServerConnection conn, IReadOnlyItem item)
   : base(conn, item)
 {
   var aml = conn.AmlContext;
   _assignment = aml.Item(aml.Type("Activity Assignment"), aml.Id(item.Property("AssignmentId").Value),
     aml.SourceId(aml.KeyedName(item.KeyedName()), aml.Type(item.Type().Value), item.Id()),
     aml.Property("id", item.Property("AssignmentId").Value)
   );
   _delegate = aml.Item(aml.Type("Activity Assignment"), aml.Id(item.Property("ToAssignmentId").Value),
     aml.SourceId(aml.KeyedName(item.KeyedName()), aml.Type(item.Type().Value), item.Id()),
     aml.Property("id", item.Property("ToAssignmentId").Value)
   );
 }
Ejemplo n.º 26
0
        public void Add(IReadOnlyItem item)
        {
            if (item.Attribute(XmlFlags.Attr_ScriptType).HasValue())
            {
                return;
            }

            switch (item.TypeName().ToLowerInvariant())
            {
            case "method":
                _methods.Add(new Method(item, _coreIds.Contains(item.ConfigId().Value ?? item.Id())));
                break;

            case "relationshiptype":
                if (item.Property("relationship_id").HasValue())
                {
                    Add(item.Property("relationship_id").AsItem());
                }
                break;

            case "itemtype":
                var itemType = new ItemType(item);
                if (string.IsNullOrEmpty(itemType.Name))
                {
                    return;
                }
                _itemTypesByName[itemType.Name] = itemType;
                Add(item.Relationships("Property"));
                break;

            case "sql":
                var sql = Sql.FromFullItem(item, false);
                sql.KeyedName = item.Property("name").Value
                                ?? item.KeyedName().Value
                                ?? item.IdProp().KeyedName().Value
                                ?? "";
                sql.Type = item.Property("type").AsString("");
                if (string.IsNullOrEmpty(sql.KeyedName))
                {
                    return;
                }
                _sql[sql.KeyedName.ToLowerInvariant()] = sql;
                break;

            case "property":
                _propertyNames[item.Id()] = item.Property("name").Value
                                            ?? item.KeyedName().Value
                                            ?? item.IdProp().KeyedName().Value;
                break;
            }
        }
Ejemplo n.º 27
0
 public DatabaseList(IReadOnlyItem list)
 {
     Id          = list.Id();
     Name        = list.Property("name").Value;
     Label       = list.Property("label").Value;
     Description = list.Property("description").Value;
     Values      = list.Relationships()
                   .Select(i => new ListValue()
     {
         Label  = i.Property("label").Value,
         Value  = i.Property("value").Value,
         Filter = i.Property("filter").Value
     }).ToList();
 }
Ejemplo n.º 28
0
 public ItemType(IReadOnlyItem itemType, HashSet <string> coreIds = null)
 {
     Id            = itemType.Id();
     IsCore        = itemType.Property("core").AsBoolean(coreIds?.Contains(itemType.Id()) == true);
     IsDependent   = itemType.Property("is_dependent").AsBoolean(false);
     IsFederated   = itemType.Property("implementation_type").Value == "federated";
     IsPolymorphic = itemType.Property("implementation_type").Value == "polymorphic";
     IsVersionable = itemType.Property("is_versionable").AsBoolean(false);
     Label         = itemType.Property("label").Value;
     Name          = itemType.Property("name").Value
                     ?? itemType.KeyedName().Value
                     ?? itemType.IdProp().KeyedName().Value;
     Reference   = ItemReference.FromFullItem(itemType, true);
     Description = itemType.Property("description").Value;
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WorkflowContext"/> class.
        /// </summary>
        /// <param name="conn">The connection.</param>
        /// <param name="item">The item.</param>
        public WorkflowContext(IServerConnection conn, IReadOnlyItem item)
        {
            Conn     = conn;
            Activity = item as Activity;
            _result  = conn.AmlContext.Result();
            switch (item.Property("WorkflowEvent").Value)
            {
            case "on_activate":
                WorkflowEvent = WorkflowEvent.OnActivate;
                break;

            case "on_assign":
                WorkflowEvent = WorkflowEvent.OnAssign;
                break;

            case "on_close":
                WorkflowEvent = WorkflowEvent.OnClose;
                break;

            case "on_delegate":
                WorkflowEvent = WorkflowEvent.OnDelegate;
                break;

            case "on_due":
                WorkflowEvent = WorkflowEvent.OnDue;
                break;

            case "on_escalate":
                WorkflowEvent = WorkflowEvent.OnEscalate;
                break;

            case "on_refuse":
                WorkflowEvent = WorkflowEvent.OnRefuse;
                break;

            case "on_remind":
                WorkflowEvent = WorkflowEvent.OnRemind;
                break;

            case "on_vote":
                WorkflowEvent = WorkflowEvent.OnVote;
                break;

            default:
                WorkflowEvent = WorkflowEvent.Other;
                break;
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Specify an item to be used for parameter substitution
        /// </summary>
        /// <param name="item">Parameter item</param>
        public Command WithParamItem(IReadOnlyItem item)
        {
            foreach (var prop in item.Elements()
                     .OfType <IReadOnlyProperty_Base>()
                     .Where(p => p.HasValue()))
            {
                _sub.AddParameter(prop.Name, prop.Value);
            }

            foreach (var attr in item.Attributes()
                     .Where(a => a.HasValue()))
            {
                _sub.AddParameter("@" + attr.Name, attr.Value);
            }
            return(this);
        }
        private IElement CreateDetailElement(IReadOnlyItem item, string report)
        {
            var detail = _fault.ElementByName("detail");

            if (item != null)
            {
                detail.Add(new AmlElement(_fault.AmlContext, "item"
                                          , new Attribute("type", item.Type().Value)
                                          , new Attribute("id", item.Id())));
            }
            detail.Add(new AmlElement(_fault.AmlContext, "error_resolution_report", report));
            if (!detail.Exists)
            {
                _fault.Add(detail);
            }
            return(detail);
        }
Ejemplo n.º 32
0
        public Method(IReadOnlyItem elem, bool isCore = false)
        {
            FillItemRef(this, elem, false);
            this.KeyedName     = elem.Property("name").AsString("");
            this.IsCore        = elem.Property("core").AsBoolean(isCore);
            this.Documentation = OperationElement.Parse(this.KeyedName, elem.Property("method_code").AsString(""));
            if (this.Documentation.Summary.Count < 1 && elem.Property("comments").HasValue())
            {
                this.Documentation.Summary.Add(new TextRun(elem.Property("comments").Value));
            }
            var execution = elem.Property("execution_allowed_to");

            ExecutionAllowedTo = execution.KeyedName().Value
                                 ?? execution.AsItem().KeyedName().Value
                                 ?? execution.AsItem().Property("name").Value;
            IsServerMethod = elem.Property("method_type").Value != "JavaScript";
        }
Ejemplo n.º 33
0
 private XmlElement CreateDetailElement(IReadOnlyItem item, params string[] properties)
 {
   if (item != null)
   {
     var detail = _faultNode.Elem("detail");
     detail.Elem("item").Attr("type", item.Type().Value).Attr("id", item.Id());
     if (properties.Any())
     {
       var props = detail.Elem("properties");
       foreach (var prop in properties)
       {
         props.Elem("property", prop);
       }
     }
     return detail;
   }
   return null;
 }
Ejemplo n.º 34
0
    private Vault GetReadVaultForFile(IReadOnlyItem file, IEnumerable<Vault> readPriority)
    {
      var located = file.Relationships("Located").ToList();
      if (located.Count < 1)
      {
        return null;
      }
      else if (located.Count == 1)
      {
        return Vault.GetVault(located[0].RelatedId().AsItem());
      }
      else
      {
        // The maximum file version
        var maxVersion = located.Select(l => l.Property("file_version").AsInt(-1)).Max();
        if (maxVersion < 0) return Vault.GetVault(located[0].RelatedId().AsItem());
        located = located.Where(l => l.Property("file_version").AsInt(-1) == maxVersion).ToList();
        if (located.Count == 1) return Vault.GetVault(located[0].RelatedId().AsItem());

        // The vault sortOrders
        var vaultSort = new Dictionary<string, int>();
        var vaultList = readPriority.ToList();
        // Looping in reverse order to ensure that the minimum number is stored
        for (int i = vaultList.Count - 1; i >= 0; i--)
        {
          vaultSort[vaultList[i].Id] = i;
        }

        // Sort based on the vault priorities
        located.Sort((x, y) =>
        {
          int xSort, ySort;
          if (!vaultSort.TryGetValue(x.RelatedId().Value, out xSort)) xSort = 999999;
          if (!vaultSort.TryGetValue(y.RelatedId().Value, out ySort)) ySort = 999999;

          int compare = xSort.CompareTo(ySort);
          if (compare == 0) compare = x.Id().CompareTo(y.Id());
          return compare;
        });

        return Vault.GetVault(located.First(l => l.Property("file_version").AsInt(-1) == maxVersion).RelatedId().AsItem());
      }
    }
Ejemplo n.º 35
0
        /// <summary>
        /// Loads the property metadata for the current type into the schema.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="itemTypeMeta">The properties.</param>
        private void LoadProperties(ItemType type, IReadOnlyItem itemTypeMeta)
        {
            var      props   = itemTypeMeta.Relationships("Property");
            Property newProp = null;

            foreach (var prop in props)
            {
                newProp       = new Property(prop.Property("name").Value);
                newProp.Id    = prop.Id();
                newProp.Label = prop.Property("label").Value;
                newProp.SetType(prop.Property("data_type").Value);
                newProp.Precision    = prop.Property("prec").AsInt(-1);
                newProp.Scale        = prop.Property("scale").AsInt(-1);
                newProp.StoredLength = prop.Property("stored_length").AsInt(-1);
                var foreign = prop.Property("foreign_property").AsItem();
                if (foreign.Exists)
                {
                    newProp.ForeignLinkPropName = prop.Property("data_source").KeyedName().Value;
                    newProp.ForeignPropName     = foreign.Property("name").Value;
                    newProp.ForeignTypeName     = foreign.SourceId().KeyedName().Value;
                }
                newProp.DataSource = prop.Property("data_source").Value;
                if (newProp.Type == PropertyType.item && newProp.Name == "data_source" && type.Name == "Property")
                {
                    newProp.Restrictions.AddRange(new string[] { "ItemType", "List", "Property" });
                }
                else if (newProp.Type == PropertyType.item && prop.Property("data_source").Attribute("name").HasValue())
                {
                    newProp.Restrictions.Add(prop.Property("data_source").Attribute("name").Value);
                }
                newProp.Visibility =
                    (prop.Property("is_hidden").AsBoolean(false) ? PropertyVisibility.None : PropertyVisibility.MainGrid)
                    | (prop.Property("is_hidden2").AsBoolean(false) ? PropertyVisibility.None : PropertyVisibility.RelationshipGrid);
                newProp.SortOrder   = prop.Property("sort_order").AsInt(int.MaxValue);
                newProp.ColumnWidth = prop.Property("column_width").AsInt(100);
                newProp.IsRequired  = prop.Property("is_required").AsBoolean(false);
                newProp.ReadOnly    = prop.Property("readonly").AsBoolean(false);

                //default_value,column_width,is_required,readonly

                type.Properties.Add(newProp.Name, newProp);
            }
        }
Ejemplo n.º 36
0
    private void EnsureNewVersion()
    {
      if (!_newLoaded)
      {
        _newLoaded = true;
        var props = _oldVersion.LazyMap(_conn, i => new
        {
          ConfigId = i.ConfigId().Value,
          Generation = i.Generation().AsInt()
        });

        var aml = Conn.AmlContext;
        var query = aml.Item(_oldVersion.Type(), aml.Action("get"),
          aml.ConfigId(props.ConfigId),
          aml.Generation(props.Generation + 1)
        );
        if (QueryDefaults != null) QueryDefaults.Invoke(query);
        _newVersion = query.Apply(Conn).AssertItem();
      }
    }
Ejemplo n.º 37
0
 public WorkflowContext(IServerConnection conn, IReadOnlyItem item)
 {
   _conn = conn;
   _activity = new Activity(item);
   _result = conn.AmlContext.Result();
   switch (item.Property("WorkflowEvent").Value)
   {
     case "on_activate":
       _event = WorkflowEvent.OnActivate;
       break;
     case "on_assign":
       _event = WorkflowEvent.OnAssign;
       break;
     case "on_close":
       _event = WorkflowEvent.OnClose;
       break;
     case "on_delegate":
       _event = WorkflowEvent.OnDelegate;
       break;
     case "on_due":
       _event = WorkflowEvent.OnDue;
       break;
     case "on_escalate":
       _event = WorkflowEvent.OnEscalate;
       break;
     case "on_refuse":
       _event = WorkflowEvent.OnRefuse;
       break;
     case "on_remind":
       _event = WorkflowEvent.OnRemind;
       break;
     case "on_vote":
       _event = WorkflowEvent.OnVote;
       break;
     default:
       _event = WorkflowEvent.Other;
       break;
   }
 }
Ejemplo n.º 38
0
 public LifeCycleState(IReadOnlyItem item) : base(item) { }
Ejemplo n.º 39
0
 public SingleItemContext(IServerConnection conn, IReadOnlyItem item)
 {
   _conn = conn;
   _item = item;
 }
Ejemplo n.º 40
0
 public ItemWrapper(IReadOnlyItem item)
 {
   _item = item;
 }
    /// <summary>
    /// Loads the property metadata for the current type into the schema.
    /// </summary>
    /// <param name="type">The type.</param>
    /// <param name="itemTypeMeta">The properties.</param>
    private void LoadProperties(ItemType type, IReadOnlyItem itemTypeMeta)
    {
      var props = itemTypeMeta.Relationships("Property");
      Property newProp = null;
      foreach (var prop in props)
      {
        newProp = new Property(prop.Property("name").Value);
        newProp.Label = prop.Property("label").Value;
        newProp.SetType(prop.Property("data_type").Value);
        newProp.Precision = prop.Property("prec").AsInt(-1);
        newProp.Scale = prop.Property("scale").AsInt(-1);
        newProp.StoredLength = prop.Property("stored_length").AsInt(-1);
        var foreign = prop.Property("foreign_property").AsItem();
        if (foreign.Exists)
        {
          newProp.ForeignLinkPropName = prop.Property("data_source").KeyedName().Value;
          newProp.ForeignPropName = foreign.Property("name").Value;
          newProp.ForeignTypeName = foreign.SourceId().KeyedName().Value;
        }
        newProp.DataSource = prop.Property("data_source").Value;
        if (newProp.Type == PropertyType.item && prop.Property("data_source").Attribute("name").HasValue())
        {
          newProp.Restrictions.Add(prop.Property("data_source").Attribute("name").Value);
        }
        newProp.Visibility =
          (prop.Property("is_hidden").AsBoolean(false) ? PropertyVisibility.None : PropertyVisibility.MainGrid)
          | (prop.Property("is_hidden2").AsBoolean(false) ? PropertyVisibility.None : PropertyVisibility.RelationshipGrid);
        newProp.SortOrder = prop.Property("sort_order").AsInt(int.MaxValue);
        newProp.ColumnWidth = prop.Property("column_width").AsInt(100);
        newProp.IsRequired = prop.Property("is_required").AsBoolean(false);
        newProp.ReadOnly = prop.Property("readonly").AsBoolean(false);

        //default_value,column_width,is_required,readonly

        type.Properties.Add(newProp.Name, newProp);
      }
    }
Ejemplo n.º 42
0
 public static async Task<ArasProperty> NewProp(IReadOnlyItem item, IAsyncConnection conn)
 {
   var prop = NewProp(item.Id());
   await prop.Initialize(item, conn);
   return prop;
 }
Ejemplo n.º 43
0
 public PromotionContext(IServerConnection conn, IReadOnlyItem item)
 {
   _conn = conn;
   _item = item;
 }
Ejemplo n.º 44
0
 public ValidationException ValidationException(string message, Exception innerException, IReadOnlyItem item, params string[] properties)
 {
   return new ValidationException(this, message, innerException, item, properties);
 }
Ejemplo n.º 45
0
 public LifeCycleTransition(IReadOnlyItem item) : base(item) { }
Ejemplo n.º 46
0
 private void EnsureExisting()
 {
   if (!_existingLoaded)
   {
     _existingLoaded = true;
     if (!string.IsNullOrEmpty(_changes.Id()))
     {
       var aml = Conn.AmlContext;
       var query = aml.Item(Changes.Type(), aml.Id(Changes.Id()), aml.Action("get"));
       if (QueryDefaults != null) QueryDefaults.Invoke(query);
       var items = query.Apply(Conn).Items();
       if (items.Any()) _existing = items.Single();
     }
   }
 }
Ejemplo n.º 47
0
 public IErrorBuilder ErrorContext(IReadOnlyItem item)
 {
   _errorContext = item;
   return this;
 }
Ejemplo n.º 48
0
 private Vault(IReadOnlyItem i)
 {
   this.Id = i.Id();
   this.Url = i.Property("vault_url").Value;
   this.Authentication = AuthenticationSchemes.None;
 }
Ejemplo n.º 49
0
 private IEditorTreeNode ProcessTreeNode(IReadOnlyItem item)
 {
   switch (item.Classification().Value.ToLowerInvariant())
   {
     case "tree node/savedsearchintoc":
       return new EditorTreeNode()
       {
         Name = item.Property("label").Value,
         Description = "Saved Search",
         ImageKey = "xml-tag-16",
         HasChildren = item.Relationships("Tree Node Child").Any(),
         Children = item.Relationships().Select(r => ProcessTreeNode(r.RelatedItem())),
         ScriptGetter = () => Enumerable.Repeat(
           new EditorScript() {
             Name = item.Property("label").Value,
             Action = "ApplyItem",
             Script = _conn.Apply("<Item type='SavedSearch' action='get' select='criteria' id='@0' />", item.Property("saved_search_id").Value)
               .AssertItem().Property("criteria").Value
           }, 1)
       };
     case "tree node/itemtypeintoc":
       return new EditorTreeNode()
       {
         Name = item.Property("label").Value,
         ImageKey = "class-16",
         Description = "ItemType: " + item.Property("name").Value,
         HasChildren = true,
         ScriptGetter = () => ItemTypeScripts(ArasMetadataProvider.Cached(_conn).TypeById(item.Property("itemtype_id").Value)),
         Children = ItemTypeChildren(item.Property("itemtype_id").Value)
         .Concat(item.Relationships().Select(r => ProcessTreeNode(r.RelatedItem())))
       };
     default:
       return new EditorTreeNode()
       {
         Name = item.Property("label").Value,
         ImageKey = "folder-16",
         HasChildren = item.Relationships("Tree Node Child").Any(),
         Children = item.Relationships().Select(r => ProcessTreeNode(r.RelatedItem()))
       };
   }
 }
Ejemplo n.º 50
0
 public static Sql FromFullItem(IReadOnlyItem elem, bool getKeyedName)
 {
   var result = new Sql();
   FillItemRef(result, elem, getKeyedName);
   return result;
 }
Ejemplo n.º 51
0
 public WorkflowProcess(IReadOnlyItem item) : base(item) { }
Ejemplo n.º 52
0
 public VersionContext(IServerConnection conn, IReadOnlyItem item)
 {
   _conn = conn;
   _oldVersion = item;
 }
Ejemplo n.º 53
0
    private IPromise<WebResponse> DownloadFileFromVault(IReadOnlyItem fileItem, Vault vault, bool async, Command request)
    {
      var url = vault.Url;
      if (string.IsNullOrEmpty(url)) return null;

      var urlPromise = url.IndexOf("$[") < 0 ?
        Promises.Resolved(url) :
        _conn.Process(new Command("<url>@0</url>", url)
                .WithAction(CommandAction.TransformVaultServerURL), async)
                .Convert(s => s.AsString());

      return urlPromise.Continue<string, WebResponse>(u =>
      {
        if (u != vault.Url) vault.Url = u;
        var uri = new Uri(string.Format("{0}?dbName={1}&fileId={2}&fileName={3}&vaultId={4}",
          u, _conn.Database, fileItem.Id(),
          HttpUtility.UrlEncode(fileItem.Property("filename").Value),
          vault.Id));

        var req = (HttpWebRequest)System.Net.WebRequest.Create(uri);
        req.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
        req.Credentials = CredentialCache.DefaultCredentials;
        req.Method = "GET";
        req.Proxy.Credentials = CredentialCache.DefaultCredentials;
        req.Timeout = -1;

        _conn.SetDefaultHeaders((k, v) => { req.Headers.Set(k, v); });
        req.Headers.Set("VAULTID", vault.Id);

        var result = new WebRequest(req, _conn.Compression);
        foreach (var a in _conn.DefaultSettings)
        {
          a.Invoke(result);
        }
        if (request.Settings != null) request.Settings.Invoke(result);

        return result.Execute(async);
      });
    }
Ejemplo n.º 54
0
    private void EnsureContext()
    {
      if (!_contextLoaded)
      {
        _contextLoaded = true;
        var aml = Conn.AmlContext;
        var query = aml.Item(aml.Type("Workflow"), aml.Action("get"),
          aml.Select("source_type", "source_id"), aml.RelatedExpand(false),
          aml.RelatedId(
            aml.Item(aml.Type("Workflow Process"), aml.Action("get"),
              aml.Relationships(
                aml.Item(aml.Type("Workflow Process Activity"), aml.Action("get"),
                  aml.RelatedId(_activity.Id())
                )
              )
            )
          )
        );
        if (QueryDefaults != null) QueryDefaults(query);
        var workflow = Conn.ItemByQuery(query.ToAml());

        query = aml.Item(aml.TypeId(workflow.Property("source_type").Value),
          aml.Id(workflow.SourceId().Value), aml.Action("get"));
        if (QueryDefaults != null) QueryDefaults(query);
        _context = Conn.ItemByQuery(query.ToAml());
      }
    }
Ejemplo n.º 55
0
 public ValidationReportException ValidationException(string message, Exception innerException, IReadOnlyItem item, string report)
 {
   return new ValidationReportException(this, message, innerException, item, report);
 }
 internal ValidationReportException(ElementFactory factory, string message, Exception innerException
   , IReadOnlyItem item, string report)
   : base(factory, message, 1001, innerException)
 {
   CreateDetailElement(item, report);
 }
Ejemplo n.º 57
0
      public async Task Initialize(IReadOnlyItem item, IAsyncConnection conn)
      {
        this.Label = item.Property("label").AsString("");
        this.Name = item.Property("name").AsString("");
        this.Required = item.Property("is_required").AsBoolean(false)
          || item.Property("is_class_required").AsBoolean(false);
        this.PropName = LabelToProp(this.Label);
        this.VarName = NameToVar(this.Name);

        if (string.IsNullOrEmpty(this.PropName))
          this.PropName = LabelToProp(this.Name);
        if (string.IsNullOrEmpty(this.Label))
          this.Label = Strings.StrConv(this.Name.Replace('_', ' '), VbStrConv.ProperCase);

        if (item.Property("data_type").Value == "foreign")
        {
          this.PropType = PropTypes.Foreign;
          if (!item.Property("foreign_property").HasValue())
          {
            var result = await conn.ApplyAsync(@"<AML>
                                            <Item type='Property' action='get' id='@0' select='label,name,is_required,is_class_required,data_type,data_source,readonly,pattern,stored_length,foreign_property(label,name,is_required,is_class_required,data_type,data_source,readonly,pattern,stored_length)'>
                                            </Item>
                                          </AML>", true, true, item.Id()).ToTask();
            item = result.AssertItem();
          }
          ForeignProp = await NewProp(item.Property("foreign_property").AsItem(), conn);
          ForeignLinkProp = NewProp(item.Property("data_source").Value);
        }
        else if (item.Property("readonly").AsBoolean(false))
        {
          PropType = PropTypes.ReadOnly;
        }
        else
        {
          PropType = PropTypes.Normal;
        }

        if (this.ForeignProp != null)
        {
          this.DataType = ForeignProp.DataType;
        }
        else
        {
          switch (item.Property("data_type").AsString("").ToLowerInvariant())
          {
            case "decimal":
            case "float":
              DataType = "Double";
              break;
            case "date":
              DataType = "Date";
              break;
            case "item":
              DataType = Strings.StrConv(item.Property("data_source").KeyedName().Value, VbStrConv.ProperCase)
                .Replace(" ", "");
              if (item.Property("data_source").Value == "0C8A70AE86AF49AD873F817593F893D4")
              {
                this.List = item.Property("pattern").AsString("");
                this.EbsList = true;
              }
              break;
            case "integer":
              DataType = "Integer";
              break;
            case "boolean":
              DataType = "Boolean";
              break;
            case "list":
            case "filter list":
            case "mv_list":
              DataType = "String";
              this.List = item.Property("data_source").AsString("");
              this.ListFilter = item.Property("pattern").AsString("");
              break;
            case "image":
              DataType = "Gentex.Drawing.WebLazyImage";
              break;
            default: //"list", "string", "text"
              this.StringLength = item.Property("stored_length").AsInt(-1);
              this.DataType = "String";
              break;
          }
        }
      }
Ejemplo n.º 58
0
 public Activity(IReadOnlyItem item) : base(item) { }
Ejemplo n.º 59
0
 /// <summary>
 /// Loads the property metadata for the current type into the schema.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="itemTypeMeta">The properties.</param>
 private void LoadProperties(ItemType type, IReadOnlyItem itemTypeMeta)
 {
   var props = itemTypeMeta.Relationships("Property");
   Property newProp = null;
   foreach (var prop in props)
   {
     newProp = new Property(prop.Property("name").Value);
     newProp.SetType(prop.Property("data_type").Value);
     if (newProp.Type == PropertyType.item && prop.Property("data_source").Attribute("name").HasValue())
     {
       newProp.Restrictions.Add(prop.Property("data_source").Attribute("name").Value);
     }
     type.Properties.Add(newProp);
   }
 }
Ejemplo n.º 60
0
 internal ValidationException(ElementFactory factory, string message, Exception innerException
   , IReadOnlyItem item, params string[] properties)
   : base(factory, message, properties.Any() ? 1001 : 1, innerException)
 {
   CreateDetailElement(item, properties);
 }