Hey I am trying to build this application, but I am having trouble as error messages keep appearing. Using Visual Studio 2008...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Opc;
using OpcCom;
using Opc.Da;
using Opc.Hda;


namespace ConsoleApplication3
{
    class Program
    {
        public static void Main()
        {
            Run();

        }

        public static void Run()
        {
            // Create a new FileSystemWatcher and set its properties.
            FileSystemWatcher watcher = new FileSystemWatcher();
            watcher.Path = @"C:\PCHE App1\Destination\";
                      
            string sourcePath = System.Configuration.ConfigurationSettings.AppSettings["DestDir"];

            string what = System.Configuration.ConfigurationSettings.AppSettings["FileSearch"];

            watcher.Path = sourcePath;

            /* 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;


            // Only watch text files.
            watcher.Filter = what;

            // Add event handlers.
            watcher.Created += new FileSystemEventHandler(OnChanged);

            // 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') ;
        }

        // Define the event handlers.
        private static void OnChanged(object source, FileSystemEventArgs f)
        {
            string where = System.Configuration.ConfigurationSettings.AppSettings["DESTINATION"];
            File.Delete(f.FullPath);
         
            DirectoryInfo dr = new DirectoryInfo(Path.GetDirectoryName(f.FullPath)); 
            FileInfo[] files1 = dr.GetFiles("*.*");

            

            foreach (FileInfo file in files1)                
            {
              try
              {
                using (FileStream fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        using (StreamWriter sw = new StreamWriter(where,true))
                        {
                                            
                                        // Read and display lines from the file until the end of 
                                        // the file is reached.
                                String line;
                                while ((line = sr.ReadLine()) != null)
                                   {    
                                        sw.WriteLine(line);
                                     
                                        }
                                        Console.WriteLine("file: " + file.Name + " FINISHED");  
                         }
                    
                    }
                }

                DataTransfer();
              }
      
              catch (Exception e)
              {
                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine("File: " + f.FullPath + " " + f.ChangeType);
                Console.WriteLine("File: " + f.Name);
                Console.WriteLine("Folder:" + Path.GetDirectoryName(f.FullPath));
                Console.WriteLine(e.Message);
                continue;
              }
             }
           
        }

        private static void DataTransfer()
        {
            Opc.URL url = new URL(ConfigurationManager.AppSettings["serverURL "]);
            Opc.Da.Quality quality = Opc.Da.Quality.Good;


            
                Console.Out.Write("Creating new local DA server instance for {0} ... ", ConfigurationManager.AppSettings["serverURL"]);
                Opc.Da.Server server = new Opc.Da.Server(new OpcCom.Factory(), url);
                Console.Out.WriteLine("OK");

                Console.Out.Write("Connecting to remote server ... ");
                server.Connect();
                Console.Out.WriteLine("OK");

                log.Debug("Values After Execution\n");
                log.Debug(" ");


                  (Console.Out.Write("Creating new item value ... "));


                  Opc.Da.ItemValue val = new Opc.Da.ItemValue("TICA20033_SP");
                            val.Timestamp = DateTime.UtcNow;

                            val.Value = 123;
                            val.Quality = quality;
                            Console.Out.WriteLine("OK");

                            Console.Out.Write("Writing value to remote server ... ");

                            Opc.IdentifiedResult[] result = server.Write(new Opc.Da.ItemValue[] { val });

                            if (result.Length > 0)
                                {
                                Console.Out.WriteLine(result[0].ResultID);
                                }
                            else
                                Console.Out.WriteLine("OK");

                            index++;
        

                    Console.Out.WriteLine("Updated values for well: " + wellName);
                    log.Info("Updated values for well: " + wellName);
                    index = 0;
                //}

                Console.Out.Write("Disconnecting from remote server ... ");
                server.Disconnect();
                Console.Out.WriteLine("OK");

                Console.Out.Write("Disposing of local server instance ... ");
                server.Dispose();
                Console.Out.WriteLine("OK");
            }
    }
 }

The error messages that I get are: the name "configuration manager/log/index/wellname" does not exist in the current context.

Also: "only assignment, call, increment, decrement, and new object expressions can be used as a statement."

I get 3 warning messages, all saying the same thing:

Could not resolve this reference. Could not locate the assembly "Interop.Excel/Interop.VBIDE/log4net". Check to make sure the assembly exists on disk. If this reference is not required by your code, you may get compilation errors."

PLEASE HELP :S

666kennedy commented: descriptive +2

Recommended Answers

All 5 Replies

Please try to use code tags when you post code!
Have you included all the necessary references in your project?
Could you point out the lines in your code where you first encounter a problem or are this compile errors?

Also -- Do you want to include log4net with your application? If you don't know what it is then the answer is probably 'no'. Even if you do know what it is I would still be tempted to say no. :)

I have been told to use this code, and am assuming that I am to use all of it so I do want to include log4net with the application. If there is no way to make it work with log4net, then I am happy to leave it out however!

For the Error message ""only assignment, call, increment, decrement, and new object expressions can be used as a statement." the reason is probably you have used a method as a statement.Recheck the code for it

they are compilation errors. Cheers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.