示例#1
0
        public bool DeleteUser(string username)
        {
            AcknowledgementResponse response = remoteExecutor.Execute(new DeleteUserRequest
            {
                Username            = username,
                AuthenticationToken = authenticationToken
            });

            return(response.IsSuccessful);
        }
示例#2
0
        public bool CreateNewUser(string username, string password)
        {
            AcknowledgementResponse response = remoteExecutor.Execute(new CreateUserRequest
            {
                Username            = username,
                Password            = password,
                AuthenticationToken = authenticationToken
            });

            return(response.IsSuccessful);
        }
示例#3
0
        internal static DreamScreenResponse Create(Message message)
        {
            DreamScreenResponse response = new AcknowledgementResponse(message);

            switch (message.Type)
            {
            case MessageType.Brightness:
                response = new BrightnessResponse(message);
                break;

            case MessageType.GetSerial:
                response = new DeviceSerialResponse(message);
                break;

            case MessageType.Mode:
                response = new ModeResponse(message);
                break;

            case MessageType.Name:
                response = new DeviceNameResponse(message);
                break;

            case MessageType.AmbientColor:
                response = new AmbientColorResponse(message);
                break;

            case MessageType.AmbientScene:
                response = new AmbientSceneResponse(message);
                break;

            case MessageType.AmbientModeType:
                response = new AmbientModeResponse(message);
                break;

            case MessageType.GroupName:
                response = new GroupNameResponse(message);
                break;

            case MessageType.GroupNumber:
                response = new GroupNumberResponse(message);
                break;

            case MessageType.ColorData:
                response = new ColorResponse(message);
                break;

            case MessageType.DeviceDiscovery:
                response = new StateResponse(message);
                break;
            }

            return(response);
        }
示例#4
0
        public void UploadFile(string localFilepath, string remoteFilepath)
        {
            remoteFilepath = Path.IsPathRooted(remoteFilepath) ? remoteFilepath : Path.Combine(CurrentFolder, remoteFilepath);

            FileInfo localFileInfo = new FileInfo(localFilepath);
            long     localFileSize = localFileInfo.Length;

            Stopwatch sw = Stopwatch.StartNew();

            using (ConsoleStatusWriter statusWriter = new ConsoleStatusWriter("Uploading...", localFileSize))
            {
                try
                {
                    int count  = 512 * 1024;
                    int offset = 0;

                    byte[] buffer;

                    using (FileStream fs = File.OpenRead(localFilepath))
                        using (BinaryReader br = new BinaryReader(fs))
                        {
                            do
                            {
                                buffer = br.ReadBytes(count);

                                AcknowledgementResponse response = remoteExecutor.Execute(new UploadFileRequest
                                {
                                    Path   = remoteFilepath,
                                    Data   = buffer,
                                    Offset = offset
                                });

                                offset += buffer.Length;
                                statusWriter.Update(buffer.Length);

                                if (!response.IsSuccessful)
                                {
                                    throw new CustomException("Error while uploading.");
                                }
                            }while (buffer.Length == count);
                        }
                }
                catch (IOException e)
                {
                    throw new CustomException(e.Message);
                }
            }
            sw.Stop();
            WriteStatistics(sw.ElapsedMilliseconds, localFileSize);
        }