public void ScalarWithTwoArgument()
        {
            Factory2 factory2 = null;

            Assert.DoesNotThrow(() => factory2 = new Factory2());

            IFunction function = null;
            var       args     = new Field[] { Field.BigInt(2), Field.Number(new SqlNumber(54)) };

            Assert.DoesNotThrow(() => function = factory2.ResolveFunction("add2", args));
            Assert.IsNotNull(function);

            InvokeResult result = null;

            Assert.DoesNotThrow(() => result = function.Execute(args));
            Assert.IsNotNull(result);

            Assert.IsInstanceOf <SqlNumber>(result.ReturnValue.Value);

            var value = ((SqlNumber)result.ReturnValue.Value).ToInt64();

            Assert.AreEqual(56, value);
        }
Пример #2
0
        public object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            try
            {
                var dynamicMethod = DynamicMethodHelper.GetDynamicMethod("<C1 function> " + _functionToWrap.CompositeName());

                return(dynamicMethod(() => _functionToWrap.Execute(parameters, context)));
            }
            catch (Exception ex)
            {
                if (_functionToWrap.ReturnType == typeof(XhtmlDocument) || (_functionToWrap.ReturnType == typeof(void) && ex is HttpCompileException))
                {
                    XElement errorBoxHtml;
                    if (context.ProcessException(_functionToWrap.CompositeName(), ex, LogTitle, out errorBoxHtml))
                    {
                        XhtmlDocument errorInfoDocument = new XhtmlDocument();
                        errorInfoDocument.Body.Add(errorBoxHtml);
                        return(errorInfoDocument);
                    }
                }

                throw;
            }
        }
Пример #3
0
        private void CalculatePiX()
        {
            long n       = 2;
            long counter = 0;

            if (PrimesCountList.Initialzed)
            {
                n       = PrimesCountList.MaxNumber;
                counter = PrimesCountList.GetPrime(n);
            }
            m_FunctionPix_Executed(n);
            m_FunctionPix.FunctionState = FunctionState.Running;

            while (n < m_To.LongValue)
            {
                n++;
                counter = (long)m_FunctionPix.Execute(n);
            }
            m_FunctionPix.FunctionState = FunctionState.Stopped;
            if (OnStopPiX != null)
            {
                OnStopPiX();
            }
        }
        /// <exclude />
        public override object GetValue(FunctionContextContainer contextContainer)
        {
            if (contextContainer == null)
            {
                throw new ArgumentNullException("contextContainer");
            }

            string functionName = _function.CompositeName() ?? "<unknown function>";

            using (TimerProfilerFacade.CreateTimerProfiler(functionName))
            {
                ValidateNotSelfCalling();

                try
                {
                    var parameters = new ParameterList(contextContainer);

                    foreach (ParameterProfile parameterProfile in _function.ParameterProfiles)
                    {
                        List <BaseParameterRuntimeTreeNode> parameterTreeNodes = this.Parameters.Where(ptn => ptn.Name == parameterProfile.Name).ToList();

                        if (parameterTreeNodes.Count > 0)
                        {
                            parameters.AddLazyParameter(parameterProfile.Name, parameterTreeNodes[0], parameterProfile.Type);
                            continue;
                        }

                        if (parameterProfile.Type.IsGenericType &&
                            parameterProfile.Type.GetGenericTypeDefinition() == typeof(NullableDataReference <>))
                        {
                            parameters.AddConstantParameter(parameterProfile.Name, null, parameterProfile.Type);
                            continue;
                        }

                        if (parameterProfile.IsRequired)
                        {
                            var injectedValue = TryGetInjectedValue(parameterProfile.Type);

                            if (injectedValue == null)
                            {
                                throw new ArgumentException("Missing parameter '{0}' (type of {1})".FormatWith(parameterProfile.Name, parameterProfile.Type.FullName));
                            }

                            parameters.AddConstantParameter(parameterProfile.Name, injectedValue, parameterProfile.Type);
                            continue;
                        }

                        BaseValueProvider valueProvider = parameterProfile.FallbackValueProvider;

                        object value;
                        try
                        {
                            value = valueProvider.GetValue(contextContainer);
                        }
                        catch (Exception ex)
                        {
                            throw new InvalidOperationException($"Failed to get value for parameter '{parameterProfile.Name}' in function '{functionName}'.", ex);
                        }
                        parameters.AddConstantParameter(parameterProfile.Name, value, parameterProfile.Type, true);
                    }

                    object result;

                    IDisposable measurement = null;
                    try
                    {
                        if (functionName != "Composite.Utils.GetInputParameter")
                        {
                            var nodeToLog = functionName;

                            if (_function is IDynamicFunction df && df.PreventFunctionOutputCaching)
                            {
                                nodeToLog += " (PreventCaching)";
                            }

                            measurement = Profiler.Measure(nodeToLog, () => _function.EntityToken);
                        }

                        result = _function.Execute(parameters, contextContainer);
                    }
                    finally
                    {
                        measurement?.Dispose();
                    }

                    return(result);
                }
                catch (ThreadAbortException)
                {
                    return(null); // Nothing will be returned as ThreadAbort will propagate
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException($"Failed to get value for function '{functionName}'", ex);
                }
            }
        }
Пример #5
0
        public override void Execute(Context c)
        {
            string data = m_data.Execute(c);

            // TO DO: Replace with dictionary mapping the enum to lambda functions
            switch (m_request)
            {
            case Request.UpdateLocation:
                m_worldModel.PlayerUI.LocationUpdated(data);
                break;

            case Request.GameName:
                m_worldModel.PlayerUI.UpdateGameName(data);
                break;

            case Request.ClearScreen:
                m_worldModel.PlayerUI.ClearScreen();
                m_worldModel.OutputLogger.Clear();
                break;

            case Request.ShowPicture:
                m_worldModel.PlayerUI.ShowPicture(data);
                // TO DO: Picture should be added to the OutputLogger, but the data we
                // get here includes the full path/URL - we want the original filename
                // only, so this would be a breaking change.
                break;

            case Request.PanesVisible:
                m_worldModel.PlayerUI.SetPanesVisible(data);
                break;

            case Request.Background:
                m_worldModel.PlayerUI.SetBackground(data);
                break;

            case Request.Foreground:
                m_worldModel.PlayerUI.SetForeground(data);
                break;

            case Request.RunScript:
                if (m_worldModel.Version == WorldModelVersion.v500)
                {
                    // v500 games used Frame.js functions for static panel feature. This is now implemented natively
                    // in Player and WebPlayer.
                    if (data == "beginUsingTextFrame")
                    {
                        return;
                    }
                    if (data.StartsWith("setFramePicture;"))
                    {
                        string[] frameArgs = data.Split(';');
                        m_worldModel.PlayerUI.SetPanelContents("<img src=\"" + frameArgs[1].Trim() + "\" onload=\"setPanelHeight()\"/>");
                        return;
                    }
                    if (data == "clearFramePicture")
                    {
                        m_worldModel.PlayerUI.SetPanelContents("");
                    }
                }

                string[] jsArgs       = data.Split(';').Select(a => a.Trim()).ToArray();
                string   functionName = jsArgs[0];
                if (jsArgs.Length == 0)
                {
                    m_worldModel.PlayerUI.RunScript(functionName, null);
                }
                else
                {
                    m_worldModel.PlayerUI.RunScript(functionName, jsArgs.Skip(1).ToArray());
                }

                break;

            case Request.Quit:
                m_worldModel.PlayerUI.Quit();
                m_worldModel.Finish();
                break;

            case Request.FontName:
                if (m_worldModel.Version >= WorldModelVersion.v540)
                {
                    throw new InvalidOperationException("FontName request is not supported for games written for Quest 5.4 or later.");
                }
                m_worldModel.PlayerUI.SetFont(data);
                ((LegacyOutputLogger)(m_worldModel.OutputLogger)).SetFontName(data);
                break;

            case Request.FontSize:
                if (m_worldModel.Version >= WorldModelVersion.v540)
                {
                    throw new InvalidOperationException("FontSize request is not supported for games written for Quest 5.4 or later.");
                }
                m_worldModel.PlayerUI.SetFontSize(data);
                ((LegacyOutputLogger)(m_worldModel.OutputLogger)).SetFontSize(data);
                break;

            case Request.LinkForeground:
                m_worldModel.PlayerUI.SetLinkForeground(data);
                break;

            case Request.Show:
                m_worldModel.PlayerUI.Show(data);
                break;

            case Request.Hide:
                m_worldModel.PlayerUI.Hide(data);
                break;

            case Request.SetCompassDirections:
                m_worldModel.PlayerUI.SetCompassDirections(data.Split(';'));
                break;

            case Request.SetStatus:
                m_worldModel.PlayerUI.SetStatusText(data.Replace("\n", Environment.NewLine));
                break;

            case Request.Pause:
                if (m_worldModel.Version >= WorldModelVersion.v550)
                {
                    throw new Exception("The 'Pause' request is not supported for games written for Quest 5.5 or later. Use the 'SetTimeout' function instead.");
                }
                int ms;
                if (int.TryParse(data, out ms))
                {
                    m_worldModel.StartPause(ms);
                }
                break;

            case Request.Wait:
                if (m_worldModel.Version >= WorldModelVersion.v540)
                {
                    throw new Exception("The 'Wait' request is not supported for games written for Quest 5.4 or later. Use the 'wait' script command instead.");
                }
                m_worldModel.StartWait();
                break;

            case Request.SetInterfaceString:
                string[] args = data.Split('=');
                m_worldModel.PlayerUI.SetInterfaceString(args[0], args[1]);
                break;

            case Request.RequestSave:
                m_worldModel.PlayerUI.RequestSave(null);
                break;

            case Request.SetPanelContents:
                m_worldModel.PlayerUI.SetPanelContents(data);
                break;

            case Request.Log:
                m_worldModel.PlayerUI.Log(data);
                break;

            case Request.Speak:
                m_worldModel.PlayerUI.Speak(data);
                break;

            default:
                throw new ArgumentOutOfRangeException("request", "Unhandled request type");
            }
        }
Пример #6
0
        public override void Execute(Context c)
        {
            string filename = m_filename.Execute(c);

            m_worldModel.PlaySound(filename, m_synchronous.Execute(c), m_loop.Execute(c));
        }
 public object Execute(ParameterList parameters, FunctionContextContainer context)
 {
     return(_function.Execute(parameters, context));
 }
Пример #8
0
 public override void Execute(Context c)
 {
     m_worldModel.ObjectFactory.CreateTurnScript(m_expr.Execute(c), null);
 }
Пример #9
0
 public override void Execute(Context c)
 {
     m_worldModel.ObjectFactory.CreateExit(m_id == null ? null : m_id.Execute(c), m_name.Execute(c), m_from.Execute(c), m_to.Execute(c), m_initialType == null ? null : m_initialType.Execute(c));
 }
Пример #10
0
 public override void Execute(Context c)
 {
     m_worldModel.UndoLogger.RollTransaction(m_command.Execute(c));
 }
Пример #11
0
        private void ExecuteGraph(PrimesBigInteger from, PrimesBigInteger to)
        {
            CancelPiX();

            ResetControls();
            m_FunctionLiN.Reset();
            m_FunctionPiGauss.Reset();
            m_FunctionPix.Reset();

            //bool valid = false;
            //if (rbFreeRange.IsChecked.Value)
            //{
            //  valid = GetFreeParameters(ref from, ref to);
            //}
            //else if (rbFunctionRange.IsChecked.Value)
            //{
            //  valid = GetFunctionParameters(ref from, ref to);
            //}
            //if (valid)
            //{
            cgraph.ClearFunctions();

            if (m_From.CompareTo(from) != 0)
            {
                m_From = from;
                try
                {
                    m_RangeYFrom = Math.Min(m_FunctionPiGauss.Execute(m_From.DoubleValue), m_FunctionLiN.Execute(m_From.DoubleValue));
                    tbInfoGaußPrimeTheorem.Text = "";
                }
                catch (ResultNotDefinedException) { m_RangeYFrom = 2; }
                m_FunctionPiGauss.Reset();
                m_FunctionLiN.Reset();
            }

            if (m_To != to)
            {
                m_To       = to;
                m_RangeYTo = m_FunctionLiN.Execute(m_To.DoubleValue);
                m_FunctionLiN.Reset();
                tbInfoLin.Text = "";
            }

            m_FunctionLiN.MaxValue = to.DoubleValue;
            cgraph.RangeX          = new RangeX(from, to);

            string strFrom = Convert.ToInt32(Math.Floor(m_RangeYFrom)).ToString();
            string strTo   = Convert.ToInt32(Math.Ceiling(m_RangeYTo)).ToString();

            cgraph.RangeY = new RangeY(new PrimesBigInteger(strFrom), new PrimesBigInteger(strTo));
            if (cbPiGauss.IsChecked.Value)
            {
                cgraph.AddFunctionExecute(m_FunctionPiGauss, from, to, FunctionType.CONSTANT, Brushes.Blue);
            }
            if (cbPiX.IsChecked.Value)
            {
                cgraph.AddFunctionExecute(m_FunctionPix, m_From, m_To, FunctionType.STAIR, Brushes.Red);
            }
            if (cbLin.IsChecked.Value)
            {
                cgraph.AddFunctionExecute(m_FunctionLiN, from, to, FunctionType.CONSTANT, Brushes.Green);
            }
            cgraph.ExecuteFunctions();

            if (to.CompareTo(PrimesBigInteger.ValueOf(10000)) > 0)
            {
                lblInfoPixDontCalc.Visibility = Visibility.Visible;

                //cbPiX.IsEnabled = false;
                //m_CountPixThread = new CountPiXThread(m_FunctionPix as FunctionPiX, this.Dispatcher, m_FunctionPix_Executed, m_To);
                //m_CountPixThread.OnFunctionStart += new FunctionEvent(FunctionStart);
                //m_CountPixThread.OnFunctionStop += new FunctionEvent(FunctionStop);

                //m_CountPixThread.Start();
                //m_ThreadPix = new Thread(new ThreadStart(CalculatePiX));
                //m_ThreadPix.Start();
            }

            ControlHandler.SetPropertyValue(lblCalcInfoPiX, "Visibility", Visibility.Visible);
            ControlHandler.SetPropertyValue(lblCalcInfoPiGauss, "Visibility", Visibility.Visible);
            ControlHandler.SetPropertyValue(lblCalcInfoLiN, "Visibility", Visibility.Visible);
            ControlHandler.SetPropertyValue(tbInfoLin, "Visibility", Visibility.Visible);
            ControlHandler.SetPropertyValue(tbInfoPiX, "Visibility", Visibility.Visible);
            ControlHandler.SetPropertyValue(tbInfoGaußPrimeTheorem, "Visibility", Visibility.Visible);
            lblCalcInfoLiN.Text     = Primes.Resources.lang.WpfControls.Distribution.Distribution.graph_lincountinfoCalculating;
            lblCalcInfoPiGauss.Text = Primes.Resources.lang.WpfControls.Distribution.Distribution.graph_gausscountinfoCalculating;
            lblCalcInfoPiX.Text     = Primes.Resources.lang.WpfControls.Distribution.Distribution.graph_pincountinfoCalculating;
            //}
        }
Пример #12
0
        public override void Execute(Context c)
        {
            object         options           = m_options.Execute(c);
            IList <string> stringListOptions = options as IList <string>;
            IDictionary <string, string> stringDictionaryOptions = options as IDictionary <string, string>;

            if (stringListOptions != null)
            {
                if (stringListOptions.Count == 0)
                {
                    throw new Exception("No menu options specified");
                }
                m_worldModel.DisplayMenuAsync(m_caption.Execute(c), stringListOptions, m_allowCancel.Execute(c), m_callbackScript, c);
            }
            else if (stringDictionaryOptions != null)
            {
                if (stringDictionaryOptions.Count == 0)
                {
                    throw new Exception("No menu options specified");
                }
                m_worldModel.DisplayMenuAsync(m_caption.Execute(c), stringDictionaryOptions, m_allowCancel.Execute(c), m_callbackScript, c);
            }
            else
            {
                throw new Exception("Unknown menu options type");
            }
        }
        /// <summary>
        /// Toggle the checkout system on/off.
        /// </summary>
        /// <param name="sender">Object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        private void ToggleCheckOutSystem(object sender, EventArgs e)
        {
            Project project = App.Instance.SalesForceApp.CurrentProject;

            if (project != null)
            {
                string text = project.Client.Checkout.IsEnabled() ?
                              "Disabling the check out system will delete a previously created custom object and impact all Walli users of the organization.  Are you sure you want to proceed?" :
                              "Enabling the check out system requires a new custom object be created and will impact all Walli users of the organization.  Are you sure you want to proceed?";

                if (App.MessageUser(text,
                                    "Check out system",
                                    System.Windows.MessageBoxImage.Warning,
                                    new string[] { "Yes", "No" }) == "Yes")
                {
                    using (App.Wait("Updating check out system"))
                    {
                        project.Client.Checkout.Enable(!project.Client.Checkout.IsEnabled());
                        App.Instance.UpdateWorkspaces();

                        // refresh open folders
                        IFunction refreshFunction   = App.Instance.GetFunction <RefreshFolderFunction>();
                        INode     currentActiveNode = App.Instance.Navigation.ActiveNode;

                        ApexClassFolderNode classFolderNode = App.Instance.Navigation.GetNode <ApexClassFolderNode>();
                        if (classFolderNode != null)
                        {
                            App.Instance.Navigation.ActiveNode = classFolderNode;
                            refreshFunction.Execute();
                        }

                        ApexTriggerFolderNode triggerFolderNode = App.Instance.Navigation.GetNode <ApexTriggerFolderNode>();
                        if (triggerFolderNode != null)
                        {
                            App.Instance.Navigation.ActiveNode = triggerFolderNode;
                            refreshFunction.Execute();
                        }

                        ApexPageFolderNode pageFolderNode = App.Instance.Navigation.GetNode <ApexPageFolderNode>();
                        if (pageFolderNode != null)
                        {
                            App.Instance.Navigation.ActiveNode = pageFolderNode;
                            refreshFunction.Execute();
                        }

                        ApexComponentFolderNode componentFolderNode = App.Instance.Navigation.GetNode <ApexComponentFolderNode>();
                        if (componentFolderNode != null)
                        {
                            App.Instance.Navigation.ActiveNode = componentFolderNode;
                            refreshFunction.Execute();
                        }

                        App.Instance.Navigation.ActiveNode = currentActiveNode;
                    }

                    App.MessageUser("The check out system has been changed.  All users that currently have an open project in Walli for this organization will need to close those projects and then reopen them to see the change take effect.",
                                    "Check out system changed",
                                    System.Windows.MessageBoxImage.Information,
                                    new string[] { "OK" });
                }

                SourceControlSetupWindow dlg = sender as SourceControlSetupWindow;
                if (dlg != null)
                {
                    dlg.IsCheckoutEnabled = project.Client.Checkout.IsEnabled();
                }
            }
        }
Пример #14
0
        public bool Evaluate(out IJsonValue value, IJSONDocument document)
        {
            //ArithmeticOperation consideration...
            value = null;
            object functionResult = null;

            if (_executionType.Equals(FunctionExecutionType.Scalar))
            {
                if (_funcImpl == null)
                {
                    return(false);
                }

                var values = new List <IJsonValue>();
                foreach (var argument in _arguments)
                {
                    IJsonValue result;
                    if (!argument.Evaluate(out result, document))
                    {
                        return(false);
                    }
                    values.Add(result);
                }

                if (_arguments.Count != values.Count)
                {
                    return(false);
                }

                var arguments = new object[values.Count];
                for (int i = 0; i < values.Count; i++)
                {
                    arguments[i] = JsonWrapper.UnWrap(values[i]);
                }
                try
                {
                    functionResult = _funcImpl.Execute(FunctionName, arguments);
                }
                catch (System.Reflection.TargetParameterCountException)
                {
                    throw;
                }
                catch (System.ArgumentException)
                {
                    throw;
                }
                catch (Exception exception)
                {
                    if (LoggerManager.Instance.QueryLogger != null && LoggerManager.Instance.QueryLogger.IsErrorEnabled)
                    {
                        LoggerManager.Instance.QueryLogger.Error("UDFs", exception.Message);
                    }
                    throw;
                }
                value = JsonWrapper.Wrap(functionResult);
                return(true);
            }

            if (_executionType.Equals(FunctionExecutionType.Aggregate))
            {
                string evaluation = "$" + ToString();
                object outValue;
                value = JsonWrapper.Wrap(!document.TryGet(evaluation, out outValue) ? 0 : outValue);
                return(true);
            }

            return(false);
        }
Пример #15
0
        public async Task Query()
        {
            IQuery <string> query       = _database.Products.Query().Join(e => e.Owner).Where(e => e.IsAvailable).OrderBy(e => e.Name).Offset(10).Limit(20).Select(e => e.Name);
            IDelete         batchDelete = _database.Products.Delete().Where(e => e.IsAvailable);
            IInsert         batchInsert = _database.Products.Insert(new Product(), new Product());
            IUpdate         batchUpdate = _database.Products.Update().Where(e => e.IsAvailable).Set(e => new Product {
                IsAvailable = false
            });

            IUpdate singleUpdate = _database.Products.Update().Set(e => e.NetPrice, e => e.NetPrice * 1.1m).Set(e => e.DateAdded, DateTime.UtcNow);

            var(queryResult, deleteAffected, updateAffected, insertAffected) = _database.Execute(query, batchDelete, batchUpdate, batchInsert);
            (queryResult, deleteAffected, updateAffected, insertAffected)    = await _database.ExecuteAsync(query, batchDelete, batchUpdate, batchInsert);

            string querySql  = query.ToSqlString();
            string deleteSql = batchDelete.ToSqlString();
            string updateSql = batchUpdate.ToSqlString();
            string insertSql = batchInsert.ToSqlString();

            var product1 = await _database.Products.Query().Where(e => e.Id == 1).Single().ExecuteAsync();

            var product2 = await _database.Products.Query().Where(e => e.Id == 2).Single().ExecuteAsync();

            var updatedExplicitly = await _database.Products.Update(product1, product2).ExecuteAsync();

            var product3 = await _database.Products.Query().Where(e => e.Id == 3).Single().ExecuteAsync();

            var product4 = await _database.Products.Query().Where(e => e.Id == 4).Single().ExecuteAsync();

            var deletedExplicitly = await _database.Products.Delete(product3, product4).ExecuteAsync();

            var copyInsert = _database.ArchivedProducts.InsertFrom(_database.Products.Query().Where(p => !p.IsAvailable && p.DateAdded < DateTime.UtcNow.AddYears(-1)).Select(e => new ArchivedProduct { /* ... */
            }));
            var copiedRows = await copyInsert.ExecuteAsync();

            queryResult = _database.ExecuteSql <List <string> >(querySql, new { x = 1 });
            queryResult = await _database.ExecuteSqlAsync <List <string> >(querySql, new { x = 1 });

            IStoredProcedure <List <ProductDto> > searchedProductsProcedure = _database.SearchProducts("name");
            var searchedProducts = searchedProductsProcedure.Execute();

            searchedProducts = await searchedProductsProcedure.ExecuteAsync();

            searchedProducts = _database.Execute(searchedProductsProcedure);
            searchedProducts = await _database.ExecuteAsync(searchedProductsProcedure);

            IFunction <decimal> priceFunction = _database.CalculatePrice(123);
            var price = priceFunction.Execute();

            price = await priceFunction.ExecuteAsync();

            price = _database.Execute(priceFunction);
            price = await _database.ExecuteAsync(priceFunction);

            _database.Insert(new Product()).Execute();
            var product5 = _database.Query <Product>().Where(e => e.Id == 5).Execute();

            _database.Update(product5).Execute();
            _database.Delete(product5).Execute();

            var q1 = _database.Products.Query().Where(e => e.OwnerId == 5);
            var q2 = _database.Products.Query().Where(e => e.OwnerId == 6);
            var q3 = _database.Products.Query().Where(e => e.OwnerId == 7);

            List <Product> unionList123 = q1.Union(q2).UnionAll(q3).Execute();
            List <Product> unionList    = _database.Products
                                          .Query().Where(e => e.OwnerId == 5)
                                          .UnionAll()
                                          .Query().Where(e => e.OwnerId == 6)
                                          .Execute();

            var product7 = _database.Query <Product>(options => options.AsEditable().WithComment("my query tag").WithHint("NOLOCK"))
                           .Where(e => e.Id == 7).Execute();

            // WITH CTE explicit
            var cte1      = _database.Query <Product>();
            var cte2      = _database.Query(cte1).Where(e => e.IsAvailable);
            var withQuery = _database.Query(cte2).Where(e => e.NetPrice > 0);

            // Recursive CTE
            var managerQuery = _database.Query <Employee>().Where(e => e.ManagerId == null)
                               .Select(e => new EmployeeDto {
                Id = e.Id, Name = e.Name, ManagerId = e.ManagerId, Level = 1
            });
            var employeeQuery = _database.Query <Employee>().Join(managerQuery, (l, r) => l.ManagerId == r.Id)
                                .Where((e, mq) => e.Id == 234)
                                .Select((e, mq) => new EmployeeDto {
                Id = e.Id, Name = e.Name, ManagerId = e.ManagerId, Level = mq.Level + 1
            });
            var hierarchyUnion = managerQuery.UnionAll(employeeQuery);

            var employeeHierarchy = _database.Query(hierarchyUnion)
                                    .OrderBy(e => e.Level)
                                    .ThenOrderByDescending(e => e.ManagerId)
                                    .Select(e => new EmployeeHierarchy
            {
                Employee = e.Name,
                Level    = e.Level,
                Manager  = _database.Query <Employee>().Where(m => m.Id == e.ManagerId).Select(m => m.Name).First().Execute()
            })
                                    .Distinct()
                                    .Execute();

            // Subquery
            _database.Products.Query().Select(e => new ProductDto()).OrderBy(e => e.Price).Execute();

            // Multiquery
            _database.Query <Product, Owner, Employee>();

            _database.Query(_database.Products, _database.AvailableProducts, hierarchyUnion)
            .Join(managerQuery, (p, _, _, m) => p.Id == m.Id);

            // Group by
            var groupedProducts = _database.Query <Product>()
                                  .GroupBy(p => new { p.Id, p.Name })
                                  .Having(p => p.Key.Id > 4 && p.Count() > 5 && p.Max(e => e.NetPrice) > 50)
                                  .Select(p => new
            {
                p.Key.Id,
                p.Key.Name,
                Count          = p.Count(),
                Max            = p.Max(e => e.NetPrice),
                CountAvailable = p.Where(e => e.IsAvailable).Count(),
                MaxAvailable   = p.Where(e => e.IsAvailable).Max(e => e.NetPrice),
                AllAvailable   = p.Where(e => e.IsAvailable).Select(e => new { e.Name, e.NetPrice }).AsList()
            })
                                  .Execute();

            // Mapping
            Product[] productArray = _database.Query <Product>().AsArray().Execute();
            Dictionary <int, Product> productByOwnerDict = _database.Query <Product>().AsDictionary(e => e.OwnerId).Execute();
        }
Пример #16
0
 public override void Execute(Context c)
 {
     m_worldModel.GetElementFactory(ElementType.Timer).Create(m_expr.Execute(c));
 }
Пример #17
0
 public override void Execute(Context c)
 {
     m_worldModel.ShowQuestionAsync(m_caption.Execute(c), m_callbackScript, c);
 }
Пример #18
0
        public override void Execute(Context c)
        {
            Element obj = m_obj.Execute(c);

            obj.Fields.Set(m_field.Execute(c), m_value.Execute(c));
        }