Ejemplo n.º 1
0
        protected override void Load()
        {
            base.Load();

            ConnectHelper.SyncData();

            if (!HasValidLicense())
            {
                return;
            }

            var settingsRepository = GetInstance <ISettingsRepository <WorkshopSettings> >();
            var workshopSettings   = settingsRepository.GetWorkshopSettings();

            if (workshopSettings.IsStatusReportCheckEnabled)
            {
                var allTechnicians = GetInstance <IRepository <Technician> >().Where(c => c.Deleted == null).ToList();
                var statusReport   = new StatusReportViewModel(allTechnicians);
                if (!statusReport.IsUpToDate())
                {
                    if (ShowWarning(Resources.TXT_INFO_OUT_OF_DATE, Resources.TXT_OUT_OF_DATE_TITLE, MessageBoxButton.YesNo))
                    {
                        statusReport.GenerateStatusReport();
                        workshopSettings.CentreQuarterlyCheckDate = DateTime.Now.Date;
                        settingsRepository.Save(workshopSettings);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ISHES proxy = ConnectHelper.ConnectToSHES();
            List <Dictionary <String, Double> > measurementsForDay = proxy.GetInfoForDate(GraphDate.SelectedValue.ToString());

            Dictionary <String, Double> solarPanelProduction = measurementsForDay[0];

            ((LineSeries)chart.Series[0]).ItemsSource = solarPanelProduction;

            Dictionary <String, Double> batteryConsumptionProduction = measurementsForDay[1];

            ((LineSeries)chart.Series[1]).ItemsSource = batteryConsumptionProduction;

            Dictionary <String, Double> powerFromUtility = measurementsForDay[2];

            ((LineSeries)chart.Series[2]).ItemsSource = powerFromUtility;

            Dictionary <String, Double> powerToUtility = measurementsForDay[3];

            ((LineSeries)chart.Series[3]).ItemsSource = powerToUtility;

            Dictionary <String, Double> totalConsumption = measurementsForDay[4];

            ((LineSeries)chart.Series[4]).ItemsSource = totalConsumption;

            Dictionary <String, Double> powerPrice = measurementsForDay[5];

            ((LineSeries)chart.Series[5]).ItemsSource = powerPrice;

            Dictionary <String, Double> moneyBalance = measurementsForDay[6];

            ((LineSeries)chart.Series[6]).ItemsSource = moneyBalance;
        }
Ejemplo n.º 3
0
        protected override void Add()
        {
            if (Document.Created == default(DateTime))
            {
                Document.Created = DateTime.Now;
            }

            if (Document.CalibrationTime == null)
            {
                Document.CalibrationTime = DateTime.Now;
            }

            if (SelectedCustomerContact == null)
            {
                CustomerContactRepository.Add(new CustomerContact
                {
                    Name = Document.CustomerContact
                });
            }

            AddInspectionInfoCommand.Execute(null);

            TachographDocumentRepository.AddOrUpdate(Document);
            ConnectHelper.Upload(Document);
        }
Ejemplo n.º 4
0
        static void ConnectCallback(IAsyncResult asyncres)
        {
            ConnectHelper hlp = asyncres.AsyncState as ConnectHelper;

            lock (hlp.Mutex)
            {
                hlp.CallbackDone = true;

                try
                {
                    if (hlp.Client.Client != null)
                    {
                        hlp.Client.EndConnect(asyncres);
                    }
                }
                catch (SocketException)
                {
                    // catch that away
                }

                if (hlp.DoCleanup)
                {
                    asyncres.AsyncWaitHandle.Close();
                    if (hlp.Client is IDisposable)
                    {
                        ((IDisposable)hlp.Client).Dispose();
                    }
                    hlp.Client = null;
                }
            }
        }
Ejemplo n.º 5
0
        // 关闭client
        private void Close()
        {
            server.RemoveClient(this);            //Server中移除对自身的管理
            ConnectHelper.Close(mySqlConnection); //关闭和数据库的连接

            if (clientSocket != null)             //关闭和客户端通信的socket
            {
                clientSocket.Close();
                Debug.Log("关闭客户端连接");
            }

            //如果在房间中,对房间进行处理
            //如果是房主,关闭所在的房间
            //如果不是房主,从房间中把自身移除
            //todo,最好在server中统一处理客户端关闭的其他逻辑
            if (room == null)
            {
                return;
            }

            if (IsOwner())
            {
                room.Close();
            }
            else
            {
                room.RemoveClient(this);
            }
        }
Ejemplo n.º 6
0
        private static void Driving(ElectricVehicleCharger evc, double drivingHours)
        {
            double drivingMinutes = drivingHours * Constants.MINUTES_IN_HOUR;

            int iterationStart = ConnectHelper.ConnectUniversalClock().GetTimeInMinutes();
            int dayStart       = ConnectHelper.ConnectUniversalClock().GetDay();

            do
            {
                int currentMoment = ConnectHelper.ConnectUniversalClock().GetTimeInMinutes();
                int currentDay    = ConnectHelper.ConnectUniversalClock().GetDay();
                if (currentDay > dayStart || currentMoment - iterationStart >= 1)
                {
                    iterationStart = currentMoment;
                    dayStart       = currentDay;
                }
                else
                {
                    continue;
                }

                ElectricVehicleCharger evcFromDb = DBManager.S_Instance.GetSingleElectricVehicleCharger(evc.BatteryID);
                double capacityChange            = evcFromDb.CurrentCapacity * Constants.MINUTES_IN_HOUR - 1;
                evcFromDb.CurrentCapacity = Math.Round(capacityChange / Constants.MINUTES_IN_HOUR, 2);
                DBManager.S_Instance.UpdateElecticVehicleCharger(evcFromDb);
                drivingMinutes--;
            }while (drivingMinutes > 0);
        }
Ejemplo n.º 7
0
        public BaseCNCResultModel <ReadProgramListItemResultModel> ReadProgramList(string folder)
        {
            ushort flib = 0;
            var    ret  = ConnectHelper.BuildConnect(ref flib, m_ip, m_port, m_timeout);

            if (ret == 0)
            {
                var res = new List <ReadProgramListItemResultModel>();

                var ret_1 = new ProgramListHelper().ReadProgramList(flib, folder, ref res);
                ConnectHelper.FreeConnect(flib);

                if (ret_1.Item1 == 0)
                {
                    return(new BaseCNCResultModel <ReadProgramListItemResultModel>()
                    {
                        Value = res, ErrorMessage = ret_1.Item2
                    });
                }
                else
                {
                    return(new BaseCNCResultModel <ReadProgramListItemResultModel>()
                    {
                        ErrorMessage = ret_1.Item2
                    });
                }
            }
            else
            {
                return(new BaseCNCResultModel <ReadProgramListItemResultModel>()
                {
                    ErrorMessage = "获得程序列表失败,连接失败"
                });
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Utility: Hello world!");

            PowerPrice_Server server = new PowerPrice_Server();

            server.Open();
            Thread.Sleep(Constants.WAITING_TIME);

            double price = 0;
            double hourOfTheDay;

            double USDToRSDRatio = 101.94;
            double highPrice     = 7.117 / USDToRSDRatio;
            double lowPrice      = 2.372 / USDToRSDRatio;

            while (true)
            {
                hourOfTheDay = ConnectHelper.ConnectUniversalClock().GetTimeInHours();
                price        = (hourOfTheDay >= 1.0 && hourOfTheDay < 7.0) ? lowPrice : highPrice;

                Console.WriteLine($"Price of kwh ($/kwh): {Math.Round(price, 5)}   time[{hourOfTheDay}]");
                Thread.Sleep(500);
            }
        }
Ejemplo n.º 9
0
        private string ReadFeedrateHandle(ref ushort flib, string para)
        {
            string message = null;

            var res = new ReadFeedrateResultModel();

            var ret = new FeedrateHelper().ReadFeedrate(flib, ref res);

            if (ret.Item1 == -16)
            {
                var ret_conn = ConnectHelper.BuildConnect(ref flib, m_ip, m_port, m_timeout);

                if (ret_conn == 0)
                {
                    ret = new FeedrateHelper().ReadFeedrate(flib, ref res);
                }
            }

            if (ret.Item1 != 0)
            {
                message = ret.Item2;
            }
            GetResultEvent?.Invoke(new BaseCNCResultModel <ReadFeedrateResultModel>()
            {
                Value = new List <ReadFeedrateResultModel>()
                {
                    res
                }, Id = para
            });

            return(message);
        }
 public void StartTask()
 {
     Task.Run(() =>
     {
         CurrentPower = CalculatePower(ConnectHelper.ConnectWeatherForecast(), ConnectHelper.ConnectUniversalClock().GetTimeInHours());
         DBManager.S_Instance.UpdateSolarPanel(this);
     });
 }
Ejemplo n.º 11
0
        private string ReadPositionHandle(ref ushort flib, string para)
        {
            string message = null;

            var paraModel = JsonConvert.DeserializeObject <ReadPositionModel>(para);
            var res       = new List <ReadPositionResultItemModel>();

            Dictionary <CncPositionTypeEnum, int[]> datas = new Dictionary <CncPositionTypeEnum, int[]>();

            foreach (var item in paraModel.Readers)
            {
                int[] data = new int[Focas1.MAX_AXIS];
                var   ret  = new PositionHelper().ReadPositionRange(flib, item.PositionType, ref data);
                if (ret.Item1 == -16 || ret.Item1 == -8)
                {
                    var ret_conn = ConnectHelper.BuildConnect(ref flib, m_ip, m_port, m_timeout);

                    if (ret_conn == 0)
                    {
                        ret = new PositionHelper().ReadPositionRange(flib, item.PositionType, ref data);
                    }
                }

                if (ret.Item1 == 0)
                {
                    datas.Add(item.PositionType, data);
                }
            }

            foreach (var item in paraModel.Decompilers)
            {
                int    data    = 0;
                string ret_dec = "";
                if (datas.ContainsKey(item.PositionType))
                {
                    ret_dec = new PositionHelper().DecompilerReadPositionInfo(datas[item.PositionType], item, ref data);
                }

                if (ret_dec != null)
                {
                    message = ret_dec;
                }
                else
                {
                    res.Add(new ReadPositionResultItemModel()
                    {
                        Id    = item.Id,
                        Value = (double)data / m_increment
                    });
                }
            }
            GetResultEvent?.Invoke(new BaseCNCResultModel <ReadPositionResultItemModel>()
            {
                Value = res, Id = ""
            });

            return(message);
        }
Ejemplo n.º 12
0
        private string ReadPmcHandle(ref ushort flib, string para)
        {
            string message = null;

            var paraModel = JsonConvert.DeserializeObject <ReadPmcModel>(para);
            var res       = new List <ReadPmcResultItemModel>();

            Dictionary <short, int[]> datas = new Dictionary <short, int[]>();

            foreach (var item in paraModel.Readers)
            {
                int[] data = new int[item.DwordQuantity];
                var   ret  = new PmcHelper().ReadPmcRange(flib, item.AdrType, item.StartNum, item.DwordQuantity, ref data);
                if (ret.Item1 == -16 || ret.Item1 == -8)
                {
                    var ret_conn = ConnectHelper.BuildConnect(ref flib, m_ip, m_port, m_timeout);

                    if (ret_conn == 0)
                    {
                        ret = new PmcHelper().ReadPmcRange(flib, item.AdrType, item.StartNum, item.DwordQuantity, ref data);
                    }
                }

                if (ret.Item1 == 0)
                {
                    datas.Add(item.AdrType, data);
                }
            }

            foreach (var item in paraModel.Decompilers)
            {
                string data    = "";
                string ret_dec = "";
                if (datas.ContainsKey(item.AdrType))
                {
                    ret_dec = new PmcHelper().DecompilerReadPmcInfo(datas[item.AdrType], item, ref data);
                }
                // var ret_dec = PmcHelper.DecompilerReadPmcInfo(datas[item.AdrType], item, ref data);
                if (ret_dec != null)
                {
                    message = ret_dec;
                }
                else
                {
                    res.Add(new ReadPmcResultItemModel()
                    {
                        Id    = item.Id,
                        Value = data
                    });
                }
            }
            GetResultEvent?.Invoke(new BaseCNCResultModel <ReadPmcResultItemModel>()
            {
                Value = res, Id = ""
            });
            return(message);
        }
        public static void BatteryBehavior()
        {
            Double hourOfTheDay;

            int iterationStart = ConnectHelper.ConnectUniversalClock().GetTimeInMinutes();
            int dayStart       = ConnectHelper.ConnectUniversalClock().GetDay();

            while (true)
            {
                int currentMoment = ConnectHelper.ConnectUniversalClock().GetTimeInMinutes();
                int currentDay    = ConnectHelper.ConnectUniversalClock().GetDay();
                if (currentDay > dayStart || currentMoment - iterationStart >= 1)
                {
                    iterationStart = currentMoment;
                    dayStart       = currentDay;
                }
                else
                {
                    continue;
                }

                Dictionary <string, Battery> batteries = DBManager.S_Instance.GetAllBatteries();
                hourOfTheDay = ConnectHelper.ConnectUniversalClock().GetTimeInHours();

                if (hourOfTheDay >= 3 && hourOfTheDay <= 6)
                {
                    batteries = ChargeBatteries(batteries);
                }
                else if (hourOfTheDay >= 14 && hourOfTheDay <= 17)
                {
                    batteries = DischargeBatteries(batteries);
                }
                else
                {
                    foreach (Battery b in batteries.Values)
                    {
                        if (b is ElectricVehicleCharger evc)
                        {
                            if (evc.Mode == EMode.CONSUMING && evc.OnCharger)
                            {
                                evc.Consuming();
                                continue;
                            }
                        }

                        b.Mode = EMode.NONE;
                    }
                }

                foreach (Battery b in batteries.Values)
                {
                    DBManager.S_Instance.UpdateBattery(b);
                }
                //Thread.Sleep(Constants.MILISECONDS_IN_MINUTE);
            }
        }
Ejemplo n.º 14
0
        protected override void Add()
        {
            if (IsReadOnly)
            {
                return;
            }

            Document.Created = DateTime.Now;
            UndownloadabilityRepository.Add(Document);
            ConnectHelper.Upload(Document);
        }
        protected override void Add()
        {
            if (IsHistoryMode)
            {
                return;
            }

            Document.Created = DateTime.Now;
            LetterForDecommissioningRepository.Add(Document);
            ConnectHelper.Upload(Document);
        }
Ejemplo n.º 16
0
        public override void Open()
        {
            if (IsOpen)
            {
                throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected");
            }

            if (String.IsNullOrEmpty(host))
            {
                throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host");
            }

            if (port <= 0)
            {
                throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open without port");
            }

            if (client == null)
            {
                InitSocket();
            }

            if (timeout == 0)            // no timeout -> infinite
            {
                client.Connect(host, port);
            }
            else                        // we have a timeout -> use it
            {
                ConnectHelper hlp        = new ConnectHelper(client);
                IAsyncResult  asyncres   = client.BeginConnect(host, port, new AsyncCallback(ConnectCallback), hlp);
                bool          bConnected = asyncres.AsyncWaitHandle.WaitOne(timeout) && client.Connected;
                if (!bConnected)
                {
                    lock (hlp.Mutex)
                    {
                        if (hlp.CallbackDone)
                        {
                            asyncres.AsyncWaitHandle.Close();
                            client.Close();
                        }
                        else
                        {
                            hlp.DoCleanup = true;
                            client        = null;
                        }
                    }
                    throw new TTransportException(TTransportException.ExceptionType.TimedOut, "Connect timed out");
                }
            }

            inputStream  = client.GetStream();
            outputStream = client.GetStream();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 业务逻辑处理
        /// </summary>
        /// <returns>false:中断后面的方式执行并返回Error</returns>
        public override bool TakeAction()
        {
            int errorCnt;

            ConnectHelper.SendResultToConnect(actionGetter, _userSid.Split(';'), out errorCnt);
            if (errorCnt > 0)
            {
                TraceLog.WriteWarn("Action101 error,UserSid:{0},errorCnt:{1}", _userSid, errorCnt);
            }
            //
            IsNotRespond = true;
            return(true);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 业务逻辑处理
        /// </summary>
        /// <returns>false:中断后面的方式执行并返回Error</returns>
        public override bool TakeAction()
        {
            int errorCnt;

            ConnectHelper.BroadcastAll(actionGetter, out errorCnt);
            if (errorCnt > 0)
            {
                TraceLog.WriteWarn("Action105 error,errorCnt:{0}", errorCnt);
            }
            //
            IsNotRespond = true;
            return(true);
        }
        public static void CollectingMeasurements()
        {
            int iterationStart = ConnectHelper.ConnectUniversalClock().GetTimeInMinutes();
            int dayStart       = ConnectHelper.ConnectUniversalClock().GetDay();

            while (true)
            {
                int currentMoment = ConnectHelper.ConnectUniversalClock().GetTimeInMinutes();
                int currentDay    = ConnectHelper.ConnectUniversalClock().GetDay();
                if (currentDay > dayStart || currentMoment - iterationStart >= 1)
                {
                    iterationStart = currentMoment;
                    dayStart       = currentDay;
                }
                else
                {
                    continue;
                }

                IPowerPrice            powerPriceProxy     = ConnectHelper.ConnectUtility();
                IUniversalClockService universalClockProxy = ConnectHelper.ConnectUniversalClock();

                Measurement currentMeasurement = new Measurement
                {
                    BatteryConsumption   = 0,
                    BatteryProduction    = 0,
                    ConsumersConsumption = 0,
                    SolarPanelProduction = 0,
                };

                Dictionary <string, Battery> batteries           = DBManager.S_Instance.GetAllBatteries();
                Dictionary <string, ElectricVehicleCharger> evcs = DBManager.S_Instance.GetAllElectricVehicleChargers();
                Dictionary <string, SolarPanel>             sps  = DBManager.S_Instance.GetAllSolarPanels();
                Dictionary <string, Consumer> consumers          = DBManager.S_Instance.GetAllConsumers();

                Measurement currentConsumptionMeasurement = CalculateCurrentConsumption(batteries, evcs, consumers);
                currentMeasurement.BatteryConsumption   = currentConsumptionMeasurement.BatteryConsumption;
                currentMeasurement.ConsumersConsumption = currentConsumptionMeasurement.ConsumersConsumption;

                Measurement currentProductionMeasurement = CalculateCurrentProduction(batteries, evcs, sps);
                currentMeasurement.SolarPanelProduction = currentProductionMeasurement.SolarPanelProduction;
                currentMeasurement.BatteryProduction    = currentMeasurement.BatteryProduction;

                currentMeasurement.PowerPrice   = powerPriceProxy.GetPowerPrice(universalClockProxy.GetTimeInHours());
                currentMeasurement.Day          = universalClockProxy.GetDay();
                currentMeasurement.HourOfTheDay = universalClockProxy.GetTimeInHours();

                DBManager.S_Instance.AddMeasurement(currentMeasurement);
                //Thread.Sleep(Constants.MILISECONDS_IN_MINUTE);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// The route handler for the request which connects the PhotoHunt
        /// user to Google+.
        /// </summary>
        /// <param name="context">The request/response context.</param>
        public override void ProcessRequest(HttpContext context)
        {
            User          user          = GetUser(context);
            ConnectHelper connectHelper = new ConnectHelper();

            if (user == null)
            {
                if (context.Request.Cookies[Properties.Resources.MOBILE_SESSION_COOKIEID] != null)
                {
                    context.Request.Cookies.Remove(Properties.Resources.MOBILE_SESSION_COOKIEID);
                }

                // Get the authorization code from the request POST body.
                StreamReader sr = new StreamReader(
                    context.Request.InputStream);
                string input = sr.ReadToEnd();

                TokenData td = (TokenData)(new TokenData().FromJson(input));

                // Manually perform the OAuth2 flow for now.
                // TODO(class) Use the library for code exchange once
                // "postmessage" no longer throws exceptions in URI.
                if (td.code != null)
                {
                    var authObject = ManualCodeExchanger.ExchangeCode(td.code);

                    // Create an authorization state from the returned token.
                    _authState = CreateState(
                        authObject.access_token, authObject.refresh_token,
                        DateTime.UtcNow,
                        DateTime.UtcNow.AddSeconds(authObject.expires_in));
                }
                else
                {
                    // Create an authorization state from the returned token.
                    _authState = CreateState(
                        td.access_token, td.refresh_token,
                        DateTime.UtcNow,
                        DateTime.UtcNow.AddSeconds(td.expires_in));
                }

                PhotoHunt.utils.ConnectHelper.VerifyToken(_authState);

                user = connectHelper.SaveTokenForUser(_authState);
                context.Session[Properties.Resources.CURRENT_USER_SESSION_KEY] = user.ToJson();
            }

            SendResponse(context, new JsonUser(user));
        }
Ejemplo n.º 21
0
 public override void Open()
 {
     if (IsOpen)
     {
         throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected");
     }
     if (String.IsNullOrEmpty(Host))
     {
         throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host");
     }
     if (Port <= 0)
     {
         throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open without port");
     }
     if (Client == null)
     {
         InitSocket();
     }
     if (_Timeout != 0)
     {
         var connectHelper = new ConnectHelper(Client);
         var t             = Client.ConnectAsync(Host, Port);
         t.Wait();
         //, new AsyncCallback(TSocket.ConnectCallback), connectHelper);
         //if ((!asyncResult.AsyncWaitHandle.WaitOne(this.timeout) ? true : !this.client.Connected))
         //{
         //    lock (connectHelper.Mutex)
         //    {
         //        if (!connectHelper.CallbackDone)
         //        {
         //            connectHelper.DoCleanup = true;
         //            this.client = null;
         //        }
         //        else
         //        {
         //            asyncResult.AsyncWaitHandle.Dispose();
         //            this.client.Dispose();
         //        }
         //    }
         //    throw new TTransportException(TTransportException.ExceptionType.TimedOut, "Connect timed out");
         //}
     }
     else
     {
         Client.ConnectAsync(Host, Port).Wait();
     }
     inputStream  = Client.GetStream();
     outputStream = Client.GetStream();
 }
Ejemplo n.º 22
0
        private void Close()
        {
            ConnectHelper.CloseConnection(mySqlConn);
            if (clientSocket != null)
            {
                Console.WriteLine("一个远程连接已关闭");

                clientSocket.Close();
                if (room != null)
                {
                    room.Close(this);
                }
                server.RemoveClient(this);
            }
        }
Ejemplo n.º 23
0
        private string ReadMacroHandle(ref ushort flib, string para)
        {
            string message = null;

            var paraModel = JsonConvert.DeserializeObject <ReadMacroModel>(para);
            var res       = new List <ReadMacroResultItemModel>();

            foreach (var item in paraModel.Readers)
            {
                var datas = new double[item.Quantity];

                var ret = new MacroHelper().ReadMacroRange(flib, item.StartNum, item.Quantity, ref datas);
                if (ret.Item1 == -16)
                {
                    var ret_conn = ConnectHelper.BuildConnect(ref flib, m_ip, m_port, m_timeout);

                    if (ret_conn == 0)
                    {
                        ret = new MacroHelper().ReadMacroRange(flib, item.StartNum, item.Quantity, ref datas);
                    }
                }
            }

            //foreach (var item in paraModel.Decompilers)
            //{
            //    double[] data = ;
            //    var ret_dec = MacroHelper.DecompilerReadMacroInfo(datas, item, ref data);
            //    if (ret_dec != null)
            //    {
            //        message = ret_dec;
            //    }
            //    else
            //    {
            //        res.Add(new ReadMacroResultItemModel()
            //        {
            //            Id = item.Id,
            //            Value = data
            //        });
            //    }
            //}
            GetResultEvent?.Invoke(new BaseCNCResultModel <ReadMacroResultItemModel>()
            {
                Value = res, Id = ""
            });

            return(message);
        }
Ejemplo n.º 24
0
        protected override void Add()
        {
            if (IsReadOnly || IsHistoryMode)
            {
                return;
            }

            Document.Created = DateTime.Now;
            Repository.AddOrUpdate(Document.Downcast <QCReport>());

            var settingsRepository = GetInstance <ISettingsRepository <WorkshopSettings> >();
            var workshopSettings   = settingsRepository.GetWorkshopSettings();

            workshopSettings.CentreQuarterlyCheckDate = DateTime.Now.Date;
            settingsRepository.Save(workshopSettings);

            ConnectHelper.Upload(Document.Downcast <QCReport>());
        }
Ejemplo n.º 25
0
        private void OnReprint(Window window)
        {
            if (string.IsNullOrEmpty(RegistrationNumber))
            {
                return;
            }

            IsLoading = true;

            Document document = FindDocumentLocally();

            if (document != null)
            {
                Print(document);
                window.Close();
                return;
            }

            GetInstance <IConnectClient>().CallAsync(ConnectHelper.GetConnectKeys(), client =>
            {
                return(client.Service.Find(RegistrationNumber.ToUpper().Replace(" ", string.Empty), DocumentType.Tachograph | DocumentType.Undownloadability | DocumentType.LetterForDecommissioning));
            },
                                                     result =>
            {
                if (result.Data == null)
                {
                    MessageBoxHelper.ShowError(Resources.ERR_UNABLE_FIND_ANY_MATCHES, Window);
                    return;
                }

                Print((Document)result.Data);
            },
                                                     exception =>
            {
                MessageBoxHelper.ShowError(Resources.TXT_ONE_OR_MORE_ERRORS, new object[] { ExceptionPolicy.HandleException(ContainerBootstrapper.Container, exception) }, window);
            },
                                                     () =>
            {
                window.Close();
            });
        }
Ejemplo n.º 26
0
        public void RegisterDependency()
        {
            using (SqlConnection connection = new SqlConnection(ConnectHelper.ConnectConnectionString()))
            {
                try
                {
                    SqlCommand command = new SqlCommand("SELECT [Last Login], [Application Running], [User Name], [Computer Name], [Version] FROM [dbo].[Checkin] ", connection);

                    //Monitor the Service Broker, and get notified if there is change in the query result
                    SqlDependency dependency = new SqlDependency(command, "Service=SPMConnectClientService;local database=SPM_Database", int.MaxValue);

                    //Fire event when message is arrived
                    dependency.OnChange += this.Dependency_OnChange;

                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }
                    SqlDataReader reader = command.ExecuteReader();
                    //while (reader.Read())
                    //{
                    //    Leave leave = new Leave();
                    //    leave.ID = reader["Computer Name"].ToString();
                    //    leave.ApplicantName = reader["Application Running"].ToString();
                    //    leave.Status = reader["User Name"].ToString();

                    //    Console.WriteLine(string.Format("{0}\t{1}\t{2}", leave.ID, leave.ApplicantName, leave.Status));
                    //}
                    connection.Close();
                }
                catch (SqlException ex)
                {
                    Console.WriteLine(string.Format("Error: {0}", ex.Message));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(string.Format("Error: {0}", ex.Message));
                }
            }
        }
Ejemplo n.º 27
0
        private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                IUniversalClockService universalClockProxy = ConnectHelper.ConnectUniversalClock();
                TotalMinutes = universalClockProxy.GetTimeInMinutes();
                TimeSpan ts = TimeSpan.FromMinutes(TotalMinutes);

                IPowerPrice utilityProxy = ConnectHelper.ConnectUtility();

                Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>
                {
                    CurrentTimeProperty  = String.Format($"{ts.Hours} : {ts.Minutes}");
                    CurrentPriceProperty = String.Format($"Power price: {utilityProxy.GetPowerPrice(universalClockProxy.GetTimeInHours())} [$/kWh]");

                    Int32 day = universalClockProxy.GetDay();
                    if (day - 1 != 0)
                    {
                        String newDayString = $"{day - 1}. dan od startovanja aplikacije";

                        if (!ListOfDays.Contains(newDayString))
                        {
                            ListOfDays.Add(newDayString);
                        }
                    }
                    else
                    {
                        String newDayString = $"Dan u kojem je startovana aplikacija";

                        if (!ListOfDays.Contains(newDayString))
                        {
                            ListOfDays.Add(newDayString);
                        }
                    }
                }));

                Thread.Sleep(Constants.MILISECONDS_IN_SECOND);
            }
        }
    void connectTwoSide(bool isLeftRight, List <QuadTreeConnectedNode> firstSideNodes, List <QuadTreeConnectedNode> secondSideNodes)
    {
        // Debug.Log(firstSideNodes.Count + "," + secondSideNodes.Count);
        var compareHelper = new ConnectHelper(isLeftRight, firstSideNodes, secondSideNodes);

        compareHelper.AddFirstSide();
        compareHelper.AddSecondSide();
        while (true)
        {
            // 當2個buffer的sum值相等,就可以ConnectNode
            if (compareHelper.IsEqual())
            {
                // Debug.Log("IsEqual");
                compareHelper.ConnectNode(); // 實際做connect的地方
                compareHelper.ClearBuffer();

                if (compareHelper.IsFinish())
                {
                    return;
                }
                else
                {
                    compareHelper.AddFirstSide();
                    compareHelper.AddSecondSide();
                }
            }
            else if (compareHelper.FirstSideIsBigger())
            {
                // Debug.Log("FirstSideIsBigger");
                compareHelper.AddSecondSide();
            }
            else
            {
                // Debug.Log("SecondSideIsBigger");
                compareHelper.AddFirstSide();
            }
        }
    }
Ejemplo n.º 29
0
 // 构造函数
 // clientSocket:和客户端通信的socket
 // server:服务器实例
 public Client(Socket clientSocket, Server server)
 {
     this.clientSocket = clientSocket;
     this.server       = server;
     mySqlConnection   = ConnectHelper.Connect();
 }
        public override void Open()
        {
            if (IsOpen)
            {
                throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected");
            }

            if (String.IsNullOrEmpty(host))
            {
                throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host");
            }

            if (port <= 0)
            {
                throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open without port");
            }

            if (client == null)
            {
                InitSocket();
            }

            if( timeout == 0)            // no timeout -> infinite
            {
                client.Connect(host, port);
            }
            else                        // we have a timeout -> use it
            {
                ConnectHelper hlp = new ConnectHelper(client);
                IAsyncResult asyncres = client.BeginConnect(host, port, new AsyncCallback(ConnectCallback), hlp);
                bool bConnected = asyncres.AsyncWaitHandle.WaitOne(timeout) && client.Connected;
                if (!bConnected)
                {
                    lock (hlp.Mutex)
                    {
                        if( hlp.CallbackDone)
                        {
                            asyncres.AsyncWaitHandle.Close();
                            client.Close();
                        }
                        else
                        {
                            hlp.DoCleanup = true;
                            client = null;
                        }
                    }
                    throw new TTransportException(TTransportException.ExceptionType.TimedOut, "Connect timed out");
                }
            }

            inputStream = client.GetStream();
            outputStream = client.GetStream();
        }
Ejemplo n.º 31
0
 protected override void Update()
 {
     UndownloadabilityRepository.AddOrUpdate(Document);
     ConnectHelper.Upload(Document, true);
 }