Exemplo n.º 1
0
        private void ProcessUnschdeuledAdjustment()
        {
            this.Logger.Log(TraceEventType.Information, LoggingMessageId.PortalOfcomEvaluation, "processing unscheduled adjustments started at " + DateTime.Now);

            string directoryPath = this.GetDirectoryPath("Stage4");
            string tableName     = "RGN5Stage4UnscheduledAdjustments";
            string fileName      = "Stage 4 - Unscheduled Adjustments.csv";

            string filePath = directoryPath + fileName;

            try
            {
                // Get All PmseAssigments
                IEnumerable <DTTDataAvailability> dttData = this.regionDataAccess.GetDTTDataAvailability(tableName);

                if (dttData.Count() > 0)
                {
                    // delete all assignments
                    this.regionDataAccess.DeleteDTTDataAvailability(dttData, tableName);
                }

                List <DTTDataAvailability> listPD = new List <DTTDataAvailability>();
                foreach (var line in File.ReadAllLines(filePath))
                {
                    string[] values = line.Split(',');
                    if (values[0] == "Easting" || string.IsNullOrEmpty(values[0]))
                    {
                        continue;
                    }

                    DTTDataAvailability pd = new DTTDataAvailability();
                    var dttvalues          = values.Skip(2).Select(obj => obj.ToInt32()).ToArray();
                    pd.DataRecord = Conversion.IntToByte(dttvalues);
                    var test = Conversion.ByteToInt(pd.DataRecord);
                    pd.Easting      = values[0].ToInt32();
                    pd.Northing     = values[1].ToInt32();
                    pd.PartitionKey = "Stage4Unscheduled";
                    pd.RowKey       = string.Format("{0}-{1}", pd.Easting, pd.Northing);

                    listPD.Add(pd);
                }

                this.regionDataAccess.InsertDTTDataAvailability(listPD, tableName);
            }
            catch (Exception)
            {
            }

            this.Logger.Log(TraceEventType.Information, LoggingMessageId.PortalOfcomEvaluation, "processing unscheduled adjustments ended at " + DateTime.Now);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Decompresses the DTT data.
        /// </summary>
        /// <param name="dttblockdata">The DTT block data.</param>
        /// <returns>returns DTTSquare.</returns>
        public static DTTSquare DecompressDTTData(DTTDataAvailability dttblockdata)
        {
            DTTSquare dttdata = null;

            using (MemoryStream ms = new MemoryStream())
            {
                int msgLength = BitConverter.ToInt32(dttblockdata.DataRecord, 0);
                ms.Write(dttblockdata.DataRecord, 0, dttblockdata.DataRecord.Length - 0);
                byte[] buffer = new byte[msgLength];
                ms.Position = 0;
                GZipStream zip = new GZipStream(ms, CompressionMode.Decompress);
                zip.Read(buffer, 0, buffer.Length);

                // Convert byte to integer array
                int[] block = new int[buffer.Length / sizeof(int)];
                Buffer.BlockCopy(buffer, 0, block, 0, block.Length);

                dttdata = new DTTSquare(dttblockdata.Easting, dttblockdata.Northing, block);
            }

            return(dttdata);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Processes the unscheduled adjustments.
        /// </summary>
        /// <param name="dataStream">The data stream.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="replyMessage">The reply message.</param>
        /// <returns>returns List{DTTDataAvailability}.</returns>
        private bool ProcessUnscheduledAdjustments(string[] dataStream, string fileName, out string replyMessage)
        {
            AuditId auditId         = AuditId.PmseSync;
            string  auditMethodName = "ProcessUnscheduledAdjustments";

            try
            {
                List <DTTDataAvailability> listPD = new List <DTTDataAvailability>();
                foreach (var line in dataStream)
                {
                    var values = line.Split(',');
                    if (values[0].ToLower().Contains("easting"))
                    {
                        continue;
                    }

                    try
                    {
                        if (!this.CheckRequiredInteger(values[0]) || !this.CheckRequiredInteger(values[1]) || !this.CheckUnscheduledData(values))
                        {
                            listPD       = null;
                            replyMessage = Utils.Configuration["mailBodyFileNotValid"];
                            break;
                        }
                        else
                        {
                            DTTDataAvailability pd = new DTTDataAvailability();
                            var dttvalues          = values.Skip(2).Select(obj => obj.ToInt32()).ToArray();
                            pd.DataRecord = Conversion.IntToByte(dttvalues);
                            var test = Conversion.ByteToInt(pd.DataRecord);
                            pd.Easting      = values[0].ToInt32();
                            pd.Northing     = values[1].ToInt32();
                            pd.PartitionKey = fileName;
                            pd.RowKey       = string.Format("{0}-{1}", pd.Easting, pd.Northing);
                            listPD.Add(pd);
                        }
                    }
                    catch
                    {
                        this.PmseAssignmentLogger.Log(TraceEventType.Error, LoggingMessageId.PmseSyncGenericMessage, string.Format("Error in File:{0}, Line :{1}", fileName, line));
                        listPD = null;
                    }
                }

                if (listPD != null && listPD.Count > 0 && listPD.Select(obj => obj.RowKey).Distinct().Count() == listPD.Count)
                {
                    try
                    {
                        bool result = this.PmseSync.InsertPMSEUnscheduledAdjustment(listPD, Utils.GetRegionalTableName(Constants.UnscheduledAdjustmentsTableName));
                        if (result)
                        {
                            List <DTTDataAvailability> existingPMSEUnscheduledData = this.CommonDalc.FetchEntity <DTTDataAvailability>(Utils.GetRegionalTableName(Constants.UnscheduledAdjustmentsTableName), null);
                            if (existingPMSEUnscheduledData.Count > 0)
                            {
                                existingPMSEUnscheduledData = existingPMSEUnscheduledData.Where(obj => obj.PartitionKey != fileName).ToList();
                                this.CommonDalc.DeleteRecords(Constants.UnscheduledAdjustmentsTableName, existingPMSEUnscheduledData);
                            }

                            replyMessage = Utils.Configuration["mailBodySyncSuccessfully"];
                        }
                        else
                        {
                            replyMessage = Utils.Configuration["mailBodyServerError"];
                        }
                    }
                    catch
                    {
                        replyMessage = Utils.Configuration["mailBodyServerError"];
                    }
                }
                else
                {
                    replyMessage = Utils.Configuration["mailBodyFileNotValid"];
                    return(false);
                }

                return(true);
            }
            catch (Exception e)
            {
                replyMessage = Utils.Configuration["mailBodyFailToProcessFile"];
                this.PmseAssignmentLogger.Log(TraceEventType.Information, LoggingMessageId.PmseSyncGenericMessage, "Exception Occured while processing file  " + fileName + " Exception :- " + e.ToString());
                this.PmseAssignmentAuditor.Audit(auditId, AuditStatus.Failure, this.stopWatch.ElapsedMilliseconds, auditMethodName + "Exception Occured while processing file  " + fileName + " Exception :- " + e.ToString());
                return(false);
            }
        }