Beispiel #1
0
        public static void SetDams(List <Dam> dams)
        {
            bool       isChange = false;
            List <Dam> newDams  = new List <Dam>();

            System.Threading.Monitor.Enter(DAMCommon.CommonDams);
            foreach (Dam dam in dams)
            {
                if (DAMCommon.CommonDams.Where(d => d.ID == dam.ID).FirstOrDefault() == null)
                {
                    DAMCommon.CommonDams.Add(dam);
                    newDams.Add(dam);
                    isChange = true;
                }
            }
            System.Threading.Monitor.Exit(DAMCommon.CommonDams);

            if (isChange)
            {
                string        filePath   = AppDomain.CurrentDomain.BaseDirectory + "DamConfig.xml";
                XmlSerializer serialiser = new XmlSerializer(typeof(List <Dam>));
                using (StreamWriter writer = new StreamWriter(filePath))
                {
                    serialiser.Serialize(writer, DAMCommon.CommonDams);
                }
            }


            //add new
            foreach (Dam dam in newDams)
            {
                DAMCommon.SetDamDetail(dam);
            }
        }
        public static bool LoadDamInfo()
        {
            List <Dam> dams = DAMCommon.GetDamConfig();

            foreach (Dam dam in dams)
            {
                DAMCommon.SetDamDetail(dam);
            }

            if (DAMCommon.CommonDamDetails.Count == 0)
            {
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        public static void UploadERMFile()
        {
            UploadERMFileProcess();
            if (_UploadingTaskList.Count > _MaxThreadCount)
            {
                return;
            }
            //read xml, get dam

            //get reg status
            //load xml, read dam
            List <Dam> dams = DAMCommon.GetDamConfig();

            foreach (Dam dam in dams)
            {
                DAMCommon.SetDamDetail(dam);
            }

            if (DAMCommon.CommonDamDetails.Count == 0)
            {
                System.Threading.Monitor.Enter(_UploadingIDs);
                _UploadingIDs.Clear();
                System.Threading.Monitor.Exit(_UploadingIDs);

                System.Threading.Monitor.Enter(_UploadingTaskList);
                _UploadingTaskList.Clear();
                System.Threading.Monitor.Exit(_UploadingTaskList);
                return;
            }

            string scrInfo = Utilities.GetProcessID();

            _logger.Debug("scrInfo:" + scrInfo);
            try
            {
                foreach (DamDetail dam in DAMCommon.CommonDamDetails)
                {
                    //get task
                    using (var client = new HttpClient())
                    {
                        var parameters = String.Format("/api/v1/upload/uploadtasks/{0}", scrInfo);
                        _logger.Debug("url:" + dam.WebApiurl + parameters);
                        HttpResponseMessage response = client.GetAsync(dam.WebApiurl + parameters).Result;
                        if (response.IsSuccessStatusCode)
                        {
                            var result = response.Content.ReadAsAsync <List <UploadFileTaskWorkDto> >().Result;
                            foreach (UploadFileTaskWorkDto uploadFileTaskWorkDto in result)
                            {
                                UploadTask uploadTask = new UploadTask();
                                uploadTask.UniqueID = uploadFileTaskWorkDto.UniqueID;
                                uploadTask.UploadFileTaskWorkDto = uploadFileTaskWorkDto;
                                uploadTask.Dam = dam;
                                System.Threading.Monitor.Enter(_UploadingTaskList);
                                if (_UploadingTaskList.Where(t => t.UniqueID == uploadFileTaskWorkDto.UniqueID).FirstOrDefault() == null)
                                {
                                    _UploadingTaskList.Add(uploadTask);
                                    _logger.Debug("new task:" + uploadFileTaskWorkDto.UniqueID);
                                }
                                System.Threading.Monitor.Exit(_UploadingTaskList);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Threading.Monitor.Enter(_UploadingIDs);
                _UploadingIDs.Clear();
                System.Threading.Monitor.Exit(_UploadingIDs);

                System.Threading.Monitor.Enter(_UploadingTaskList);
                _UploadingTaskList.Clear();
                System.Threading.Monitor.Exit(_UploadingTaskList);
                _logger.Error("UploadERMFile error:" + ex.ToString());
            }
        }