Пример #1
0
        /// <summary>
        /// 同步发送接收
        /// </summary>
        /// <param name="buffer">Can't be null! </param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public DtuMsg Ssend(byte[] buffer, int timeout)
        {
            if (buffer == null || buffer.Length == 0)
            {
                log.Error("Null send buffer required. ");
                return(NewErrorMsg(Errors.ERR_NULL_SEND_DATA));
            }
            if (!this.IsOnline)
            {
                log.Error("Connection Not Ready");
                return(NewErrorMsg(Errors.ERR_NOT_CONNECTED));
            }
            if (this.Status != WorkingStatus.IDLE)
            {
                log.Error("I'm BUSY!");
                return(NewErrorMsg(Errors.ERR_DTU_BUSY));
            }
            this.Status = WorkingStatus.WORKING_SYNC;
            log.DebugFormat("SSending message, size={0}, timeout={1} s", buffer.Length, timeout);
            IDtuDataHandler  oldHandler = this.handler;
            AsyncMsgReceiver worker     = new AsyncMsgReceiver(this.DtuID, timeout);

            this.handler = worker;
            ServerManager.Send(this.DtuID, buffer);
            Thread thread = new Thread(worker.DoWork);

            thread.Start();
            thread.Join(); // wait thread dead.
            this.Status  = WorkingStatus.IDLE;
            this.handler = oldHandler;
            return(worker.Received());
        }
Пример #2
0
        public IHttpActionResult PutWorkingStatus(int id, WorkingStatus WorkingStatus)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != WorkingStatus.WorkingStatusID)
            {
                return(BadRequest());
            }

            db.Entry(WorkingStatus).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkingStatusExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
 private static void fireConnectionStatusChanged(Connection c, WorkingStatus oldStatus, WorkingStatus newStatus)
 {
     foreach (IConnectEventListener listener in _connectEventListeners)
     {
         listener.OnConnectionStatusChanged(c, oldStatus, newStatus);
     }
 }
Пример #4
0
    public void SetClient(TcpClient client)
    {
        this.client = client;
        stream      = client.GetStream();
        status      = WorkingStatus.Working;

        try
        {
            if (receiveThread != null)
            {
                receiveThread.Abort();
            }
            if (sendThread != null)
            {
                sendThread.Abort();
            }
        }
        catch
        {
        }


        receiveThread = new Thread(new ThreadStart(ReceiveHandler));
        receiveThread.Start();

        sendQueue  = ArrayList.Synchronized(new ArrayList());
        sendThread = new Thread(new ThreadStart(SendHandler));
        sendThread.Start();

        if (onConnectEvent != null)
        {
            onConnectEvent();
        }
    }
Пример #5
0
 public static Guid GetFromName(String text)
 {
     using (DataContext db = new DataContext())
     {
         WorkingStatus model = db.WorkingStatus.Find(text);
         return(model.kWorkingStatusId);
     }
 }
Пример #6
0
 public static void Edit(WorkingStatus model)
 {
     using (DataContext db = new DataContext())
     {
         db.Entry(model).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Пример #7
0
 public static void Create(WorkingStatus model)
 {
     using (DataContext db = new DataContext())
     {
         db.WorkingStatus.Add(model);
         db.SaveChanges();
     }
 }
Пример #8
0
 public static WorkingStatus GetById(Guid id)
 {
     using (DataContext db = new DataContext())
     {
         WorkingStatus model = db.WorkingStatus.Find(id);
         return(model);
     }
 }
Пример #9
0
 private void FireConnectionStatusChanged(GprsDtuConnection c, WorkingStatus oldStatus, WorkingStatus newStatus)
 {
     if (OnConnectStatusChanged != null)
     {
         _log.InfoFormat("DtuConnection {0} going {1}", c, newStatus);
         OnConnectStatusChanged(c, oldStatus, newStatus);
     }
 }
Пример #10
0
 public UC_Category(MainWindow parent)
 {
     InitializeComponent();
     this.parent        = parent;
     this.workingStatus = WorkingStatus.NEW;
     this.entityStatus  = EntityStatus.UNATTACHED;
     Initalize();
 }
        //Arrange
        private HonoplayDbContext InitAndGetDbContext(out int workingStatusId, out int departmentId, out int adminUserId, out Guid tenantId)
        {
            var context = GetDbContext();

            var salt      = ByteArrayExtensions.GetRandomSalt();
            var adminUser = new AdminUser
            {
                Email        = "*****@*****.**",
                Password     = "******".GetSHA512(salt),
                PasswordSalt = salt,
                LastPasswordChangeDateTime = DateTime.Today.AddDays(-5),
            };

            context.AdminUsers.Add(adminUser);

            var tenant = new Tenant
            {
                Name     = "TestTenant#01",
                HostName = "localhost"
            };

            context.Tenants.Add(tenant);

            context.TenantAdminUsers.Add(new TenantAdminUser
            {
                TenantId    = tenant.Id,
                AdminUserId = adminUser.Id,
                CreatedBy   = adminUser.Id
            });

            var department = new Department
            {
                CreatedBy = adminUser.Id,
                Name      = "testDepartment",
                TenantId  = tenant.Id
            };

            context.Departments.Add(department);

            var workingStatus = new WorkingStatus
            {
                Name      = "testWorkingStatus",
                TenantId  = tenant.Id,
                CreatedBy = adminUser.Id
            };

            context.WorkingStatuses.Add(workingStatus);

            context.SaveChanges();

            workingStatusId = workingStatus.Id;
            departmentId    = department.Id;
            adminUserId     = adminUser.Id;
            tenantId        = tenant.Id;
            return(context);
        }
Пример #12
0
 public ComDtuConnection(DtuNode dtu)
 {
     this.DtuID  = dtu.DtuCode;
     this.Status = WorkingStatus.IDLE;
     this._port  = (SerialPort)dtu.GetProperty("serial");
     this._port.ReadBufferSize = 1048;
     //    this._timeout = dtu..DacTimeout;
     this._port.DataReceived  += this.OnDataReceived;
     this._port.ErrorReceived += this.OnErrorReceived;
 }
 public UC_Password(MainWindow parent, WorkingStatus workingStatus)
 {
     InitializeComponent();
     BTNBack.Visibility = Visibility.Hidden;
     this.parent        = parent;
     this.workingStatus = workingStatus;
     this.entityStatus  = EntityStatus.UNATTACHED;
     Initialize();
     LoadValues(currentPassword);
 }
Пример #14
0
 public UC_Category(MainWindow parent, DAL.Kategorie category, WorkingStatus workingStatus)
 {
     this.parent        = parent;
     this.category      = category;
     this.workingStatus = category == null ? WorkingStatus.NEW : workingStatus;
     this.entityStatus  = category == null ? EntityStatus.UNCHANGED : EntityStatus.MODIFIED;
     PreName            = category.Name;
     InitializeComponent();
     Initalize();
 }
Пример #15
0
        public IHttpActionResult GetWorkingStatus(int id)
        {
            WorkingStatus WorkingStatus = db.WorkingStatus.Find(id);

            if (WorkingStatus == null)
            {
                return(NotFound());
            }

            return(Ok(WorkingStatus));
        }
Пример #16
0
 public JsonResult Edit(int Id, WorkingStatus data)
 {
     if (data != null)
     {
         data.WorkingStatusID = Id;
         db.Entry(data).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(new { Message = "Đã sửa thành công!" }, JsonRequestBehavior.AllowGet));
     }
     return(null);
 }
Пример #17
0
        public ActionResult Delete(int id)
        {
            WorkingStatus entity = db.WorkingStatus.FirstOrDefault(a => a.WorkingStatusID == id);

            if (entity != null)
            {
                db.WorkingStatus.Remove(entity);
                db.SaveChanges();
            }
            return(Json(new { Message = "Đã xóa thành công!" }, JsonRequestBehavior.AllowGet));
        }
Пример #18
0
 private void OnAddPointOfInterest(object commandParameter)
 {
     this.Status       = WorkingStatus.New;
     this.SelectedItem = new PointOfInterestViewModel
     {
         Graphics = new GraphicsViewModel
         {
             Width  = 60,
             Height = 60
         }
     };
 }
Пример #19
0
        private void btn_DangXuat_Click(object sender, EventArgs e)
        {
            WorkingStatus workingStatus = new WorkingStatus();

            workingStatus         = DataContext.WorkingStatus.Where(a => a.WorkingStatusId == Cons.WorkingStatusId).Single();
            workingStatus.timeEnd = DateTime.Now;
            DataContext.SubmitChanges();


            this.Hide();
            this.Close();
        }
Пример #20
0
        public IHttpActionResult PostWorkingStatus(WorkingStatus WorkingStatus)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.WorkingStatus.Add(WorkingStatus);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = WorkingStatus.WorkingStatusID }, WorkingStatus));
        }
Пример #21
0
        public static void Delete(Guid id)
        {
            using (DataContext db = new DataContext())
            {
                WorkingStatus model = db.WorkingStatus.Find(id);

                if (model.iDefault == 0)
                {
                    db.WorkingStatus.Remove(model);
                    db.SaveChanges();
                }
            }
        }
Пример #22
0
        public IHttpActionResult DeleteWorkingStatus(int id)
        {
            WorkingStatus WorkingStatus = db.WorkingStatus.Find(id);

            if (WorkingStatus == null)
            {
                return(NotFound());
            }

            db.WorkingStatus.Remove(WorkingStatus);
            db.SaveChanges();

            return(Ok(WorkingStatus));
        }
Пример #23
0
        public async Task <ResponseModel <CreateWorkingStatusModel> > Handle(CreateWorkingStatusCommand request, CancellationToken cancellationToken)
        {
            var redisKey      = $"WorkingStatusesByTenantId{request.TenantId}";
            var workingStatus = new WorkingStatus
            {
                Name      = request.Name,
                CreatedBy = request.CreatedBy,
                TenantId  = request.TenantId
            };

            using (var transaction = await _context.Database.BeginTransactionAsync(cancellationToken))
            {
                try
                {
                    await _context.WorkingStatuses.AddAsync(workingStatus, cancellationToken);

                    await _context.SaveChangesAsync(cancellationToken);

                    transaction.Commit();

                    await _cacheService.RedisCacheUpdateAsync(redisKey,
                                                              _ => _context.WorkingStatuses
                                                              .Where(x => x.TenantId == request.TenantId)
                                                              .ToList()
                                                              , cancellationToken);
                }
                catch (DbUpdateException ex) when((ex.InnerException is SqlException sqlException && (sqlException.Number == 2627 || sqlException.Number == 2601)) ||
                                                  (ex.InnerException is SqliteException sqliteException && sqliteException.SqliteErrorCode == 19))
                {
                    transaction.Rollback();
                    throw new ObjectAlreadyExistsException(nameof(WorkingStatus), request.Name);
                }
                catch (NotFoundException)
                {
                    transaction.Rollback();
                    throw;
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw new TransactionException();
                }
            }
            var workingStatusModel = new CreateWorkingStatusModel(workingStatus.Id,
                                                                  workingStatus.Name,
                                                                  workingStatus.CreatedBy,
                                                                  workingStatus.CreatedAt);

            return(new ResponseModel <CreateWorkingStatusModel>(workingStatusModel));
        }
Пример #24
0
 private void BTNSave_Click(object sender, RoutedEventArgs e)
 {
     if (category.Name == PreName)
     {
         MessageBox.Show("No changes", "Unchanged", MessageBoxButton.OK, MessageBoxImage.Information);
     }
     else if (IsSelectionValid())
     {
         if (!BLL.Kategorie.Existiert(TXTName.Text))
         {
             if (entityStatus == EntityStatus.UNATTACHED)
             {
                 var id = BLL.Kategorie.Erstellen(category);
                 if (id > 0)
                 {
                     MessageBox.Show("Category has been created", "Created", MessageBoxButton.OK, MessageBoxImage.Information);
                     category = BLL.Kategorie.LesenID(id);
                     parent.UpdateCategoryList();
                     parent.LoadPasswordListView(category);
                     entityStatus  = EntityStatus.MODIFIED;
                     workingStatus = WorkingStatus.LOADED;
                 }
                 else
                 {
                     MessageBox.Show("Some error occurred while creating the category", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                 }
             }
             else if (entityStatus == EntityStatus.MODIFIED)
             {
                 BLL.Kategorie.Aktualisieren(category);
                 var entity = BLL.Kategorie.LesenID(category.KategorieId);
                 category = entity;
                 PreName  = category.Name;
                 LoadValues(category);
                 parent.UpdateCategoryList();
                 parent.MainTitle.Content = category.Name;
                 MessageBox.Show("The category has been updated", "Update", MessageBoxButton.OK, MessageBoxImage.Information);
             }
         }
         else
         {
             MessageBox.Show("The name of the category is already taken", "Exists", MessageBoxButton.OK, MessageBoxImage.Warning);
         }
     }
     else
     {
         MessageBox.Show("The cateory already exists or the content is invalid", "Invalid", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Пример #25
0
        private void GetWorkingStatus()
        {
            Login  login = (Login)Session[DataCleaningConstant.LoginInfoSession];
            string step  = Request.QueryString["step"];
            WorkingStatusHelper working = new WorkingStatusHelper();
            WorkingStatus       status  = working.GetWorkingStatus(login.UserLogin.user_name, step);

            status.total_time = Math.Round(status.total_time, 1);
            status.speed      = Math.Round(status.speed, 1);
            var jsonSerialiser = new JavaScriptSerializer();
            var json           = jsonSerialiser.Serialize(status);

            Response.Write(json);
            Response.End();
        }
Пример #26
0
        private void OnSavePointOfInterest(object commandParameter)
        {
            if (this.Status == WorkingStatus.New)
            {
                this.SelectedItem.Timestamp = DateTime.Now;
                this.Entities.Add(this.SelectedItem);
                this.SaveDataBase();
            }
            else if (this.Status == WorkingStatus.Edit)
            {
                this.SelectedItem.Timestamp = DateTime.Now;
                this.SaveDataBase();
            }

            this.Status = WorkingStatus.Wait;
        }
Пример #27
0
    public void Close()
    {
        if (stream != null)
        {
            stream.Close();
            //stream.Dispose();
        }
        if (sendThreadEvent != null)
        {
            sendThreadEvent.Set();
        }

        stream = null;

        if (client != null)
        {
            client.Close();
        }
        client = null;

        switch (status)
        {
        case WorkingStatus.Connecting:
            status = WorkingStatus.Close;
            if (onConnectErrorEvent != null)
            {
                onConnectErrorEvent();
            }
            break;

        case WorkingStatus.Working:
            status = WorkingStatus.Close;
            if (onCloseEvent != null)
            {
                onCloseEvent();
            }
            break;

        case WorkingStatus.None:
        case WorkingStatus.Close:
            return;

        default:
            break;
        }
    }
Пример #28
0
        public JsonResult Create(WorkingStatus model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." }));
                }
                model.kWorkingStatusId = Guid.NewGuid();

                WorkingStatusManager.Create(model);
                return(Json(new { Result = "OK", Record = model }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Пример #29
0
        private void DtuOnline(IDtuConnection dtuConnection, WorkingStatus old, WorkingStatus news)
        {
            var gprsDtuConnection = dtuConnection as GprsDtuConnection;

            if (gprsDtuConnection == null)
            {
                return;
            }
            if (news == WorkingStatus.IDLE)
            {
                gprsDtuConnection.registerDataHandler(this);
            }
            // DtuConnection.onDataReceived+= OnDataReceived;
            if (this.OnClientConnected != null)
            {
                this.OnClientConnected(gprsDtuConnection, news);
            }
        }
Пример #30
0
        public DtuMsg Ssend(byte[] buffer, int timeout)
        {
            try
            {
                if (!this.Connect())
                {
                    return(this.NewErrorMsg((int)Errors.ERR_NOT_CONNECTED));
                }
                if (this.Status != WorkingStatus.IDLE)
                {
                    return(this.NewErrorMsg((int)Errors.ERR_DTU_BUSY));
                }
                if (buffer == null || buffer.Length == 0)
                {
                    return(this.NewErrorMsg((int)Errors.ERR_NULL_SEND_DATA));
                }
                this.Status = WorkingStatus.WORKING_SYNC;
                IDtuDataHandler oldHandler = this._handler;

                this._port.DiscardInBuffer();
                this._port.DataReceived -= this.OnDataReceived;
                SyncComReceiver worker    = new SyncComReceiver(this, this.DtuID, timeout);
                Thread          t         = new Thread(worker.DoWork);
                long            sentStart = DateTime.Now.Ticks;
                t.Start();
                Log.DebugFormat("Sending message: {0} , timeout = {1}", buffer.Length, timeout);
                this._port.Write(buffer, 0, buffer.Length);
                Log.DebugFormat("Sent in {0} ms.", (System.DateTime.Now.Ticks - sentStart) / 10000);
                t.Join();
                this._port.DataReceived += this.OnDataReceived;

                return(worker.Received());
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("SSend error: {0}", ex.Message);
                return(this.NewErrorMsg((int)Errors.ERR_WRITE_COM, ex.Message));
            }
            finally
            {
                this.Status = WorkingStatus.IDLE;
            }
        }
Пример #31
0
        string PrepPrintWorkingCell(WorkingStatus stats, ColumnDefinition col)
        {
            ConsoleColor color;
            string symbol;

            switch (stats) {
                case WorkingStatus.Added:
                    symbol = "+"; color = ConsoleColor.Green; break;

                case WorkingStatus.Modified:
                    symbol = "~"; color = ConsoleColor.Cyan; break;

                case WorkingStatus.Removed:
                    symbol = "-"; color = ConsoleColor.Yellow; break;

                case WorkingStatus.Unmerged:
                    symbol = "!"; color = ConsoleColor.White; break;

                default:
                    symbol = string.Empty;
                    color = ConsoleColor.Gray;
                    break;
            }

            col.Foreground = color;
            return symbol;
        }
        private void Update()
        {
            if (CurrentStatus != WorkingStatus.Started)
                return;

            if (Environment.TickCount >= _nextUpdateTime ||
                (Environment.TickCount < 0 && _nextUpdateTime > 0))
            {
                // If the previous status call hasn't exited yet, we'll wait until it is
                // so we don't queue up a bunch of commands
                if (UICommands.RepoChangedNotifier.IsLocked || Module.IsRunningGitProcess())
                {
                    _statusIsUpToDate = false;//tell that computed status isn't up to date
                    return;
                }

                _statusIsUpToDate = true;
                AsyncLoader.DoAsync(RunStatusCommand, UpdatedStatusReceived, (e) => { CurrentStatus = WorkingStatus.Stopped; });
                // Always update every 5 min, even if we don't know anything changed
                ScheduleNextJustInCaseUpdate();
            }
        }
        private void TryStartWatchingChanges(string workTreePath, string gitDirPath)
        {
            // reset status info, it was outdated
            Text = CommitTranslatedString;
            Image = IconClean;

            try
            {
                if (!string.IsNullOrEmpty(workTreePath) && Directory.Exists(workTreePath) &&
                    !string.IsNullOrEmpty(gitDirPath) && Directory.Exists(gitDirPath))
                {
                    _workTreeWatcher.Path = workTreePath;
                    _gitDirWatcher.Path = gitDirPath;
                    _gitPath = Path.GetDirectoryName(gitDirPath);
                    _submodulesPath = Path.Combine(_gitPath, "modules");
                    UpdateIgnoredFiles(true);
                    ignoredFilesTimer.Stop();
                    ignoredFilesTimer.Start();
                    CurrentStatus = WorkingStatus.Started;
                }
                else
                {
                    CurrentStatus = WorkingStatus.Stopped;
                }
            }
            catch { }
        }
 private void GitUICommands_PreCheckout(object sender, GitUIBaseEventArgs e)
 {
     CurrentStatus = WorkingStatus.Paused;
 }
 private void GitUICommands_PostCheckout(object sender, GitUIPostActionEventArgs e)
 {
     CurrentStatus = WorkingStatus.Started;
 }
        private void Update()
        {
            // If the previous status call hasn't exited yet, we'll wait until it is
            // so we don't queue up a bunch of commands
            if (gitGetUnstagedCommand.IsRunning)
            {
                hasDeferredUpdateRequests = true; // defer this update request
                return;
            }

            hasDeferredUpdateRequests = false;

            if (Environment.TickCount > nextUpdateTime)
            {
                try
                {
                    string command = GitCommandHelpers.GetAllChangedFilesCmd(true, true);
                    gitGetUnstagedCommand.CmdStartProcess(Settings.GitCommand, command);

                    if (hasDeferredUpdateRequests)
                        // New changes were detected while processing previous changes, schedule deferred update
                        ScheduleDeferredUpdate();
                    else
                        // Always update every 5 min, even if we don't know anything changed
                        ScheduleNextJustInCaseUpdate();
                }
                catch (Exception)
                {
                    CurrentStatus = WorkingStatus.Stopped;
                }
            }
        }
Пример #37
0
        private void TryStartWatchingChanges(string watchingPath, string watchingGitPath)
        {
            // reset status info, it was outdated
            Text = string.Empty;
            Image = null;

            try
            {
                if (!string.IsNullOrEmpty(watchingPath) && Directory.Exists(watchingPath) &&
                    !string.IsNullOrEmpty(watchingGitPath) && Directory.Exists(watchingGitPath))
                {
                    watcher.Path = watchingPath;
                    gitDirWatcher.Path = watchingGitPath;
                    gitPath = Path.GetDirectoryName(watchingGitPath);
                    CurrentStatus = WorkingStatus.Started;
                }
                else
                {
                    CurrentStatus = WorkingStatus.Stopped;
                }
            }
            catch { }
        }
Пример #38
0
        private void TryStartWatchingChanges(string workTreePath, string gitDirPath)
        {
            // reset status info, it was outdated
            Text = string.Empty;
            Image = null;

            try
            {
                if (!string.IsNullOrEmpty(workTreePath) && Directory.Exists(workTreePath) &&
                    !string.IsNullOrEmpty(gitDirPath) && Directory.Exists(gitDirPath))
                {
                    workTreeWatcher.Path = workTreePath;
                    gitDirWatcher.Path = gitDirPath;
                    gitPath = Path.GetDirectoryName(gitDirPath);
                    submodulesPath = Path.Combine(gitPath, "modules");
                    CurrentStatus = WorkingStatus.Started;
                }
                else
                {
                    CurrentStatus = WorkingStatus.Stopped;
                }
            }
            catch { }
        }
Пример #39
0
 public ItemStatus(IndexStatus index, WorkingStatus working)
 {
     IndexStatus = index; WorkingStatus = working;
 }
Пример #40
0
 private void OnUpdateStatusError(AsyncErrorEventArgs e)
 {
     _commandIsRunning = false;
     CurrentStatus = WorkingStatus.Stopped;
 }