Esempio n. 1
0
        public static void OpenEmailToSend(Settings_Permanent settings)
        {
            m_Settings = settings;
            try
            {
                string tempStr = "mailto:[email protected]? Subject=User Registration &body=";

                String[] temp = m_Settings.UsersInfoToUpload.Split(',');
                foreach (string s in temp)
                {
                    tempStr += "%0A" + s;
                }
                Process.Start(tempStr);
                //m_Settings.UsersInfoToUpload = Registered ;
                m_Settings.RegistrationComplete = true;
                m_Settings.SaveSettings();
            }
            catch (System.Exception ex)
            {
                ProjectView.ProjectView.WriteToLogFile_Static(ex.ToString());
            }
        }
Esempio n. 2
0
        public static void UploadUserInformation(Settings_Permanent settings)
        {
            if (settings == null || m_BackgroundWorker.IsBusy)
            {
                return;
            }
            m_Settings = settings;
            string fileName           = GenerateFileName();
            string uploadPath         = Code.UploadCode.UploadDirectoryPath + fileName;
            string userName           = Code.UploadCode.userName;
            string pass               = Code.UploadCode.Code;
            string dataToUpload       = settings.UsersInfoToUpload;
            bool   isUploadSuccessful = false;

            m_BackgroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(delegate(object sender, System.ComponentModel.DoWorkEventArgs e)
            {
                if (m_CurrentCulture != null)
                {
                    System.Threading.Thread.CurrentThread.CurrentUICulture = m_CurrentCulture;
                }
                System.IO.MemoryStream memoryStream = null;
                System.IO.Stream stream             = null;

                try
                {
                    byte[] byteArray = Encoding.UTF8.GetBytes(dataToUpload);
                    memoryStream     = new System.IO.MemoryStream(byteArray);

                    // Create FtpWebRequest object
                    FtpWebRequest ftpRequest = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(new Uri(uploadPath));
                    // Provide username and password
                    ftpRequest.Credentials = new System.Net.NetworkCredential(userName, pass);

                    // after a command is executed, do not keep connection alive
                    ftpRequest.KeepAlive = false;
                    ftpRequest.Timeout   = 30000;
                    // Specify the command to be executed
                    ftpRequest.Method    = System.Net.WebRequestMethods.Ftp.UploadFile;
                    ftpRequest.UseBinary = true;

                    ftpRequest.ContentLength = memoryStream.Length;
                    // buffer size is kept 2kb.
                    int bufferLength = 2048;
                    byte[] buff      = new byte[bufferLength];

                    stream = ftpRequest.GetRequestStream();
                    // Read the memory stream 2kb at a time and copy to ftpStream
                    int dataLength = memoryStream.Read(buff, 0, bufferLength);

                    while (dataLength != 0)
                    {
                        // Write Content from the memory stream to the FTP Upload Stream.
                        stream.Write(buff, 0, dataLength);
                        dataLength = memoryStream.Read(buff, 0, bufferLength);
                    }
                    isUploadSuccessful = true;
                }
                catch (System.Exception ex)
                {
                    m_Settings.UploadAttemptsCount++;
                    m_Settings.SaveSettings();
                    Console.WriteLine(ex.ToString());
                    ProjectView.ProjectView.WriteToLogFile_Static(ex.ToString());
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Close();
                        stream.Dispose();
                    }
                    if (memoryStream != null)
                    {
                        memoryStream.Close();
                        memoryStream.Dispose();
                    }
                }
            });

            m_BackgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(delegate(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
            {
                if (m_CurrentCulture != null)
                {
                    System.Threading.Thread.CurrentThread.CurrentUICulture = m_CurrentCulture;
                }
                if (!isUploadSuccessful)
                {
                    return;
                }
                try
                {
                    FtpWebRequest ftpRequest = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(new Uri(uploadPath));
                    ftpRequest.Credentials   = new System.Net.NetworkCredential(userName, pass);
                    ftpRequest.KeepAlive     = false;
                    ftpRequest.Timeout       = 20000;
                    ftpRequest.Method        = WebRequestMethods.Ftp.GetFileSize;
                    ftpRequest.UseBinary     = true;

                    // if successful then update settings for the same

                    if (ftpRequest.GetResponse().ContentLength > 0)
                    {
                        Console.WriteLine("registered");
                        //m_Settings.UsersInfoToUpload = Registered;
                        m_Settings.RegistrationComplete = true;
                        m_Settings.SaveSettings();
                        //MessageBox.Show("done");
                    }
                    else
                    {
                        m_Settings.UploadAttemptsCount++;
                        m_Settings.SaveSettings();
                    }
                }
                catch (System.Exception ex)
                {
                    m_Settings.UploadAttemptsCount++;
                    m_Settings.SaveSettings();
                    Console.WriteLine(ex.ToString());
                    ProjectView.ProjectView.WriteToLogFile_Static(ex.ToString());
                }
            });
            m_BackgroundWorker.RunWorkerAsync();
        }
Esempio n. 3
0
        private void m_btnOk_Click(object sender, EventArgs e)
        {
            //string fileName = System.DateTime.Now.ToShortDateString() + System.DateTime.Now.ToShortTimeString() + System.DateTime.Now.ToUniversalTime().ToShortTimeString();
            //fileName = fileName.Replace(":", "") + ".txt";
            //fileName = fileName.Replace("/", "");

            // the upload data should be in following format
            // "un:User Name,em:[email protected],og:Organization Name,ct:Delhi,cn:India",vr:Obi version,os:windows version;
            //if (m_txtName.Text == "" || m_txtEmail.Text == "" || m_txtCountry.Text == "" || m_txtOrganizationName.Text == "" ||
            //  m_txtCity.Text == "" || m_txtCountry.Text == "" || ((m_txtName.Text.Contains(" ")) && m_txtName.Text.Trim().Length==0 )
            //  || ((m_txtEmail.Text.Contains(" ")) && m_txtEmail.Text.Trim().Length == 0)
            //  || ((m_txtOrganizationName.Text.Contains(" ")) && m_txtOrganizationName.Text.Trim().Length == 0)
            //   || ((m_txtCity.Text.Contains(" ")) && m_txtCity.Text.Trim().Length == 0))
            bool   flag = false;
            string str  = Localizer.Message("UserRegistration_EnterFollowing");

            if (m_txtName.Text == "" || ((m_txtName.Text.Contains(" ")) && m_txtName.Text.Trim().Length == 0) || (m_txtName.Text.StartsWith(".") && m_txtName.Text.EndsWith(".")))
            {
                str += "\n" + Localizer.Message("UserRegistration_Name");
                flag = true;
            }
            if (m_txtEmail.Text == "" || ((m_txtEmail.Text.Contains(" ")) && m_txtEmail.Text.Trim().Length == 0) || (m_txtEmail.Text.StartsWith(".") && m_txtEmail.Text.EndsWith(".")))
            {
                str += "\n" + Localizer.Message("UserRegistration_Email");
                flag = true;
            }
            if (m_txtOrganizationName.Text == "" || ((m_txtOrganizationName.Text.Contains(" ")) && m_txtOrganizationName.Text.Trim().Length == 0) || (m_txtOrganizationName.Text.StartsWith(".") && m_txtOrganizationName.Text.EndsWith(".")))
            {
                str += "\n" + Localizer.Message("UserRegistration_Org_Name");
                flag = true;
            }
            if (m_txtCity.Text == "" || ((m_txtCity.Text.Contains(" ")) && m_txtCity.Text.Trim().Length == 0) || (m_txtCity.Text.StartsWith(".") && m_txtCity.Text.EndsWith(".")))
            {
                str += "\n" + Localizer.Message("UserRegistration_City");
                flag = true;
            }
            if (m_txtCountry.Text == "" || ((m_txtCountry.Text.Contains(" ")) && m_txtCountry.Text.Trim().Length == 0) || (m_txtCountry.Text.StartsWith(".") && m_txtCountry.Text.EndsWith(".")))
            {
                str += "\n" + Localizer.Message("UserRegistration_Country");
                flag = true;
            }
            if (flag)
            {
                MessageBox.Show(str, Localizer.Message("Caption_Warning"));
            }


            else if (!m_txtEmail.Text.Contains("@") || !m_txtEmail.Text.Contains(".") || m_txtEmail.Text.Contains(" "))
            {
                MessageBox.Show(Localizer.Message("UserRegistration_WrongEmail"));
            }
            else if (m_txtEmail.Text.Trim().CompareTo(m_txtRetypeEmail.Text.Trim()) != 0)
            {
                MessageBox.Show(Localizer.Message("UserRegistration_NoMatchEmail"));
            }
            else if ((m_rdbDaisyProduction.Checked == false && m_rdbTryingObi.Checked == false))
            {
                MessageBox.Show(Localizer.Message("UserRegistration_IndiacateUsage"));
            }
            else
            {
                string userInfo = "un:" + m_txtName.Text
                                  + ",em:" + m_txtEmail.Text
                                  + ",og:" + m_txtOrganizationName.Text
                                  + ",ct:" + m_txtCity.Text
                                  + ",cn:" + m_txtCountry.Text
                                  + ",ss:" + (m_rdbDaisyProduction.Checked ? "used" : "not-used")
                                  + ",vr:" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
                                  + ",os:" + System.Environment.OSVersion.ToString();

                Console.WriteLine(userInfo);
                m_Settings.UsersInfoToUpload = userInfo;
                m_Settings.ObiVersionWhileSendingUserInfo = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
                m_Settings.SaveSettings();
                //MessageBox.Show(userInfo);
                Close();
                //return;
            }
        }