コード例 #1
0
        //=============================================================================
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // Apply application theme from TXT file
            var assembly     = Assembly.GetExecutingAssembly();
            var resourceName = "RackDrawingApp.Resources.ApplicationTheme.txt";

            //
            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                ColorTheme appTheme = ColorTheme.ReadFromStream(stream);

                // apply theme
                if (appTheme != null)
                {
                    CurrentTheme.CurrentColorTheme = appTheme;
                }
            }

            // Application should be closed after 24 hours run.
            AppCloseTimer.Initialize(AppShutdown);

            bool bShowLoginWindows = true;

            // If some arguments are passed, then try to get login, password and license path.
            if (e.Args.Count() > 0)
            {
                string strLogin          = string.Empty;
                string strPassword       = string.Empty;
                string strLicensePath    = string.Empty;
                string strCutomerName    = string.Empty;
                string strEnqNo          = string.Empty;
                string strContactNo      = string.Empty;
                string strEmailID        = string.Empty;
                string strBillingAddress = string.Empty;
                string strSiteAddress    = string.Empty;
                string strDrawingPath    = string.Empty;
                //
                foreach (string strArg in e.Args)
                {
                    if (string.IsNullOrEmpty(strArg))
                    {
                        continue;
                    }

                    if (strArg.StartsWith(ARG_LOGIN))
                    {
                        strLogin = strArg.Replace(ARG_LOGIN, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_PASSWORD))
                    {
                        strPassword = strArg.Replace(ARG_PASSWORD, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_LICENSE))
                    {
                        strLicensePath = strArg.Replace(ARG_LICENSE, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_CUSTOMER_NAME))
                    {
                        strCutomerName = strArg.Replace(ARG_CUSTOMER_NAME, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_ENQ_NO))
                    {
                        strEnqNo = strArg.Replace(ARG_ENQ_NO, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_CONTACT_NO))
                    {
                        strContactNo = strArg.Replace(ARG_CONTACT_NO, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_EMAIL_ID))
                    {
                        strEmailID = strArg.Replace(ARG_EMAIL_ID, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_BILLING_ADDRESS))
                    {
                        strBillingAddress = strArg.Replace(ARG_BILLING_ADDRESS, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_SITE_ADDRESS))
                    {
                        strSiteAddress = strArg.Replace(ARG_SITE_ADDRESS, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_DRAWING_PATH))
                    {
                        strDrawingPath = strArg.Replace(ARG_DRAWING_PATH, string.Empty);
                    }
                }

                UserInfo.Login                  = strLogin;
                UserInfo.CustomerName           = strCutomerName;
                UserInfo.EnqNo                  = strEnqNo;
                UserInfo.CustomerContactNo      = strContactNo;
                UserInfo.CustomerEmailID        = strEmailID;
                UserInfo.CustomerBillingAddress = strBillingAddress;
                UserInfo.CustomerSiteAddress    = strSiteAddress;
                UserInfo.DrawingPath            = strDrawingPath;
                if (!string.IsNullOrEmpty(strLicensePath))
                {
                    string strError;
                    int    iRes = LicenseUtilities.IsValidLicense(strLicensePath, strLogin, strPassword, out strError);
                    if (iRes >= 0)
                    {
                        bShowLoginWindows = false;
                    }
                }
            }

            if (bShowLoginWindows)
            {
                LoginWindow loginWnd = new LoginWindow();
                loginWnd.Show();
            }
            else
            {
                StartupWindow startupWnd = new StartupWindow();
                if (!string.IsNullOrEmpty(UserInfo.DrawingPath))
                {
                    startupWnd.StartOldApp();
                }
                else
                {
                    startupWnd.Show();
                }
            }
        }
コード例 #2
0
        //=============================================================================
        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            if (m_VM == null)
            {
                return;
            }

            string strLicenseFilePath = string.Empty;

            if (m_VM.ConnectToServer)
            {
                try
                {
                    // Try to connect to the login server.
                    using (WebClient webClient = new WebClient())
                    {
                        webClient.QueryString.Add(LoginServerData.PARAM_USERNAME, m_VM.UserName);
                        webClient.QueryString.Add(LoginServerData.PARAM_PASSWORD, _PasswordBox.Password.ToString());

                        // Try to create license file in the assembly directory.
                        string assemblyFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                        strLicenseFilePath = assemblyFolder + "\\RackDrawingAppLicense.lic";

                        //
                        webClient.DownloadFile(LoginServerData.LOGIN_SERVER_URI, strLicenseFilePath);
                    }
                }
                catch (Exception exception)
                {
                    m_VM.Error = exception.Message;
                    return;
                }
            }
            else
            {
                strLicenseFilePath = m_VM.LicenseFilePath;
            }

            if (string.IsNullOrEmpty(strLicenseFilePath))
            {
                if (m_VM.ConnectToServer)
                {
                    m_VM.Error = "An error occurred while downloading the license file";
                }
                else
                {
                    m_VM.Error = "License file is not selected.";
                }
                return;
            }

            if (!File.Exists(strLicenseFilePath))
            {
                if (m_VM.ConnectToServer)
                {
                    m_VM.Error = "An error occurred while downloading the license file";
                }
                else
                {
                    m_VM.Error = "License file doesnt exists.";
                }
                return;
            }

            string strError;
            int    iRes = LicenseUtilities.IsValidLicense(strLicenseFilePath, m_VM.UserName, _PasswordBox.Password.ToString(), out strError);

            if (iRes >= 0)
            {
                UserInfo.Login = m_VM.UserName;

                StartupWindow startupWnd = new StartupWindow();
                if (!string.IsNullOrEmpty(UserInfo.DrawingPath))
                {
                    startupWnd.StartOldApp();
                }
                else
                {
                    startupWnd.Show();
                }
                this.Close();
            }
            else
            {
                m_VM.Error = strError;
            }
        }