protected override async Task <IEnumerable <TModel> > SelectOperationAsync(IDbConnection dbConnection)
        {
            {
                if (SelectProxy is IIdentifiablesQuery identifiablesQuery)
                {
                    IEnumerable <Field> fields = SelectProxy is IFieldableQuery <TModel> fieldableQuery?GetFieldableQueryResult(fieldableQuery) : null;

                    return(await dbConnection.QueryAsync <TModel>(identifiablesQuery.Ids, fields, null, MaxSelectCount, Hints, Cacheable?.Key, Cacheable?.ItemExpiration, CommandTimeout, Transaction, Cacheable?.Cache, Trace, StatementBuilder));
                }
            }

            {
                if (SelectProxy is ISearchableQuery <TModel> searchableQuery)
                {
                    IReadOnlyLogbook searchableQueryLogs = searchableQuery.Build(out QueryGroup queryGroup);

                    Logs.AddRange(searchableQueryLogs);

                    if (searchableQueryLogs.Safely)
                    {
                        IEnumerable <Field> fields = SelectProxy is IFieldableQuery <TModel> fieldableQuery?GetFieldableQueryResult(fieldableQuery) : null;

                        IEnumerable <OrderField> orderFields = SelectProxy is IOrderFieldableQuery <TModel> orderFieldableQuery?GetOrderFieldableQueryResult(orderFieldableQuery) : null;

                        return(await dbConnection.QueryAsync <TModel>(queryGroup, fields, orderFields, MaxSelectCount, Hints, Cacheable?.Key, Cacheable?.ItemExpiration, CommandTimeout, Transaction, Cacheable?.Cache, Trace, StatementBuilder));
                    }
                }
            }

            return(null);
        }
Esempio n. 2
0
 public ReportCalls(IClient client, string reportPeriod, ITariffPlan tariffPlan, decimal durationOfConversations, decimal currentMoney, decimal totalSummCollect, IList <IClientLog> clientLogs)
 {
     Client_                 = client;
     ReportPeriod            = reportPeriod;
     TariffPlan_             = tariffPlan;
     DurationOfConversations = durationOfConversations;
     CurrentMoney            = currentMoney;
     TotalSummCollect        = totalSummCollect;
     Logs.AddRange(clientLogs);
 }
Esempio n. 3
0
        public void RefreshLogs()
        {
            QQuery query = new QQuery(string.Empty, (DBTable)Row.Table.LogTable);

            query.BuildParam(Row.Table.LogTable.BaseKey, CompareType.Equal, row.PrimaryId);
            query.BuildParam(Row.Table.LogTable.StatusKey, CompareType.Equal, (int)DBStatus.New);
            Logs.AddRange(Row.Table.LogTable.LoadItems(query, DBLoadParam.Load | DBLoadParam.Synchronize).Cast <DBLogItem>());

            RefreshChanges();
        }
Esempio n. 4
0
        // Method ReadLogs
        public static List <LogModel> ReadLogs()
        {
            string originalPath = Application.StartupPath;

            string fileConfigConnect = originalPath.Substring(0, originalPath.LastIndexOf("bin")) + "Logs.txt";

            if (!File.Exists(fileConfigConnect))
            {
                return(null);
            }

            using (StreamReader reader = new StreamReader(fileConfigConnect))
            {
                List <LogModel> logs = null;

                try
                {
                    logs = new List <LogModel>();

                    string line = "";

                    int i = 0;

                    while ((line = reader.ReadLine()) != null)
                    {
                        logs.Add(new LogModel
                        {
                            Number     = ++i,
                            ContentLog = line
                        });
                    }

                    Logs.Clear();

                    Logs.AddRange(logs);

                    return(logs);
                }
                catch
                {
                    return(null);
                }
                finally
                {
                    reader.Close();
                }
            };
        }
Esempio n. 5
0
        protected override async Task <TModel> UpdateOperationAsync(IDbConnection dbConnection)
        {
            int updatedCount = await dbConnection.UpdateAsync(SourceModel, null, Hints, CommandTimeout, Transaction, Trace, StatementBuilder);

            if (updatedCount > 0)
            {
                SingleSelectById <TModel> singleSelectById = new SingleSelectById <TModel>(SourceModel.Id);

                Logs.AddRange(singleSelectById.ReadOnlyLogs);

                if (singleSelectById.IsSucceed)
                {
                    return(singleSelectById.SelectedModel);
                }
            }

            return(null);
        }
Esempio n. 6
0
        public Logs GetLog()
        {
            using (var ctx = _provider.GetContexto())
            {
                var tmp = ctx.Logs.Select(d =>
                                          new Log()
                {
                    Id         = d.Id,
                    Dt_created = d.Dt_created,
                    Status     = d.Status,
                    Url        = d.Url,
                    Message    = d.Message
                }
                                          ).ToList();

                var a = new Logs();
                a.AddRange(tmp);
                return(a);
            }
        }
Esempio n. 7
0
        protected override async Task <IEnumerable <TModel> > DeleteOperationAsync(IDbConnection dbConnection)
        {
            IEnumerable <TModel> selectedModels = null;

            {
                if (DeleteProxy is IIdentifiablesQuery identifiablesQuery)
                {
                    IEnumerable <Field> fields = DeleteProxy is IFieldableQuery <TModel> fieldableQuery?GetFieldableQueryResult(fieldableQuery) : null;

                    selectedModels = await dbConnection.QueryAsync <TModel>(identifiablesQuery.Ids, fields, null, null, Hints, Cacheable?.Key, Cacheable?.ItemExpiration, CommandTimeout, Transaction, Cacheable?.Cache, Trace, StatementBuilder);
                }
            }

            {
                if (DeleteProxy is ISearchableQuery <TModel> searchableQuery)
                {
                    IReadOnlyLogbook searchableQueryLogs = searchableQuery.Build(out QueryGroup queryGroup);

                    Logs.AddRange(searchableQueryLogs);

                    if (searchableQueryLogs.Safely)
                    {
                        IEnumerable <Field> fields = DeleteProxy is IFieldableQuery <TModel> fieldableQuery?GetFieldableQueryResult(fieldableQuery) : null;

                        IEnumerable <OrderField> orderFields = DeleteProxy is IOrderFieldableQuery <TModel> orderFieldableQuery?GetOrderFieldableQueryResult(orderFieldableQuery) : null;

                        selectedModels = await dbConnection.QueryAsync <TModel>(queryGroup, fields, orderFields, null, Hints, Cacheable?.Key, Cacheable?.ItemExpiration, CommandTimeout, Transaction, Cacheable?.Cache, Trace, StatementBuilder);
                    }
                }
            }

            if (!(selectedModels is null) && selectedModels.Count() > 0)
            {
                int deletedCount = await dbConnection.DeleteAllAsync(selectedModels, Hints, CommandTimeout, Transaction, Trace, StatementBuilder);
            }


            return(null);
        }
Esempio n. 8
0
        public LogService()
        {
            Task.Run(() =>
            {
                while (true)
                {
                    SpinWait.SpinUntil(() => false, 10);
                    if (!presentQueue.TryDequeue(out var item))
                    {
                        continue;
                    }

                    if (Logs.Count > 500)
                    {
                        var temp = Logs.Take(50);
                        Logs.Clear();
                        Logs.AddRange(temp);
                    }

                    Logs.Insert(0, item);
                    OnLog?.Invoke(this, item);
                }
            });
        }
        protected override async Task <TModel> UpdateOperationAsync(IDbConnection dbConnection)
        {
            object updateId     = default;
            int    updatedCount = 0;

            {
                if (UpdateProxy is ISearchableQuery <TModel> searchableQuery)
                {
                    QueryGroup queryGroup = GetSearchableProxyResult(searchableQuery);

                    IEnumerable <Field> fields = UpdateProxy is IFieldableQuery <TModel> fieldableQuery?GetFieldableQueryResult(fieldableQuery) : null;

                    IEnumerable <OrderField> orderFields = UpdateProxy is IOrderFieldableQuery <TModel> orderFieldableQuery?GetOrderFieldableQueryResult(orderFieldableQuery) : null;

                    if (!(queryGroup is null))
                    {
                        TModel searchModel = await GetModelAsync(dbConnection, queryGroup, fields, orderFields);

                        if (searchModel is null)
                        {
                            return(null);
                        }

                        if (UpdateProxy is IIdentifiableQuery identifiableQuery)
                        {
                            updateId = identifiableQuery.Id;

                            updatedCount = await dbConnection.UpdateAsync(searchModel, updateId, fields, Hints, CommandTimeout, Transaction, Trace, StatementBuilder);
                        }
                        else
                        {
                            TModel updateModel = null;

                            if (UpdateProxy is IModelableQuery <TModel> modelableQuery)
                            {
                                updateModel = GetModelableQueryResult(modelableQuery);
                            }

                            if (UpdateProxy is ISourceableQuery <TModel> sourceableModelQuery)
                            {
                                updateModel = GetSourceableQueryResult(sourceableModelQuery);
                            }

                            if (updateModel is null)
                            {
                                return(null);
                            }

                            updateId = updateModel.Id = searchModel.Id;

                            updatedCount = await dbConnection.UpdateAsync(updateModel, fields, Hints, CommandTimeout, Transaction, Trace, StatementBuilder);
                        }
                    }
                }
            }

            {
                if (UpdateProxy is ISourceableQuery <TModel> sourceableModelQuery)
                {
                    TModel sourceModel = GetSourceableQueryResult(sourceableModelQuery);

                    if (sourceModel is null)
                    {
                        return(null);
                    }

                    IEnumerable <Field> fields = UpdateProxy is IFieldableQuery <TModel> fieldableQuery?GetFieldableQueryResult(fieldableQuery) : null;

                    if (UpdateProxy is IIdentifiableQuery identifiableQuery)
                    {
                        updateId = identifiableQuery.Id;

                        updatedCount = await dbConnection.UpdateAsync(sourceModel, updateId, fields, Hints, CommandTimeout, Transaction, Trace, StatementBuilder);
                    }
                    else
                    {
                        updateId = sourceModel.Id;

                        updatedCount = await dbConnection.UpdateAsync(sourceModel, fields, Hints, CommandTimeout, Transaction, Trace, StatementBuilder);
                    }
                }
            }

            {
                if (UpdateProxy is IModelableQuery <TModel> modelableQuery)
                {
                    IReadOnlyLogbook modelableQueryLogs = modelableQuery.ModelQuery.Build(out TModel model);

                    Logs.AddRange(modelableQueryLogs);

                    if (!modelableQueryLogs.Safely && model is null)
                    {
                        return(null);
                    }

                    IEnumerable <Field> fields = UpdateProxy is IFieldableQuery <TModel> fieldableQuery?GetFieldableQueryResult(fieldableQuery) : null;

                    if (UpdateProxy is IIdentifiableQuery identifiableQuery)
                    {
                        updateId = identifiableQuery.Id;

                        updatedCount = await dbConnection.UpdateAsync(model, updateId, fields, Hints, CommandTimeout, Transaction, Trace, StatementBuilder);
                    }
                    else
                    {
                        updateId = model.Id;

                        updatedCount = await dbConnection.UpdateAsync(model, fields, Hints, CommandTimeout, Transaction, Trace, StatementBuilder);
                    }
                }
            }

            if (updatedCount > 0)
            {
                return(await GetModelAsync(dbConnection, updateId));
            }

            return(null);
        }
Esempio n. 10
0
        // Method WriteLog
        public static List <LogModel> WriteLog(string contentLog)
        {
            string originalPath = Application.StartupPath;

            string fileConfig = originalPath.Substring(0, originalPath.LastIndexOf("bin")) + "Logs.txt";

            FileStream stream = null;

            if (!File.Exists(fileConfig))
            {
                stream = File.Create(fileConfig);
            }

            List <LogModel> logs = null;

            try
            {
                logs = new List <LogModel>();

                if (stream != null)
                {
                    using (StreamWriter writer = new StreamWriter(fileConfig))
                    {
                        try
                        {
                            writer.WriteLine(contentLog);
                        }
                        catch { }
                        finally
                        {
                            writer.Close();
                        }

                        logs.Add(new LogModel
                        {
                            Number     = 1,
                            ContentLog = contentLog
                        });
                    }
                }
                else
                {
                    logs = ReadLogs();

                    logs.Add(new LogModel
                    {
                        Number     = logs.Count + 1,
                        ContentLog = contentLog
                    });

                    using (StreamWriter writer = new StreamWriter(fileConfig))
                    {
                        try
                        {
                            logs.ForEach(p =>
                            {
                                writer.WriteLine(p.ContentLog);
                            });
                        }
                        catch { }
                        finally
                        {
                            writer.Close();
                        }
                    }
                }

                Logs.Clear();

                Logs.AddRange(logs);

                return(logs);
            }
            catch { return(null); }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }
        /// <summary>
        /// Run application against the commands in the excel file
        /// </summary>
        /// <param name="rangeName"></param>
        /// <param name="rangeParameter"></param>
        /// <returns></returns>
        public List <string> Run(string rangeName = "", string rangeParameter = "")
        {
            // The start cell
            Excel.Range startCell = null;

            // if the range name is null get the name of the current sheet plus type
            if (string.IsNullOrEmpty(rangeName))
            {
                startCell = _worksheet.Range[_worksheet.Name + "Type"];
            }
            else
            {
                startCell = _worksheet.Range[rangeName];
            }

            if (startCell == null)
            {
                throw new Exception("Could not find start range");
            }

            // Column for the type of commands we are running
            var typeCol = startCell.Column;

            // Name of the document or sub we are working with
            var nameCol = typeCol + 1;

            // Parent of the document we are working
            var parentCol = nameCol + 1;

            // Value to set or get based on command
            var value = parentCol + 1;

            // Secondary value for some commands
            var value2 = value + 1;

            // Set the start orw
            var i = startCell.Row + 1;

            // loop while the command column is not null
            while (!string.IsNullOrEmpty(GetString(i, typeCol)))
            {
                // get the command we are working with
                var command = GetString(i, typeCol).ToUpper();

                // if the command is a comment continue
                if (command == Commands.Comment)
                {
                    i++;
                    continue;
                }
                // Open the document
                else if (command == Commands.OpenDocument)
                {
                    _methods.OpenDocument(GetString(i, nameCol), GetString(i, parentCol), GetString(i, value), GetString(i, value2));
                    i++;
                    continue;
                }

                // Assign the working document
                var workingDocumentName = GetString(i, parentCol);

                // working document name is null then assign the working document to the document
                if (string.IsNullOrEmpty(workingDocumentName))
                {
                    if (_topDocument == null)
                    {
                        _topDocument = InventorApplication.ActiveDocument;
                    }

                    _workingDocument = _topDocument;
                }
                // Assign the working document
                else
                {
                    // if the working document is null then assign
                    if (_workingDocument == null)
                    {
                        _workingDocument = DocumentHelper.GetDocument(workingDocumentName);

                        if (_workingDocument == null)
                        {
                            Logs.Add($"Could not find document {workingDocumentName}. If all occurences are suppressed you can ignore this error.");
                            i++;
                            continue;
                        }
                    }
                    // if the working document does not match working document name then assign it.
                    else
                    {
                        if (_workingDocument.Name != workingDocumentName)
                        {
                            _workingDocument = DocumentHelper.GetDocument(workingDocumentName);
                        }

                        if (_workingDocument == null)
                        {
                            Logs.Add($"Could not find document {workingDocumentName}. If all occurences are suppressed you can ignore this error.");
                            i++;
                            continue;
                        }
                    }
                }

                switch (command)
                {
                case Commands.TopLevelName:
                    var topLevelName = GetString(i, nameCol);

                    if (InventorApplication.ActiveDocument.Name != topLevelName)
                    {
                        throw new Exception("Top level name does not match active model");
                    }
                    else
                    {
                        _topDocument = InventorApplication.ActiveDocument;
                    }
                    break;

                case Commands.Parameter:
                    _methods.SetParameter(_workingDocument, GetString(i, nameCol), GetString(i, value));
                    break;

                case Commands.GetParameter:
                    var parameterValue = _methods.GetParameter(_workingDocument, GetString(i, nameCol));
                    SetValue(i, value, parameterValue);
                    break;

                case Commands.SetProperty:
                    _methods.SetProperty(_workingDocument, GetString(i, nameCol), GetString(i, value));
                    break;

                case Commands.GetProperty:
                    var propertyValue = _methods.GetProperty(_workingDocument, GetString(i, nameCol));
                    SetValue(i, value, propertyValue);
                    break;

                case Commands.ComponentActivity:
                    _methods.Suppression(_workingDocument, GetString(i, nameCol), GetString(i, value), SuppresionType.Component);
                    break;

                case Commands.ConstraintActivity:
                    _methods.Suppression(_workingDocument, GetString(i, nameCol), GetString(i, value), SuppresionType.Constraint);
                    break;

                case Commands.PatternActivity:
                    _methods.Suppression(_workingDocument, GetString(i, nameCol), GetString(i, value), SuppresionType.Pattern);
                    break;

                case Commands.FeatureActivity:
                    _methods.Suppression(_workingDocument, GetString(i, nameCol), GetString(i, value), SuppresionType.Feature);
                    break;

                case Commands.DeleteComponent:
                    _methods.Delete(_workingDocument, GetString(i, nameCol));
                    break;

                case Commands.DeleteReferencedDocuments:
                    _methods.DeleteReferenced(_workingDocument, GetString(i, nameCol));
                    break;

                case Commands.Stop:
                    throw new Exception("Program Stopped");

                case Commands.UpdateDocument:
                    _workingDocument.Update();
                    break;

                case Commands.Sub:
                    ProcessRunBlockInventor runBlock = null;
                    var subName       = GetString(i, nameCol);
                    var workSheetName = "";

                    if (subName.Contains("!"))
                    {
                        var subSplit = subName.Split('!');

                        workSheetName = subSplit[0];
                        subName       = subSplit[1];

                        runBlock = new ProcessRunBlockInventor(Globals.ThisAddIn.Application.ActiveWorkbook.GetWorksheets().FirstOrDefault(x => x.Name == workSheetName), _topDocument);
                    }
                    else
                    {
                        runBlock = new ProcessRunBlockInventor(_worksheet, _topDocument);
                    }

                    runBlock.Run(subName, GetString(i, value));

                    Logs.AddRange(runBlock.Logs);
                    break;

                case Commands.If:
                    ValidateIf(i, typeCol);

                    var booleanValue = GetBoolean(i, value);

                    if (!booleanValue)
                    {
                        i = GetEndIfRow(i, typeCol);
                    }
                    break;

                case Commands.Repeat:
                    ValidateRepeat(i, typeCol);
                    repeatStart = i;
                    repeatEnd   = GetEndRepeatRow(i, typeCol);
                    repeatCount = GetInt(i, value);
                    repeatIndex = 1;
                    SetValue(i, value2, repeatIndex.ToString());
                    inRepeat = true;
                    break;
                }

                i++;

                if (inRepeat)
                {
                    if (i == repeatEnd)
                    {
                        if (repeatIndex == repeatCount)
                        {
                            i           = repeatEnd + 1;
                            repeatStart = 0;
                            repeatEnd   = 0;
                            repeatCount = 0;
                            repeatIndex = 0;
                            inRepeat    = false;
                        }
                        else
                        {
                            i = repeatStart + 1;
                            repeatIndex++;
                            SetValue(repeatStart, value2, repeatIndex.ToString());
                        }
                    }
                }
            }

            if (_topDocument != null)
            {
                if (InventorApplication.ActiveDocument.Name != _topDocument.Name)
                {
                    InventorApplication.ActiveDocument.Save();

                    InventorApplication.ActiveDocument.Close();
                }
            }

            InventorApplication.ActiveDocument.Update();

            InventorApplication.ActiveDocument.Save();

            Logs.AddRange(_methods.Logs);

            return(Logs);
        }
Esempio n. 12
0
 public void AddAllLogs(List <KeyValuePair <string, string> > logs)
 {
     Logs.AddRange(logs);
     PInfo.Tag = Logs.Count;
 }
Esempio n. 13
0
 public void ReloadLogs()
 {
     Logs.Clear();
     Logs.AddRange(logProvider.GetFileNames());
 }