Пример #1
0
        static void MainSafe(string[] Args)
        {
            Console.Write("Finding USB fan device ... ");

            int Dev = USB.OpenUSBDevice(3141, 29024);

            if (Dev == -1)
            {
                Console.WriteLine("FAIL");
                Console.ReadLine();
                return;
            }
            else
            {
                Console.WriteLine("OK");
            }

            string[] DataLines = File.ReadAllLines("fage.txt");

            foreach (var DataLine in DataLines)
            {
                byte[] DataArray = DataLine.Split(';').Where((In) => !string.IsNullOrWhiteSpace(In)).Select((In) => byte.Parse(In)).ToArray();

                fixed(byte *DataArrayPtr = DataArray)
                {
                    USB.WriteUSB(Dev, (IntPtr)DataArrayPtr, DataArray.Length, out int Written);
                    USB.ReadUSB(Dev, (IntPtr)DataArrayPtr, 3, out int Read);
                }
            }

            USB.CloseUSBDevice(Dev);
            Console.WriteLine("Done!");
            Console.ReadLine();
        }
        public GccMakefileParser(String MakeFile)
        {
            FileInfo fIfoMakeFile = new FileInfo(MakeFile);

            Root         = fIfoMakeFile.Directory;
            Vars         = new SortedList <string, string>();
            SourceFiles  = new SortedList <string, FileInfo>();
            IncludePaths = new SortedList <string, DirectoryInfo>();
            LibraryFiles = new SortedList <string, FileInfo>();
            Defines      = new List <string>();

            String[] DataLines = File.ReadAllLines(MakeFile);

            //
            // Process all data-lines
            //
            foreach (String DataLine in DataLines)
            {
                // split makefile lines by spaces => results in words
                String[] DataItems = DataLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (DataItems.Length > 0)
                {
                    //
                    // sometimes +=: does not have spaces, so if first word contains +=: which should be in DataItems[1]
                    // replace +=: with " += : " and split again
                    //
                    if (DataItems[0].Contains("+=:"))
                    {
                        String DataLineTmp = DataLine.Replace(DataItems[0], DataItems[0].Replace("+=:", " += :"));
                        DataItems = DataLineTmp.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    }
                    //
                    // sometimes += does not have spaces, so if first word contains += which should be in DataItems[1]
                    // replace += with " += " and split again
                    //
                    if (DataItems[0].Contains("+="))
                    {
                        String DataLineTmp = DataLine.Replace(DataItems[0], DataItems[0].Replace("+=", " += "));
                        DataItems = DataLineTmp.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    }

                    //
                    // sometimes = does not have spaces, so if first word contains = which should be in DataItems[1]
                    // replace = with " = " and split again
                    //
                    else if (DataItems[0].Contains("="))
                    {
                        String DataLineTmp = DataLine.Replace(DataItems[0], DataItems[0].Replace("=", " = "));
                        DataItems = DataLineTmp.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    }
                }
                if (DataItems.Length > 2)
                {
                    //
                    // check second word is "=" which starts a new variable
                    //
                    if (DataItems[1].Equals("="))
                    {
                        if (Vars.ContainsKey(DataItems[0]))
                        {
                            Vars.Remove(DataItems[0]);
                        }
                        String Val = DataLine.Substring(DataLine.IndexOf('=') + 1);
                        Vars.Add(DataItems[0], Val.TrimStart());
                    }

                    //
                    // check second word is "+=" which appends a variable
                    //
                    else if (DataItems[1].Equals("+="))
                    {
                        if (!Vars.ContainsKey(DataItems[0]))
                        {
                            Vars.Add(DataItems[0], "");
                        }
                        String Val = DataLine.Substring(DataLine.IndexOf('=') + 1);
                        Vars[DataItems[0]] += " " + Val.TrimStart();
                    }
                }
            }

            //
            // Search for source files in the specified VPATH variable
            //
            String[] VPATH = Vars["VPATH"].Replace(":", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            String[] SRC   = Vars["SRC"].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (String SourceFile in SRC)
            {
                foreach (String SearchDir in VPATH)
                {
                    String absSearchDir = Path.Combine(Root.FullName, SearchDir.Replace("/", "\\"));
                    absSearchDir = Path.GetFullPath((new Uri(absSearchDir)).LocalPath);
                    String checkFilePath = Path.Combine(absSearchDir, SourceFile);
                    if (File.Exists(checkFilePath))
                    {
                        SourceFiles.Add(SourceFile, new FileInfo(checkFilePath));
                        break;
                    }
                }
            }

            //
            // Process include paths
            //
            String[] INCLUDES = Vars["INCLUDES"].Split(new String[] { "-I" }, StringSplitOptions.RemoveEmptyEntries);
            Vars.Add("INCLUDESSTRING", "");
            foreach (String Include in INCLUDES)
            {
                String IncludePath = Path.Combine(Root.FullName, Include.TrimStart().Replace("/", "\\"));
                IncludePath = Path.GetFullPath((new Uri(IncludePath)).LocalPath);
                IncludePaths.Add(Include.TrimStart(), new DirectoryInfo(IncludePath));
                Vars["INCLUDESSTRING"] += Include.Trim() + ";";
            }

            //
            // Process libraries
            //
            if (Vars.ContainsKey("LIBS"))
            {
                String[] LIBS = Vars["LIBS"].Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                Vars.Add("LIBSSTRING", "");
                foreach (String Lib in LIBS)
                {
                    String LibPath = Path.Combine(Root.FullName, Lib.TrimStart().Replace("/", "\\"));
                    LibPath             = Path.GetFullPath((new Uri(LibPath)).LocalPath);
                    Vars["LIBSSTRING"] += Lib.Trim() + ";";
                    LibraryFiles.Add(Lib, new FileInfo(LibPath));
                }
            }

            //
            // Generate defines string
            //
            String[] DEFINES = Vars["DEFINES"].Split(new String[] { "-D" }, StringSplitOptions.RemoveEmptyEntries);
            Vars.Add("DEFINESSTRING", "");
            foreach (String Define in DEFINES)
            {
                if (!String.IsNullOrEmpty(Define.Trim()))
                {
                    Defines.Add(ReplaceVars(Define.Trim()));
                    String DefineVar = ReplaceVars(Define.Trim());
                    if (DefineVar.Contains("="))
                    {
                        Vars["DEFINESSTRING"] += DefineVar + ";";
                    }
                    else
                    {
                        Vars["DEFINESSTRING"] += DefineVar + "=1;";
                    }
                }
            }

            Vars.Add("CFLAGSSTRING", ReplaceVars(Vars["CFLAGS"]));
        }
Пример #3
0
        private void OnChanged(object sender, FileSystemEventArgs e)
        {
            //FileSystemWatcher.EnableRaisingEvents = false;

            foreach (string FullPath in System.IO.Directory.GetFiles(Path.GetDirectoryName(e.FullPath)))
            {
                try
                {
                    while (!IsFileReady(System.IO.Directory.GetFiles(Path.GetDirectoryName(e.FullPath)).ToList()))
                    {
                        Thread.Sleep(2000);
                    }

                    DateTime FileNameDateTime      = new DateTime();
                    DateTime FileExtensionDateTime = new DateTime();
                    DateTime ActualDateTime        = new DateTime();

                    Console.WriteLine("Checking File name and extensions...");
                    try
                    {
                        if (FileType.Settings.UseFileName && !FileType.Settings.UseFileExtension)
                        {
                            ActualDateTime = DateTime.ParseExact(Path.GetFileNameWithoutExtension(FullPath).Replace(FileType.Settings.TextToIgnoreFileName, ""), FileType.Settings.DateTimeFormatFileName, CultureInfo.InvariantCulture);
                        }
                        if (FileType.Settings.UseFileExtension && !FileType.Settings.UseFileName)
                        {
                            ActualDateTime = DateTime.ParseExact(Path.GetExtension(FullPath).Replace(FileType.Settings.TextToIgnoreFileName, ""), FileType.Settings.DateTimeFormatFileExtension, CultureInfo.InvariantCulture);
                        }
                        if (FileType.Settings.UseFileName && FileType.Settings.UseFileExtension)
                        {
                            FileNameDateTime      = DateTime.ParseExact(Path.GetFileNameWithoutExtension(FullPath).Replace(FileType.Settings.TextToIgnoreFileName, ""), FileType.Settings.DateTimeFormatFileName, CultureInfo.InvariantCulture);
                            FileExtensionDateTime = DateTime.ParseExact(Path.GetExtension(FullPath).Replace(FileType.Settings.TextToIgnoreFileName, ""), FileType.Settings.DateTimeFormatFileExtension, CultureInfo.InvariantCulture);
                            ActualDateTime        = new DateTime(FileNameDateTime.Year, FileNameDateTime.Month, FileNameDateTime.Day, FileExtensionDateTime.Hour, FileExtensionDateTime.Minute, FileExtensionDateTime.Second);
                        }
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine("Failed to get a DateTime from file. " + exception.Message);

                        if (eventLog != null)
                        {
                            eventLog.WriteEntry("Failed to get a DateTime from file. " + exception.Message, EventLogEntryType.Error);
                        }
                    }

                    if (FileType.Settings.TruncateTable)
                    {
                        try
                        {
                            DataDAO dataDAO = new DataDAO(CollectionDatabase);
                            dataDAO.TruncateTable(FileType.DatabaseStoredProcedureName);
                            eventLog.WriteEntry("Successfully truncated table " + FileType.DatabaseStoredProcedureName + ".", EventLogEntryType.Information);
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine("Failed to truncate table " + FileType.DatabaseStoredProcedureName + ". " + exception.Message);

                            if (eventLog != null)
                            {
                                eventLog.WriteEntry("Failed to truncate table " + FileType.DatabaseStoredProcedureName + ". " + exception.Message, EventLogEntryType.Error);
                            }
                        }
                    }

                    string[] AllRowsInFile = File.ReadAllLines(FullPath);

                    if (AllRowsInFile.Count() > 0)
                    {
                        string[] DataRows = AllRowsInFile.Skip(FileType.Headers.Count).ToArray();

                        foreach (string DataLine in DataRows)
                        {
                            int index = 0;

                            string[] Data = DataLine.Split(FileType.CharacterDelimiter);

                            foreach (Column column in FileType.Columns.OrderBy(x => x.ColumnNumber))
                            {
                                try
                                {
                                    if (!column.Ignore)
                                    {
                                        if (FileType.Settings.LinkDateTime && FileType.Settings.DateTimeColumn == column.ColumnName)
                                        {
                                            DateTime linkedDate = DateTime.ParseExact(Data[index], FileType.Settings.DateTimeFormatLinkDate, CultureInfo.InvariantCulture);

                                            if (linkedDate != null)
                                            {
                                                column.ColumnData = linkedDate;
                                            }

                                            //column.ColumnData = ActualDateTime;
                                        }
                                        else
                                        {
                                            column.ColumnData = Data[index];
                                        }
                                        if (!column.NotInFile)
                                        {
                                            index++;
                                        }
                                    }
                                    else //Added
                                    {
                                        index++;
                                    }
                                }
                                catch (Exception exception)
                                {
                                    Console.WriteLine("Failed to process row: " + DataLine + " - " + exception.Message);

                                    if (eventLog != null)
                                    {
                                        eventLog.WriteEntry("Failed to process row: LinkDate Format: " + FileType.Settings.DateTimeFormatLinkDate + ": " + DataLine + " - " + exception.Message, EventLogEntryType.Error);
                                    }
                                }
                            }

                            if (CollectionDatabase != null)
                            {
                                try
                                {
                                    DataDAO dataDAO   = new DataDAO(CollectionDatabase);
                                    string  debugData = "";

                                    /*
                                     * foreach(Column column in FileType.Columns)
                                     * {
                                     *  debugData += column.ColumnNumber + ":" + column.ColumnName + ":" + column.DatabaseColumnName + ":" + column.ColumnData + "\n";
                                     * }
                                     */
                                    //eventLog.WriteEntry("Attempting data: " + debugData, EventLogEntryType.Warning);

                                    dataDAO.Insert(FileType.DatabaseStoredProcedureName, FileType.Columns);
                                }
                                catch (Exception exception)
                                {
                                    Console.WriteLine("Failed to insert row: " + DataLine + " - " + exception.Message);

                                    if (eventLog != null)
                                    {
                                        eventLog.WriteEntry("Failed to insert row: " + DataLine + " - " + exception.Message, EventLogEntryType.Error);
                                    }
                                }
                            }
                        }
                    }

                    Console.WriteLine("Successfuly processed file: " + FullPath + "!");

                    if (eventLog != null)
                    {
                        eventLog.WriteEntry("Successfuly processed file: " + FullPath + "!", EventLogEntryType.Information);
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine("Failed to prcoess file: " + FullPath + ". " + exception.Message);

                    if (eventLog != null)
                    {
                        eventLog.WriteEntry("Failed to prcoess file: " + FullPath + ". " + exception.Message, EventLogEntryType.Error);
                    }
                }

                try
                {
                    if (File.Exists(Path.GetDirectoryName(FullPath) + @"\Processed\" + Path.GetFileName(FullPath)))
                    {
                        File.Delete(Path.GetDirectoryName(FullPath) + @"\Processed\" + Path.GetFileName(FullPath));
                        File.Move(FullPath, Path.GetDirectoryName(FullPath) + @"\Processed\" + Path.GetFileName(FullPath));
                    }
                    else
                    {
                        File.Move(FullPath, Path.GetDirectoryName(FullPath) + @"\Processed\" + Path.GetFileName(FullPath));
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine("Failed to move file to Processed folder: " + FullPath + ". " + exception.Message);

                    if (eventLog != null)
                    {
                        eventLog.WriteEntry("Failed to move file to Processed folder: " + FullPath + ". " + exception.Message, EventLogEntryType.Error);
                    }
                }
            }

            //FileSystemWatcher.EnableRaisingEvents = true;
        }