Ejemplo n.º 1
0
        private void ProcessDDPUpdate()
        {
            while (mRun == true)
            {
                //Each 1min
                var now = DateTime.Now.Ticks;
                if (TimeSpan.FromTicks(now - mLastDDPUpdateCheck).TotalSeconds < 60)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                    continue;
                }

                log.Info("ProcessDDPUpdate: Checking for pending updates");
                DDPManager mgr = new DDPManager();
                mgr.ProcessPendingUpdates();

                mLastDDPUpdateCheck = now;
            }
        }
Ejemplo n.º 2
0
        public void UpdateIncrementalOrRegular(PendingDDPUpdate pending)
        {
            XmlDocument newdoc = new XmlDocument();

            ICSharpCode.SharpZipLib.Zip.ZipFile zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(new MemoryStream(pending.DDPUpdate.DDPFile.ToArray()));
            Stream stream = zipFile.GetInputStream(0);

            newdoc.Load(stream);

            //---------------------------------------------------
            XmlNamespaceManager nsmanager = new XmlNamespaceManager(newdoc.NameTable);

            nsmanager.AddNamespace("lr", "http://gisis.imo.org/XML/LRIT/ddp/2008");
            //---------------------------------------------------

            XmlNode root = newdoc.SelectSingleNode("/lr:DataDistributionPlan-IncrementalUpdate", nsmanager);

            //Get ddp to modify
            var verman = new DDPVersionManager();

            //Just get what is ready from the XML
            string qstr = string.Format("/lr:DataDistributionPlan-IncrementalUpdate/lr:{0}[@base{0}VersionNum='{1}' and @target{0}VersionNum='{2}']",
                                        pending.type == 0?"Immediate":"Regular", pending.baseVersion, pending.targetVersion);

            //Ontener el nodo "inmediate" o "regular"
            XmlNode inmediate = newdoc.SelectSingleNode(qstr, nsmanager);

            string   baseVer   = inmediate.Attributes[pending.type == 0 ? "baseImmediateVersionNum" : "baseRegularVersionNum"].Value;
            string   targetVer = inmediate.Attributes[pending.type == 0 ? "targetImmediateVersionNum" : "targetRegularVersionNum"].Value;
            DateTime targetImplementationAt = DateTime.Parse(inmediate.Attributes["targetImplementationAt"].Value);

            var ddpver = pending.type == 0 ? verman.GetInmediateDDPVersion(baseVer) : verman.GetRegularDDPVersion(baseVer);

            if (ddpver == null)
            {
                log.Error(string.Format("UpdateIncrementalOrRegular: Unable to get old DDP file with version {1} type:{0}--> aborting", baseVer, pending.type));
                return;
            }

            byte[]       rawbuffer = ddpver.DDPFile.ToArray();
            MemoryStream xms       = new MemoryStream(rawbuffer);
            XmlDocument  olddoc    = new XmlDocument();

            if (rawbuffer[0] == 0x50 && rawbuffer[1] == 0x4b)
            {
                ICSharpCode.SharpZipLib.Zip.ZipFile zipFile0 = new ICSharpCode.SharpZipLib.Zip.ZipFile(xms);
                Stream s = zipFile0.GetInputStream(0);
                olddoc.Load(s);
            }
            else
            {
                olddoc.Load(xms);
            }

            //Generar nueva version del xml mezclando los dos docuemtnos;
            var theNewXml = MixDocs(inmediate, olddoc, nsmanager);

            string newver = ddpver.regularVer + ":" + targetVer;

            if (pending.type != 0)
            {
                newver = targetVer + ":" + ddpver.inmediateVer;
            }

            var ms = new MemoryStream(300000);

            theNewXml.Save(ms);
            var raw = ms.ToArray();

            File.WriteAllBytes(@"c:\" + newver.Split(':')[0] + "x" + newver.Split(':')[1] + ".textos", raw);

            Import(theNewXml, DDPManager.InsertCompleteDDP(newver, targetImplementationAt, raw));
            log.Info("UpdateIncrementalOrRegular: New version ready => " + newver);

            stream.Close();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Esta funcion es llamada cuando hay un mensaje nuevo en la cola de entrada
        /// </summary>
        /// <param name="sender">Object Sender</param>
        /// <param name="e">Async events</param>
        private void queue_PeekCompleted(object sender, PeekCompletedEventArgs e)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.FromMinutes(15)))
            {
                Message msg   = null;
                string  msgId = "NA";
                try
                {
                    msg = inputQueue.Receive(MessageQueueTransactionType.Automatic);

                    if (msg.Label == "receipt")
                    {
                        log.Debug("Se detecto receipt en queue...");
                        var receipt = (DataCenterLogic.DataCenterTypes.ReceiptType)(msg.Body);
                        msgId = receipt.MessageId;
                        var rman = new ReceiptManager();
                        rman.ProcessReceipt(receipt);
                    }
                    else
                    if (msg.Label == "pricingNotification")
                    {
                        log.Debug("Se detecto pricingNotification en queue...");
                        var pricingNotification = (PricingNotificationType)(msg.Body);
                        msgId = pricingNotification.MessageId;
                        var pman = new PricingManager();
                        pman.ProcessPricingNotification(pricingNotification);
                    }
                    else
                    if (msg.Label == "shipPositionReport")
                    {
                        log.Debug("Se detecto shipPositionReport en queue...");
                        var shipPositionReport = (DataCenterLogic.DataCenterTypes.ShipPositionReportType)(msg.Body);
                        msgId = shipPositionReport.MessageId;
                        var sprman = new ShipPositionReportManager();
                        sprman.ProcessShipPositionReport(shipPositionReport);
                    }
                    else
                    if (msg.Label == "pricingUpdate")
                    {
                        log.Debug("Se detecto pricingUpdate en queue...");
                        var pricingUpdate = (DataCenterLogic.DataCenterTypes.PricingUpdateType)(msg.Body);
                        msgId = pricingUpdate.MessageId;
                        var pman = new PricingManager();
                        pman.ProcessPricingUpdate(pricingUpdate);
                    }
                    else
                    if (msg.Label == "SARSURPICRequest")
                    {
                        log.Debug("Se detecto SARSURPICRequest en queue...");
                        var SARSURPICRequest = (DataCenterLogic.DataCenterTypes.SARSURPICType)(msg.Body);
                        msgId = SARSURPICRequest.MessageId;
                        var ssman = new SARSURPICManager();
                        ssman.ProcessSARSURPICRequest(SARSURPICRequest);
                    }
                    else
                    if (msg.Label == "ddpNotification")
                    {
                        log.Debug("Se detecto ddpNotification en queue...");
                        var ddpNotification = (DataCenterLogic.DataCenterTypes.DDPNotificationType)(msg.Body);
                        msgId = ddpNotification.MessageId;
                        var DDPman = new DDPManager();
                        DDPman.ProcessDDPNotification(ddpNotification);
                    }
                    else
                    if (msg.Label == "ddpUpdate")
                    {
                        log.Debug("Se detecto ddpUpdate en queue...");
                        var DDPman    = new DDPManager();
                        var ddpUpdate = (DataCenterTypes.DDPUpdateType)(msg.Body);
                        msgId = ddpUpdate.MessageId;
                        DDPman.ProcessDDPUpdate(ddpUpdate);
                    }
                    else
                    if (msg.Label == "shipPositionRequest")
                    {
                        log.Debug("Se detecto shipPositionRequest en queue...");
                        var shipPositionRequest = (DataCenterTypes.ShipPositionRequestType)(msg.Body);
                        msgId = shipPositionRequest.MessageId;
                        var sprm = new ShipPositionRequestManager();
                        sprm.ProcessShipPositionRequest(shipPositionRequest);
                    }
                    else
                    if (msg.Label == "systemStatus")
                    {
                        log.Debug("Se detecto systemStatus en queue...");
                        var systemStatus = (DataCenterTypes.SystemStatusType)(msg.Body);
                        msgId = systemStatus.MessageId;
                        var ssm = new SystemStatusManager();
                        ssm.ProcessSystemStatus(systemStatus);
                    }
                    else
                    if (msg.Label == "")
                    {
                        log.Debug("Se detecto mensaje del ASP en queue... tipo:");
                        var type = msg.Body.GetType().ToString();

                        switch (type)
                        {
                        case "Common.PositionMessage":
                        {
                            log.Debug("Position Message");
                            var aspPos = (Common.PositionMessage)(msg.Body);
                            var spm    = new ShipPositionManager();
                            spm.ProcessASPPosition(aspPos);
                            break;
                        }

                        case "Common.PollResponse":
                        {
                            log.Debug("PollResponse");
                            var aspPollResponse = (Common.PollResponse)(msg.Body);
                            var spm             = new ShipManager();
                            spm.ProcessPollResponse(aspPollResponse);
                            break;
                        }

                        case "Common.HeartBeatMessage":
                        {
                            log.Debug("HeartBeat");
                            var aspHb = (Common.HeartBeatMessage)(msg.Body);
                            var spm   = new SystemStatusManager();
                            spm.ProcessAspHeartBeat(aspHb);
                            break;
                        }

                        default:
                        {
                            break;
                        }
                        }
                    }
                    else
                    {
                        log.Error(string.Format("Mensaje no conocido en cola '{0}'", msg.Label));
                    }

                    scope.Complete();
                    wrong_count = 0;

                    //Dump message to disk
                    try
                    {
                        if (System.Configuration.ConfigurationManager.AppSettings["save_messages"] == "yes")
                        {
                            string folder = System.Configuration.ConfigurationManager.AppSettings["save_folder"];
                            if (folder == string.Empty)
                            {
                                folder = "c:\\msgs";
                            }
                            string fullpath = string.Format("{0}\\{1:yyyyMMdd}\\in", folder, DateTime.UtcNow);
                            Directory.CreateDirectory(fullpath);

                            string xmlstr = OutputMessageManager.messageToString(msg);
                            string lbl    = msg.Label;
                            if (lbl == "")
                            {
                                lbl = msg.Body.GetType().ToString();
                            }
                            File.WriteAllText(string.Format("{0}\\{1}-{2}.txt", fullpath, lbl, msgId), xmlstr);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error("Error intentando guardar mensaje de entrada en disco", ex);
                    }
                }
                catch (Exception ex)
                {
                    wrong_count++;
                    try
                    {
                        log.Error("Error handling message" + Environment.NewLine + Environment.NewLine + ex + Environment.NewLine + Environment.NewLine);
                    }
                    catch
                    {
                    }

                    //Poison messages
                    if (wrong_count > 3)
                    {
                        wrong_count = 0;
                        try
                        {
                            var serializer   = new System.Xml.Serialization.XmlSerializer(msg.Body.GetType());
                            var stringWriter = new System.IO.StringWriter();
                            serializer.Serialize(stringWriter, msg.Body);

                            scope.Complete();
                            log.Error("MSGDUMP: " + stringWriter.ToString());
                        }
                        catch (Exception ex2)
                        {
                            log.Error("UNABLE TO DUMP MESSAGE: " + ex.Message, ex2);
                        }
                    }
                }
            }

            inputQueue.BeginPeek();
        }
Ejemplo n.º 4
0
        public ActionResult CreateAndSendDDPRequest()
        {
            var ddpRequest = new DataCenterLogic.DDPServerTypes.DDPRequestType();

            string archivedVersion   = Request.Params["archivedVersion"];
            int    updateType        = int.Parse(Request.Params["updateType"]);
            string archivedTimeStamp = Request.Params["archivedTimeStamp"];

            ViewData["archivedVersion"]   = archivedVersion;
            ViewData["updateType"]        = updateType;
            ViewData["archivedTimeStamp"] = archivedTimeStamp;

            DateTime test = DateTime.UtcNow;

            if (updateType == 4 && DateTime.TryParse(archivedTimeStamp, out test) == false)
            {
                ViewData["error"] = "Fecha invalida";
                return(View("NewDDPRequest"));
            }

            if (updateType == 4 && archivedVersion.Trim().Length == 0)
            {
                ViewData["error"] = "Version no especificada";
                return(View("NewDDPRequest"));
            }

            ddpRequest.ArchivedDDPVersionNum         = null;
            ddpRequest.ArchivedDDPTimeStamp          = DateTime.UtcNow;
            ddpRequest.ArchivedDDPTimeStampSpecified = false;

            if (updateType == 4)
            {
                ddpRequest.ArchivedDDPTimeStampSpecified = true;
                ddpRequest.ArchivedDDPTimeStamp          = DateTime.Parse(archivedTimeStamp).ToUniversalTime();
            }

            switch (updateType)
            {
            case 0:
                ddpRequest.UpdateType = DataCenterLogic.DDPServerTypes.DDPRequestTypeUpdateType.Item0;
                break;

            case 1:
                ddpRequest.UpdateType = DataCenterLogic.DDPServerTypes.DDPRequestTypeUpdateType.Item1;
                break;

            case 2:
                ddpRequest.UpdateType = DataCenterLogic.DDPServerTypes.DDPRequestTypeUpdateType.Item2;
                break;

            case 3:
                ddpRequest.UpdateType = DataCenterLogic.DDPServerTypes.DDPRequestTypeUpdateType.Item3;
                break;

            case 4:
                ddpRequest.UpdateType = DataCenterLogic.DDPServerTypes.DDPRequestTypeUpdateType.Item4;
                break;
            }

            string outQueue = System.Configuration.ConfigurationManager.AppSettings["CoreOutQueue"];

            QueueManager.Instance().SetOut(outQueue);

            var mgr = new DataCenterLogic.DDPManager();

            QueueManager.Instance().EnqueueOut(mgr.MakeDDPRequest(ddpRequest));

            return(View("Sent"));
        }