Ejemplo n.º 1
0
        public Service1()
        {
            try
            {
                InitializeComponent();

                //ServicePollInterval = Convert.ToInt32(ConfigurationManager.AppSettings["TimerIntervalSeconds"]);
                //ServicePollInterval = ServicePollInterval*1000;

                //_timer.Elapsed += TimerElapsed;
                ////providing the time in miliseconds
                //_timer.Interval = ServicePollInterval;
                //_timer.AutoReset = true;

                //#if _PERFORMANCE_LOG_
                //    PerfLog.Enter("Interval set to " + ServicePollInterval.ToString(CultureInfo.InvariantCulture));
                //#endif

                //StartTimer();
            }
            catch (Exception e)
            {
                #if _PERFORMANCE_LOG_
                PerfLog.Enter("Service1 constructor: " + e.Message);
                #endif
                throw;
            }
            finally
            {
                #if _PERFORMANCE_LOG_
                PerfLog.Exit();
                #endif
            }
        }
Ejemplo n.º 2
0
        private static void PreAuthenticate(Uri remoteUri)
        {
#if _PERFORMANCE_LOG_
            PerfLog.Enter(remoteUri);
#endif
            try
            {
                var httpRequest = (HttpWebRequest)WebRequest.Create(remoteUri);

                httpRequest.Credentials = new CredentialCache {
                    { remoteUri, "NTLM", (NetworkCredential)CredentialCache.DefaultCredentials }
                };
                httpRequest.UnsafeAuthenticatedConnectionSharing = true;
                httpRequest.UserAgent     = UserAgent;
                httpRequest.Method        = "HEAD";
                httpRequest.Timeout       = int.MaxValue;
                httpRequest.ContentLength = 0;

                var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
                httpResponse.Close();
            }
            catch (Exception e)
            {
                Logger.Error("Unexpected Exception.", e);
                throw;
            }
#if _PERFORMANCE_LOG_
            finally
            {
                PerfLog.Exit();
            }
#endif
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     The main entry point for the application.
        /// </summary>
        private static void Main()
        {
            try
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Main_UnhandledException);
                if (Convert.ToBoolean(ConfigurationManager.AppSettings["debugmode"].ToString()))
                {
                    // Debug code: this allows the process to run as a non-service.
                    // It will kick off the service start point, but never kill it.
                    // Shut down the debugger to exit
                    #if _PERFORMANCE_LOG_
                    PerfLog.Enter("Program.InDebugBase");
                    #endif

                    ModelQueue.LogToOracle(0, "Main", "InDebugBase", "starting up");

                    var service = new Service1();
                    service.MainProcessor();
                    Thread.Sleep(Timeout.Infinite);
                }
                else
                {
                    #if _PERFORMANCE_LOG_
                    PerfLog.Enter("Program.InServiceBase");
                    #endif

                    //ModelQueue.LogToOracle(0, "Main", "InServiceBase", "starting up");

                    ServiceBase[] ServicesToRun;
                    ServicesToRun = new ServiceBase[]
                    {
                        new Service1()
                    };
                    ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception e)
            {
                #if _PERFORMANCE_LOG_
                PerfLog.Enter("Program.Exception-" + e.Message);
                #endif

                ModelQueue.LogToOracle(0, "Main", "fatal exception", e.Message);

                Logger.Fatal("Unhandled Exception.", e);
                throw;
            }
            finally
            {
            }

            #if _PERFORMANCE_LOG_
            PerfLog.Exit();
            #endif
        }
Ejemplo n.º 4
0
        //public void ShowConnectDialog(Form ParentForm){zDisplayDialog(ParentForm,1);}
        /// <summary>
        ///     Display windows dialog for mapping a network drive
        /// </summary>
        /// <summary>
        ///     Display windows dialog for disconnecting a network drive
        /// </summary>
        //public void ShowDisconnectDialog(Form ParentForm){zDisplayDialog(ParentForm,2);}

        #endregion

        #region Core functions

        // Map network drive
        private void zMapDrive(string psUsername, string psPassword)
        {
#if _PERFORMANCE_LOG_
            PerfLog.Enter(psUsername);
#endif
            try
            {
                //create struct data
                var stNetRes = new structNetResource();
                stNetRes.iScope       = 2;
                stNetRes.iType        = RESOURCETYPE_DISK;
                stNetRes.iDisplayType = 3;
                stNetRes.iUsage       = 1;
                stNetRes.sRemoteName  = ls_ShareName;
                stNetRes.sLocalName   = ls_Drive;
                //prepare params
                int iFlags = 0;
                if (lf_SaveCredentials)
                {
                    iFlags += CONNECT_CMD_SAVECRED;
                }
                if (lf_Persistent)
                {
                    iFlags += CONNECT_UPDATE_PROFILE;
                }
                if (ls_PromptForCredentials)
                {
                    iFlags += CONNECT_INTERACTIVE + CONNECT_PROMPT;
                }
                if (psUsername == "")
                {
                    psUsername = null;
                }
                if (psPassword == "")
                {
                    psPassword = null;
                }
                //if force, unmap ready for new connection
                if (lf_Force)
                {
                    try
                    {
                        zUnMapDrive(true);
                    }
                    catch
                    {
                    }
                }
                //call and return
                int i = WNetAddConnection2A(ref stNetRes, psPassword, psUsername, iFlags);
                if (i > 0)
                {
                    throw new Win32Exception(i);
                }
            }
            catch (Exception e)
            {
                Logger.Fatal("Unexpected Exception.", e);
                throw;
            }
#if _PERFORMANCE_LOG_
            finally
            {
                PerfLog.Exit();
            }
#endif
        }