Esempio n. 1
0
        public Program()
        {
            // Fields are handled by S3010
            privateField = this;
            publicField  = this;

            StaticMethod(null);
            StaticMethod(this);
            StaticMethod(((this)));
            StaticProperty = this;
            StaticProperty = ((this));

            Other.StaticMethod(this);    // Noncompliant
            Other.StaticList.Add(this);  // Noncompliant
            Other.StaticProperty = this; // Noncompliant
            ProgramsStatic.Add(this);    // Noncompliant
            InstanceList.Add(this);      // Noncompliant
            this.InstanceList.Add(this); // Noncompliant
            InstanceProperty = this;
            InstanceMethod(this);
            this.InstanceMethod(this);
            Renamed(this);                      // Compliant, False Negative

            new Program().InstanceMethod(this); // Noncompliant
        }
Esempio n. 2
0
        /// <summary>
        /// Loads instance source from a dictionary object (provided by JSON)
        /// </summary>
        /// <param name="obj">Key/value dictionary with <c>instances</c> and other optional elements</param>
        /// <exception cref="eduJSON.InvalidParameterTypeException"><paramref name="obj"/> type is not <c>Dictionary&lt;string, object&gt;</c></exception>
        public virtual void Load(object obj)
        {
            if (obj is Dictionary <string, object> obj2)
            {
                InstanceList.Clear();

                // Parse all instances listed. Don't do it in parallel to preserve the sort order.
                foreach (var el in eduJSON.Parser.GetValue <List <object> >(obj2, "instances"))
                {
                    var instance = new Instance();
                    instance.Load(el);
                    InstanceList.Add(instance);
                }

                // Parse sequence.
                Sequence = (uint)eduJSON.Parser.GetValue <int>(obj2, "seq");

                // Parse signed date.
                SignedAt = eduJSON.Parser.GetValue(obj2, "signed_at", out string signed_at) && DateTime.TryParse(signed_at, out var signed_at_date) ? signed_at_date : (DateTime?)null;
            }
            else
            {
                throw new eduJSON.InvalidParameterTypeException(nameof(obj), typeof(Dictionary <string, object>), obj.GetType());
            }
        }
Esempio n. 3
0
 public void LoadInstances()
 {
     InstanceList.Clear();
     foreach (Instance inst in Instance.LoadInstances(AppSettings.Main.InstanceDir))
     {
         InstanceList.Add(inst);
     }
 }
Esempio n. 4
0
 public void Method()
 {
     StaticMethod(this);
     StaticMethod(((this)));
     Other.StaticMethod(this);
     Other.StaticList.Add(this);
     ProgramsStatic.Add(this);
     InstanceList.Add(this);
     InstanceMethod(this);
 }
Esempio n. 5
0
        public void RegisterComponentType <TInst>(DrawComponentsFunc <TInst> drawFunc)
            where TInst : struct, IInstance, IEquatable <TInst>
        {
            // FIXME: Better error
            if (ComponentsDict.ContainsKey(typeof(TInst)))
            {
                throw new Exception($"Instance type already registered! (type: {typeof(TInst)})");
            }

            InstanceList list = InstanceList.Create <TInst>(16);

            ComponentsDict.Add(typeof(TInst), list);
            DrawFuncs.Add((cr, comps) => drawFunc(cr, comps.GetInstances <TInst>()));
            AddFuncDict.Add(typeof(TInst), (list, inst) => list.Add((TInst)inst));
            RemoveFuncDict.Add(typeof(TInst), (list, inst) => list.Remove((TInst)inst));
        }
Esempio n. 6
0
        public async Task InitScanServerAsync()
        {
            var targets = await store.GetTargetListAsync();

            foreach (var ext in TerminalClient.Instance.ChannelList)
            {
                try
                {
                    //PLC实例下所有节点
                    var nodes = (from u in targets
                                 where u.PlcId == ext.Id
                                 select new TargetNode(u.Address, u.Name, u.Id, u.Interval, u.IsStoreTarget)
                    {
                        DataType = (PLC.Drive.S7.NetCore.DataType)u.DataType,
                        OpcNodeType = u.OpcNodeType,
                        VarType = (VarType)u.VarType,
                        DB = u.DB,
                        StartByteAdr = u.StartByteAdr,
                        BitAdr = (byte)u.BitAdr,
                        Count = u.Count
                    }).ToList();

                    foreach (var node in nodes)
                    {
                        ext.Nodes.Add(node.Key, node);
                    }

                    //逻辑分组
                    LogicGroup logic = new LogicGroup(ext.Name);
                    logic.IntervalList = (from u in nodes select u.Interval).Distinct().ToList();

                    foreach (var inter in logic.IntervalList)
                    {
                        var keys = (from u in nodes where u.Interval == inter select u.Key).ToList();
                        logic.TargetNodeIdList.Add(inter, keys);

                        ScanInstance instance = new ScanInstance(ext, logic, inter, store);
                        InstanceList.Add(instance);
                    }
                    ext.LogicGroups.Add(logic);
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.Error("InitScanServerAsync:" + ex.Message);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Loads instance source from a dictionary object (provided by JSON)
        /// </summary>
        /// <param name="obj">Key/value dictionary with <c>instances</c> and other optional elements</param>
        /// <exception cref="eduJSON.InvalidParameterTypeException"><paramref name="obj"/> type is not <c>Dictionary&lt;string, object&gt;</c></exception>
        public virtual void Load(object obj)
        {
            if (!(obj is Dictionary <string, object> obj2))
            {
                throw new eduJSON.InvalidParameterTypeException(nameof(obj), typeof(Dictionary <string, object>), obj.GetType());
            }

            InstanceList.Clear();

            // Parse all instances listed. Don't do it in parallel to preserve the sort order.
            foreach (var el in eduJSON.Parser.GetValue <List <object> >(obj2, "instances"))
            {
                var instance = new Instance();
                instance.Load(el);
                InstanceList.Add(instance);
            }
        }
Esempio n. 8
0
        public virtual T GetInstance()
        {
            CheckInstanceAvailable();
            T instance;

            if (deactiveInstanceList.Count >= 1)
            {
                instance = deactiveInstanceList[0];
                deactiveInstanceList.Remove(instance);
                ActiveInstanceList.Add(instance);
                instance.gameObject.SetActive(true);
                return(instance);
            }

            //足りない場合は生成する
            instance = Instantiate(GetOriginal, transform);
            InstanceList.Add(instance);
            ActiveInstanceList.Add(instance);
            instance.gameObject.SetActive(true);
            return(instance);
        }
Esempio n. 9
0
        /// <summary>
        ///     Creates a new NLog configuration.
        /// </summary>
        /// <param name="applicationName">
        ///     Name of the application.
        /// </param>
        /// <param name="companyName">
        ///     Name of the company.
        /// </param>
        /// <param name="logFilesFolder">
        ///     Folder name where o store log files.
        /// </param>
        /// <returns>
        ///     A SettingsHelper.
        /// </returns>
        public static SettingsHelper NewConfiguration(
            string applicationName,
            string companyName,
            string logFilesFolder = "logs")
        {
            if (settingsHelperLogger != null)
            {
                settingsHelperLogger.Debug("Entered static method.");
                settingsHelperLogger.Trace("applicationName: {0}", applicationName);
                settingsHelperLogger.Trace("companyName:     {0}", companyName);
                settingsHelperLogger.Trace("logFilesFolder:  {0}", logFilesFolder);
            }

            var nLogConfiguration = new SettingsHelper
            {
                ApplicationName = applicationName,
                CompanyName     = companyName,
                LogFilesFolder  = logFilesFolder
            };

            InstanceList.Add(applicationName, nLogConfiguration);
            return(nLogConfiguration);
        }