private static List <string> GetLibraryContent(IDoc app, string contentName = "") { try { var results = new List <string>(); var readItems = new List <string>() { contentName }; if (String.IsNullOrEmpty(contentName)) { //Search for all App Specific ContentLibraries var libs = app.GetContentLibrariesAsync().Result; readItems = libs.qItems.Where(s => s.qAppSpecific == true).Select(s => s.qName).ToList(); } foreach (var item in readItems) { var qUrls = GetLibraryContentInternal(app, item); results.AddRange(qUrls); } return(results); } catch (Exception ex) { logger.Error(ex, "Could not read the content library."); return(new List <string>()); } }
public static bool HasText(IDoc doc) { try { var ta = new TextAbsorber(); using (var document = new Document(doc.Stream)) { foreach (Page page in document.Pages) { page.Accept(ta); if (ta.Text.Trim(' ', '\n', '\r').Length != 0) { return(true); } } } } catch (Exception e) { var identifier = string.IsNullOrWhiteSpace(doc.Identifier) ? "???" : doc.Identifier; Log.Error(e, "HasText für {Identifier} failed.", identifier); } return(false); }
public QlikSessionObject(string filtertext, IDoc senseApp) { SenseApp = senseApp; FilterText = filtertext; GenericObject = GetGenericObject(); Cardinal = GetListObject()?.qDimensionInfo?.qCardinal ?? 0; CurrentIndex = -1; }
private void D_PositionChanged(object sender, EventArgs e) { IDoc doc = sender as IDoc; if (doc != null) { lblCount.Text = $"Count: {doc.Current+1} of {doc.Count}"; } }
public ChangeEventsExample(IDoc app) : base(app) { app?.GetAppLayoutAsync() .ContinueWith(t => { #region Handle AlternateStates var res = t.Result; if (res != null) { var states = res.qStateNames?.ToList() ?? new List <string>(); states.Add("$"); if (CachedCurrentSelection == null) { CachedCurrentSelection = new ConcurrentDictionary <string, IGenericObject>(); } var delList = from c in CachedCurrentSelection.Keys where !states.Contains(c) select c; var addList = from c in states where !CachedCurrentSelection.Keys.Contains(c) select c; foreach (var stateToAdd in addList) { var req = JObject.FromObject(new { qProp = new { qInfo = new { qType = "CurrentSelection" }, qSelectionObjectDef = new { qStateName = stateToAdd } } }); app?.CreateSessionObjectAsync(req) .ContinueWith(ts => { if (ts.Result != null) { if (CachedCurrentSelection.TryAdd(stateToAdd, ts.Result)) { ts.Result.Changed += CachedCurrentSelection_Changed; Console.WriteLine("Call manualy"); CachedCurrentSelection_Changed(ts.Result, new EventArgs()); } } }).Wait(); } } #endregion }).Wait(); }
private async Task InsertDoc(IDoc doc) { if (doc is DocEntry docEntry) { await DocsCollection.InsertOneAsync(docEntry); } else if (doc is FailedDoc failedDoc) { await FailedDocsCollection.InsertOneAsync(failedDoc); } }
private void materialToolStripMenuItem_Click(object sender, EventArgs e) { if (fMaterials == null || fMaterials.IsDisposed) { fMaterials = new frmMaterials(); fMaterials.MdiParent = this; IDoc d = fMaterials as IDoc; d.PositionChanged += D_PositionChanged; } fMaterials.Show(); }
private void productToolStripMenuItem_Click(object sender, EventArgs e) { if (fProduct == null || fProduct.IsDisposed) { fProduct = new frmProducts(); fProduct.MdiParent = this; IDoc d = fProduct as IDoc; d.PositionChanged += D_PositionChanged; } fProduct.Show(); }
private void frmMain_MdiChildActivate(object sender, EventArgs e) { IDoc doc = ActiveMdiChild as IDoc; if (doc != null) { lblCount.Text = $"Count: {doc.Current + 1} of {doc.Count}"; } else { lblCount.Text = ""; } }
public DocsController( IJournal journal, IDocFile docFile, IDoc doc, IDocJournal docJournal, IStage stage) { _journal = journal; _docJournal = docJournal; _docFile = docFile; _doc = doc; _stage = stage; }
public override ExtractionResult ExtractText(IDoc doc, ITextExtractorSettings settings) { var result = new ExtractionResult(settings.MaxExtractionSize); var textAbsorber = new TextAbsorber(); using (var pdfDocument = new Document(doc.Stream)) { pdfDocument.Pages.Accept(textAbsorber); } result.Append(textAbsorber.Text); return(result); }
private static string TestCalc(IDoc app, CancellationToken token) { try { var result = app.EvaluateExAsync("1+1").Result; return(result.qText); } catch (Exception ex) { Console.Write(ex.Message, "Could not do it"); if (token.IsCancellationRequested) { return(null); } Thread.Sleep(2000); return(TestCalc(app, token)); } }
private IGenericObject CreateListBox(IDoc appIDoc, string FieldName) { IGenericObject listbox = null; var request = JObject.FromObject(new { qProp = new { qInfo = new { qType = "ListObject" }, qListObjectDef = new { qInitialDataFetch = new List <NxPage> { new NxPage() { qTop = 0, qHeight = 4000, qLeft = 0, qWidth = 1 } }, qDef = new { qFieldDefs = new List <string> { FieldName, }, qFieldLabels = new List <string> { FieldName, } }, qShowAlternatives = false, } } }); appIDoc.CreateSessionObjectAsync(request).ContinueWith((res) => { listbox = res.Result; }).Wait(); return(listbox); }
private void WriteComment(CommentTarget target, string targetName, IDoc doc) { if (doc != null && doc.Text.Length > 0) { ICodeWriterPlSql sql = Model.Lamp.CodeWritersFactory.CreateCodeWriterPlSql(); sql.Write("COMMENT ON "); switch (target) { case CommentTarget.Table: sql.Write("TABLE "); break; default: sql.Write("COLUMN "); break; } sql.Write("{0} IS {1}", targetName, sql.ToConst(doc.Text)); genie.Config.NotifyAssistants("Doc", doc, sql.ToString(true)); WriteExecImmediat(sql); creator.WriteFrom(sql); creator.WriteSeparator(); } }
public SelectionExample(IDoc app) : base(app) { }
public abstract ExtractionResult ExtractText(IDoc doc, ITextExtractorSettings settings);
public Database(IDoc iDoc, Db db) { this._iDoc = iDoc; this._db = db; }
public TableHelper GetTableInfosFromApp(string tableName, ScriptCode script, IDoc app) { try { var resultTable = new ResultTable() { Name = tableName, }; var fields = new List <ResultHeader>(); var rows = new List <ResultRow>(); var size = new Size(); if (app == null) { throw new Exception("No App session."); } var tableObject = app.GetObjectAsync(script.ObjectId).Result; if (tableObject == null) { throw new Exception("No Table object found."); } logger.Debug($"TableObject objectId: {script.ObjectId} - objectType {tableObject.qGenericType}"); dynamic hyperCubeLayout = tableObject.GetLayoutAsync <JObject>().Result; HyperCube hyperCube = hyperCubeLayout.qHyperCube.ToObject <HyperCube>(); var columnOrder = hyperCube.qColumnOrder.ToList(); size = hyperCube.qSize; fields.AddRange(GetHyperCubeFields(hyperCube.qDimensionInfo, hyperCube.qMeasureInfo, script)); if (columnOrder == null || columnOrder.Count == 0) { columnOrder = new List <int>(); for (int i = 0; i < fields.Count; i++) { columnOrder.Add(i); } } var preview = new PreviewResponse() { MaxCount = 15, }; if (script != null) { var allPages = new List <IEnumerable <NxDataPage> >(); if (script.Full) { //DataLoad preview.MaxCount = 0; var pageHeight = Math.Min(size.qcy * size.qcx, 5000) / size.qcx; logger.Debug($"read data - column count: {size.qcx}"); var counter = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(size.qcy) / Convert.ToDouble(pageHeight))); allPages = new List <IEnumerable <NxDataPage> >(counter); var options = new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }; Parallel.For(0, counter, options, i => { var initalPage = new NxPage { qTop = 0, qLeft = 0, qWidth = size.qcx, qHeight = pageHeight }; initalPage.qTop = i * pageHeight; var pages = tableObject.GetHyperCubeDataAsync("/qHyperCubeDef", new List <NxPage>() { initalPage }).Result; allPages.Add(pages); }); } else { //Preview var initalPage = new NxPage { qTop = 0, qLeft = 0, qWidth = size.qcx, qHeight = preview.MaxCount }; var pages = tableObject.GetHyperCubeDataAsync("/qHyperCubeDef", new List <NxPage>() { initalPage }).Result; allPages.Add(pages); } if (allPages == null) { throw new Exception($"no dimension in table {script.ObjectId} exits."); } logger.Debug($"read pages - count {allPages.Count}"); var hrow = new PreviewRow(); preview.qPreview.Add(hrow); foreach (var page in allPages) { var allMatrix = page?.SelectMany(p => p.qMatrix); foreach (var matrix in allMatrix) { var drow = new PreviewRow(); preview.qPreview.Add(drow); foreach (var order in columnOrder) { if (order < fields.Count) { var row = new ResultRow(); var field = fields[order]; row.Value = matrix[order].qText; row.Num = matrix[order]?.qNum ?? Double.NaN; row.Header = field.Name; if (order == 0) { row.IsFirstRow = true; } if (order == fields.Count - 1) { row.IsLastRow = true; } rows.Add(row); if (!preview.qPreview.Any(s => s.qValues.Contains(field.Name))) { hrow.qValues.Add(field.Name); } if (preview.qPreview.Count <= preview.MaxCount) { drow.qValues.Add(matrix[order].qText); } } } } } } resultTable.Headers.AddRange(fields); resultTable.Rows.AddRange(rows); logger.Debug($"return table {resultTable.Name}"); return(new TableHelper(resultTable, preview)); } catch (Exception ex) { logger.Error(ex, "can´t read table infos."); return(null); } }
private static List <string> GetLibraryContentInternal(IDoc app, string qName) { var libContent = app.GetLibraryContentAsync(qName).Result; return(libContent.qItems.Select(u => u.qUrl).ToList()); }
public async Task InsertEntry(IEntry entry) { IDoc doc = MapEntryToDoc(entry); await InsertDoc(doc); }
public QlikSelections(IDoc senseApp) { SenseApp = senseApp; Dimensions = new QlikDimensions(senseApp); }
public BookmarkExample(IDoc app) : base(app) { }
public MultipleRequests(IDoc app) : base(app) { }
public abstract void Salvar(IDoc iDoc);
public BaseExample(IDoc app) { App = app; }
static void Main(string[] args) { Console.WriteLine("Starting..."); Console.WriteLine("Read Settings..."); var content = File.ReadAllText("settings.json"); var settings = JsonConvert.DeserializeObject <Settings>(content); Session session = null; IDoc app = null; try { var config = new EnigmaConfigurations() { Url = settings.ServerUri.AbsoluteUri, CreateSocket = async(url) => { var ws = new ClientWebSocket(); await ws.ConnectAsync(new Uri(url), CancellationToken.None); return(ws); } }; session = Enigma.Create(config); var globalTask = session.OpenAsync(); globalTask.Wait(); IGlobal global = Impromptu.ActLike <IGlobal>(globalTask.Result); var appName = settings.App; Console.WriteLine($"Connect to App {appName}..."); app = global.OpenDocAsync(appName).Result; Console.WriteLine($"Create Connections..."); foreach (var qconn in settings.Connections) { try { var connConfig = new Connection() { qType = qconn.Type, qName = qconn.Name, qConnectionString = qconn.ConnectionString }; Console.WriteLine($"Create connection..."); var test = app.CreateConnectionAsync(connConfig).Result; } catch (Exception ex) { Console.WriteLine($"No Connection created: {ex.ToString()}"); } } foreach (var scriptPath in settings.Scripts) { var scriptContent = File.ReadAllText(scriptPath); Console.WriteLine($"Reload Script..."); app.SetScriptAsync(scriptContent).Wait(); app.DoReloadAsync().Wait(); } Console.WriteLine($"Finish."); } catch (Exception ex) { Console.WriteLine($"Error:\n{ex.ToString()}"); Console.ReadLine(); } }
public ListObjectExample(IDoc app) : base(app) { }
public override void Salvar(IDoc iDoc) { _documentos.Add(iDoc); }
static void Main(string[] args) { SetLoggerSettings("App.config"); logger.Info("Start"); Session session = null; IDoc app = null; //Result exception in TryConvert. try { var config = new EnigmaConfigurations() { Url = $"ws://127.0.0.1:4848/app/engineData/identity/{Guid.NewGuid()}", //Url = $"wss://127.0.0.1/app/engineData/identity/{Guid.NewGuid()}", // if you want to create your own Connection with for example header / cookies, just inject this in line CreateSocket = async(url) => { var ws = new ClientWebSocket(); #if NETCOREAPP2_1 var ck = new CookieContainer(); ck.Add(new Uri(url), new Cookie("X-Qlik-Session", "xxxxxxxxx")); ws.Options.Cookies = ck; ws.Options.RemoteCertificateValidationCallback += new RemoteCertificateValidationCallback((object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => { return(true); }); #endif //!!!!!!!!!here you can inject your cookie, header authentification,... await ws.ConnectAsync(new Uri(url), CancellationToken.None); return(ws); } }; session = Enigma.Create(config); // connect to the engine var globalTask = session.OpenAsync(); globalTask.Wait(); IGlobal global = Impromptu.ActLike <IGlobal>(globalTask.Result); var appName = SenseUtilities.GetFullAppName("Executive Dashboard"); app = global.OpenDocAsync(appName).Result; app.Closed += App_Closed; } catch (Exception ex) { logger.Error(ex); } var mytasks = new List <Task>(); var ce1 = new CalculationExample(app); ce1.CalcRandom(120); Task.WaitAll(mytasks.ToArray()); var count = mytasks.Count; //global.EngineVersionAsync() // .ContinueWith((engVer) => // { // Console.WriteLine("CastedEngineVer:" + engVer.Result.qComponentVersion); // }); //global.OpenDocAsync(appName) // .ContinueWith((newApp) => // { // Console.WriteLine("Object " + (newApp.Result).ToString()); // var app = newApp.Result; // // test the changed notification of the opend app // app.Changed += App_Changed; // // just a normal get script // app.GetScriptAsync() // .ContinueWith((script) => // { // Console.WriteLine("Script" + script.Result.ToString().Substring(1, 100)); // }); // // change the script, so that the app changed is triggered // app.SetScriptAsync("HALLO") // .ContinueWith((res) => // { // // read the changed script // app.GetScriptAsync() // .ContinueWith((script) => // { // Console.WriteLine("Script2" + script.Result.ToString()); // }); // }); // }); //Thread.Sleep(3000); var example = new ChangeEventsExample(app); example.RunExample(); var tasks = new List <Task>(); //Set bookmark test var bookmark = app.GetBookmarkAsync("demobookmark").Result; //evaluate request var request = JObject.FromObject(new { qExpression = "'$(vCurrentYear)'" }); //Use this Overload from EvaluateExAsync it works fine. var result = app.EvaluateExAsync(request).Result; //Use this Overload it crashes!!! result = app.EvaluateExAsync("'$(vCurrentYear)'").Result; //Caluculation Test var calc = new CalculationExample(app); calc.CalcRandom(1); //find the bookmark with type var bookmarkExample = new BookmarkExample(app); tasks.Add(bookmarkExample.ListBookmarksAsync()); //find dimensions var dimensionExample = new DimensionExample(app); tasks.Add(dimensionExample.ListDimensionsAsync()); //find current selections var selectionExample = new SelectionExample(app); tasks.Add(selectionExample.ListCurrentSelectionsAsync()); ////find list object data var listObjectExample = new ListObjectExample(app); tasks.Add(listObjectExample.ListListObjectDataAsync()); ////Fire Multiple Requests var multipleRequestsExample = new MultipleRequests(app); tasks.Add(multipleRequestsExample.FireMultipleRequestsAsync()); Task.WaitAll(tasks.ToArray()); var task5 = listObjectExample.GetGenericObjectAsync("Region"); var task6 = listObjectExample.GetListObjectDataAsync(task5.Result); dynamic jsonObject = task6.Result; foreach (var item in jsonObject[0].qMatrix) { Console.WriteLine(item[0]?.qText + ""); } Console.WriteLine("Finish"); var _ = session.CloseAsync(); Console.ReadLine(); }
public CalculationExample(IDoc app) : base(app) { }