Esempio n. 1
0
        public int addEntity(XTRMFSEntity newEntity)
        {
            //string[] args = System.Environment.GetCommandLineArgs();
            try
            {
                if (Directory.Exists(newEntity.entityPath))
                {
                    // Set Properties for FileSystemWatcher.
                    FileSystemWatcher watcher = new FileSystemWatcher();
                    watcher.InternalBufferSize = newEntity.entityBufsize;
                    watcher.Path = newEntity.entityPath;

                    /* Watch for changes in LastAccess and LastWrite times, and
                     * the renaming of files or directories. */
                    watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
                    //watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
                    //watcher.NotifyFilter = NotifyFilters.LastWrite;
                    // Only watch text files.
                    watcher.Filter = newEntity.entityPattern;
                    if (newEntity.entityRecurse.Equals(1))
                    {
                        watcher.IncludeSubdirectories = true;
                    }
                    else
                    {
                        watcher.IncludeSubdirectories = false;
                    }

                    // Add event handlers.
                    watcher.Changed += new FileSystemEventHandler(OnChanged);
                    watcher.Created += new FileSystemEventHandler(OnChanged);
                    watcher.Deleted += new FileSystemEventHandler(OnChanged);
                    watcher.Renamed += new RenamedEventHandler(OnRenamed);
                    watcher.Error   += OnError;

                    // Begin watching.
                    watcher.EnableRaisingEvents = true;

                    // Wait for the user to quit the program.
                    //Console.WriteLine("Press \'q\' to quit the sample.");
                    //while (Console.Read() != 'q') ;

                    watchList.Add(watcher);
                }
                else
                {
                    //Error
                    string tempstr = string.Format("Path Not Valid : {0}", newEntity.entityPath);
                    myLog.WriteEntry(tempstr);
                }
            }
            catch (Exception ex)
            {
                string tempstr = string.Format("FileSystemWatcher Exception : {0}", ex.Message);
                myLog.WriteEntry(tempstr);
            }
            return(0);
        }
Esempio n. 2
0
        // From the event, determine the entity to enable creation of XEvent!
        private XTRMFSEntity findEntity(FileSystemEventArgs e)
        {
            XTRMFSEntity matchEntity = null;

            foreach (XTRMFSEntity thisEntity in entities)
            {
                //e.FullPath
                FileInfo myFileInfo = new FileInfo(e.FullPath);
                string   shortName  = myFileInfo.Name;
                string   pathName   = myFileInfo.DirectoryName;
                //if (thisEntity.entityPath.Equals(pathName))
                if ((Directory.Exists(pathName)) && (pathName.Contains(thisEntity.entityPath)))
                {
                    matchEntity = thisEntity;
                }
                else if (thisEntity.entityPath.Equals(pathName))
                {
                    // Check the full path using Visual Basic LikeString() Method.
                    string fullPattern = thisEntity.entityPath + "\\" + thisEntity.entityPattern;
                    if (Operators.LikeString(e.FullPath, fullPattern, CompareMethod.Text))
                    {
                        //Console.WriteLine("This matched!");
                        matchEntity = thisEntity;
                    }
                }
                else
                {
                    if (thisEntity.entityRecurse.Equals(1) && pathName.Contains(thisEntity.entityPath))
                    {
                        // Check ony the file name using Visual Basic LikeString() Method.
                        string fullPattern = thisEntity.entityPath + "\\" + thisEntity.entityPattern;
                        if (Operators.LikeString(e.FullPath, fullPattern, CompareMethod.Text))
                        {
                            //Console.WriteLine("This matched!");
                            matchEntity = thisEntity;
                        }
                    }
                }
            }
            return(matchEntity);
        }
Esempio n. 3
0
        public static XTRMObject consumeXML(string XmlFragment, int lVariant = 0, bool bDeep = false)
        {
            //XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
            //myDictionaryLoader.Augment();
            //
            // Consume XML to create the XComponent object.
            // if bDeep is false, then ONLY do this object.
            // if bDeep is true, then also do recursive objects.
            XmlTextReader    reader     = null;
            XmlParserContext context    = null;
            XTRMFSEntity     thisEntity = null;

            if (lVariant == 1)
            {
                thisEntity = new XTRMFSEntity();
                thisEntity.Initialize(-1);
            }
            else
            {
                thisEntity = new XTRMFSEntity();
            }
            thisEntity.variant = lVariant;

            try
            {
                // Load the reader with the data file and ignore all white space nodes.
                context = new XmlParserContext(null, null, null, XmlSpace.None);
                reader  = new XmlTextReader(XmlFragment, XmlNodeType.Element, context);
                reader.WhitespaceHandling = WhitespaceHandling.None;
                // Parse the file and display each of the nodes.
                bool bResult      = reader.Read();
                int  lElementType = 0;
                XDictionaryLoader           myDictionaryLoader = new XDictionaryLoader();
                Dictionary <String, String> elementAttributes;
                while (bResult)
                {
                    bool bProcessed = false;
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        string elementName = reader.Name;
                        if (!bProcessed)
                        {
                            // May wish to get all the attributes here for new elements!
                            elementAttributes = new Dictionary <String, String>();
                            if (reader.HasAttributes)
                            {
                                reader.MoveToFirstAttribute();
                                for (int i = 0; i < reader.AttributeCount; i++)
                                {
                                    //reader.GetAttribute(i);
                                    elementAttributes.Add(reader.Name, reader.Value);
                                    reader.MoveToNextAttribute();
                                }
                                // Check to see if ID is supplied!
                                //if (elementAttributes["ID"] != null)
                                if (elementAttributes.ContainsKey("Tag"))
                                {
                                    thisEntity.entityTag = elementAttributes["Tag"];
                                }
                                if (elementAttributes.ContainsKey("Source"))
                                {
                                    thisEntity.entitySource = elementAttributes["Source"];
                                }
                                if (elementAttributes.ContainsKey("User"))
                                {
                                    thisEntity.entityUser = elementAttributes["User"];
                                }
                                if (elementAttributes.ContainsKey("EventPath"))
                                {
                                    thisEntity.entityEventPath = elementAttributes["EventPath"];
                                }
                                reader.MoveToElement();
                            }
                            // Need to see if we are interested in this element!
                            //string elementName = reader.Name;
                            switch (elementName.ToUpper())
                            {
                            case "PATH":         // Path
                                lElementType = 1;
                                bResult      = reader.Read();
                                break;

                            case "PATTERN":         // Pattern
                                lElementType = 2;
                                bResult      = reader.Read();
                                break;

                            case "RECURSE":         // Recurse
                                lElementType = 3;
                                bResult      = reader.Read();
                                break;

                            case "BUFSIZE":         // Bufsize
                                lElementType = 4;
                                bResult      = reader.Read();
                                break;

                            case "HOLDTIME":         // HoldTime
                                lElementType = 5;
                                bResult      = reader.Read();
                                break;

                            default:
                                bResult = reader.Read();
                                break;
                            }
                        }
                        break;

                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:
                        //writer.WriteProcessingInstruction(reader.Name, reader.Value);
                        bResult = reader.Read();
                        break;

                    case XmlNodeType.Comment:
                        //writer.WriteComment(reader.Value);
                        bResult = reader.Read();
                        break;

                    case XmlNodeType.EndElement:
                        //writer.WriteFullEndElement();
                        bResult = reader.Read();
                        break;

                    case XmlNodeType.Text:
                        //Console.Write(reader.Value);
                        switch (lElementType)
                        {
                        case 1:             // Path
                            thisEntity.entityPath = reader.Value;
                            break;

                        case 2:             // Pattern
                            thisEntity.entityPattern = reader.Value;
                            break;

                        case 3:             // Recurse
                            thisEntity.entityRecurse = Convert.ToInt16(reader.Value);
                            break;

                        case 4:             // Bufsize
                            thisEntity.entityBufsize = Convert.ToInt16(reader.Value);
                            break;

                        case 5:             // HoldTime
                            thisEntity.entityHoldTime = Convert.ToInt16(reader.Value);
                            break;

                        default:
                            break;
                        }
                        lElementType = 0;
                        bResult      = reader.Read();
                        break;

                    default:
                        bResult = reader.Read();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                exCount_XML++;
                XLogger(2210, -1, string.Format("XML={0}; Message={1}", XmlFragment, ex.Message));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(thisEntity);
        }
Esempio n. 4
0
        public int addEntity(XTRMFSEntity newEntity)
        {
            //string[] args = System.Environment.GetCommandLineArgs();
            try
            {
                if (Directory.Exists(newEntity.entityPath))
                {
                    // Set Properties for FileSystemWatcher.
                    FileSystemWatcher watcher = new FileSystemWatcher();
                    watcher.InternalBufferSize = newEntity.entityBufsize;
                    watcher.Path = newEntity.entityPath;
                    /* Watch for changes in LastAccess and LastWrite times, and
                       the renaming of files or directories. */
                    watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
                    //watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
                    //watcher.NotifyFilter = NotifyFilters.LastWrite;
                    // Only watch text files.
                    watcher.Filter = newEntity.entityPattern;
                    if (newEntity.entityRecurse.Equals(1))
                    {
                        watcher.IncludeSubdirectories = true;
                    }
                    else
                    {
                        watcher.IncludeSubdirectories = false;
                    }

                    // Add event handlers.
                    watcher.Changed += new FileSystemEventHandler(OnChanged);
                    watcher.Created += new FileSystemEventHandler(OnChanged);
                    watcher.Deleted += new FileSystemEventHandler(OnChanged);
                    watcher.Renamed += new RenamedEventHandler(OnRenamed);
                    watcher.Error += OnError;

                    // Begin watching.
                    watcher.EnableRaisingEvents = true;

                    // Wait for the user to quit the program.
                    //Console.WriteLine("Press \'q\' to quit the sample.");
                    //while (Console.Read() != 'q') ;

                    watchList.Add(watcher);
                }
                else
                {
                    //Error
                    string tempstr = string.Format("Path Not Valid : {0}", newEntity.entityPath);
                    myLog.WriteEntry(tempstr);
                }
            }
            catch (Exception ex)
            {
                string tempstr = string.Format("FileSystemWatcher Exception : {0}", ex.Message);
                myLog.WriteEntry(tempstr);
            }
            return 0;
        }
Esempio n. 5
0
        public static XTRMObject consumeXML(string XmlFragment, int lVariant = 0, bool bDeep = false)
        {
            //XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
            //myDictionaryLoader.Augment();
            //
            // Consume XML to create the XComponent object.
            // if bDeep is false, then ONLY do this object.
            // if bDeep is true, then also do recursive objects.
            XmlTextReader reader = null;
            XmlParserContext context = null;
            XTRMFSEntity thisEntity = null;
            if (lVariant == 1)
            {
                thisEntity = new XTRMFSEntity();
                thisEntity.Initialize(-1);
            }
            else
            {
                thisEntity = new XTRMFSEntity();
            }
            thisEntity.variant = lVariant;

            try
            {
                // Load the reader with the data file and ignore all white space nodes.
                context = new XmlParserContext(null, null, null, XmlSpace.None);
                reader = new XmlTextReader(XmlFragment, XmlNodeType.Element, context);
                reader.WhitespaceHandling = WhitespaceHandling.None;
                // Parse the file and display each of the nodes.
                bool bResult = reader.Read();
                int lElementType = 0;
                XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
                Dictionary<String, String> elementAttributes;
                while (bResult)
                {
                    bool bProcessed = false;
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            string elementName = reader.Name;
                            if (!bProcessed)
                            {
                                // May wish to get all the attributes here for new elements!
                                elementAttributes = new Dictionary<String, String>();
                                if (reader.HasAttributes)
                                {
                                    reader.MoveToFirstAttribute();
                                    for (int i = 0; i < reader.AttributeCount; i++)
                                    {
                                        //reader.GetAttribute(i);
                                        elementAttributes.Add(reader.Name, reader.Value);
                                        reader.MoveToNextAttribute();
                                    }
                                    // Check to see if ID is supplied!
                                    //if (elementAttributes["ID"] != null)
                                    if (elementAttributes.ContainsKey("Tag"))
                                    {
                                        thisEntity.entityTag = elementAttributes["Tag"];
                                    }
                                    if (elementAttributes.ContainsKey("Source"))
                                    {
                                        thisEntity.entitySource = elementAttributes["Source"];
                                    }
                                    if (elementAttributes.ContainsKey("User"))
                                    {
                                        thisEntity.entityUser = elementAttributes["User"];
                                    }
                                    if (elementAttributes.ContainsKey("EventPath"))
                                    {
                                        thisEntity.entityEventPath = elementAttributes["EventPath"];
                                    }
                                    reader.MoveToElement();
                                }
                                // Need to see if we are interested in this element!
                                //string elementName = reader.Name;
                                switch (elementName.ToUpper())
                                {
                                    case "PATH": // Path
                                        lElementType = 1;
                                        bResult = reader.Read();
                                        break;
                                    case "PATTERN": // Pattern
                                        lElementType = 2;
                                        bResult = reader.Read();
                                        break;
                                    case "RECURSE": // Recurse
                                        lElementType = 3;
                                        bResult = reader.Read();
                                        break;
                                    case "BUFSIZE": // Bufsize
                                        lElementType = 4;
                                        bResult = reader.Read();
                                        break;
                                    case "HOLDTIME": // HoldTime
                                        lElementType = 5;
                                        bResult = reader.Read();
                                        break;
                                    default:
                                        bResult = reader.Read();
                                        break;
                                }
                            }
                            break;
                        case XmlNodeType.XmlDeclaration:
                        case XmlNodeType.ProcessingInstruction:
                            //writer.WriteProcessingInstruction(reader.Name, reader.Value);
                            bResult = reader.Read();
                            break;
                        case XmlNodeType.Comment:
                            //writer.WriteComment(reader.Value);
                            bResult = reader.Read();
                            break;
                        case XmlNodeType.EndElement:
                            //writer.WriteFullEndElement();
                            bResult = reader.Read();
                            break;
                        case XmlNodeType.Text:
                            //Console.Write(reader.Value);
                            switch (lElementType)
                            {
                                case 1:     // Path
                                    thisEntity.entityPath = reader.Value;
                                    break;
                                case 2:     // Pattern
                                    thisEntity.entityPattern = reader.Value;
                                    break;
                                case 3:     // Recurse
                                    thisEntity.entityRecurse = Convert.ToInt16(reader.Value);
                                    break;
                                case 4:     // Bufsize
                                    thisEntity.entityBufsize = Convert.ToInt16(reader.Value);
                                    break;
                                case 5:     // HoldTime
                                    thisEntity.entityHoldTime = Convert.ToInt16(reader.Value);
                                    break;
                                default:
                                    break;
                            }
                            lElementType = 0;
                            bResult = reader.Read();
                            break;
                        default:
                            bResult = reader.Read();
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                exCount_XML++;
                XLogger(2210, -1, string.Format("XML={0}; Message={1}", XmlFragment, ex.Message));
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }
            return thisEntity;
        }
Esempio n. 6
0
        public int ParseConfig(string configFile, bool bDeep = false)
        {
            //
            // Consume XML to create the XFSEntity objects.
            // if bDeep is false, then ONLY do this object.
            // if bDeep is true, then also do recursive objects.
            XmlTextReader reader = null;

            int                         rc            = -1;
            string                      connectString = XTRMObject.getDictionaryEntry("TaskConnectString");
            string                      outerXML;
            int                         lElementType       = 0;
            XDictionaryLoader           myDictionaryLoader = new XDictionaryLoader();
            Dictionary <String, String> elementAttributes;

            entities.Clear();
            try
            {
                // Load the reader with the data file and ignore all white space nodes.
                reader = new XmlTextReader(configFile);
                reader.WhitespaceHandling = WhitespaceHandling.None;
                // Parse the file and display each of the nodes.
                bool bResult = reader.Read();
                while (bResult)
                {
                    bool bProcessed = false;
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        string elementName = reader.Name;
                        switch (elementName.ToUpper())
                        {
                        case "XFSENTITY":
                            outerXML = reader.ReadOuterXml();
                            XTRMFSEntity thisEntity = (XTRMFSEntity)XTRMFSEntity.consumeXML(outerXML, 1, true);
                            entities.Add(thisEntity);
                            bProcessed = true;
                            break;
                        }
                        if (!bProcessed)
                        {
                            // May wish to get all the  attributes here for new elements!
                            elementAttributes = new Dictionary <String, String>();
                            if (reader.HasAttributes)
                            {
                                reader.MoveToFirstAttribute();
                                for (int i = 0; i < reader.AttributeCount; i++)
                                {
                                    //reader.GetAttribute(i);
                                    elementAttributes.Add(reader.Name, reader.Value);
                                    reader.MoveToNextAttribute();
                                }
                                if (elementAttributes.ContainsKey("Tag"))
                                {
                                    agentTag = elementAttributes["Tag"];
                                }
                                if (elementAttributes.ContainsKey("Source"))
                                {
                                    agentSource = elementAttributes["Source"];
                                }
                                if (elementAttributes.ContainsKey("User"))
                                {
                                    agentUser = elementAttributes["User"];
                                }
                                if (elementAttributes.ContainsKey("EventPath"))
                                {
                                    agentEventPath = elementAttributes["EventPath"];
                                }
                                reader.MoveToElement();
                            }
                            // Need to see if we are interested in this element!
                            //string elementName = reader.Name;
                            switch (elementName.ToUpper())
                            {
                            case "XFILEAGENTCONFIG":
                                // Advance into Elements!
                                reader.MoveToContent();
                                bResult = reader.Read();
                                break;

                            default:
                                bResult = reader.Read();
                                break;
                            }
                        }
                        break;

                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:
                        //writer.WriteProcessingInstruction(reader.Name, reader.Value);
                        bResult = reader.Read();
                        break;

                    case XmlNodeType.Comment:
                        //writer.WriteComment(reader.Value);
                        bResult = reader.Read();
                        break;

                    case XmlNodeType.EndElement:
                        //writer.WriteFullEndElement();
                        bResult = reader.Read();
                        break;

                    case XmlNodeType.Text:
                        //Console.Write(reader.Value);
                        switch (lElementType)
                        {
                        default:
                            break;
                        }
                        bResult = reader.Read();
                        break;

                    default:
                        bResult = reader.Read();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                exCount_XML++;
                XLogger(2400, -1, string.Format("XTRMFileAgent::parseConfig(); ConfigFile={0}; Message={1}", configFile, ex.Message));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }


            return(rc);
        }
Esempio n. 7
0
        public int ProcessEvents()
        {
            int    rc      = 0;
            string tempstr = "";

            try
            {
                _pool.WaitOne();
                // Process Everything in XFileList
                XFileAction thisAction;
                while (ChangesQueue.TryDequeue(out thisAction))
                //foreach (XFileAction thisAction in XFileList)
                {
                    XTRMFSEntity thisEntity = findEntity(thisAction);
                    XTRMEvent    thisEvent  = new XTRMEvent();
                    thisEvent.Initialize(-1);
                    //  <XEvent ID="626">
                    //		<Source>P4V</Source>
                    //		<Action>edit</Action>
                    //		<DateStamp>20120103 19:23:03</DateStamp>
                    //		<User>shlori</User>
                    //		<PIN>A342158B864EE75025C6F08F42C9544A</PIN>
                    //		<Status>0</Status>
                    //		<Path>//depot/main/product/doc/Portable/English/*</Path>
                    //		<Desc>Fixed page/line breaks.</Desc>
                    //		<!-- Parm1 = {Depot File} -->
                    //		<Parm1>//depot/main/product/doc/Portable/English/Basic Analysis and Graphing.pdf</Parm1>
                    //		<!-- Parm2 = {Depot Version} -->
                    //		<Parm2>56</Parm2>
                    //		<!-- Parm3 = {Change List} -->
                    //		<Parm3>83234</Parm3>
                    //		<!-- Parm4 = {File Type} -->
                    //		<Parm4>binary+lm</Parm4>
                    //		<!-- Parm5 = {File Size} -->
                    //		<Parm5>4216714</Parm5>
                    //		<!-- Parm6 = {Client} -->
                    //		<Parm6>shlori-Win</Parm6>
                    //		<!-- Parm7 = {SCM Time} -->
                    //		<Parm7>1325636582</Parm7>
                    //	</XEvent>
                    thisEvent.eventAction = thisAction.ChangeType.ToString();
                    thisEvent.eventDate   = DateTime.Now.ToString();
                    thisEvent.eventState  = -1;
                    thisEvent.eventParm1  = thisAction.FullPath;
                    string thisEventPath = "";
                    if (thisEntity == null)
                    {
                        // Use Defaults.
                        thisEvent.eventTag    = agentTag;
                        thisEvent.eventSource = agentSource;
                        thisEvent.eventUser   = agentUser;
                        //thisEventPath = agentEventPath;
                        thisEvent.meta.eventPath = agentEventPath;
                        thisEvent.meta.holdTime  = 0;
                    }
                    else
                    {
                        // Use this entity, then defaults.
                        if (thisEntity.entityTag.Equals(""))
                        {
                            thisEvent.eventTag = agentTag;
                        }
                        else
                        {
                            thisEvent.eventTag = thisEntity.entityTag;
                        }
                        if (thisEntity.entitySource.Equals(""))
                        {
                            thisEvent.eventSource = agentSource;
                        }
                        else
                        {
                            thisEvent.eventSource = thisEntity.entitySource;
                        }
                        if (thisEntity.entityUser.Equals(""))
                        {
                            thisEvent.eventUser = agentUser;
                        }
                        else
                        {
                            thisEvent.eventUser = thisEntity.entityUser;
                        }
                        if (thisEntity.entityTag.Equals(""))
                        {
                            thisEvent.eventTag = agentTag;
                        }
                        else
                        {
                            thisEvent.eventTag = thisEntity.entityTag;
                        }
                        if (thisEntity.entityEventPath.Equals(""))
                        {
                            //thisEventPath = agentEventPath;
                            thisEvent.meta.eventPath = agentEventPath;
                        }
                        else
                        {
                            //thisEventPath = thisEntity.entityEventPath;
                            thisEvent.meta.eventPath = thisEntity.entityEventPath;
                        }
                        if (thisEntity.entityHoldTime.Equals(""))
                        {
                            thisEvent.meta.holdTime = 0;
                        }
                        else
                        {
                            thisEvent.meta.holdTime = thisEntity.entityHoldTime;
                        }
                    }

                    //thisEvent.eventDate = DateTime.Now.ToString();
                    thisEvent.eventDate = thisAction.actionTime.ToString();

                    // Add Event to Dictionaries (by time and by path::action).
                    thisEvent.eventPath = thisEventPath;
                    string eventKey = string.Format("{0}::{1}", thisEvent.eventParm1, thisEvent.eventAction);
                    // Are we holding this event already?
                    if (eventOrder.ContainsKey(eventKey).Equals(false))
                    {
                        //eventInventory.Add(eventKey);
                        //eventOrder.Add(DateTime.Now, thisEvent);
                        eventOrder.Add(eventKey, thisEvent);
                    }
                }
                //XFileList.Clear();
            }
            catch (Exception ex)
            {
                tempstr = string.Format("FileSystemWatcher Exception : {0}", ex.Message);
                myLog.WriteEntry(tempstr);
            }
            finally
            {
                _pool.Release();
            }
            return(rc);
        }