Пример #1
0
        }         // func GetStringArray

        private async Task OpenCursorAsync(LuaTable table)
        {
            // not optional
            var selectExpression = table.GetOptionalValue("name", (string)null) ?? throw new ArgumentNullException("name");

            // parse selector
            var selectorExpression = PpsDataFilterExpression.Parse(table.GetMemberValue("filter"));

            // parse optional columns
            var columns = PpsDataColumnExpression.Parse(table.GetMemberValue("columns")).ToArray();

            // parse optional order
            var orderExpressions = PpsDataOrderExpression.Parse(table.GetMemberValue("order")).ToArray();

            // try to get a list
            int cursorId;

            lock (cursors)
                cursorId = ++lastCursorId;

            var cursor = new OpenCursor(cursorId, await provider.GetListAsync(selectExpression, columns, selectorExpression, orderExpressions));

            lock (cursors)
                cursors.Add(cursorId, cursor);

            // return the cursor id
            await PushPacketAsync(new LuaTable()
            {
                ["id"] = cursorId
            });
        }         // proc OpenCursorAsync
Пример #2
0
        public void TestMember01()
        {
            LuaTable t = new LuaTable();

            t["test"] = "t";
            Assert.AreEqual(t["test"], "t");
            t.SetMemberValue("Test", "a", true);
            Assert.AreEqual(t.GetMemberValue("Test", true, true), "a");
            t.SetMemberValue("Test", "b");
            Assert.AreEqual(t["Test"], "b");
            t.SetMemberValue("Test", "n", true);
            Assert.AreEqual(t["test"], "n");

            IDictionary <string, object> a = t.Members;

            string[] r = new string[2];
            a.Keys.CopyTo(r, 0);
            Assert.IsTrue(r[0] == "test" && r[1] == "Test");

            t.SetMemberValue("Test", null, true, true);
            t.SetMemberValue("Test", null, true, true);

            Assert.IsTrue(t["Test"] == null);
            Assert.IsTrue(t["test"] == null);
        }
Пример #3
0
        }         // CompareStringKey

        public static T ReturnOptionalValue <T>(this LuaTable table, string name, T @default, bool ignoreCase = false, bool rawGet = false)
        {
            var value = table.GetMemberValue(name, ignoreCase, rawGet);

            if (value == null)
            {
                return(@default);
            }
            else
            {
                if (Lua.RtInvokeable(value))
                {
                    value = new LuaResult(Lua.RtInvoke(value))[0];
                }

                if (value == null)
                {
                    return(@default);
                }
                try
                {
                    return(value.ChangeType <T>());
                }
                catch
                {
                    return(@default);
                }
            }
        } // func ReturnOptionalValue
Пример #4
0
		private void Button_Click_1(object sender, RoutedEventArgs e)
		{
			using (Lua l = new Lua())
			{
				var t = new LuaTable();
				var c = l.CompileChunk(
					String.Join(Environment.NewLine,
						"local v1 = 2;",
						"local v2 = 4;",
						"function f()",
						"  return v1 + v2;",
						"end;",
						"return f();"), "test", null);
				var r = c.Run(t);
				txtResult.Text = String.Format("Test: v1=[{0}], v2=[{1}], r={2}", Lua.RtGetUpValue(t.GetMemberValue("f") as Delegate, 1), Lua.RtGetUpValue(t.GetMemberValue("f") as Delegate, 2), r.ToInt32());
			}
		}
Пример #5
0
        }         // proc Rollback

        #endregion

        #region -- Prepare/Execute ----------------------------------------------------

        /// <summary>Prepare a database statement.</summary>
        /// <param name="parameter"></param>
        /// <param name="firstArgs"></param>
        /// <returns></returns>
        public PpsDataCommand Prepare(LuaTable parameter, LuaTable firstArgs)
        {
            if (parameter.GetMemberValue("rows") != null)
            {
                throw new ArgumentNullException("rows", "Prepare does not support 'rows'.");
            }

            return(PrepareCore(parameter, firstArgs));
        }         // func Prepare
        private LuaResult LuaRequirePane(LuaTable self, string path, LuaTable initialTable = null)
        {
            // get the current root
            var webRequest = self.GetMemberValue(nameof(IPpsRequest.Request)) as DEHttpClient ?? Request;
            var fullUri    = webRequest.CreateFullUri(path);
            var paneData   = this.LoadPaneDataAsync(initialTable ?? new LuaTable(), fullUri).AwaitTask();

            return(new LuaResult(new PpsGenericWpfChildPane(this, paneData, fullUri)));
        }         // func LuaRequirePane
Пример #7
0
        /// <summary>Invoke lua event handler.</summary>
        /// <param name="t"></param>
        /// <param name="methodName"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public LuaResult InvokeLuaFunction(LuaTable t, string methodName, params object[] args)
        {
            var handler = t.GetMemberValue(methodName, rawGet: true);

            if (Lua.RtInvokeable(handler))
            {
                return(new LuaResult(Lua.RtInvoke(handler, args)));
            }
            return(LuaResult.Empty);
        }         // func InvokeClientFunction
        }         // proc Dispose

        /// <summary></summary>
        /// <param name="otherArgumens"></param>
        /// <returns></returns>
        public override PpsWindowPaneCompareResult CompareArguments(LuaTable otherArgumens)
        {
            var r = base.CompareArguments(otherArgumens);

            if (r == PpsWindowPaneCompareResult.Reload || r == PpsWindowPaneCompareResult.Incompatible)
            {
                var otherObj = otherArgumens.GetMemberValue("Object");
                return(otherObj == obj ? PpsWindowPaneCompareResult.Same : PpsWindowPaneCompareResult.Reload);
            }
            return(r);
        }         // func CompareArguments
Пример #9
0
		static void Main(string[] args)
		{
			Console.Write(TestAsync().Result);
			using (Lua l = new Lua())
			{
				var t = new LuaTable();
				var c = l.CompileChunk(
					String.Join(Environment.NewLine,
						"local v1 = 2;",
						"local v2 = 4;",
						"function f()",
						"  return v1 + v2;",
						"end;",
						"return f();"), "test", null);
				var r = c.Run(t);
				Console.WriteLine("Test: v1=[{0}], v2=[{1}], r={2}", Lua.RtGetUpValue(t.GetMemberValue("f") as Delegate, 1), Lua.RtGetUpValue(t.GetMemberValue("f") as Delegate, 2), r.ToInt32());
			}

			//LinqTest2();
			Console.ReadKey();
		}
Пример #10
0
            }             // proc Dispose

            private static ILogger GetHostLog(LuaTable table)
            {
                // Check for a logger
                var sp = table.GetMemberValue("host") as IServiceProvider;

                if (sp != null)
                {
                    return(sp.GetService <ILogger>(false));
                }

                return(null);
            }             // func LogMsg
Пример #11
0
        }         // proc CloseCursorAsync

        private async Task GetDataSetAsync(LuaTable table)
        {
            var identification = table.GetMemberValue("id") ?? throw new ArgumentNullException("id");
            var tableFilter    = GetStringArray(table, "filter");

            var dataset = await provider.GetDataSetAsync(identification, tableFilter);

            var result = new LuaTable();

            foreach (var tab in dataset.Tables)
            {
                if (tableFilter.Length != 0 &&
                    Array.Exists(tableFilter, c => String.Compare(c, tab.TableName, StringComparison.OrdinalIgnoreCase) != 0))
                {
                    continue;
                }

                var resultTable = new LuaTable();

                var columnList = new LuaTable();
                foreach (var col in tab.Columns)
                {
                    var resultColumn = GetColumnData(col, new LuaTable());

                    if (col.IsRelationColumn)
                    {
                        resultColumn["parentReleation"] = new LuaTable()
                        {
                            ["table"]  = col.ParentColumn.ParentColumn.Table.Name,
                            ["column"] = col.ParentColumn.ParentColumn.Name
                        };
                    }

                    columnList.Add(resultColumn);
                }

                resultTable["columns"] = columnList;

                // convert rows
                foreach (var row in tab)
                {
                    resultTable.Add(GetRowData(new LuaTable(), row));
                }

                result[tab.TableName] = resultTable;
            }

            await PushPacketAsync(result);
        }         // proc ExecuteAsync
Пример #12
0
        public void DebugReport(LuaTable table)
        {
            table["DebugOutput"] = new Action <string>(text => Log.LogMsg(LogMsgType.Debug, text));
            var resultFile = RunReportAsync(table).AwaitTask();

            // move to a unique name
            var moveFileTo = table.GetMemberValue("name") as string;
            var p          = moveFileTo.LastIndexOfAny(new char[] { '/', '\\' });

            moveFileTo = Path.Combine(Path.GetDirectoryName(resultFile), moveFileTo.Substring(p + 1)) + ".pdf";
            if (File.Exists(moveFileTo))
            {
                File.Delete(moveFileTo);
            }
            File.Move(resultFile, moveFileTo);
        }         // proc DebugReport
Пример #13
0
        }         // func TryGetCursor

        private static string[] GetStringArray(LuaTable table, string memberName)
        {
            switch (table.GetMemberValue(memberName))
            {
            case string stringList:
                return(stringList.Split(',').Where(s => !String.IsNullOrEmpty(s)).ToArray());

            case LuaTable tableArray:
                return(tableArray.ArrayList.Select(o => o.ToString()).ToArray());

            case null:
                return(Array.Empty <string>());

            default:
                throw new ArgumentOutOfRangeException(memberName, $"'{memberName}' should be a string list or a lua array.");
            }
        }         // func GetStringArray
Пример #14
0
        private OpenCursor GetCursor(LuaTable table)
        {
            var id = Procs.ChangeType <int>(table.GetMemberValue("id") ?? throw new ArgumentNullException("id"));

            lock (cursors)
            {
                if (cursors.TryGetValue(id, out var cursor))
                {
                    if (cursor.IsDisposed)
                    {
                        cursors.Remove(id);
                    }
                    else
                    {
                        return(cursor);
                    }
                }
            }
            throw new ArgumentOutOfRangeException("id", $"Cursor '{id}' not found.");
        }         // func TryGetCursor
Пример #15
0
        }         // proc NextCursorAsync

        private async Task NextCursorCountAsync(LuaTable table)
        {
            // get parameter
            var cursor = GetCursor(table);
            var count  = Procs.ChangeType <int>(table.GetMemberValue("count") ?? -1);

            // collect rows
            var rows = new LuaTable();

            while (count-- > 0 && cursor.MoveNext())
            {
                rows.Add(cursor.GetCurrentRow());
            }

            // send result
            await PushPacketAsync(new LuaTable()
            {
                ["id"]  = cursor.Id,
                ["row"] = rows.Length == 0 ? null : rows
            });
        }         // proc NextCursorCountAsync
Пример #16
0
		public void TestMember01()
		{
			LuaTable t = new LuaTable();
			t["test"] = "t";
			Assert.AreEqual(t["test"], "t");
			t.SetMemberValue("Test", "a", true);
			Assert.AreEqual(t.GetMemberValue("Test", true, true), "a");
			t.SetMemberValue("Test", "b");
			Assert.AreEqual(t["Test"], "b");
			t.SetMemberValue("Test", "n", true);
			Assert.AreEqual(t["test"], "n");

			IDictionary<string, object> a = t.Members;
			string[] r = new string[2];
			a.Keys.CopyTo(r, 0);
			Assert.IsTrue(r[0] == "test" && r[1] == "Test");

			t.SetMemberValue("Test", null, true, true);
			t.SetMemberValue("Test", null, true, true);

			Assert.IsTrue(t["Test"] == null);
			Assert.IsTrue(t["test"] == null);
		}
Пример #17
0
        private (IEnumerator <object>, PpsDataCommand) PrepareWithData(LuaTable parameter)
        {
            if (parameter.GetMemberValue("rows") is IEnumerable <IDataRow> rows)            // from datatable or other row source
            {
                var rowEnumerator = rows.GetEnumerator();
                if (rows is IDataColumns columns)
                {
                    rowEnumerator.MoveNext();
                }
                else
                {
                    if (!rowEnumerator.MoveNext())                     // no arguments defined
                    {
                        rowEnumerator.Dispose();
                        return(null, null);                          // silent return nothing
                    }

                    columns = rowEnumerator.Current as IDataColumns;
                }

                // create columns list parameter
                parameter["columnList"] = columns ?? throw new ArgumentException("IDataColumns not implemented.", nameof(parameter));

                return(rowEnumerator, PrepareCore(parameter, null));
            }
            else
            {
                var rowEnumerator = parameter.ArrayList.OfType <LuaTable>().GetEnumerator();
                if (!rowEnumerator.MoveNext())
                {
                    rowEnumerator.Dispose();
                    return(null, PrepareCore(parameter, null));
                }

                return(rowEnumerator, PrepareCore(parameter, rowEnumerator.Current));
            }
        }         // func PrepareWithData
Пример #18
0
        public string DebugEmitter(LuaTable table)
        {
            var arguments  = table.GetOptionalValue("converter", (string)null);
            var columnName = table.GetOptionalValue("columnName", (string)null);
            // create row
            var row = GetRowContent((table.GetMemberValue("row") as LuaTable) ?? throw new ArgumentNullException("row", "Row information is missing."));

            using (var session = reporting.CreateDebugReportSession())
                using (var sw = new StringWriter())
                    using (var xml = XmlWriter.Create(sw, new XmlWriterSettings()
                    {
                        NewLineHandling = NewLineHandling.Entitize, IndentChars = "  ", Async = true
                    }))
                    {
                        // emit column
                        var emitter = session.CreateColumnEmitter(arguments, columnName, row);
                        xml.WriteStartElement(emitter.ElementName);
                        emitter.WriteAsync(xml, row).AwaitTask();
                        xml.WriteEndElement();
                        xml.Flush();

                        return(sw.GetStringBuilder().ToString());
                    }
        }         // func DebugEmitter
Пример #19
0
 public GSubLuaTableMatchEvaluator(LuaTable t)
 {
     this.t = t;
     this.lIgnoreCase = (bool)Lua.RtConvertValue(t.GetMemberValue("__IgnoreCase"), typeof(bool));
 }
Пример #20
0
 /// <summary></summary>
 /// <param name="args"></param>
 /// <returns></returns>
 protected override Task OnLoadAsync(LuaTable args)
 {
     ClosePdf();
     return(OpenPdfAsync(args.GetMemberValue("Object") ?? args.GetMemberValue("FileName")));
 }         // proc OnLoadAsync
Пример #21
0
 public GSubLuaTableMatchEvaluator(LuaTable t)
 {
     this.t           = t;
     this.lIgnoreCase = (bool)Lua.RtConvertValue(t.GetMemberValue("__IgnoreCase"), typeof(bool));
 }             // ctor
Пример #22
0
            }             // ctor

            protected override string MatchEvaluatorImpl(Match m)
            {
                return((string)Lua.RtConvertValue(t.GetMemberValue(m.Groups[1].Value, lIgnoreCase), typeof(string)));
            }     // func MatchEvaluator
Пример #23
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     using (Lua l = new Lua())
     {
         var t = new LuaTable();
         var c = l.CompileChunk(
             String.Join(Environment.NewLine,
                         "local v1 = 2;",
                         "local v2 = 4;",
                         "function f()",
                         "  return v1 + v2;",
                         "end;",
                         "return f();"), "test", null);
         var r = c.Run(t);
         txtResult.Text = String.Format("Test: v1=[{0}], v2=[{1}], r={2}", Lua.RtGetUpValue(t.GetMemberValue("f") as Delegate, 1), Lua.RtGetUpValue(t.GetMemberValue("f") as Delegate, 2), r.ToInt32());
     }
 }
Пример #24
0
 private static void Test()
 {
     using (Lua l = new Lua())
     {
         var t = new LuaTable();
         var c = l.CompileChunk(
             String.Join(Environment.NewLine,
                         "local v1 = 2;",
                         "local v2 = 4;",
                         "function f()",
                         "  return v1 + v2;",
                         "end;",
                         "return f();"), "test", null);
         var r = c.Run(t);
         Console.WriteLine("Test: v1=[{0}], v2=[{1}], r={2}", Lua.RtGetUpValue(t.GetMemberValue("f") as Delegate, 1), Lua.RtGetUpValue(t.GetMemberValue("f") as Delegate, 2), r.ToInt32());
     }
 }
        /// <summary></summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        protected override async Task LoadInternAsync(LuaTable arguments)
        {
            async Task CreateNewObjectAsync()
            {
                // load schema
                var documentType = (string)arguments.GetMemberValue("createNew");

                if (documentType == null)
                {
                    throw new ArgumentException("No 'object' or 'createNew' set.");
                }

                // get the object info for the type
                var objectInfo = Shell.ObjectInfos[documentType];

                if (objectInfo.CreateServerSiteOnly || String.IsNullOrEmpty(objectInfo.DocumentUri))
                {
                    throw new ArgumentNullException("object", "Parameter 'object' is missing.");
                }

                // create the new object entry
                obj = await Shell.CreateNewObjectAsync(objectInfo);
            }             // proc CreateNewObject

            // get the object reference for the document
            obj = (PpsObject)arguments.GetMemberValue("Object");

            // new document or load one
            using (var transaction = await Shell.MasterData.CreateTransactionAsync(PpsMasterDataTransactionLevel.Write))
            {
                if (obj == null)                 // no object given
                {
                    await CreateNewObjectAsync();
                }

                data = await obj.GetDataAsync <PpsObjectDataSet>();

                // register events, owner, and in the openDocuments dictionary
                dataAccess = await data.AccessAsync(arguments);

                dataAccess.DisableUI    = new Func <IDisposable>(() => DisableUI("Verarbeite Daten...", -1));
                dataAccess.DataChanged += (sender, e) => OnDataChanged();

                transaction.Commit();
            }

            // get the pane to view, if it is not given
            if (!arguments.ContainsKey("pane"))
            {
                // try to get the uri from the pane list
                var info    = Shell.GetObjectInfo(obj.Typ);
                var paneUri = info["defaultPane"] as string;
                if (!String.IsNullOrEmpty(paneUri))
                {
                    arguments.SetMemberValue("Pane", paneUri);
                }
                else
                {
                    // read the schema meta data
                    paneUri = data.DataSetDefinition.Meta.GetProperty <string>(PpsDataSetMetaData.DefaultPaneUri, null);
                    if (!String.IsNullOrEmpty(paneUri))
                    {
                        arguments.SetMemberValue("Pane", paneUri);
                    }
                }
            }

            // Load mask
            await base.LoadInternAsync(arguments);

            InitializeData();
        }         // proc LoadInternAsync