Archive for Luglio 30th, 2008

check for html tags regular expression

CodeKeep C# Feed Luglio 30th, 2008

Description: checks a string for any text that looks to be an html tags.

Link: http://www.codekeep.net/snippets/d4fdda36-75f0-47f6-904c-66b969d4f3ed.aspx

</?(\w+)(?:[^">]|\"[^"]*")*>

Stop Watch

CodeKeep C# Feed Luglio 30th, 2008

Description: use this to find out how long it take to execute a line(s) of code

Link: http://www.codekeep.net/snippets/f07e36d8-6d3e-4869-ab8c-96dae6ee8ebb.aspx

System.Diagnostics.Stopwatch sp = new System.Diagnostics.Stopwatch();
sp.Start();
sp.Stop();
sp.Elapsed.ToString();

POUAnalyser

CodeKeep C# Feed Luglio 30th, 2008

Description: Temporary nested classes of HSCPTOVariableRules.cs

Link: http://www.codekeep.net/snippets/3c5b7817-5f93-40a8-b095-998c2c9e5631.aspx

#region Nested Class

        internal class POUAnalyser
        {
            #region Private Members

            private POUs _activePOUs;

            #endregion

            #region Contructors / Desctructors

            public POUAnalyser(IBuildAnalyserRule analyser)
            {
                
            }

            #endregion


        }

        internal class POUs: CollectionBase, IList, ICollection, IEnumerable
        {
            #region Contructors / Desctructors

            public POUs()
            {

            }

            #endregion

            #region Public Methods



            #endregion

            #region Private Methods

            /// <summary>
            /// Returns the list of the active POUs which are configured in the task configuration.
            /// </summary>
            /// <param name="analyser"></param>
            /// <returns></returns>
            private List<IPouObject> GetActivePOUs(IBuildMessageLogger analyser)
            {
                List<IPouObject> activePOUs = new List<IPouObject>();

                // get the application meta object passed in the arguments
                IMetaObject appMetaObj = SystemInstances.ObjectMgr.GetObjectToRead(analyser.ProjectHandle, analyser.Application);

                foreach (Guid subGuid in appMetaObj.SubObjectGuids)
                {
                    // Search in all the child objects, the application object
                    IMetaObject childMetaObj = SystemInstances.ObjectMgr.GetObjectToRead(analyser.ProjectHandle, subGuid);
                    //get the "Embedded Functions" object
                    //if (childMetaObj.Object.GetType().ToString().Equals("_3S.CoDeSys.TaskConfigObject.TaskConfigObject"))
                    if (childMetaObj.Object is ITaskConfigObject)
                    {
                        ITaskConfigObject taskConfig = childMetaObj.Object as ITaskConfigObject;
                        foreach (ITaskObject task in taskConfig.Tasks)
                        {
                            foreach (IPouObject pou in task.POUs)
                            {
                                activePOUs.Add(pou);
                            }
                        }
                    }
                }
                return activePOUs;
            }
            /// <summary>
            /// Returns the list of all the POUs which are stored in the project.
            /// </summary>
            /// <param name="analyser"></param>
            private Dictionary<string, IPOUObject> GetAllPOUs(IBuildMessageLogger analyser)
            {
                Dictionary<string, IPOUObject> POUs = new Dictionary<string, IPOUObject>();

                foreach (Guid guid in SystemInstances.ObjectMgr.GetAllObjects(analyser.ProjectHandle))
                {
                    IMetaObject metaObject = SystemInstances.ObjectMgr.GetObjectToRead(analyser.ProjectHandle, guid);
                    if (metaObject.Object is IPOUObject)
                    {
                        IPOUObject pouObj = metaObject.Object as IPOUObject;
                        POUs.Add(pouObj.MetaObject.Name, pouObj);
                    }
                }
                return POUs;
            }

            #endregion
        }

        #endregion