示例#1
0
        /// <summary>
        /// This method is called if we're running a report in the Windows Serivce. It checks if a comparisons file was uploaded for a bulk report
        /// using the "From File" method and processes that if we have one. Then we save the serialized comparison data along with the file to
        /// the database, and we call the web service which the windows service extends to notify it of the new job to be processed.
        /// </summary>
        /// <param name="testPage">If this is a test, we pass it in so we can get our comparison data.</param>
        private void ProcessInBackgroundService(FST.Web.Admin.frmTestCenter testPage)
        {
            bool isTest = testPage != null;

            DataTable fromFileTable = null;
            Guid      jobGuid       = Guid.Empty;

            // if we're doing a bulk comparison or we're doing a test
            if (comparisonData.BulkType == ComparisonData.enBulkType.FromFile || isTest)
            {
                // this is the GUID we send to the database that identifies this set of profiles as associated with this comparison
                Guid fromFileID = Guid.NewGuid();
                // if this isn't the test, process the uploaded file. read the Business_Interfae.GetProfilesFromFile() method for details on file format and other peculiarities
                fromFileTable = isTest ? testPage.comparisonProfiles : bi.GetProfilesFromFile(fuPopulationUpload, Server.MapPath("~/Admin/Upload/"), comparisonData.LabKitID);
                comparisonData.FromFileName = isTest ? string.Empty : fuPopulationUpload.FileName;
                if (fromFileTable == null)
                {
                    return;                        // the error message comes from Business_Interface.GetProfilesFromFile((, don't worry
                }
                fromFileTable.Columns.Add(new DataColumn("GUID", typeof(Guid)));
                // set our GUID for each of the rows
                foreach (DataRow dr in fromFileTable.Rows)
                {
                    dr["GUID"] = fromFileID;
                }
                // set our GUID so we know how to get the data back when we get to the Windows Service
                comparisonData.FromFileGuid = fromFileID;
            }

            // serialize the ComparisonData class
            string xml = comparisonData.Serialize();

            // write the "Case" which is the ComparisonData class, a set of associated parameters, and the associated 'from file' data, if any.
            bi.SaveCase(
                xml,
                Session["FST_VERSION"].ToString(),
                comparisonData.DNAAmount.ToString(),
                comparisonData.FB1,
                comparisonData.Comparison,
                comparisonData.FB2,
                comparisonData.Item,
                comparisonData.UserName,
                comparisonData.Theta.ToString(),
                comparisonData.CompareMethodID,
                comparisonData.Deducible ? "Yes" : "No",
                comparisonData.Degradation == ComparisonData.enDegradation.None ? "ND" : comparisonData.Degradation == ComparisonData.enDegradation.Mild ? "MD" : "SD",
                string.Empty,
                comparisonData.HdHead,
                comparisonData.HpHead,
                comparisonData.Bulk ? "B" : "N",
                comparisonData.BulkType == ComparisonData.enBulkType.FromFile ? "From File" : comparisonData.BulkType == ComparisonData.enBulkType.LabTypes ? "Lab Types" : "Population",
                "N",
                comparisonData.LabKitID.ToString(),
                comparisonData.FromFileGuid,
                fromFileTable,
                out jobGuid);

            // call the webservice in a separate thread to notify it that we're trying to run a comparison
            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object o)
            {
                try
                {
                    FSTWebService.FSTWebServiceClient webSvcClient = new FSTWebService.FSTWebServiceClient();
                    webSvcClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(ConfigurationManager.AppSettings["FST_SERVICE_ADDRESS"]);
                    webSvcClient.RunJob(jobGuid.ToString());
                }
                catch (Exception ex)
                {
                    Log.Error(User.Identity.Name.ToString(), (string)o, isTest ? null : Session, "Web Service Exception", string.Empty, ex);
                }
            }), isTest ? null : (object)Request.FilePath);

            // notify the user that the comparison will run in the background
            if (!isTest)
            {
                MessageBox.Show("Your comparison will run in the background, and you will receive an e-mail with the results.");
            }
        }
        /// <summary>
        /// This method is called if we're running a report in the Windows Serivce. It checks if a comparisons file was uploaded for a bulk report
        /// using the "From File" method and processes that if we have one. Then we save the serialized comparison data along with the file to
        /// the database, and we call the web service which the windows service extends to notify it of the new job to be processed.
        /// </summary>
        /// <param name="testPage">If this is a test, we pass it in so we can get our comparison data.</param>
        private void ProcessInBackgroundService(Admin.frmTestCenter testPage)
        {
            bool isTest = testPage != null;

            DataTable fromFileTable = null;
            Guid      jobGuid       = Guid.Empty;
            Guid      fromFileID    = Guid.Empty;

            // if we're doing a bulk comparison or we're doing a test
            if (comparisonData.BulkType == ComparisonData.enBulkType.FromFile || isTest)
            {
                // this is the GUID we send to the database that identifies this set of profiles as associated with this comparison
                fromFileID = Guid.NewGuid();
                comparisonData.FromFileGuid = fromFileID;
                comparisonData.FromFileName = Session["Known_FromFileName"].ToString();
                fromFileTable = (DataTable)Session["Known_FromFile"];
                // if we don't have a GUID column, add it.
                if (!fromFileTable.Columns.Contains("GUID"))
                {
                    fromFileTable.Columns.Add(new DataColumn("GUID", typeof(Guid)));
                }
                // set our GUID for each of the rows
                foreach (DataRow dr in fromFileTable.Rows)
                {
                    dr["GUID"] = fromFileID;
                }
            }

            // serialize the ComparisonData class
            string xml = comparisonData.Serialize();

            // write the "Case" which is the ComparisonData class, a set of associated parameters, and the associated 'from file' data, if any.
            bi.SaveCase(
                xml,
                Session["FST_VERSION"].ToString(),
                comparisonData.DNAAmount.ToString(),
                comparisonData.FB1,
                comparisonData.Comparison,
                comparisonData.FB2,
                comparisonData.Item,
                comparisonData.UserName,
                comparisonData.Theta.ToString(),
                comparisonData.CompareMethodID,
                comparisonData.Deducible ? "Yes" : "No",
                comparisonData.Degradation == ComparisonData.enDegradation.None ? "ND" : comparisonData.Degradation == ComparisonData.enDegradation.Mild ? "MD" : "SD",
                string.Empty,
                comparisonData.HdHead,
                comparisonData.HpHead,
                comparisonData.Bulk ? "B" : "N",
                comparisonData.BulkType == ComparisonData.enBulkType.FromFile ? "From File" : comparisonData.BulkType == ComparisonData.enBulkType.LabTypes ? "Lab Types" : "Population",
                "N",
                comparisonData.LabKitID.ToString(),
                comparisonData.FromFileGuid,
                fromFileTable,
                out jobGuid);

            // call the webservice in a separate thread to notify it that we're trying to run a comparison
            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object o)
            {
                try
                {
                    FSTWebService.FSTWebServiceClient webSvcClient = new FSTWebService.FSTWebServiceClient();
                    webSvcClient.RunJob(jobGuid.ToString());
                }
                catch (Exception ex)
                {
                    Log.Error(User.Identity.Name.ToString(), (string)o, isTest ? null : Session, "Web Service Exception", string.Empty, ex);
                }
            }), isTest ? null : (object)Request.FilePath);

            // notify the user that the comparison will run in the background
            if (!isTest)
            {
                MessageBox.Show("Your comparison will run in the background, and you will receive an e-mail with the results.");
            }
        }