0

Have a quote application, which we fill the data and send from source system to receiver system. That receiver system will be sending status of that quote(Success/Failed) as Acknowledgement to source system. We have an option to revise the same quote. whenever we revise the quote, the Status is inherited from previous quote. we need to clear the latest revision's status. which is not happening. but it clears previous revision's status. Could anyone help me.

               if (plm == "PLM")
                {
                    if (id.Revision != 0)
                    {

                        var javascriptSerializer = new JavaScriptSerializer();
                        var urn = line.CustomProperties?.FirstOrDefault(k => k.Key.ToLower() == "urn")?.Value;
                        oRecordLog.WriteToLogFile("Updating DBValue");

                   //initilizing document store object to query the documents from database.   
                        IDocumentStore ravenDB = new DocumentStore { Url = "http://localhost:8072", DefaultDatabase = "Configit.Quote" }.Initialize();

                        try
                        {
                            List<Document> docs;
                            using (var session = ravenDB.OpenSession())
                            {

                                oRecordLog.WriteToLogFile("Opened RavenDB session");
                                //getting the URN value.
                                var javaScriptSerializer = new JavaScriptSerializer();
                                string urnString = urn;
                                ModelKeyValuePair urnKeyValue = new ModelKeyValuePair();
                                urnKeyValue.Key = "URN";
                                urnKeyValue.Value = javaScriptSerializer.Serialize(urnString);


                                //wait for 5 seconds before the next query
                                docs = session.Query<Document>().Customize(x => x.WaitForNonStaleResults(TimeSpan.FromSeconds(5))).Where(x => x.Lines.Any(l => l.Properties.Any(ID => ID == urnKeyValue))).ToList();
                                try
                                {
                                    oRecordLog.WriteToLogFile("docs " + docs.Count);
                                    //processing one by one document from RavenDB.
                                    foreach (var doc in docs)
                                    {
                                        string quoteGuid = null;
                                        if (doc.LinesCount > 0)
                                        {
                                            int lineCnt = doc.LinesCount;

                                            // processing each line in the docuement getting the quoteID
                                            foreach (var quoteline in doc.Lines)

                                            {

                                                if ((quoteline.Properties.ContainsKey("Urn")) || (quoteline.Properties.ContainsKey("URN")) || (quoteline.Properties.ContainsKey("urn")))
                                                {
                                                    Guid lGuid = quoteline.LineId;
                                                    var quote_ForID = _quoteStorage.GetQuote(new QuoteRevisionId(id.QuoteId, id.Revision));
                                                    var urn_ForQuoteId = quoteline.Properties?.FirstOrDefault(k => k.Key == "URN")?.Value;

                                                    if (GetUniqueRefnum(quote_ForID, quoteline) == urn_ForQuoteId)
                                                    {
                                                        quoteGuid = doc.DocumentId.ToString();
                                                        oRecordLog.WriteToLogFile("quoteGuid " + quoteGuid);
                                                        var TransferStatus = quoteline.Properties?.FirstOrDefault(p => p.Key == "TransferStatus");
                                                        var PLMDetailedStatus = quoteline.Properties?.FirstOrDefault(p => p.Key == "PLMDetailedStatus");
                                                        TransferStatus.Value = "";
                                                        PLMDetailedStatus.Value = "";
                                                     }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            oRecordLog.WriteToLogFile("Quote ID not found");
                                        }

                                    }
                                    session.SaveChanges();
                                }
                                catch (Exception e)
                                {
                                    //printing error logs in Acknowledgement.txt.
                                    oRecordLog.WriteToLogFile(" exception caught main Stacktrace-----" + e.StackTrace);
                                    oRecordLog.WriteToLogFile(" exception caught main Message-----" + e.Message);
                                    oRecordLog.WriteToLogFile(" exception caught main Inner Exception-----" + e.InnerException);
                                    return null;
                                }


                            }

                        }
                        catch (Exception e)
                        {
                            //printing error logs in Acknowledgement.txt.
                            oRecordLog.WriteToLogFile(" exception caught main Stacktrace-----" + e.StackTrace);
                            oRecordLog.WriteToLogFile(" exception caught main Message-----" + e.Message);
                            oRecordLog.WriteToLogFile(" exception caught main Inner Exception-----" + e.InnerException);
                            return null;
                        }

                        orderupdateservice.BeginUpload(lineCount, linid, TargetSystem.Plm);



                    }
                    else
                    {
                        oRecordLog.WriteToLogFile("This is new quote");
                        orderupdateservice.BeginUpload(lineCount, linid, TargetSystem.Plm);
                    }

                }
Nikita
  • 17
  • 5
  • I can only give you some general Advice: It sounds like "Quotes" should be a table in your database, not some session scope information. A lot ot stuff can go wrong with session data. – Christopher Nov 26 '19 at 03:42
  • 1
    Exception handling is a pet peeve of mine. And yours is bad. While you properly log, you still catch to wide - inclduing fatal exceptions. You also forgot to give the user information on Exceptions - while full details are obviously not adviseable, something generic like "DataBase Error" should be okay. Here are two articles on Exception handling I link often: https://blogs.msdn.microsoft.com/ericlippert/2008/09/10/vexing-exceptions/ | https://www.codeproject.com/Articles/9538/Exception-Handling-Best-Practices-in-NET – Christopher Nov 26 '19 at 03:43
  • Hi Cristopher, Thank you for the comment. This is already built application. Could you please advice on how to clear the data for the latest page which is picking values from Ravendb... – Nikita Nov 26 '19 at 03:50
  • Thanks for the link, surely i will go through it and update the exception handling code part – Nikita Nov 26 '19 at 03:51
  • Hi, you question is not clear. Are you talking about the Revisions feature (https://ravendb.net/docs/article-page/4.2/Csharp/server/extensions/revisions) ? if so, they are Immutable and cannot be changed. – garay Nov 26 '19 at 10:00
  • Hi garay, creating revision is a simple mechanism in our application of creating a same quote with some newer configuration. – Nikita Nov 29 '19 at 18:10

0 Answers0