Пример #1
0
        private void downloadPayloads(int mid)
        {
            lock (_lockObj) {
                int taskId = 0;

                do
                {
                    using (var db = new ATTDbContext()) {
                        SqlParameter para1 = new SqlParameter("mid", mid);
                        SqlParameter para2 = new SqlParameter("tid", System.Data.SqlDbType.Int);
                        para2.Direction = System.Data.ParameterDirection.Output;
                        db.Database.ExecuteSqlCommand("exec SP_GetTaskId @mid, @tid output", para1, para2);
                        taskId = int.Parse(para2.Value.ToString());
                    }


                    if (taskId > 0)
                    {
                        var t = getPayloadsDownloadTask(taskId);
                        t.AppendTo(allPayloadsTasks);
                    }


                    if (allPayloadsTasks.Count >= 5)
                    {
                        int tid = Task.WaitAny(allPayloadsTasks.ToArray());
                    }
                }while (taskId > 0);
            }

            Task.WaitAll(allPayloadsTasks.ToArray());
        }
Пример #2
0
        public void Upload()
        {
            using (var db = new ATTDbContext()) {
                var msgIds = db.MsgIDs.Include(m => m.ProAwsys).Where(m => m.TaskId == _data.TaskId &&
                                                                      m.IsNeedTransform == true &&
                                                                      m.IsSend == false &&
                                                                      m.ProAwsysId != null).ToList();
                var          iDocTypeIds   = msgIds.GroupBy(g => g.IDocTypeId).Select(g => g.Key).ToList();
                var          SourceIds     = msgIds.GroupBy(g => g.ProAwsys.SourceId).Select(g => g.Key).ToList();
                var          senderConfigs = db.SenderConfigs.Where(c => iDocTypeIds.Contains(c.IDocTypeId) && SourceIds.Contains(c.SourceId)).ToList();
                ProgressInfo info          = new ProgressInfo(1, msgIds.Count, "");
                foreach (var item in msgIds)
                {
                    var    senderConfig = senderConfigs.Where(c => c.IDocTypeId == item.IDocTypeId && c.SourceId == item.ProAwsys.SourceId).First();
                    string msg          = $"MsgID:{item.MsgId} sent to interface:{senderConfig.senderinterface} component:{senderConfig.itgsendercomponent}";
                    ATTPayLoadsLog.Write(_data.GetLog(msg, LogType.Normal));

                    send(item, senderConfig);
                    item.IsSend = true;
                    item.SentDt = DateTime.UtcNow;
                    info.Msg    = item.MsgId;
                    _stepReporter.Report(info);
                    info.Current++;
                    ATTPayLoadsLog.Write(_data.GetLog(msg, LogType.Success));
                }

                ATTPayLoadsLog.Write(_data.GetLog(_data.UpdateMsgLog, LogType.Normal));

                db.SaveChanges();
                ATTPayLoadsLog.Write(_data.GetLog(_data.UpdateMsgLog, LogType.Success));
            }
        }
Пример #3
0
        public void CopyAndTransform()
        {
            ATTPayLoadsLog.Write(_data.GetLog(_data.GetXPathConfigLog, LogType.Normal));

            using (var db = new ATTDbContext()) {
                var para = new SqlParameter("TaskId", _data.TaskId);

                var xPathConfigs = db.Database.SqlQuery <ATT.Data.VW_EDITransFormConfig>("exec SP_GetXPathConfig @TaskId", para).ToList();
                ATTPayLoadsLog.Write(_data.GetLog(_data.GetXPathConfigLog, LogType.Success));

                ATTPayLoadsLog.Write(_data.GetLog(_data.UpdateTransformConfigLog, LogType.Normal));

                para = new SqlParameter("TaskId", _data.TaskId);
                db.Database.ExecuteSqlCommand("exec SP_UpdateTransform @TaskId", para);
                ATTPayLoadsLog.Write(_data.GetLog(_data.UpdateTransformConfigLog, LogType.Success));

                ATTPayLoadsLog.Write(_data.GetLog(_data.TransformLog, LogType.Normal));
                var msgIds = db.MsgIDs.Where(m => m.TaskId == _data.TaskId && m.MsgId != null).ToList();

                if (msgIds.Count > 0)
                {
                    foreach (var k in msgIds)
                    {
                        var configs = xPathConfigs.Where(x => x.IDocTypeId == k.IDocTypeId && x.ProAwsysId == k.ProAwsysId);
                        transformFile(configs, k);
                    }
                    db.SaveChanges();
                }
                ATTPayLoadsLog.Write(_data.GetLog(_data.TransformLog, LogType.Success));
            }
        }
Пример #4
0
        //private List<Task> allPayloadsTasks;

        public ATTUpload()
        {
            _db = new ATTDbContext();

            allTasks         = new List <Task>();
            allPayloadsTasks = new List <Task>();
        }
Пример #5
0
        private void runTask()
        {
            _data.GetNext();

            var mission = new Missions()
            {
                StartDt   = _data.Start,
                StartHour = _data.Start.Hour
            };

            using (var db = new ATTDbContext()) {
                db.Missions.Add(mission);
                db.SaveChanges();
            }

            _data.Mid = mission.Id;

            _start = DateTime.Now;

            _data.Mid = mission.Id;


            var newMission = new MissionVM();

            newMission.Id    = mission.Id;
            newMission.Start = _start;
            dg_Status.Dispatcher.BeginInvoke(new Action(() => _missions.Add(newMission)));

            script.Run(_data);


            newMission.IsComplete = true;
        }
Пример #6
0
        public void Download()
        {
            List <MsgIDs> edikeys = null;

            var log = _data.GetLog(_data.GetTaskIdLog, LogType.Normal);

            ATTPayLoadsLog.Write(log);


            using (var db = new ATTDbContext()) {
                edikeys = db.MsgIDs.Where(m => m.TaskId == _data.TaskId && m.IsDownload == false).ToList();
            }

            log = _data.GetLog(_data.GetTaskIdLog, LogType.Success);
            ATTPayLoadsLog.Write(log);

            if (edikeys.Count > 0)
            {
                log = _data.GetLog(_data.DownloadFileLog, LogType.Normal);
                ATTPayLoadsLog.Write(log);

                string postData = "msgids=";

                foreach (var edikey in edikeys)
                {
                    postData += edikey.MsgId + Environment.NewLine;
                }

                postData += "&lastVersion=false&fullEnvelope=false";

                downloadFile(postData);

                ATTPayLoadsLog.Write(_data.GetLog(_data.DownloadFileLog, LogType.Success));
            }
        }
Пример #7
0
        private async void loadData()
        {
            _db = new ATTDbContext();
            dg_Interfaces.ItemsSource = null;
            var data = await Task.Run(() => _db.SAPInterfaces.ToList());

            viewModels = new List <InterfaceVM>();
            data.ForEach(s => viewModels.Add(new InterfaceVM(s)));
            dg_Interfaces.ItemsSource = viewModels;
        }
Пример #8
0
 public void ReadFile()
 {
     if (File.Exists(_file))
     {
         var msgId_ITGs = Tools.GetDataEntites <MsgIDs_ITG>(_file);
         using (var db = new ATTDbContext()) {
             db.MsgIDs_ITG.AddRange(msgId_ITGs);
             db.SaveChanges();
         }
     }
 }
Пример #9
0
 public void UploadFile()
 {
     if (File.Exists(_data.File))
     {
         var idoc_ITGS = Tools.GetDataEntites <IDocNumbers_ITG>(_data.File);
         using (var db = new ATTDbContext()) {
             db.IDocNumbers_ITG.AddRange(idoc_ITGS);
             db.SaveChanges();
         }
         File.Delete(_data.File);
     }
 }
Пример #10
0
        public App()
        {
            using (ATTDbContext db = new ATTDbContext()) {
                SqlParameter para = new SqlParameter("@cid", SqlDbType.Int);
                para.Direction = ParameterDirection.Output;
                db.Database.ExecuteSqlCommand("exec sp_GetClient @cid output", para);
                ClientId = int.Parse(para.Value.ToString());

                SqlParameter para1 = new SqlParameter("@cid", ((App)App.Current).ClientId);
                db.Database.ExecuteSqlCommand("exec sp_UpdateMissionInterfaces @cid", para1);
            }
        }
Пример #11
0
        //static object GetConfigData<T>(ATTTask task) {
        //    string xmlData = null;
        //    string typeName = null;
        //    using(var db = new ATTDbContext()) {
        //        var tData = db.TaskDataConfigs.Single(t => t.AttTask == task);
        //        xmlData = tData.Data;
        //        typeName = tData.TypeName;
        //    }

        //    var tp = typeof(T);

        //    StringReader sr = new StringReader(xmlData);

        //    XmlSerializer xs = new XmlSerializer(tp);
        //    var obj = xs.Deserialize(sr);
        //    return obj;

        //}

        public static void SetConfigData <T>(T data)
        {
            using (var db = new ATTDbContext()) {
                var           tData    = db.TaskDataConfigs.Single(t => t.TypeName == typeof(T).FullName);
                var           typeName = tData.TypeName;
                XmlSerializer xs       = new XmlSerializer(typeof(T));
                StringBuilder sb       = new StringBuilder();
                StringWriter  sw       = new StringWriter(sb);
                xs.Serialize(sw, data);
                tData.Data = sb.ToString();
                db.SaveChanges();
            }
        }
Пример #12
0
        public static T GetConfigData <T>()
        {
            string xmlData = null;

            using (var db = new ATTDbContext()) {
                var tData = db.TaskDataConfigs.Single(t => t.TypeName == typeof(T).FullName);
                xmlData = tData.Data;
            }
            StringReader  sr = new StringReader(xmlData);
            XmlSerializer xs = new XmlSerializer(typeof(T));

            var obj = xs.Deserialize(sr);

            return((T)obj);
        }
Пример #13
0
        public void DispatchTask()
        {
            using (var db = new ATTDbContext()) {
                var p1 = new SqlParameter("patchSize", GlobalConfig.DownloadPatchSize);
                var p2 = new SqlParameter("from", System.Data.SqlDbType.Int)
                {
                    Direction = System.Data.ParameterDirection.Output
                };
                var p3 = new SqlParameter("to", System.Data.SqlDbType.Int)
                {
                    Direction = System.Data.ParameterDirection.Output
                };
                db.Database.ExecuteSqlCommand("exec SP_DispatchTask @patchSize,@from output,@to output", p1, p2, p3);
                var         from          = int.Parse(p2.Value.ToString());
                var         to            = int.Parse(p3.Value.ToString());
                List <Task> payloadsTasks = new List <Task>();
                int         count         = 0;

                if (from > to)
                {
                    throw new BreakException("No Data Found");
                }


                for (int i = from; i <= to; i++)
                {
                    if (count >= 5)
                    {
                        int tid = Task.WaitAny(payloadsTasks.ToArray());
                        payloadsTasks.RemoveAt(tid);
                    }
                    int  a = i;
                    Task t = GetDownloadAndUpdateTask(a);
                    payloadsTasks.Add(t);
                    count++;
                }



                Task.WaitAll(payloadsTasks.ToArray());

                //ExitWithMsg($"Download and Update Finished from {from} to {to}");
            }
        }
Пример #14
0
        public void UpdateEDIKeyInfo()
        {
            List <IDocTypes> iDocTypes = null;

            List <ProAwsys> proAwsys = null;

            ATTPayLoadsLog.Write(_data.GetLog(_data.UploadLog, LogType.Normal));

            using (var db = new ATTDbContext()) {
                iDocTypes = db.IDocTypes.Where(i => i.Name != null).ToList();
                proAwsys  = db.ProAwsys.Where(p => p.Name != null).ToList();

                var msgIds = db.MsgIDs.Where(m => m.TaskId == _data.TaskId).ToList();
                foreach (var i in msgIds)
                {
                    if (dic.ContainsKey(i.MsgId))
                    {
                        var iDocType = iDocTypes.Where(s => s.Name.Trim().ToLower() == dic[i.MsgId].IDocType.Trim().ToLower()).FirstOrDefault();

                        if (iDocType == null)
                        {
                            iDocType = new IDocTypes()
                            {
                                Name = dic[i.MsgId].IDocType
                            };
                            db.IDocTypes.Add(iDocType);
                            i.IDocTypes = iDocType;
                        }
                        else
                        {
                            i.IDocTypeId = iDocType.Id;
                        }

                        //i.IDocTypeId = iDocTypes.Where(s => s.Name.Trim().ToLower() == dic[i.MsgId].IDocType.Trim().ToLower()).FirstOrDefault()?.Id;
                        i.ProAwsysId = proAwsys.Where(s => s.Name.Trim().ToLower() == dic[i.MsgId].Awsys?.Trim().ToLower()).FirstOrDefault()?.Id;
                        i.IsDownload = true;
                        i.DownloadDt = _downloadDt;
                    }
                }

                db.SaveChanges();
                ATTPayLoadsLog.Write(_data.GetLog(_data.UploadLog, LogType.Success));
            }
            #region Hide
            //using (var db = new ATT.Data.AttDbContext()) {
            //    using (var transaction = db.Database.BeginTransaction()) {
            //        foreach (var item in dic) {
            //            var ediKey = db.Database.SqlQuery<MsgIDs>("exec SP_UpdateSource @id,@Awsys,@IDocType,@DownloadDt",
            //                new SqlParameter("id", item.Value.Id),
            //                new SqlParameter("Awsys", item.Value.Awsys),
            //                new SqlParameter("IDocType", item.Value.IDocType),
            //                new SqlParameter("DownloadDt", _downloadDtUtc)).SingleOrDefault();

            //            if (ediKey != null)
            //                ediKeys.Add(ediKey);
            //        }
            //        try {
            //            transaction.Commit();
            //        }
            //        catch {
            //            transaction.Rollback();
            //        }
            //    }
            //}
            #endregion
        }
Пример #15
0
        public void GetMessageId()
        {
            _data.NewGuid(_data.SAPInterface.Name);
            sap.Session.StartTransaction("ZIDOCAUDREP");
            if (sap.PopupWindow != null)
            {
                sap.PopupWindow.FindDescendantByProperty <GuiRadioButton>((r => r.Text.Contains("Continue With"))).Select();
                sap.PopupWindow.FindDescendantByProperty <GuiButton>(r => r.Text.Contains("Confirm Selection")).Press();
            }


            // Fill Control/Status Record Search
            sap.MainWindow.FindByName <GuiCTextField>("S_CREDAT-LOW").Text = _data.Start.ToString("dd.MM.yyyy");
            //DateTime toDate = _data.Start.AddHours(_data.StartTime + _data.Interval);
            sap.MainWindow.FindByName <GuiCTextField>("S_CREDAT-HIGH").Text = _data.GetEnd().ToString("dd.MM.yyyy");


            sap.MainWindow.FindByName <GuiCTextField>("S_CRETIM-LOW").Text  = _data.Start.ToString("HH:mm:ss");
            sap.MainWindow.FindByName <GuiCTextField>("S_CRETIM-HIGH").Text = _data.End;

            sap.MainWindow.FindByName <GuiCTextField>("S_SNDPRN-LOW").Text = _data.SAPInterface.PartnerNumber;
            sap.MainWindow.FindByName <GuiTextField>("S_STAMID-LOW").Text  = "*";
            sap.MainWindow.FindByName <GuiCTextField>("S_STATUS-LOW").Text = _data.IDocStatus;
            sap.MainWindow.FindByName <GuiCTextField>("P_DIRECT").Text     = "2";


            // Fill Message Type
            sap.MainWindow.FindByName <GuiRadioButton>("R_ACCDOC").Select();
            sap.MainWindow.FindByName <GuiCTextField>("S_MESTYP-LOW").Text = "ACC_DOCUMENT";

            sap.MainWindow.FindByName <GuiTextField>("S_MESFCT-LOW").SetFocus();
            sap.MainWindow.SendKey(SAPKeys.F2);
            sap.PopupWindow.FindDescendantByProperty <GuiGridView>().SelectedRows = "0";
            sap.PopupWindow.FindByName <GuiButton>("btn[0]").Press();
            sap.MainWindow.FindByName <GuiTextField>("S_MESFCT-LOW").Text = _data.SAPInterface.MsgFunction;

            //Fill IDoc Data Segments
            sap.MainWindow.FindByName <GuiButton>("%_S_BUKRS_%_APP_%-VALU_PUSH").Press();
            sap.PopupWindow.FindDescendantByProperty <GuiTableControl>().SetBatchValues(_data.SAPInterface.SAPCompanyCodes.Select(c => c.Name).ToList());
            sap.PopupWindow.FindByName <GuiButton>("btn[8]").Press();

            sap.MainWindow.FindByName <GuiButton>("%_S_BLART_%_APP_%-VALU_PUSH").Press();
            sap.PopupWindow.FindDescendantByProperty <GuiTableControl>().SetBatchValues(_data.SAPInterface.SAPDocTypes.Select(c => c.Name).ToList());
            sap.PopupWindow.FindByName <GuiButton>("btn[8]").Press();

            //Fill Download Option
            sap.MainWindow.FindByName <GuiCheckBox>("P_DOWNLD").Selected = true;

            sap.MainWindow.FindByName <GuiTextField>("P_CPATH").Text = _data.IDocReportFile;

            //Report Output Options
            sap.MainWindow.FindByName <GuiRadioButton>("P_DOC").Select();

            sap.MainWindow.FindByName <GuiButton>("btn[8]").Press();

            if (sap.PopupWindow != null)
            {
                sap.PopupWindow.FindByName <GuiButton>("btn[0]").Press();
            }


            if (File.Exists(_data.IDocReportFile))
            {
                var docs = Tools.GetDataEntites <IDoc>(_data.IDocReportFile);
                if (docs != null && docs.Count > 0)
                {
                    using (db = new ATTDbContext()) {
                        docs.ForEach(i => db.IDocNumbers.Add(i.GetATTIDoc()));
                        db.SaveChanges();
                    }
                    File.Delete(_data.IDocReportFile);
                }

                sap.Session.StartTransaction("SE16");
                sap.MainWindow.FindByName <GuiCTextField>("DATABROWSE-TABLENAME").Text = "EDIDC";
                sap.MainWindow.SendKey(SAPKeys.Enter);
                sap.MainWindow.FindByName <GuiButton>("%_I1_%_APP_%-VALU_PUSH").Press();
                sap.PopupWindow.FindDescendantByProperty <GuiTableControl>().SetBatchValues(docs.Select(d => d.IDocNumber).ToList());

                sap.PopupWindow.FindByName <GuiButton>("btn[8]").Press();


                sap.MainWindow.FindByName <GuiTextField>("MAX_SEL").Text = "";
                sap.MainWindow.FindByName <GuiButton>("btn[8]").Press();

                string cols = "EDI Archive Key,IDoc number";
                sap.Export("wnd[0]/mbar/menu[0]/menu[10]/menu[3]/menu[2]", cols, _data.EDIKeyFile);


                if (File.Exists(_data.EDIKeyFile))
                {
                    var msgIds = Tools.GetDataEntites <ATTMsg>(_data.EDIKeyFile, '|');
                    if (msgIds != null && msgIds.Count > 0)
                    {
                        using (db = new ATTDbContext()) {
                            msgIds.ForEach(a => {
                                var attmsg         = a.GetATTMsg();
                                attmsg.CreateDt    = DateTime.UtcNow;
                                attmsg.InterfaceId = _data.SAPInterface.Id;
                                attmsg.Mid         = _data.Mid;
                                db.MsgIDs.Add(attmsg);
                            });
                            db.SaveChanges();
                        }
                        File.Delete(_data.EDIKeyFile);
                    }
                }
            }

            sap.CloseSession();
        }