public IPromise <IEnumerable <Property> > GetPropertiesByTypeId(string id)
        {
            ItemType itemType;

            if (!_itemTypesById.TryGetValue(id, out itemType))
            {
                return(Promises.Rejected <IEnumerable <Property> >(new KeyNotFoundException()));
            }
            return(GetProperties(itemType));
        }
示例#2
0
        public void TestSelect()
        {
            var actual = 0;

            Promises.Resolved(1.Wrap()).Select(_ => 2.Wrap()).Done(_ => actual++);
            Promises.Rejected <TWrapper <int> > (new Exception()).Select(_ => 2.Wrap()).Fail(_ => actual++);
            Promises.Disposed <TWrapper <int> > ().Select(_ => 2.Wrap()).Disposed(() => actual++);
            Promises.Resolved(1.Wrap()).Select <TWrapper <int> > (_ => {
                throw new Exception();
            }).Fail(_ => actual++);
            Assert.That(actual, Is.EqualTo(4));
        }
        private IPromise <Property> LoadedProperty(ItemType itemType, string name)
        {
            Property prop;

            if (itemType.Properties.TryGetValue(name, out prop))
            {
                return(Promises.Resolved(prop));
            }
            else
            {
                return(Promises.Rejected <Property>(new KeyNotFoundException()));
            }
        }
示例#4
0
        public void TestWhere()
        {
            var actual = 0;

            Promises.Resolved(1.Wrap()).Where(n => n.val == 1).Done(_ => actual++);
            Promises.Resolved(1.Wrap()).Where(n => n.val == 2)
            .Done(_ => Assert.Fail()).Fail(_ => Assert.Fail())
            .Disposed(() => actual++);
            Promises.Rejected <TWrapper <int> > (new Exception()).Where(_ => true).Fail(_ => actual++);
            Promises.Disposed <TWrapper <int> > ().Where(_ => true).Disposed(() => actual++);
            Promises.Resolved(1.Wrap()).Where(_ => {
                throw new Exception();
            }).Fail(_ => actual++);
            Assert.That(actual, Is.EqualTo(5));
        }
示例#5
0
        public static IPromise <IEditorProxy> FromConn(ConnectionData conn)
        {
            Func <ConnectionData, IPromise <IEditorProxy> > factory;

            if (_factories.TryGetValue(conn.Type, out factory))
            {
                return(factory.Invoke(conn));
            }
            else
            {
                switch (conn.Type)
                {
                case ConnectionType.Innovator:
                    return(conn.ArasLogin(true)
                           .Convert(c => (IEditorProxy) new Editor.ArasEditorProxy(c, conn)));
                }
                return(Promises.Rejected <IEditorProxy>(new NotSupportedException("Unsupported connection type")));
            }
        }
示例#6
0
        public static IPromise <IEditorProxy> FromConn(ConnectionData conn)
        {
            Func <ConnectionData, IPromise <IEditorProxy> > factory;

            if (_factories.TryGetValue(conn.Type, out factory))
            {
                return(factory.Invoke(conn));
            }
            else
            {
                switch (conn.Type)
                {
                case ConnectionType.Innovator:
                    return(conn.ArasLogin(true)
                           .Convert(c => (IEditorProxy) new Editor.ArasEditorProxy(c, conn)));

                case ConnectionType.Soap:
                    var http = new HttpClient();
                    return(http.GetStreamAsync(conn.Url).ToPromise()
                           .Convert(r =>
                    {
                        ServiceDescription descrip;
                        using (var reader = new StreamReader(r))
                            using (var xml = XmlReader.Create(reader))
                            {
                                descrip = ServiceDescription.Read(xml);
                            }

                        return (IEditorProxy) new Editor.SoapEditorProxy(conn, descrip
                                                                         , Editor.XmlSchemas.SchemasFromDescrip(descrip));
                    }));

                case ConnectionType.SqlServer:
                    return(Promises.Resolved <IEditorProxy>(new Editor.SqlEditorProxy(conn)));

                case ConnectionType.Sharepoint:
                    return(new Editor.SharepointEditorProxy(conn).Initialize().ToPromise());
                }
                return(Promises.Rejected <IEditorProxy>(new NotSupportedException("Unsupported connection type")));
            }
        }
示例#7
0
        public IPromise <CompletionContext> Completions(string prefix, ITextSource all, int caret, string termCharacter
                                                        , bool tableNameColumnPrefix = false)
        {
            try
            {
                _tableNameColumnPrefix = tableNameColumnPrefix;
                var lastIndex = string.IsNullOrEmpty(termCharacter) ? -1 : all.IndexOf(termCharacter, caret, all.TextLength - caret, StringComparison.Ordinal);
                var sql       = prefix + (lastIndex < 0 ? all.GetText(caret, all.TextLength - caret) : all.GetText(caret, lastIndex - caret));
                if (sql.StartsWith("(") && sql.EndsWith(")"))
                {
                    sql = sql.Substring(1, sql.Length - 2);
                }
                var parseTree = new SqlTokenizer(sql).Parse();
                if (!parseTree.Any())
                {
                    return(Promises.Resolved(new CompletionContext()));
                }

                var currNode = parseTree.NodeByOffset(prefix.Length);
                var literal  = currNode as SqlLiteral;

                if (literal != null)
                {
                    var parGroup = literal.Parent as SqlGroup;
                    if (_overloadWin != null && (parGroup == null || !parGroup.First().TextEquals(_overloadName)))
                    {
                        _overloadWin.Close();
                    }

                    if (SqlTokenizer.KeywordPrecedesTable(literal))
                    {
                        var context = new SqlContext(parGroup);
                        return(ContextFromData(Tables(null).Concat(Schemas())
                                               .Concat(context.Definitions.Select(d => new SqlGeneralCompletionData()
                        {
                            Text = d,
                            Description = "Locally defined table",
                            Image = Icons.Class16.Wpf
                        }))
                                               .OrderBy(i => i.Text)));
                    }
                    else if (literal.Text == "(")
                    {
                        var prev = literal.PreviousLiteral();

                        if (prev != null)
                        {
                            if (CurrentTextArea != null)
                            {
                                var overloads = from f in _coreFunctions
                                                where string.Equals(f.Name, prev.Text, StringComparison.OrdinalIgnoreCase)
                                                select new Overload(f.Usage, f.Description);
                                if (overloads.Any())
                                {
                                    _overloadWin             = new OverloadInsightWindow(CurrentTextArea);
                                    _overloadWin.StartOffset = caret;
                                    _overloadWin.EndOffset   = caret + 1;
                                    _overloadWin.Provider    = new OverloadList().AddRange(overloads);
                                    _overloadWin.Show();
                                    _overloadWin.Closed += (s, e) => {
                                        _overloadWin  = null;
                                        _overloadName = null;
                                    };
                                    _overloadName = prev.Text;
                                }
                            }

                            switch (prev.Text.ToUpperInvariant())
                            {
                            case "DATEADD":
                            case "DATEDIFF":
                            case "DATEDIFF_BIG":
                            case "DATEFROMPARTS":
                            case "DATENAME":
                            case "DATEPART":
                                return(ContextFromData(_datePartNames.Select(n => new SqlGeneralCompletionData()
                                {
                                    Text = n[0] + (n[1] == n[0] ? "" : " (" + n[1] + ")"),
                                    Description = n[1],
                                    Image = Icons.EnumValue16.Wpf,
                                    Action = () => n[0]
                                })
                                                       .OrderBy(i => i.Text)));
                            }
                        }
                    }
                    else if (literal.Text == ".")
                    {
                        var name = literal.Parent as SqlName;
                        if (name != null)
                        {
                            if (name.IsTable)
                            {
                                var idx    = name.IndexOf(literal);
                                var schema = name[idx - 1].Text;
                                if (_provider.GetSchemaNames().Contains(schema, StringComparer.OrdinalIgnoreCase))
                                {
                                    return(ContextFromData(Tables(schema).Concat(Functions(true, schema))
                                                           .OrderBy(i => i.Text)));
                                }
                            }
                            else
                            {
                                var group = name.Parent as SqlGroup;
                                if (group != null)
                                {
                                    var          idx     = name.IndexOf(literal);
                                    var          context = new SqlContext(group);
                                    SqlTableInfo info;
                                    if (idx > 0 && name[idx - 1] is SqlLiteral &&
                                        context.TryByName(((SqlLiteral)name[idx - 1]).Text.ToLowerInvariant(), out info))
                                    {
                                        return(Columns(info, false).ToPromise().Convert(c => new CompletionContext()
                                        {
                                            Items = c
                                        }));
                                    }
                                }
                            }
                        }
                    }
                    else if (literal.Type == SqlType.Keyword ||
                             literal.Type == SqlType.Operator)
                    {
                        switch (literal.Text.ToLowerInvariant())
                        {
                        case "union":
                            return(ContextFromData(MatchCase(literal.Text, "all", "select")
                                                   .GetCompletions <SqlGeneralCompletionData>()));

                        case "group":
                        case "order":
                        case "partition":
                            return(ContextFromData(MatchCase(literal.Text, "by")
                                                   .GetCompletions <SqlGeneralCompletionData>()));

                        case "insert":
                            return(ContextFromData(MatchCase(literal.Text, "into")
                                                   .GetCompletions <SqlGeneralCompletionData>()));

                        case "delete":
                            return(ContextFromData(MatchCase(literal.Text, "from")
                                                   .GetCompletions <SqlGeneralCompletionData>()));
                        }

                        var group = literal.Parent as SqlGroup;
                        if (group != null)
                        {
                            // List of sql specific constructs for the context
                            var sqlOthers = new List <string>();

                            switch (literal.Text.ToLowerInvariant())
                            {
                            case "select":
                                sqlOthers.Add("*");
                                sqlOthers.Add("distinct");
                                sqlOthers.Add("top");
                                break;
                            }

                            // Table aliases and functions
                            var context = new SqlContext(group);
                            var others  = context.Tables
                                          .Where(t => !string.IsNullOrEmpty(t.Alias))
                                          .Select(t => t.Alias)
                                          .Distinct()
                                          .Select(t => new SqlGeneralCompletionData()
                            {
                                Text  = t,
                                Image = Icons.Class16.Wpf
                            })
                                          .Concat(Functions(false, null));

                            // Table columns
                            return(Promises.All(context.Tables.Select(t => Columns(t).ToPromise()).ToArray())
                                   .Convert(l => new CompletionContext()
                            {
                                Items = l.OfType <IEnumerable <ICompletionData> >()
                                        .SelectMany(p => p)
                                        .Concat(MatchCase(literal.Text, sqlOthers).Select(o => new SqlGeneralCompletionData()
                                {
                                    Text = o,
                                    Image = Icons.Operator16.Wpf
                                }))
                                        .Concat(others)
                                        .Concat(Schemas())
                                        .OrderBy(i => i.Text, StringComparer.OrdinalIgnoreCase)
                            }));
                        }
                    }
                }

                return(Promises.Resolved(new CompletionContext()));
            }
            catch (Exception ex)
            {
                return(Promises.Rejected <CompletionContext>(ex));
            }
        }
示例#8
0
 private Promise <CUnit> CallApi()
 {
     Debug.Log("CallApi called");
     return(Promises.Rejected <CUnit>(new SystemException()));
 }
 public static Promise <CUnit> Rejected(Exception e)
 {
     return(Promises.Rejected <CUnit>(e));
 }