Avatar billede frostholm Praktikant
11. februar 2004 - 13:40 Der er 1 kommentar og
1 løsning

kan ikke starte min serivce på serveren

Hejsa Jeg har kodet en service i c#, som jeg har afviklet lokalt på både en windows 2000 og windows xp maskine uden problemer.

Så snart jeg flytter den til vores windows 2k server, og installerer den der, vil serveren ikke starte. Windows giver følgende fejl :

The FTP2MQ service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion. 

ID: 7000

Jeg har læst en masse på nettet, men intet er forståeligt for mig, håber der er en der kan hjælpe mig med dett problem.

Hilsen
Michael
Avatar billede frostholm Praktikant
11. februar 2004 - 13:41 #1
vedlægger lige min kode :

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.IO;
using NORDDATA;


namespace Windowsfilelistener_service
{
    public class filelistener_service : System.ServiceProcess.ServiceBase
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;
        private System.IO.FileSystemWatcher fileSystemWatcher1;
        public NORDDATA.logClass LogObj;
        public NORDDATA.mqClass mqObj;
        private System.Diagnostics.EventLog eventLog1;
        private string fejltekst;
        private string ftpcpy_dir;
        private string logfil;
        private string logfil_dir;
        private string logdato;
        private string logtid;
        private string logmedie;
        private string logfilinterval;
        private string mqmanagername;
        private string mqquename;
        private string mqquetype;
        private string fillogging;
        private string eventlogging;


        public filelistener_service()
        {
            // This call is required by the Windows.Forms Component Designer.
            InitializeComponent();

            // TODO: Add any initialization after the InitComponent call
        }

        // The main entry point for the process
        static void Main()
        {
            System.ServiceProcess.ServiceBase[] ServicesToRun;
   
            // More than one user Service may run within the same process. To add
            // another service to this process, change the following line to
            // create a second service object. For example,
            //
            //  ServicesToRun = new System.ServiceProcess.ServiceBase[] {new filelistener_service(), new MySecondUserService()};
            //
            ServicesToRun = new System.ServiceProcess.ServiceBase[] { new filelistener_service() };

            System.ServiceProcess.ServiceBase.Run(ServicesToRun);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
            this.fileSystemWatcher1 = new System.IO.FileSystemWatcher();
            this.eventLog1 = new System.Diagnostics.EventLog();
            ((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcher1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
            //
            // fileSystemWatcher1
            //
            this.fileSystemWatcher1.EnableRaisingEvents = true;
            this.fileSystemWatcher1.Filter = ((string)(configurationAppSettings.GetValue("fileSystemWatcher1.Filter", typeof(string))));
            this.fileSystemWatcher1.Path = ((string)(configurationAppSettings.GetValue("fileSystemWatcher1.Path", typeof(string))));
            this.fileSystemWatcher1.Created += new System.IO.FileSystemEventHandler(this.fileSystemWatcher1_Created);
            //
            // eventLog1
            //
            this.eventLog1.Log = ((string)(configurationAppSettings.GetValue("eventLog1.Log", typeof(string))));
            this.eventLog1.Source = ((string)(configurationAppSettings.GetValue("eventLog1.Source", typeof(string))));
            ((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcher1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();
            // egne
            this.ftpcpy_dir = ((string)(configurationAppSettings.GetValue("backupdir", typeof(string))));
            this.logfil = ((string)(configurationAppSettings.GetValue("logfil", typeof(string))));
            this.logfil_dir = ((string)(configurationAppSettings.GetValue("logfildir", typeof(string))));
            this.logdato = ((string)(configurationAppSettings.GetValue("logdato", typeof(string))));
            this.logtid = ((string)(configurationAppSettings.GetValue("logtid", typeof(string))));
            this.logmedie = ((string)(configurationAppSettings.GetValue("logmedie", typeof(string))));
            this.logfilinterval = ((string)(configurationAppSettings.GetValue("logfilinterval", typeof(string))));
            this.mqmanagername = ((string)(configurationAppSettings.GetValue("mqmanagername", typeof(string))));
            this.mqquename = ((string)(configurationAppSettings.GetValue("mqquename", typeof(string))));
            this.mqquetype = ((string)(configurationAppSettings.GetValue("mqquetype", typeof(string))));
            this.fillogging = ((string)(configurationAppSettings.GetValue("fillogging", typeof(string))));
            this.eventlogging = ((string)(configurationAppSettings.GetValue("eventlogging", typeof(string))));
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        /// <summary>
        /// Set things in motion so your service can do its work.
        /// </summary>
        protected override void OnStart(string[] args)
        {
            //initialisering af log objektet

            if (this.fillogging=="yes")
            {

                LogObj = new logClass();
           
                //skal datoen angives ved logning
                LogObj.Logdato = (this.logdato == "yes");
           
                //skal tiden angives ved logning
                LogObj.Logtid  = (this.logtid == "yes");
               
                //logobjektet sættes til at logge i en fil
                if (this.logmedie=="fil")
                {
                    LogObj.logfildir = this.logfil_dir;
                    LogObj.Filnavn  = this.logfil;
                };
           
                this.loggit("Logfil initialiseret",0,1);
            }

            this.loggit("Listener service kører",0,2);

        }

        /// <summary>
        /// Stop this service.
        /// </summary>
        protected override void OnStop()
        {
            // TODO: Add code here to perform any tear-down necessary to stop your service.
            this.loggit("Listener service stoppet",0,3);
        }

        private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
        {
            this.loggit("Indkommen fil : " + e.FullPath,0,4);

            //start af mq objektet
            mqObj = new mqClass();
            mqObj.managername = this.mqmanagername;
            mqObj.quename    = this.mqquename;
            mqObj.quetype    = this.mqquetype;
           
       
            //    mqObj.start(ref fejltekst);
            //    mqObj.sendbesked("service besked",ref fejltekst);
           
            if(!mqObj.start(ref fejltekst))
            {
                this.loggit("Mq initialisering fejlet",1,5);
            }
            else
            {
                this.loggit("Mq initialiseret",0,6);
            };

           
           
            bool ok = false;

            while (!ok)
            {
               
                try
                {
                    using (FileStream fs = File.Open(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.None));
                    ok = true;
                }
                catch
                {
                    ok = false;
                }
            }
           

            behand_fil(e.Name,e.FullPath);

            kontrol_check(10);
           
        }

        private void loggit(string logtext,int fejltype, int myID)
        {
           
        /*   
            LogObj.doLog(this.fillogging);
            LogObj.doLog(this.eventlogging);
            LogObj.doLog(this.logdato);
            LogObj.doLog(this.logtid);
        */


            if (this.fillogging=="yes")
                LogObj.doLog(logtext);

            if (this.eventlogging=="yes")
                if (fejltype == 0) // 0 = normal event
                    eventLog1.WriteEntry(logtext,EventLogEntryType.Information, myID);
                if (fejltype == 1) // 1 = error event
                    eventLog1.WriteEntry(logtext,EventLogEntryType.Error, myID);
           

        }

        private void behand_fil(string filnavn, string fuldfilnavn)
        {
            using (StreamReader file1 = File.OpenText(fuldfilnavn))
            {
                try
                {
                    // mqObj.sendbesked("test",ref fejltekst);
                    if(!mqObj.sendbesked(file1.ReadToEnd(),ref fejltekst))
                    {
                        this.loggit(fejltekst,1,7);
                    }

                    this.loggit("Beksed sendt til MQ",0,8);

                }
                catch (Exception g)
                {
                    this.loggit(g.Message,1,9);
                }
            }

            try
            {
                string tofile = ftpcpy_dir + filnavn + "_" + get_filestamp();
                FileInfo fil = new FileInfo(fuldfilnavn);
                fil.MoveTo(tofile);

                this.loggit(fuldfilnavn + " moved to backup dir",0,10);
            }
            catch(Exception f)
            {
                this.loggit(f.Message,1,11);
            }
        }

        private void kontrol_check(int interval_sek)
        {
            try
            {
                DirectoryInfo di = new DirectoryInfo(fileSystemWatcher1.Path);
               
                DirectoryInfo[] dirs = di.GetDirectories();
                foreach (DirectoryInfo diNext in dirs)
                {
                   
                    //LogObj.doLog(diNext.Name);

                    FileInfo[] filer = diNext.GetFiles("*.*");

                    foreach(FileInfo f in filer)
                    {
                      behand_fil(f.Name,f.FullName);
                    }


                }
            }
            catch (Exception e)
            {
                this.loggit(e.Message,1,12);
            }
        }

        private string get_filestamp()
        {
            string timer;
            string minutter;
            string sekunder;
            string maaned;
            string dag;
            string aar;

            DateTime startTime = DateTime.Now;

            timer    = (startTime.Hour < 10)  ? "0" + startTime.Hour.ToString()  : startTime.Hour.ToString();
            minutter = (startTime.Minute < 10) ? "0" + startTime.Minute.ToString() : startTime.Minute.ToString();
            sekunder = (startTime.Second < 10) ? "0" + startTime.Second.ToString() : startTime.Second.ToString();
           
            dag      = (startTime.Day < 10)    ? "0" + startTime.Day.ToString()    : startTime.Day.ToString();
            maaned  = (startTime.Month < 10)  ? "0" + startTime.Month.ToString()  : startTime.Month.ToString();
            aar      = startTime.Year.ToString();

           
            string tiddato = dag +
                maaned +
                aar +
                timer +
                minutter +
                sekunder;

            return(tiddato);
        }


    }   
}
Avatar billede frostholm Praktikant
29. september 2006 - 02:10 #2
lukker spg
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester