示例#1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            btnLogin.Enabled = false;
            Cursor.Current   = Cursors.WaitCursor;

            string        userName        = txtUserName.Text;
            string        Password        = txtPass.Text;
            string        SiteURL         = txtURL.Text;
            SecureString  securePassword  = null;
            ClientContext spclientContext = null;

            try
            {
                if (!String.IsNullOrEmpty(userName) && !String.IsNullOrEmpty(Password) && !String.IsNullOrEmpty(SiteURL))
                {
                    securePassword = new SecureString();
                    foreach (char c in Password)
                    {
                        securePassword.AppendChar(c);
                    }
                    if (spclientContext != null)
                    {
                        spclientContext.Dispose();
                    }


                    spclientContext = new ClientContext(SiteURL);


                    spclientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);
                    spclientContext.ExecuteQuery();

                    Common.UpdateConfig("UserName", userName);
                    Common.UpdateConfig("Password", Common.EncodePasswordToBase64(Password));
                    Common.UpdateConfig("SiteURL", SiteURL);


                    if (FrmSearch.FrmSearchInstace == null)
                    {
                        FrmSearch searchfrom = new FrmSearch();
                        searchfrom.spclientContext = spclientContext;
                        searchfrom.SiteURL         = SiteURL;
                        this.Hide();
                        searchfrom.Show();
                    }
                    else
                    {
                        FrmSearch.FrmSearchInstace.ClearControl();
                        FrmSearch.FrmSearchInstace.spclientContext = spclientContext;
                        FrmSearch.FrmSearchInstace.SiteURL         = SiteURL;
                        this.Hide();
                        FrmSearch.FrmSearchInstace.Show();
                    }
                    Cursor.Current   = Cursors.Default;
                    btnLogin.Enabled = true;
                }
                else
                {
                    Cursor.Current   = Cursors.Default;
                    btnLogin.Enabled = true;



                    MyMessageBox msgb = new MyMessageBox("Please enter username, password and site url.", "Validation Failed !!!");
                    msgb.Show();
                }
            }
            catch (Exception ex)
            {
                Cursor.Current   = Cursors.Default;
                btnLogin.Enabled = true;
                MyMessageBox msgb = new MyMessageBox(ex.Message, "Error!!!");
                msgb.Show();
                Common.ErrorLog(ex.Message + " Stack Trace:" + ex.StackTrace);
            }
        }
        private void btnsearch_Click(object sender, EventArgs e)
        {
            if (txtinputfile.Text.Trim() == "" || txtoutput.Text.Trim() == "")
            {
                MyMessageBox msgb = new MyMessageBox("Please select Input file and output folder location.", "Validation Failed!!!");
                msgb.Show();

                return;
            }
            btnsearch.Enabled = false;
            Cursor.Current    = Cursors.WaitCursor;
            string strQueryRule = string.Empty;
            String strSourceID  = String.Empty;
            String strRankID    = String.Empty;
            String strScope     = String.Empty;

            try
            {
                if (!String.IsNullOrEmpty(txtSortBy.Text.Trim()) && cmbsortdir.Text == "Select Order")
                {
                    MyMessageBox msgb1 = new MyMessageBox("Please select sort order.", "Validation Failed!!!");
                    msgb1.Show();

                    cmbsortdir.Focus();
                    btnsearch.Enabled = true;
                    return;
                }
                if (chkuseQueryRules.Checked)
                {
                    strQueryRule = "True";
                }
                else
                {
                    strQueryRule = "False";
                }
                if (cmbResultSource.SelectedValue != null && cmbResultSource.SelectedValue.ToString() != "-1")
                {
                    strSourceID = cmbResultSource.SelectedValue.ToString();
                }
                if (cmbResultSource.SelectedValue == null && cmbResultSource.Text.Trim() != "")
                {
                    strSourceID = cmbResultSource.Text.Trim();
                }

                if (cmbRank.SelectedValue != null && cmbRank.SelectedValue.ToString() != "-1")
                {
                    strRankID = cmbRank.SelectedValue.ToString();
                }
                if (cmbRank.SelectedValue == null && cmbRank.Text.Trim() != "")
                {
                    strRankID = cmbRank.Text.Trim();
                }
                if (cmbScope.SelectedIndex != 0)
                {
                    strScope = cmbScope.Text;
                }

                List <String> Keywords = Common.ReadInputFile(txtinputfile.Text);
                Common.SearchMethod(spclientContext, Keywords, textQueryPath.Text.Trim(), txtQueryTemplate.Text.Trim(), strSourceID, txtoutput.Text.Trim(), strRankID, txtRefinedBy.Text.Trim(), txtSortBy.Text.Trim(), cmbsortdir.Text, txtgroupBy.Text, strQueryRule, strScope, this.SiteURL);

                Common.UpdateConfig("InputFileLocation", txtinputfile.Text.Trim());
                Common.UpdateConfig("OutputFolderLocation", txtoutput.Text.Trim());
                Common.UpdateConfig("QueryText", txtQueryTemplate.Text.Trim());
                Common.UpdateConfig("SearchPath", textQueryPath.Text.Trim());
                Common.UpdateConfig("ResultSourceID", strSourceID);
                Common.UpdateConfig("RankingModelID", strRankID);
                Common.UpdateConfig("RefinedBy", txtRefinedBy.Text.Trim());
                Common.UpdateConfig("SortBy", txtSortBy.Text.Trim());
                Common.UpdateConfig("SortDir", cmbsortdir.Text);
                Common.UpdateConfig("GroupBy", txtgroupBy.Text.Trim());
                Common.UpdateConfig("UseQueryRule", strQueryRule);
                Common.UpdateConfig("Scope", strScope);


                Cursor.Current = Cursors.Default;
                MyMessageBox msgb = new MyMessageBox("Search results exported to excel successfully.", "Success!!");
                msgb.Show();

                btnsearch.Enabled = true;
            }
            catch (Exception ex)
            {
                MyMessageBox msgb = new MyMessageBox(ex.Message, "Error!!");
                msgb.Show();
                btnsearch.Enabled = true;
                Cursor.Current    = Cursors.Default;
                Common.ErrorLog(ex.Message + " Stack Trace:" + ex.StackTrace);
            }
        }