示例#1
0
        private void FullTest(Network network)
        {
            var total        = 0;
            var valid        = 0;
            var mse          = 0D;
            var crossEntropy = 0D;

            foreach (var testData in DataProvider.GetAllTestData())
            {
                var actual = network.Run(testData.Input);
                if (actual == null)
                {
                    return;
                }
                mse          += CompareResults.Mse(testData.Output, actual);
                crossEntropy += CompareResults.CrossEntropy(testData.Output, actual);
                if (CompareResults.Validate(testData.Output, actual))
                {
                    valid++;
                }
                total++;
            }
            var classificationError = ((double)total - valid) / total;

            mse          /= total;
            crossEntropy /= total;
            var newFullTestResult = new FullTestResultDto(classificationError, mse, crossEntropy);

            Application.Current.Dispatcher.Invoke(() => ViewModel.FullTestResults.Add(newFullTestResult));
        }
示例#2
0
        public static CompareResults CompareSessions(Session originalSession, Session newSession)
        {
            String outputPath = Properties.Settings.Default.DefaultPicturePath + "\\" + originalSession.Time.ToFileTimeUtc() + "_" + newSession.Time.ToFileTimeUtc();

            Directory.CreateDirectory(outputPath);
            CompareResults    results          = new CompareResults(originalSession, newSession);
            List <UrlResults> ListOfUrlResults = new List <UrlResults>();

            foreach (var url in originalSession.Urls)
            {
                if (url.Uri == null || url.Uri.Trim() == "")
                {
                    continue;
                }

                UrlResults urlResults = new UrlResults();
                urlResults.OriginalUrl = url;
                MagickImage image = new MagickImage(url.PicturePath);

                Url url2 = null;
                foreach (Url urla in newSession.Urls)
                {
                    if (urla.Uri == url.Uri)
                    {
                        url2 = urla;
                    }
                }

                if (url2 != null && url2.PicturePath != "")
                {
                    urlResults.NewUrl = url2;
                    MagickImage compareImage = new MagickImage();
                    MagickImage anotherImage = new MagickImage(url2.PicturePath);
                    image.Compare(anotherImage, ErrorMetric.Absolute, compareImage);
                    String compareImagePath = outputPath + "\\" + new FileInfo(url.PicturePath).Name;
                    compareImage.Write(compareImagePath);
                    urlResults.ResultPicturePath = compareImagePath;
                    image.Dispose();
                    anotherImage.Dispose();
                    compareImage.Dispose();
                }
                else
                {
                    urlResults.Result = "No Matching Url In New Session Found";
                }

                ListOfUrlResults.Add(urlResults);
            }

            results.UrlResults = ListOfUrlResults.ToArray();

            //            foreach (var url in newSession.Urls)
            //            {
            //
            //            }

            //Foreach url in the original session, compare source and images...

            return(results);
        }
示例#3
0
        /// <summary>
        ///     Processes the specified left value.
        /// </summary>
        /// <param name="leftValue">The left value.</param>
        /// <param name="rightValue">The right value.</param>
        /// <param name="context">The context.</param>
        /// <returns>CompareResults.</returns>
        public CompareResults Process(object leftValue, object rightValue, CompareContext context)
        {
            var            instance = new DeepCompare(context);
            CompareResults result   = instance.Execute(leftValue, rightValue);

            return(result);
        }
示例#4
0
        private void CreateTable()
        {
            StaticDicomCompare  compare      = new StaticDicomCompare();
            FlagsDicomAttribute flags        = FlagsDicomAttribute.Compare_values | FlagsDicomAttribute.Compare_present | FlagsDicomAttribute.Include_sequence_items;
            StringCollection    descriptions = new StringCollection();

            descriptions.Add("Src Dataset");
            descriptions.Add("Annonymized Dataset");
            CompareResults compareResults = compare.CompareAttributeSets("DataSet compare results", datasets, descriptions, flags);
            string         tableString    = compareResults.Table.ConvertToHtml();
            StreamWriter   writer         = new StreamWriter(resultFileName);

            if (utility.AnonymizationType)
            {
                writer.Write("<b><font size='3' color='#0000ff'>Anonymized DCM File (Basic)</font></b>");
            }
            else
            {
                writer.Write("<b><font size='3' color='#0000ff'>Anonymized DCM File (Complete)</font></b>");
            }

            writer.Write(tableString);
            writer.Write("<br/>");
            writer.Close();

            dvtkWebBrowser.Navigate(resultFileName);
        }
示例#5
0
        private void compareSessionButton_Clicked(object sender, EventArgs e)
        {
            //Prompt First...
            CompareResults results = WebDiffMainClass.CompareSessions(sessionBrowser1.SelectedSession, sessionBrowser1.SelectedSession);

            DataSource.GetInstance().Save(results);
            MessageBox.Show("Saved To Mongo");
        }
示例#6
0
        public CompareResults Process(object leftValue, object rightValue, CompareContext context)
        {
            bool equal  = leftValue.Equals(rightValue);
            var  retVal = new CompareResults();

            if (!equal)
            {
                retVal.MarkAsDifferent();
            }
            return(retVal);
        }
示例#7
0
    /// <summary>
    /// Actually calls into Compare Service to perform comparison. Currently it used a hardcoded
    /// binding wsHttpBinding. After the call has returned successfully, it calls the results
    /// routine to display the results.
    /// </summary>
    /// <param name="sOriginalFile"></param>
    /// <param name="sModifiedFile"></param>
    /// <param name="sVirtualPath"></param>
    private void DoCompare(string sOriginalFile, string sModifiedFile, string sVirtualPath)
    {
        ResponseOptions responseOptions = ResponseOptions.Rtf;

        string password = (string)Session["Passw"];

        password = CodePassword(password);

        // Hardcoded wsHttpBinding. Host info is picked from config file
        ComparerClient cp = new ComparerClient("CompareWebServiceWCF");

        cp.ClientCredentials.Windows.ClientCredential.UserName = UserNameTextBox.Text;
        cp.ClientCredentials.Windows.ClientCredential.Password = password;
        cp.ClientCredentials.Windows.ClientCredential.Domain   = RealmTextBox.Text;

        // Authenticate first.
        if (cp.Authenticate(RealmTextBox.Text, UserNameTextBox.Text, password))
        {
            byte[] original      = File.ReadAllBytes(sOriginalFile);
            byte[] modified      = File.ReadAllBytes(sModifiedFile);
            string sRenderingSet = RenderingSetDropDownList.SelectedValue;
            string sOptionSet    = File.ReadAllText(Request.MapPath(Path.Combine(sRenderSetPath, sRenderingSet)));

            ExecuteParams executeParams = new ExecuteParams()
            {
                CompareOptions       = sOptionSet,
                ResponseOption       = responseOptions,
                Original             = original,
                Modified             = modified,
                OriginalDocumentInfo = new DocumentInfo()
                {
                    DocumentDescription = Path.GetFileName(sOriginalFile), DocumentSource = Path.GetFileName(sOriginalFile)
                },
                ModifiedDocumentInfo = new DocumentInfo()
                {
                    DocumentDescription = Path.GetFileName(sModifiedFile), DocumentSource = Path.GetFileName(sModifiedFile)
                },
            };
            // Peform comparison
            CompareResults results = cp.ExecuteEx(executeParams);

            // Prepare and Display results.
            HandleResults(results, responseOptions, sOriginalFile, sModifiedFile, sRenderingSet, sVirtualPath);
        }
        else
        {
            ShowMessage("Authentication failed.");
        }
    }
示例#8
0
 public void Ping()
 {
     Log.Write(TraceEventType.Information, "Ping");
     try
     {
         ComparerClient cp = GetComparerClient();
         CompareResults cr = cp.Ping();
     }
     catch (Exception ex)
     {
         _session[_connection] = null;
         Log.Write(TraceEventType.Error, "{0}", ex);
         throw ex;
     }
 }
示例#9
0
        /// <summary>
        /// Start the compare job
        /// </summary>
        private void DoCompare()
        {
            if (_filePath1 == null || _filePath2 == null)
            {
                return;
            }

            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

            _cmp = new CompareResults()
            {
                Tollerance = NumDiff.Properties.Settings.Default.Tollerance, Separators = GetSeparators(), FilePath1 = _filePath1, FilePath2 = _filePath2
            };
            if (!NumDiffUtil.ReadCompare(_cmp))
            {
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;

                string errMsg = string.Join("\n", _cmp.Errors);
                MessageBox.Show(errMsg, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // read first block (it could be optimized)
            UpdateReadBlock(0);

            // set UI data
            SetData(_cmp.GetMaxCountRows(), _cmp.GetMaxCountCols());

            //%toolstrip%
            if (_cmp.Differences.Count == 0)
            {
                toolStripStatusDiffResult.Text = "No difference found";
            }
            else
            {
                toolStripStatusDiffResult.Text = "Differences found: " + _cmp.Differences.Count;
            }

            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
        }
示例#10
0
        void CreateTableWithoutNav()
        {
            StaticDicomCompare  compare      = new StaticDicomCompare();
            FlagsDicomAttribute flags        = FlagsDicomAttribute.Compare_values | FlagsDicomAttribute.Compare_present | FlagsDicomAttribute.Include_sequence_items;
            StringCollection    descriptions = new StringCollection();

            descriptions.Add("Src Dataset");
            descriptions.Add("Annonymized Dataset");
            CompareResults compareResults = compare.CompareAttributeSets("DataSet compare results", datasets, descriptions, flags);

            StringBuilder tableString = new StringBuilder();

            tableString.Append("<left><font color='#0000ff' size = '4'>");
            tableString.Append(string.Format("Comparing the DICOM file {0} with anonymized file", resultFileName));
            tableString.Append("</font>");
            tableString.Append("</left>");
            tableString.Append("<br></br>");
            tableString.Append(compareResults.Table.ConvertToHtml());

            StreamWriter writer = new StreamWriter(initialDirectory + "\\" + resultFileName + "_" + counter.ToString() + ".html");

            writer.Write(tableString.ToString());
            writer.Close();
        }
示例#11
0
 void tabdet_onSymbolSelectForFind(object sender, CompareResults.SelectSymbolEventArgs e)
 {
     StartTableViewer(e.SymbolName);
 }
示例#12
0
        private void barButtonItem23_ItemClick(object sender, ItemClickEventArgs e)
        {
            // ask the user for which value to search and if searching should include symbolnames and/or symbol description
            if (m_currentfile != "")
            {
                SymbolCollection result_Collection = new SymbolCollection();
                frmSearchMaps searchoptions = new frmSearchMaps();
                if (searchoptions.ShowDialog() == DialogResult.OK)
                {

                    SetProgress("Start searching data...");
                    SetProgressPercentage(0);

                    System.Windows.Forms.Application.DoEvents();
                    int cnt = 0;
                    SetProgress("Searching...");
                    foreach (SymbolHelper sh in m_symbols)
                    {

                        SetProgressPercentage((cnt * 100) / m_symbols.Count);
                        bool hit_found = false;
                        if (searchoptions.UseSpecificMapLength)
                        {
                            if (sh.Length != (int)searchoptions.MapLength)
                            {
                                continue;
                            }
                        }
                        if (searchoptions.IncludeSymbolNames)
                        {
                            if (searchoptions.SearchForNumericValues)
                            {
                                if (sh.Varname.Contains(searchoptions.NumericValueToSearchFor.ToString()))
                                {
                                    hit_found = true;
                                }
                            }
                            if (searchoptions.SearchForStringValues)
                            {
                                if (searchoptions.StringValueToSearchFor != string.Empty)
                                {
                                    if (sh.Varname.Contains(searchoptions.StringValueToSearchFor))
                                    {
                                        hit_found = true;
                                    }
                                }
                            }
                        }
                        if (searchoptions.IncludeSymbolDescription)
                        {
                            if (searchoptions.SearchForNumericValues)
                            {
                                if (sh.Description.Contains(searchoptions.NumericValueToSearchFor.ToString()))
                                {
                                    hit_found = true;
                                }
                            }
                            if (searchoptions.SearchForStringValues)
                            {
                                if (searchoptions.StringValueToSearchFor != string.Empty)
                                {
                                    if (sh.Description.Contains(searchoptions.StringValueToSearchFor))
                                    {
                                        hit_found = true;
                                    }
                                }
                            }
                        }
                        // now search the symbol data
                        if (sh.Flash_start_address < m_currentfile_size)
                        {
                            byte[] symboldata = readdatafromfile(m_currentfile, (int)sh.Flash_start_address, sh.Length);
                            if (searchoptions.SearchForNumericValues)
                            {
                                if (isSixteenBitTable(sh.Varname))
                                {
                                    for (int i = 0; i < symboldata.Length / 2; i += 2)
                                    {
                                        float value = Convert.ToInt32(symboldata.GetValue(i)) * 256;
                                        value += Convert.ToInt32(symboldata.GetValue(i + 1));
                                        value *= (float)GetMapCorrectionFactor(sh.Varname);
                                        value += (float)GetMapCorrectionOffset(sh.Varname);
                                        if (value == (float)searchoptions.NumericValueToSearchFor)
                                        {
                                            hit_found = true;
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < symboldata.Length; i++)
                                    {
                                        float value = Convert.ToInt32(symboldata.GetValue(i));
                                        value *= (float)GetMapCorrectionFactor(sh.Varname);
                                        value += (float)GetMapCorrectionOffset(sh.Varname);
                                        if (value == (float)searchoptions.NumericValueToSearchFor)
                                        {
                                            hit_found = true;
                                        }
                                    }
                                }
                            }
                            if (searchoptions.SearchForStringValues)
                            {
                                if (searchoptions.StringValueToSearchFor.Length > symboldata.Length)
                                {
                                    // possible...
                                    string symboldataasstring = System.Text.Encoding.ASCII.GetString(symboldata);
                                    if (symboldataasstring.Contains(searchoptions.StringValueToSearchFor))
                                    {
                                        hit_found = true;
                                    }
                                }
                            }
                        }

                        if (hit_found)
                        {
                            // add to collection
                            result_Collection.Add(sh);
                        }
                        cnt++;
                    }
                    SetProgressIdle();
                    if (result_Collection.Count == 0)
                    {
                        MessageBox.Show("No results found...");
                    }
                    else
                    {
                        // start result screen
                        dockManager1.BeginUpdate();
                        try
                        {
                            SymbolTranslator st = new SymbolTranslator();
                            DockPanel dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500));
                            CompareResults tabdet = new CompareResults();
                            tabdet.ShowAddressesInHex = m_appSettings.ShowAddressesInHex;
                            tabdet.SetFilterMode(m_appSettings.ShowAddressesInHex);
                            tabdet.Dock = DockStyle.Fill;
                            tabdet.UseForFind = true;
                            tabdet.Filename = openFileDialog1.FileName;
                            tabdet.onSymbolSelect += new CompareResults.NotifySelectSymbol(tabdet_onSymbolSelectForFind);
                            dockPanel.Controls.Add(tabdet);
                            string resultText = "Search results: ";
                            if (searchoptions.SearchForNumericValues)
                            {
                                resultText += " number " + searchoptions.NumericValueToSearchFor.ToString();
                            }
                            if (searchoptions.SearchForStringValues)
                            {
                                resultText += " string " + searchoptions.StringValueToSearchFor;
                            }
                            dockPanel.Text = resultText;

                            dockPanel.DockTo(dockManager1, DockingStyle.Left, 1);

                            dockPanel.Width = 700;

                            System.Data.DataTable dt = new System.Data.DataTable();
                            dt.Columns.Add("SYMBOLNAME");
                            dt.Columns.Add("SRAMADDRESS", Type.GetType("System.Int32"));
                            dt.Columns.Add("FLASHADDRESS", Type.GetType("System.Int32"));
                            dt.Columns.Add("LENGTHBYTES", Type.GetType("System.Int32"));
                            dt.Columns.Add("LENGTHVALUES", Type.GetType("System.Int32"));
                            dt.Columns.Add("DESCRIPTION");
                            dt.Columns.Add("ISCHANGED", Type.GetType("System.Boolean"));
                            dt.Columns.Add("CATEGORY"); //0
                            dt.Columns.Add("DIFFPERCENTAGE", Type.GetType("System.Double"));
                            dt.Columns.Add("DIFFABSOLUTE", Type.GetType("System.Int32"));
                            dt.Columns.Add("DIFFAVERAGE", Type.GetType("System.Double"));
                            dt.Columns.Add("CATEGORYNAME");
                            dt.Columns.Add("SUBCATEGORYNAME");
                            dt.Columns.Add("SymbolNumber1", Type.GetType("System.Int32"));
                            dt.Columns.Add("SymbolNumber2", Type.GetType("System.Int32"));
                            string category = "";
                            string ht = string.Empty;
                            double diffperc = 0;
                            int diffabs = 0;
                            double diffavg = 0;
                            XDFCategories cat = XDFCategories.Undocumented;
                            XDFSubCategory subcat = XDFSubCategory.Undocumented;
                            foreach (SymbolHelper shfound in result_Collection)
                            {
                                string helptext = st.TranslateSymbolToHelpText(shfound.Varname, out ht, out cat, out subcat);
                                shfound.createAndUpdateCategory(shfound.SmartVarname);
                                dt.Rows.Add(shfound.SmartVarname, shfound.Start_address, shfound.Flash_start_address, shfound.Length, shfound.Length, helptext, false, 0, 0, 0, 0, shfound.Category, "", shfound.Symbol_number, shfound.Symbol_number);
                            }
                            tabdet.CompareSymbolCollection = result_Collection;
                            tabdet.OpenGridViewGroups(tabdet.gridControl1, 1);
                            tabdet.gridControl1.DataSource = dt.Copy();

                        }
                        catch (Exception E)
                        {
                            logger.Debug(E.Message);
                        }
                        dockManager1.EndUpdate();

                    }

                }
            }
        }
示例#13
0
        private void CompareToFile(string filename)
        {
            if (m_currentfile != "")
            {
                if (m_symbols.Count > 0)
                {
                    dockManager1.BeginUpdate();
                    try
                    {
                        DockPanel dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500));
                        CompareResults tabdet = new CompareResults();
                        tabdet.Dock = DockStyle.Fill;
                        tabdet.Filename = filename;
                        tabdet.onSymbolSelect += new CompareResults.NotifySelectSymbol(tabdet_onSymbolSelect);
                        dockPanel.Controls.Add(tabdet);
                        dockPanel.Text = "Compare results: " + Path.GetFileName(filename);
                        dockPanel.DockTo(dockManager1, DockingStyle.Left, 1);

                        dockPanel.Width = 700;

                        SymbolCollection compare_symbols = new SymbolCollection();
                        FileInfo fi = new FileInfo(filename);
                        logger.Debug("Opening compare file");
                        TryToOpenFile(filename, out compare_symbols, (int)fi.Length);
                        System.Windows.Forms.Application.DoEvents();
                        logger.Debug("Start compare");
                        SetProgress("Start comparing symbols in files");
                        SetProgressPercentage(0);
                        System.Windows.Forms.Application.DoEvents();
                        System.Data.DataTable dt = new System.Data.DataTable();
                        dt.Columns.Add("SYMBOLNAME");
                        dt.Columns.Add("SRAMADDRESS", Type.GetType("System.Int32"));
                        dt.Columns.Add("FLASHADDRESS", Type.GetType("System.Int32"));
                        dt.Columns.Add("LENGTHBYTES", Type.GetType("System.Int32"));
                        dt.Columns.Add("LENGTHVALUES", Type.GetType("System.Int32"));
                        dt.Columns.Add("DESCRIPTION");
                        dt.Columns.Add("ISCHANGED", Type.GetType("System.Boolean"));
                        dt.Columns.Add("CATEGORY", Type.GetType("System.Int32")); //0
                        dt.Columns.Add("DIFFPERCENTAGE", Type.GetType("System.Double"));
                        dt.Columns.Add("DIFFABSOLUTE", Type.GetType("System.Int32"));
                        dt.Columns.Add("DIFFAVERAGE", Type.GetType("System.Double"));
                        dt.Columns.Add("CATEGORYNAME");
                        dt.Columns.Add("SUBCATEGORYNAME");
                        dt.Columns.Add("SymbolNumber1", Type.GetType("System.Int32"));
                        dt.Columns.Add("SymbolNumber2", Type.GetType("System.Int32"));
                        dt.Columns.Add("Userdescription");
                        dt.Columns.Add("MissingInOriFile", Type.GetType("System.Boolean"));
                        dt.Columns.Add("MissingInCompareFile", Type.GetType("System.Boolean"));

                        string ht = string.Empty;
                        double diffperc = 0;
                        int diffabs = 0;
                        double diffavg = 0;
                        int percentageDone = 0;
                        int symNumber = 0;

                        XDFCategories cat = XDFCategories.Undocumented;
                        XDFSubCategory subcat = XDFSubCategory.Undocumented;
                        if (compare_symbols.Count > 0)
                        {
                            CompareResults cr = new CompareResults();
                            cr.ShowAddressesInHex = m_appSettings.ShowAddressesInHex;
                            cr.SetFilterMode(m_appSettings.ShowAddressesInHex);
                            SymbolTranslator st = new SymbolTranslator();

                            foreach (SymbolHelper sh_compare in compare_symbols)
                            {
                                try
                                {
                                    symNumber++;
                                    percentageDone = (symNumber * 50) / compare_symbols.Count;
                                    if (Convert.ToInt32(barProgress.EditValue) != percentageDone)
                                    {
                                        barProgress.EditValue = percentageDone;
                                        System.Windows.Forms.Application.DoEvents();
                                    }
                                }
                                catch (Exception E)
                                {
                                    logger.Debug(E.Message);
                                }

                                string compareName = sh_compare.SmartVarname;
                                foreach (SymbolHelper sh_org in m_symbols)
                                {
                                    string originalName = sh_org.SmartVarname;
                                    if (compareName.Equals(originalName) && compareName != String.Empty)
                                    {
                                        if (sh_compare.Flash_start_address > 0 && sh_compare.Flash_start_address < 0x100000)
                                        {
                                            if (sh_org.Flash_start_address > 0 && sh_org.Flash_start_address < 0x100000)
                                            {
                                                if (!CompareSymbolToCurrentFile(compareName, (int)sh_compare.Flash_start_address, sh_compare.Length, filename, out diffperc, out diffabs, out diffavg))
                                                {
                                                    sh_org.createAndUpdateCategory(sh_org.SmartVarname);
                                                    dt.Rows.Add(originalName, sh_compare.Start_address, sh_compare.Flash_start_address, sh_compare.Length, sh_compare.Length, st.TranslateSymbolToHelpText(compareName, out ht, out cat, out subcat), false, 0, diffperc, diffabs, diffavg, sh_org.Category, "", sh_org.Symbol_number, sh_compare.Symbol_number, sh_org.Userdescription);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            symNumber = 0;
                            string varnamecomp = string.Empty;
                            foreach (SymbolHelper shtest in compare_symbols)
                            {
                                try
                                {
                                    symNumber++;
                                    percentageDone = 50 + (symNumber * 25) / compare_symbols.Count;
                                    if (Convert.ToInt32(barProgress.EditValue) != percentageDone)
                                    {
                                        barProgress.EditValue = percentageDone;
                                        System.Windows.Forms.Application.DoEvents();
                                    }
                                }
                                catch (Exception E)
                                {
                                    logger.Debug(E.Message);
                                }
                                bool _foundSymbol = false;
                                varnamecomp = shtest.SmartVarname;
                                if (IsSymbolCalibration(varnamecomp))
                                {
                                    foreach (SymbolHelper shoritest in m_symbols)
                                    {
                                        if (varnamecomp == shoritest.SmartVarname)
                                        {
                                            _foundSymbol = true;
                                            break;
                                        }
                                    }
                                    if (!_foundSymbol)
                                    {
                                        // add this symbol to the MissingInOriCollection
                                        dt.Rows.Add(varnamecomp, shtest.Start_address, shtest.Flash_start_address, shtest.Length, shtest.Length, st.TranslateSymbolToHelpText(varnamecomp, out ht, out cat, out subcat), false, 0, 0, 0, 0, "Missing in original", "", 0, shtest.Symbol_number, shtest.Userdescription, true, false);
                                    }
                                }
                            }

                            symNumber = 0;
                            foreach (SymbolHelper shtest in m_symbols)
                            {
                                try
                                {
                                    symNumber++;
                                    percentageDone = 75 + (symNumber * 25) / compare_symbols.Count;
                                    if (Convert.ToInt32(barProgress.EditValue) != percentageDone)
                                    {
                                        barProgress.EditValue = percentageDone;
                                        System.Windows.Forms.Application.DoEvents();
                                    }
                                }
                                catch (Exception E)
                                {
                                    logger.Debug(E.Message);
                                }
                                bool _foundSymbol = false;
                                varnamecomp = shtest.SmartVarname;
                                if (IsSymbolCalibration(varnamecomp))
                                {
                                    foreach (SymbolHelper shoritest in compare_symbols)
                                    {
                                        if (varnamecomp == shoritest.SmartVarname)
                                        {
                                            _foundSymbol = true;
                                            break;
                                        }
                                    }
                                    if (!_foundSymbol)
                                    {
                                        // add this symbol to the MissingInCompCollection
                                        dt.Rows.Add(varnamecomp, shtest.Start_address, shtest.Flash_start_address, shtest.Length, shtest.Length, st.TranslateSymbolToHelpText(varnamecomp, out ht, out cat, out subcat), false, 0, 0, 0, 0, "Missing in compare", "", 0, shtest.Symbol_number, shtest.Userdescription, false, true);
                                    }
                                }
                            }

                            tabdet.OriginalSymbolCollection = m_symbols;
                            tabdet.OriginalFilename = m_currentfile;
                            tabdet.CompareFilename = filename;
                            tabdet.CompareSymbolCollection = compare_symbols;
                            tabdet.OpenGridViewGroups(tabdet.gridControl1, 1);
                            tabdet.gridControl1.DataSource = dt.Copy();
                            SetProgressIdle();
                        }
                    }
                    catch (Exception E)
                    {
                        logger.Debug(E.Message);
                    }
                    dockManager1.EndUpdate();
                }
            }
        }
示例#14
0
        private void butCompare_Click(object sender, EventArgs e)
        {
            // Check for empty passwords if security is enabled
            if (_securityEnabled && !PasswordIsValid())
            {
                return;
            }

            // Disable the UI while we run the comparison
            groupUserCredentials.Enabled = false;
            groupDocSelection.Enabled    = false;
            groupOutput.Enabled          = false;

            this.Cursor = Cursors.WaitCursor;


            // This code demonstrates how to call the BasicHttp legacy service
            // from a Service Reference proxy (This protocol may still be imported
            // as a Web Service Reference if required for legacy language support.

            /*
             * CompareProxy.LegacyComparerClient asmxCompare = new Document.Services.Compare.Sample.CompareProxy.LegacyComparerClient();
             *
             * if( asmxCompare.Authenticate("DIS", "User", "Pass") )
             * {
             *      CompareProxy.CompareResult cr = asmxCompare.Execute2(   System.IO.File.ReadAllBytes(textBoxOriginal.Text),
             *                                                                                                                      System.IO.File.ReadAllBytes(textBoxModified.Text),
             *                                                                                                                      CompareProxy.CompareResponseFlags.Rtf,
             *                                                                                                                      "");
             * }
             */


            // This code demonstrates connecting to the Compare service via the WSHttp binding
            // which ensures more secure transport and data compression.
            CompareProxy.ComparerClient svcCompare = new CompareProxy.ComparerClient("CompareWebServiceWCF", textHost.Text);


            if (_securityEnabled)
            {
                svcCompare.ClientCredentials.Windows.ClientCredential.UserName = textUsername.Text;
                svcCompare.ClientCredentials.Windows.ClientCredential.Password = textPassword.Text;
                svcCompare.ClientCredentials.Windows.ClientCredential.Domain   = textDomain.Text;
                //svcCompare.ClientCredentials.Windows.AllowNtlm = true;
                //svcCompare.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
            }

            try
            {
                // Always call Authenticate as the first operation and use the same Client Credentials
                bool isAuthenticated = !_securityEnabled || (_securityEnabled &&
                                                             svcCompare.Authenticate(textDomain.Text, textUsername.Text, textPassword.Text));

                if (isAuthenticated)
                {
                    // Determine which option was specified for the
                    // result of the comparison.  RTF, XML, WDF etc.
                    CompareProxy.ResponseOptions desiredResults = 0;

                    if (checkWDF.Checked)
                    {
                        desiredResults = CompareProxy.ResponseOptions.Wdf;
                    }
                    else if (checkRedline.Checked)
                    {
                        //cboConvert index
                        // 0 = RTF
                        // 1 = Doc
                        // 2 = DocX
                        // 3 = Pdf
                        switch (cboConvert.SelectedIndex)
                        {
                        case 0:
                            desiredResults = CompareProxy.ResponseOptions.Rtf;
                            break;

                        case 1:
                            desiredResults = CompareProxy.ResponseOptions.Doc;
                            break;

                        case 2:
                            desiredResults = CompareProxy.ResponseOptions.DocX;
                            break;

                        case 3:
                            desiredResults = CompareProxy.ResponseOptions.Pdf;
                            break;
                        }
                    }


                    if (checkSummary.Checked)
                    {
                        desiredResults |= CompareProxy.ResponseOptions.Xml;
                    }

                    if (checkRedlinMl.Checked)
                    {
                        desiredResults |= CompareProxy.ResponseOptions.RedlinMl;
                    }

                    // Run the comparison
                    var originalInfo = new DocumentInfo()
                    {
                        DocumentDescription = Path.GetFileName(textBoxOriginal.Text),
                        DocumentSource      = textBoxOriginal.Text
                    };
                    var modifiedInfo = new DocumentInfo()
                    {
                        DocumentDescription = Path.GetFileName(textBoxModified.Text),
                        DocumentSource      = textBoxModified.Text
                    };
                    var executeParams = new ExecuteParams
                    {
                        Modified             = System.IO.File.ReadAllBytes(textBoxModified.Text),
                        Original             = System.IO.File.ReadAllBytes(textBoxOriginal.Text),
                        ResponseOption       = desiredResults,
                        OriginalDocumentInfo = originalInfo,
                        ModifiedDocumentInfo = modifiedInfo
                    };


                    // If a server-side option set has been specifed then call SetOptionsSet
                    if (checkUseDefaultOptionsSet.Checked)
                    {
                        if (comboOptionsSets.SelectedIndex != 0)
                        {
                            if (svcCompare.SetOptionsSet(comboOptionsSets.Text))
                            {// The option set is defined on the server
                                if (!_securityEnabled)
                                {
                                    //As Sessions are not supported with basic Http binding,
                                    //the name of the server-side option must be specified
                                    executeParams.CompareOptionInfo = comboOptionsSets.Text;
                                }
                            }                             // else This is not an existing server-side option set
                        }

                        //To use a server-side options set just set the options string to "".
                        executeParams.CompareOptions = string.Empty;
                    }
                    else
                    {
                        // If using client-side options set then load
                        // the options from the specified file.
                        executeParams.CompareOptions    = GetCompareOptions();
                        executeParams.CompareOptionInfo = textBoxOptionSet.Text;
                    }



                    CompareResults cr = svcCompare.ExecuteEx(executeParams);

                    //Comparison without documents details
//					CompareProxy.CompareResults cr = svcCompare.Execute(System.IO.File.ReadAllBytes(textBoxOriginal.Text),
//																		System.IO.File.ReadAllBytes(textBoxModified.Text),
//																		desiredResults,
//																		sCompareOptions);



                    // Always close the service connection as soon as possible after use.
                    svcCompare.Close();

                    if (cr != null)
                    {
                        // Write out the XML summary and display with the
                        // default application for .xml
                        if ((desiredResults & CompareProxy.ResponseOptions.Xml) == CompareProxy.ResponseOptions.Xml)
                        {
                            if (cr.Summary != null)
                            {
                                System.IO.File.WriteAllText(textSummary.Text, cr.Summary);
                                System.Diagnostics.Process.Start(textSummary.Text);
                            }
                            else
                            {
                                MessageBox.Show("Execute did not return a summary", "Compare Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }

                        if (checkRedlinMl.Checked)
                        {
                            if (cr.RedlineMl != null)
                            {
                                System.IO.File.WriteAllText(textRedlineMl.Text, cr.RedlineMl);
                                System.Diagnostics.Process.Start("Notepad.exe", textRedlineMl.Text);
                            }
                            else
                            {
                                MessageBox.Show("Execute did not return a redline ML", "Compare Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        // Write out the RTF redline, if selected, and display with the
                        // internal viewer
                        if ((desiredResults & CompareProxy.ResponseOptions.Rtf) == CompareProxy.ResponseOptions.Rtf)
                        {
                            if (cr.Redline != null)
                            {
                                string rtfRedline = FromASCIIByteArray(cr.Redline);

                                formCompareResults formResults = new formCompareResults();
                                formResults.SetRTFResults(rtfRedline);

                                formResults.ShowDialog(this);

                                System.IO.File.WriteAllBytes(textRedline.Text, cr.Redline);
                                //System.Diagnostics.Process.Start(textRedline.Text);
                            }
                            else
                            {
                                MessageBox.Show("Execute did not return a redline", "Compare Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }                        // Write out the WDF composite and display with the default application for .wdf
                        else if ((desiredResults & CompareProxy.ResponseOptions.Wdf) == CompareProxy.ResponseOptions.Wdf)
                        {
                            if (cr.Redline != null)
                            {
                                System.IO.File.WriteAllBytes(textWDF.Text, cr.Redline);
                                System.Diagnostics.Process.Start(textWDF.Text);
                            }
                            else
                            {
                                MessageBox.Show("Execute did not return a redline", "Compare Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        // Check if we want a different redline convertor then the standard RTF
                        else if ((desiredResults & CompareProxy.ResponseOptions.Doc) == CompareProxy.ResponseOptions.Doc ||
                                 (desiredResults & CompareProxy.ResponseOptions.DocX) == CompareProxy.ResponseOptions.DocX ||
                                 (desiredResults & CompareProxy.ResponseOptions.Pdf) == CompareProxy.ResponseOptions.Pdf)
                        {
                            if (cr.Redline != null)
                            {
                                System.IO.File.WriteAllBytes(textRedline.Text, cr.Redline);
                                System.Diagnostics.Process.Start(textRedline.Text);
                                MessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, "Written results to {0}", textRedline.Text),
                                                "Results", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                MessageBox.Show("Execute did not return a redline", "Compare Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Execute did not return any results", "Compare Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (System.ServiceModel.ServerTooBusyException)
            {
                MessageBox.Show("Server Too Busy", "Compare", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch (TimeoutException ex)
            {
                MessageBox.Show(ex.Message, "TimeoutException", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (System.ServiceModel.FaultException ex)
            {
                //svcCompare.Abort();
                MessageBox.Show(ex.Message, "FaultException", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (System.ServiceModel.CommunicationException ex)
            {
                //svcCompare.Abort();

                if (ex.Message.Contains("request is unauthorized"))
                {
                    MessageBox.Show(@"Unauthorized issue arised, please check User Name and/or Password and/or domain!",
                                    @"CommunicationException",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.Message, "CommunicationException", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (System.ComponentModel.Win32Exception ex)
            {
                // When attempting to open the comparison results it is possible
                // that no document is associated with the file extension.
                if (ex.NativeErrorCode == 0x00000483)
                {
                    MessageBox.Show("The redline has been saved to the specified location but no application has been associated with this file type in order to display it.", "File Associations", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                //svcCompare.Close();
                MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // Re-enable UI
            groupOutput.Enabled          = true;
            groupDocSelection.Enabled    = true;
            groupUserCredentials.Enabled = true;

            this.Cursor = Cursors.Default;
        }
示例#15
0
 void tabdet_onSymbolSelect(object sender, CompareResults.SelectSymbolEventArgs e)
 {
     logger.Debug(e.SymbolName);
     if (!e.ShowDiffMap)
     {
         StartTableViewer(e.SymbolName);
         StartCompareMapViewer(e.SymbolName, e.Filename, e.SymbolAddress, e.SymbolLength, e.Symbols);
     }
     else
     {
         // show difference map
         StartCompareDifferenceViewer(e.SymbolName, e.Filename, e.SymbolAddress, e.SymbolLength);
     }
 }
示例#16
0
    /// <summary>
    /// Prepare and stores the result objects for use by HandleFinalResults, based on output format
    /// selected by user, e.g. .rtf or .wdf etc.
    /// </summary>
    /// <param name="results"></param>
    /// <param name="responseOptions"></param>
    /// <param name="sOriginalFilePath"></param>
    /// <param name="sModifiedFilePath"></param>
    /// <param name="sRenderingSet"></param>
    /// <param name="sVirtualPath"></param>
    private void HandleResults(CompareResults results, ResponseOptions responseOptions, string sOriginalFilePath, string sModifiedFilePath, string sRenderingSet, string sVirtualPath)
    {
        string sFileName = string.Empty;
        string sOutputFileVirtualPath   = string.Empty;
        string sSummaryFileVirtualPath  = string.Empty;
        string sOriginalFileVirtualPath = string.Empty;
        string sModifiedFileVirtualPath = string.Empty;

        // Prepare the virtual path first.
        sVirtualPath = sVirtualPath.Replace('\\', '/');
        string sBasePath = Request.MapPath(sVirtualPath);

        // Prepare labels for Original File
        sFileName = Path.GetFileName(sOriginalFilePath);
        sOriginalFileVirtualPath = sVirtualPath.Replace('\\', '/');
        sOriginalFileVirtualPath = Path.Combine(sOriginalFileVirtualPath, sFileName);

        sOriginalFilePath          = Encode(sOriginalFilePath);
        OriginalFilePathLabel.Text = "<a href='" + Encode(sOriginalFileVirtualPath) + "' target='_blank'>" + sFileName + "</a>";
        RenederingSetLabel.Text    = sRenderingSet;

        // Prepare paths/labels for Output file
        if (responseOptions == ResponseOptions.Rtf)
        {
            if (results.Redline != null)
            {
                sFileName = "redline.rtf";
                sOutputFileVirtualPath = Path.Combine(sVirtualPath, sFileName);

                File.WriteAllBytes(Request.MapPath(sOutputFileVirtualPath), results.Redline);
            }
        }

        if (responseOptions == ResponseOptions.Xml ||
            responseOptions == ResponseOptions.RtfWithSummary ||
            responseOptions == ResponseOptions.WdfWithSummary)
        {
            if (results.Summary != null)
            {
                sFileName = "redline.xml";
                sSummaryFileVirtualPath = Path.Combine(sVirtualPath, sFileName);

                File.WriteAllText(Request.MapPath(sSummaryFileVirtualPath), results.Summary);
            }
        }

        // Prepare path/labels for Modified file
        if (sModifiedFilePath != string.Empty)
        {
            sFileName = Path.GetFileName(sModifiedFilePath);
            sModifiedFileVirtualPath = Path.Combine(sVirtualPath, sFileName);
            sModifiedFileVirtualPath = Encode(sModifiedFileVirtualPath);
        }

        if (sOutputFileVirtualPath != string.Empty)
        {
            sOutputFileVirtualPath = Encode(sOutputFileVirtualPath);
        }

        if (sSummaryFileVirtualPath != string.Empty)
        {
            sSummaryFileVirtualPath = Encode(sSummaryFileVirtualPath);
        }


        // Prepare and show the results table
        UpdateResultsTable(sModifiedFileVirtualPath, sOutputFileVirtualPath, sSummaryFileVirtualPath);
    }
示例#17
0
        private static int ManageCompareFiles(string filePath1, string filePath2, int nameColumnIndex, double tollerance, string[] separators)
        {
            Console.WriteLine("file 1: " + filePath1);
            Console.WriteLine("file 2: " + filePath2);

            CompareResults cmp = new CompareResults()
            {
                Tollerance = tollerance, Separators = separators, ReadHeaders = true, NameColumnIndex = nameColumnIndex, FilePath1 = filePath1, FilePath2 = filePath2
            };

            if (!NumDiffUtil.ReadCompare(cmp))
            {
                string errMsg = string.Join("\n", cmp.Errors);
                Console.WriteLine(errMsg);
                return(2);
            }

            if (cmp.Differences.Count == 0)
            {
                Console.WriteLine("No difference found");
                return(1);
            }

            Console.WriteLine("Differences found: " + cmp.Differences.Count);
            Console.WriteLine();
            Console.WriteLine("============================ differences");

            // sort and group the differences
            var    diffs     = cmp.Differences.OrderBy(x => x.Row).ThenBy(x => x.Col).GroupBy(x => x.Row).ToList();
            string oldHeader = "";

            for (int i = 0; i < diffs.Count; i++)
            {
                string header  = "ROW";
                string values1 = "" + diffs[i].Key;
                string values2 = "" + diffs[i].Key;
                if (nameColumnIndex >= 0)
                {
                    DifferentCell cell = diffs[i].ElementAt(0);
                    header  += "\t" + cmp.Headers[nameColumnIndex];
                    values1 += "\t" + cell.Name;
                    values2 += "\t" + cell.Name;
                }

                for (int j = 0; j < diffs[i].Count(); j++)
                {
                    DifferentCell cell = diffs[i].ElementAt(j);
                    header  += "\t" + cmp.Headers[cell.Col];
                    values1 += "\t" + cell.Value1;
                    values2 += "\t" + cell.Value2;
                }

                if (oldHeader != header)
                {
                    oldHeader = header;
                    Console.WriteLine();
                    Console.WriteLine(header);
                }
                Console.WriteLine(values1);
                Console.WriteLine(values2);
            }

            if (cmp.Errors.Count > 0)
            {
                Console.WriteLine("============================ errors");
                for (int i = 0; i < cmp.Errors.Count; i++)
                {
                    Console.WriteLine(cmp.Errors.ElementAt(i));
                }
            }

            return(0);
        }