Пример #1
0
 private void KeySet()
 {
     if (ShouldExecute)
     {
         RunningTransaction.Register(DynamicEntityType.Name, this);
     }
 }
 private static void ACSQuery()
 {
     foreach (ControllerListSource cls in IODataCollection.queryList.Where(c => c.name.StartsWith("ACS-")))
     {
         string queryStr = ACSQueryUtilities.GenACSSimQueryStr(cls.IOList);
         acsu.BeginTransaction(cls.name, queryStr, new AsyncCallback(OnTransaction), acsu);
         RunningTransaction.Add(cls.name);
     }
 }
Пример #3
0
        // not in use, use acs's as master
        // private static void StatThreadIODataUpdate()
        // {
        //     IODataUpdateThread = new Thread(IODataUpdate);
        //     IODataUpdateThread.IsBackground = true;
        //     IODataUpdateThread.Start();
        // }

        private static void LSQuery()
        {
            foreach (ControllerListSource cls in IODataCollection.queryList.Where(c => c.name.StartsWith(ControllerNames.LS + '-')))
            {
                Thread t = new Thread(() => { Update(cls.name, cls.IOList); });
                t.IsBackground = true;
                t.Start();
                RunningTransaction.Add(cls.name);
            }
        }
        private static void OnTransaction(IAsyncResult ar)
        {
            object[] os    = (object[])ar.AsyncState;
            string   cname = (string)os[0];
            ACSControllerUtilities _acsu = (ACSControllerUtilities)os[1];
            string queryStr = ACSQueryUtilities.GenACSSimQueryStr(IODataCollection.queryList.Find(cls => cls.name == cname).IOList);

            try
            {
                string     transStr = _acsu.EndTransaction(ar);
                List <int> tl       = ACSQueryUtilities.ConvertACSTransStr(transStr, out bool result);
                if (!result)
                {
                    string err = $"变量名错误或未定义:{cname}@{queryStr}=>{transStr}";
                    IOInterface.updateError = true;
                    RunningTransaction.Remove(cname);
                    IOInterface.ShowError(err);
                    return;
                }
                IODataCollection.UpdateIOQueryList(cname, tl);
                if (!ACSThreadAbort)
                {
                    Thread.Sleep(50);
                    _acsu.BeginTransaction(cname, queryStr, new AsyncCallback(OnTransaction), _acsu);
                }
                else
                {
                    RunningTransaction.Remove(cname);
                    if (RunningTransaction.Count == 0)
                    {
                        ACSThreadAborted = true;
                    }
                }
            }
            catch (Exception e)
            {
                string err = $"{e.Message}:{cname}@{queryStr}";
                IOInterface.updateError = true;
                RunningTransaction.Remove(cname);
                if (RunningTransaction.Count == 0)
                {
                    ACSThreadAborted = true;
                }

                IOInterface.ShowError(err);
            }
            GC.Collect();
        }
Пример #5
0
        private static void Update(string cname, List <string> queryList)
        {
            while (true)
            {
                try
                {
                    Thread.Sleep(50);
                    List <int> tl = LSu.ReadDevice(cname, queryList);
                    IODataCollection.UpdateIOQueryList(cname, tl);
                }
                catch (Exception e)
                {
                    string queryStr = string.Join(",", queryList);
                    string err      = $"{e.Message} {cname}@{queryStr}";
                    IOInterface.updateError = true;
                    RunningTransaction.Remove(cname);
                    if (RunningTransaction.Count == 0)
                    {
                        LSThreadAborted = true;
                    }

                    IOInterface.ShowError(err);
                    return;
                }

                if (LSThreadAbort)
                {
                    RunningTransaction.Remove(cname);
                    if (RunningTransaction.Count == 0)
                    {
                        LSThreadAborted = true;
                    }
                    return;
                }
            }
        }
Пример #6
0
        internal DynamicEntity(Entity entity, bool shouldExecute, object?initialize = null)
        {
            ShouldExecute = shouldExecute;
            Guid          = entity.Parent.GenerateGuid(entity.Name);

            if (entity.Parent.IsUpgraded)
            {
                throw new InvalidOperationException("You cannot use dynamic entity outside of the upgrade script.");
            }

            DynamicEntityType = entity;

            DbTransaction = Transaction.Current;
            if (ShouldExecute)
            {
                RunningTransaction.Register(this);
            }

            foreach (Property item in entity.GetPropertiesOfBaseTypesAndSelf())
            {
                RefactorActionPropertyAdded(item);
            }

            if (initialize == null)
            {
                return;
            }

            Dictionary <string, object?> values = initialize.GetType().GetProperties().ToDictionary(x => x.Name, x => (object?)x.GetValue(initialize, null));

            foreach (KeyValuePair <string, object?> init in values)
            {
                Property?property = DynamicEntityType.Search(init.Key);
                if (property is null)
                {
                    throw new ArgumentException(string.Format("The property '{0}' is not contained within entity '{1}'.", init.Key, entity.Name));
                }


                if (property.PropertyType != PropertyType.Collection)
                {
                    if (!TrySetMember(init.Key, init.Value))
                    {
                        throw new ArgumentException(string.Format("The property '{0}' is not contained within entity '{1}'.", init.Key, entity.Name));
                    }
                }
                else
                {
                    if (init.Value is null)
                    {
                        continue; // or throw that you cannot delete the collection and should call the Clear method instead?
                    }
                    IEnumerable <DynamicEntity>?input = init.Value as IEnumerable <DynamicEntity>;
                    if (input == null)
                    {
                        input = (init.Value as IEnumerable <object>)?.Cast <DynamicEntity>();
                    }
                    if (input == null)
                    {
                        throw new InvalidCastException("should be a collection of DynamicEntity");
                    }

                    object?member;
                    if (!TryGetMember(init.Key, out member))
                    {
                        throw new ArgumentException(string.Format("The property '{0}' is not contained within entity '{1}'.", init.Key, entity.Name));
                    }

                    EntityCollection <DynamicEntity>?collection = member as EntityCollection <DynamicEntity>;
                    if (collection is null)
                    {
                        throw new ArgumentException(string.Format("The property '{0}' is not contained within entity '{1}'.", init.Key, entity.Name));
                    }

                    foreach (DynamicEntity item in input)
                    {
                        if (item.GetEntity() != property.EntityReturnType)
                        {
                            throw new InvalidCastException("Wrong type of object inserted in collection...");
                        }

                        collection.Add(item, false);
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Start the timed scope
        /// </summary>
        public void Start()
        {
            if (IsDisposed)
            {
                ULSLogging.LogTraceTag(0x238174dd /* tag_96xt3 */, Categories.TimingGeneral, Levels.Error,
                                       "Attempting to start scope '{0}' that has already been disposed.", Name);
                return;
            }

            if (IsScopeActive)
            {
                ULSLogging.LogTraceTag(0x238174de /* tag_96xt4 */, Categories.TimingGeneral, Levels.Error,
                                       "Attempting to start scope '{0}' that has already been started.", Name);
                return;
            }

            string metaDataCopy = MetaData;
            string subTypeCopy  = SubType;

            CorrelationData currentCorrelation = CorrelationData;

            TimedScopeData     = currentCorrelation.Clone() ?? new CorrelationData();
            RunningTransaction = TransactionMonitor.RunningTransaction(TimedScopeData);

            if (!string.IsNullOrWhiteSpace(metaDataCopy) && string.IsNullOrWhiteSpace(MetaData))
            {
                MetaData = metaDataCopy;
            }

            if (!string.IsNullOrWhiteSpace(subTypeCopy) && string.IsNullOrWhiteSpace(SubType))
            {
                SubType = subTypeCopy;
            }

            // differentiate scope name when running under a test transaction
            if (IsTransaction)
            {
                NameSuffix = string.Concat(NameSuffix, "::Trx", RunningTransaction.ToString(CultureInfo.InvariantCulture));
            }

            // differentiate special scopes
            if (TimedScopeData.IsFallbackCall)
            {
                NameSuffix = string.Concat(NameSuffix, "::Fallback");
            }

            // differentiate scope name for inner (proxied) calls
            if (TimedScopeData.CallDepth > 0)
            {
                NameSuffix = string.Concat(NameSuffix, "::Depth", TimedScopeData.CallDepth.ToString(CultureInfo.InvariantCulture));

                if (currentCorrelation != null)
                {
                    // reset call depth so any inner scopes are reported as layer 0 again
                    currentCorrelation.CallDepth = 0;
                }
            }

            Parent        = TimedScopeStackManager.Scopes?.Peek();
            IsRoot        = Parent == null && TimedScopeData.CallDepth == 0;
            StartTick     = Stopwatch.GetTimestamp();
            IsScopeActive = true;
            ScopeLogger.LogScopeStart(this);

            PerfDiagnostics = new PerfDiagnostics(Parent != null ? Parent.PerfDiagnostics : null);
            PerfDiagnostics.Start();
        }