コード例 #1
0
ファイル: HomeController.cs プロジェクト: Sjantos/PSIMfront
        public async Task <ActionResult> SavePost(string title, string description, string tags, IFormFile file)
        {
            string _fileName = null;
            string _fileType = null;
            string _file     = null;

            if (file != null)
            {
                var memStream = new MemoryStream();
                file.OpenReadStream().CopyTo(memStream);
                var fileBytes = memStream.ToArray();
                _file     = System.Convert.ToBase64String(fileBytes);
                _fileName = file.FileName;
                _fileType = file.ContentType;
            }
            var tagsWithoutWhiteSpaces = Regex.Replace(tags, @"\s+", "");
            var tagsCollection         = tagsWithoutWhiteSpaces.Split(',');
            var newPost = new Post()
            {
                AuthorUsername = "******",
                Title          = title,
                CreatedAt      = DateTime.Now,
                Description    = description,
                Comments       = new List <Comment>(),
                Tags           = tagsCollection.Select(p => new Tag(p)).ToList(),
                FileName       = _fileName,
                FileType       = _fileType,
                File           = _file
            };
            var backendClient = new BackendClient();
            var result        = await backendClient.CreateNewPost(newPost);

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        async Task Run(IEnv env)
        {
            _expectedCount = 0M;
            var endpoints = Servers.Select(m => new SimEndpoint(m, Port)).ToArray();

            var lib = new BackendClient(env, endpoints);

            await lib.AddItem(0, 1);

            _expectedCount = 1M;

            for (int i = 0; i < Iterations; i++)
            {
                try {
                    var curr = i % RingSize;
                    var next = (i + 1) % RingSize;
                    await lib.MoveItem(curr, next, 1);

                    await env.Delay(Delay);
                } catch (ArgumentException ex) {
                    env.Error("Unexpected error", ex);
                }
            }

            _actualCount = await lib.Count();

            if (HaltOnCompletion)
            {
                env.Halt("DONE");
            }
        }
コード例 #3
0
        public async Task <IdentifyResult> LoadViewModel(Stream photoStream)
        {
            var personData = await BackendClient.CallHttp <Stream, IdentifyResult>(Endpoints.Identify,
                                                                                   HttpVerbs.POST,
                                                                                   AuthenticationHelper.TokenForUser,
                                                                                   photoStream,
                                                                                   null);

            return(personData);
        }
コード例 #4
0
ファイル: HomeController.cs プロジェクト: Sjantos/PSIMfront
        public async Task <ActionResult> Index()
        {
            var backendClient = new BackendClient();
            var posts         = await backendClient.GetAllPosts();

            var model = new IndexViewModel(posts);

            return(View(model));
            //return View();
        }
コード例 #5
0
        private async Task GetAllUsers(bool isInitialGetting)
        {
            var response = await BackendClient.CallHttp <GetAllUserByFilterRequest, PaginatedUserDetail>(
                Endpoints.GetAllUser,
                HttpVerbs.GET,
                AuthenticationHelper.TokenForUser,
                null,
                LinkToNext);

            LinkToNext = response.ODataNextLink;

            ListOfEmployees.AddRange(ListToObservable(response.value));
        }
コード例 #6
0
ファイル: HomeController.cs プロジェクト: Sjantos/PSIMfront
        public async Task <ActionResult> SaveComment(int postId, string CommentContent)
        {
            var comment = new Comment()
            {
                AuthorUsername = "******",
                CommentContent = CommentContent,
                PostId         = postId
            };
            var backendClient = new BackendClient();
            var result        = await backendClient.CreateComment(comment);

            return(RedirectToAction("Index"));
        }
コード例 #7
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                backendClient   = null;
                PropertyChanged = null;
            }

            disposed = true;
        }
コード例 #8
0
        public QrCodeForm(Bitmap idQrCodeImage,
                          Bitmap qrCodeNoSelfServiceImage,
                          Models.SystemInformation systemInformation,
                          BackendClient backendClient,
                          string backendUrl,
                          string preCheckErrorMessage,
                          bool endpointsValidationResult)
        {
            _idQrCodeImage            = idQrCodeImage;
            _qrCodeNoSelfServiceImage = qrCodeNoSelfServiceImage;
            _systemInformation        = systemInformation;
            _backendClient            = backendClient;
            _backendUrl                = backendUrl;
            _stopWatch                 = new Stopwatch();
            _preCheckErrorMessage      = preCheckErrorMessage;
            _endpointsValidationResult = endpointsValidationResult;

            _backendClient.ResultReceived += backendClient_ResultReceived;

            InitializeComponent();
        }
コード例 #9
0
        private async Task GetAllFilteredUsers()
        {
            GetAllUserByFilterRequest content = new GetAllUserByFilterRequest()
            {
                UserName       = Name,
                Surname        = Surname,
                OfficeLocation = SelectedOffice
            };

            var response = await BackendClient
                           .CallHttp <GetAllUserByFilterRequest, PaginatedUserDetail>(
                Endpoints.GetAllByFilter,
                HttpVerbs.POST,
                AuthenticationHelper.TokenForUser,
                content,
                LinkToNext);

            LinkToNext = response.ODataNextLink;

            ListOfEmployees.AddRange(ListToObservable(response.value));
        }
コード例 #10
0
ファイル: HomeController.cs プロジェクト: Sjantos/PSIMfront
        public async Task <ActionResult> DownloadFile(int postId)
        {
            var backendClient = new BackendClient();
            var result        = await backendClient.DownloadFile(postId);

            var data      = SimpleJson.SimpleJson.DeserializeObject <MyFile>(result.Content);
            var fileName  = data.FileName;
            var fileType  = data.FileType;
            var file      = Encoding.UTF8.GetString(Convert.FromBase64String(data.File));
            var fileBytes = Encoding.ASCII.GetBytes(file);

            var memory = new MemoryStream(fileBytes);
            var path   = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), fileName);

            using (var stream = new FileStream(path, FileMode.Open))
            {
                await stream.CopyToAsync(memory);
            }
            memory.Position = 0;
            return(File(memory, fileType, Path.GetFileName(path)));
            //return View();
        }
コード例 #11
0
        private void Awake()
        {
            // create backend client and subscribe to its events
            Debug.Log($"GameController: Instantiated BackendClient");
            _client = new BackendClient();
            _client.schemeDownloaded += list =>
            {
                Debug.Log($"GameController: downloaded scheme {list.Count} textures");
                // create texture cache array
                _pictogramTextures = new Texture2D[list.Count];

                // show unloaded tiles
                tilesArrayController.ShowUnloadedTiles();
            };

            _client.textureDownloaded += (tex, progress) =>
            {
                Debug.Log($"GameController: downloaded texture, {progress} left");
                // load tiles which pictogram (according to mapping) has been loaded
                tilesArrayController.LoadTile(progress, tex);

                // cache texture
                _pictogramTextures[progress] = tex;

                if (progress == 0)
                {
                    // all pictograms have been loaded

                    // animate the shadows appearance
                    shadowAnimator.enabled = true;

                    // start the game
                    StartCoroutine(GameStartCoroutine());
                }
            };

            _client.downloadFailed += _ => Debug.LogError($"Download failed!");
        }
コード例 #12
0
 public RegistrationFormController(IConstants constants, BackendClient client)
     : base(constants)
 {
     _client    = client;
     _constants = constants;
 }
コード例 #13
0
        // ap.exe should be called from OOBE [Shift] + [F10] command prompt via:

        // powershell -c iwr ap.domain.com -o ap.exe & qr
        // or
        // curl -o ap.exe ap.domain.com & ap

        // curl remarks:
        // -L is used to follow redirects e.g. redirect to https
        // curl -o ap.exe -L ap.domain.com & ap
        static async Task Main(string[] args)
        {
            _logger        = new LogUtil();
            _backendUrl    = ParseCommandlineArgs(args);
            _backendClient = new BackendClient();
            _backendClient.MessageReceived += BackendClient_MessageReceived;
            _backendClient.ResultReceived  += BackendClient_ResultReceived;
            _windowsAutopilotHashService    = new WindowsAutopilotHashService();
            _windowsAutopilotHashService.MessageReceived += WindowsAutopilotHashService_MessageReceived;

            try
            {
                // default Action is IMPORT
                var action = "IMPORT";

                // --erase device deletion request found
                if (_deleteManagedDeviceOnly)
                {
                    _logger.WriteInfo("Identified as device [DELETE] request");
                    action = "DELETE";
                }
                else
                {
                    _logger.WriteInfo("Identified as device [IMPORT] request");

                    // --skip endpoint validation found
                    if (!_skipEndpointsValidation)
                    {
                        var endpointVerificationError = false;
                        if (_endpointsValidationResult = await _backendClient.VerifyEnrollmentEndpoints())
                        {
                            _logger.WriteInfo("All enrollment URLs reachable");
                        }
                        else
                        {
                            if (!_logger.DebugMode)
                            {
                                _logger.WriteInfo("Not all enrollment URLs reachable or system time is wrong!");
                                _logger.WriteInfo($"Use '{Assembly.GetExecutingAssembly().GetName().Name} --connect --verbose' for connectivity test details.");
                                endpointVerificationError = true;
                            }
                            else
                            {
                                _logger.WriteInfo("=> Not all enrollment URLs reachable or system time is wrong!");
                                endpointVerificationError = true;
                            }
                        }
                        // --connect endpoint validation only found
                        if (_endpointsValidationOnly)
                        {
                            if (endpointVerificationError)
                            {
                                Environment.Exit(1);
                            }
                            return;
                        }
                    }

                    // --ignore Autopilot assignment found
                    if (!_ignoreAutopilotAssignment)
                    {
                        try
                        {
                            // is this already a Autopilot device?
                            var rkbase = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
                            using (RegistryKey key = rkbase.OpenSubKey(@"SOFTWARE\Microsoft\Provisioning\Diagnostics\AutoPilot"))
                            {
                                if (key != null)
                                {
                                    var tenantId = key.GetValue("CloudAssignedTenantId").ToString();
                                    if (!string.IsNullOrEmpty(tenantId))
                                    {
                                        _logger.WriteInfo("Device is already Autopilot provisioned");
                                        _logger.WriteDebug($"CloudAssignedTenantId: {tenantId}");

                                        var tenantDomain = key.GetValue("CloudAssignedTenantDomain").ToString();
                                        if (!string.IsNullOrEmpty(tenantDomain))
                                        {
                                            if (_logger.DebugMode)
                                            {
                                                _logger.WriteDebug($"CloudAssignedTenantDomain: {tenantDomain}");
                                            }
                                            else
                                            {
                                                _logger.WriteInfo($"Assigned tenant domain: {tenantDomain}");
                                            }
                                        }
                                        return;
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            _logger.WriteInfo("Couldn't check existing Autopilot assignment, proceeding.");
                        }
                    }
                }

                // main work start now
                _logger.WriteInfo("Fetching system information");
                _systemInformation        = _windowsAutopilotHashService.FetchData();
                _systemInformation.Action = action;

                if (_systemInformation == null)
                {
                    _logger.WriteInfo("No Windows 10/11 operating system, can't fetch data");
                    return;
                }

                if (string.IsNullOrEmpty(_systemInformation.HardwareHash))
                {
                    _logger.WriteInfo("Information couldn't be fetched");
                }
                else
                {
                    _logger.WriteInfo("Information successfully fetched");
                    if (_fetchHardwareDataOnly)
                    {
                        return;
                    }

                    // check if our backend server is reachable
                    if (!_backendClient.IsValidUrl(_backendUrl, out _backendUrl, "HEAD"))
                    {
                        _logger.WriteInfo("Backend URL not reachable");
                        return;
                    }
                    else
                    {
                        _logger.WriteDebug($"Resolved backend URL is {_backendUrl}");
                    }

                    // Safe the info to app service AutopilotManager... result here may be 'not allowed', catched in ResultReceived handler
                    await _backendClient.SaveDataAsync(_systemInformation, _backendUrl);

                    var url         = new Url($"{_backendUrl}/autopilot/{_systemInformation.Id}/save-information");
                    var qrCodeImage = QrCodeUtil.GenerateQrCode(url.ToString());
                    //var qrCodeImage = QrCodeUtil.GenerateQrCode(url.ToString(), 8);

                    var urlNoSelfService         = new Url($"{_backendUrl}/Home/NoSelfService");
                    var qrCodeNoSelfServiceImage = QrCodeUtil.GenerateQrCode(urlNoSelfService.ToString());

                    var form = new QrCodeForm(qrCodeImage, qrCodeNoSelfServiceImage, _systemInformation, _backendClient, _backendUrl, _preCheckErrorMessage, _endpointsValidationResult);
                    form.DisplayData();

                    if (form.DialogResult == DialogResult.Retry)
                    {
                        _logger.WriteDebug("Retry received");

                        string[] arguments = Environment.GetCommandLineArgs();

                        var path            = Assembly.GetExecutingAssembly().Location;
                        var fullPathcommand = $"{path} {string.Join(" ", arguments.Skip(1).ToArray())}";

                        _logger.WriteDebug($"Using command: {fullPathcommand}");
                        _logger.WriteDebug("Starting as external process, debug output will not be received in this command prompt.");
                        _logger.WriteDebug("Start manually (not using Retry button) from this command prompt to receive the debug output again.");

                        using (var p = new Process())
                        {
                            p.StartInfo.UseShellExecute = false;
                            p.StartInfo.FileName        = path;
                            p.StartInfo.Arguments       = string.Join(" ", arguments.Skip(1).ToArray());
                            p.StartInfo.CreateNoWindow  = true;
                            p.Start();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.WriteInfo(ex.ToString());
                _logger.WriteInfo("**************** Closing application, fix and porting try again ****************");
                return;
            }
        }
コード例 #14
0
 public LoginFormController(IConstants constants, BackendClient client)
     : base(constants)
 {
     _client    = client;
     _constants = constants;
 }
コード例 #15
0
 public Backend1Queries(BackendClient client)
 {
     this.client = client;
 }
コード例 #16
0
 public BucketController(IConstants constants, BackendClient client)
     : base(constants)
 {
     _client    = client;
     _constants = constants;
 }