示例#1
0
        public static async Task RunCadViewx()
        {
            NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
            Logger.Info("------------CadViewx Service Started . .");

            try
            {
                ShippmentUploadStatus shippmentUploadstatus = null;
                RestStatus            status = await RestHub.GetShipmentUploadStatus();

                if (status.UserObject != null)
                {
                    shippmentUploadstatus = (ShippmentUploadStatus)status.UserObject;
                }
                if (shippmentUploadstatus != null)
                {
                    shippmentUploadstatus.Status = ShippmentUploadEnumStatus.CadViewProgress.ToString();
                    await RestHub.UpdateShipmentUploadStatus(shippmentUploadstatus);

                    Logger.Info(shippmentUploadstatus.Path.ToString());

                    string DOC_ROOT       = "casdvw",
                           ARTICLE_NODE   = "article",
                           RN_NODE        = "rn",
                           SUBSTANCE_NODE = "substanc",
                           SIM_NODE       = "sim",
                           COMP_NODE      = "comp",
                           CSIM_NODE      = "csim";
                    XmlDocument xmlDoc    = null;
                    try
                    {
                        xmlDoc = FromHtml(System.IO.File.OpenText(shippmentUploadstatus.Path));
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex.ToString());
                    }
                    if (xmlDoc != null)
                    {
                        var casdvwNode = xmlDoc.ChildNodes.OfType <XmlElement>().Where(i => i.Name == DOC_ROOT).FirstOrDefault();
                        if (casdvwNode != null)
                        {
                            var    articles       = GetChilds(casdvwNode, ARTICLE_NODE);
                            var    totalArticles  = articles.Count();
                            string strTempDirPath = Path.Combine(shippmentUploadstatus.NumImagesPath, shippmentUploadstatus.BatchNo.ToString(), "Img");
                            Logger.Info($"Started Image processing from the path : {strTempDirPath}");
                            if (!Directory.Exists(strTempDirPath))
                            {
                                Directory.CreateDirectory(strTempDirPath);
                            }

                            int substanceIndex     = 0;
                            var substanceChildList = GetChilds(casdvwNode, SUBSTANCE_NODE);
                            var totalSubstances    = substanceChildList.Count();
                            foreach (var substanceNode in substanceChildList)
                            {
                                try
                                {
                                    CADViewX cadViewX = new CADViewX();
                                    substanceIndex++;
                                    // Interlocked.Increment(ref substanceIndex);
                                    Logger.Info("------------Start Processing Substance . ." + (substanceIndex));
                                    if (substanceIndex % 10 == 0)
                                    {
                                        // ShipmentException((substanceIndex) + " / " + totalSubstances + "-----------" , strSourcePath, "Testing");
                                        Logger.Info("------------Processing Substance . ." + (substanceIndex) + " / " + totalSubstances);
                                    }


                                    XmlNodeList   substanceChilds = substanceNode.ChildNodes;
                                    List <String> hexCodes        = new List <String>();

                                    for (int substacneNodeIndex = 0; substacneNodeIndex < substanceChilds.Count; substacneNodeIndex++)
                                    {
                                        regNumber = ChildNodeText(substanceNode, RN_NODE).Replace("-", "");

                                        if (substanceChilds[substacneNodeIndex].Name == SIM_NODE)
                                        {
                                            hexCodes.Add(substanceChilds[substacneNodeIndex].InnerText);
                                        }

                                        else if (substanceChilds[substacneNodeIndex].Name == COMP_NODE)
                                        {
                                            XmlNodeList compNodeChilds = substanceChilds[substacneNodeIndex].ChildNodes;
                                            if (compNodeChilds != null && compNodeChilds.Count > 0)
                                            {
                                                for (int csimNodeIndex = 0; csimNodeIndex < compNodeChilds.Count; csimNodeIndex++)
                                                {
                                                    var compChild = compNodeChilds[csimNodeIndex];
                                                    if (compChild.Name == CSIM_NODE)
                                                    {
                                                        hexCodes.Add(compChild.InnerText);
                                                    }
                                                }
                                            }
                                        }

                                        int registerNumberCount = 1;
                                        foreach (var hex in hexCodes)
                                        {
                                            if (!String.IsNullOrEmpty(hex))
                                            {
                                                try
                                                {
                                                    var byteArray = ConvertHexToBytes(hex);

                                                    var cgmFilePath = Path.GetTempPath() + Guid.NewGuid().ToString() + ".cgm";

                                                    var gifFilePath = registerNumberCount > 1 ?
                                                                      Path.Combine(strTempDirPath, regNumber + "_" + registerNumberCount + ".gif") :
                                                                      Path.Combine(strTempDirPath, regNumber + ".gif");

                                                    try
                                                    {
                                                        Logger.Info(cgmFilePath + "------------Start while gif generation . ." + (substanceIndex + regNumber));
                                                        System.IO.File.WriteAllBytes(cgmFilePath, byteArray);
                                                        Logger.Info(cgmFilePath + "------------End while gif generation . ." + (substanceIndex + regNumber));
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Logger.Info("------------Error while gif generation . ." + (substanceIndex + regNumber) + " : " + ex.Message);
                                                        // context.Clients.All.progress("Error while gif generation . ." + (substanceIndex) + " : " + ex.Message);
                                                    }
                                                    cadViewX.LoadFile(cgmFilePath);
                                                    if (!System.IO.File.Exists(gifFilePath))
                                                    {
                                                        cadViewX.SaveToFile(gifFilePath);
                                                    }
                                                    cadViewX.CloseFile();
                                                    registerNumberCount++;
                                                    if (File.Exists(cgmFilePath))
                                                    {
                                                        File.Delete(cgmFilePath);
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    Logger.Info("------------Some error Occured" + ex.Message + hex);
                                                    // Debug.WriteLine("Some error Occured" + ex.Message + hex);
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                        }
                    }
                    shippmentUploadstatus.Status = ShippmentUploadEnumStatus.CadViewCompleted.ToString();
                    RestStatus UpdateStatus = await RestHub.UpdateShipmentUploadStatus(shippmentUploadstatus);
                }
                else
                {
                    Logger.Info($"Under CADViewx Processing : ");
                }
            }
            catch (Exception ex)
            {
            }
        }