Esempio n. 1
0
        public HttpResponseMessage DownloadCryptoImage(string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }

            var crypto = new CryptoComponent().GetByCode(code);

            if (crypto == null)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError));
            }

            var bytes = new FileComponent().GetFileById(crypto.IconURL ?? Guid.Empty);

            if (bytes == null || bytes.Length == 0)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }

            var resp = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(bytes)
            };

            resp.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
            return(resp);
        }
Esempio n. 2
0
        public ServiceResult <File> Copy(FileCopyModel model)
        {
            var resultData = new ServiceResult <File>();

            try
            {
                if (!ModelState.IsValid)
                {
                    resultData.Code = MISSING_REQUIRED_FIELDS;
                    foreach (string error in ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage)))
                    {
                        resultData.Message += error + Environment.NewLine;
                    }

                    return(resultData);
                }

                var file = new FileComponent().CopyInFolder(model.Id);

                resultData.Data = file;
                resultData.Success();
            }
            catch (Exception ex)
            {
                resultData.SystemError(ex);
            }
            return(resultData);
        }
Esempio n. 3
0
        public ServiceResult <bool> CheckFileExists(Guid id)
        {
            var resultData = new ServiceResult <bool>();

            try
            {
                if (!ModelState.IsValid)
                {
                    resultData.Code = MISSING_REQUIRED_FIELDS;
                    foreach (string error in ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage)))
                    {
                        resultData.Message += error + Environment.NewLine;
                    }

                    return(resultData);
                }

                var exists = new FileComponent().CheckFileExists(id);

                resultData.Data = exists;

                resultData.Success();
            }
            catch (Exception ex)
            {
                resultData.SystemError(ex);
            }

            return(resultData);
        }
Esempio n. 4
0
        public void stDeleteTest1()
        {
            var target = new FileComponent();

            try {
                target.parse("[File delete]");
                Assert.Fail("1");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(IncorrectNodeException), ex.GetType().ToString()); }

            try {
                target.parse("[File delete.files]");
                Assert.Fail("2");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(IncorrectNodeException), ex.GetType().ToString()); }

            try {
                target.parse("[File delete.directory]");
                Assert.Fail("3");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(IncorrectNodeException), ex.GetType().ToString()); }

            try {
                target.parse("[File delete.notRalNode]");
                Assert.Fail("4");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(IncorrectNodeException), ex.GetType().ToString()); }
        }
Esempio n. 5
0
        private void CloseWebView()
        {
            if (_webView2Control != null)
            {
                _webView2Control.Close();
                _webView2Control.EnvironmentCreated -= webView2Control1_EnvironmentCreated;
                _webView2Control.BrowserCreated     -= _webView2Control_BrowserCreated;
                _webView2Control.ContainsFullScreenElementChanged -= _webView2Control_ContainsFullScreenElementChanged;
                _webView2Control.NewWindowRequested -= _webView2Control_NewWindowRequested;

                _environment.UnregisterNewVersionAvailable(_newVersionToken);

                _settingsComponent.CleanUp();
                _settingsComponent = null;

                _fileComponent.CleanUp();
                _fileComponent = null;

                _processComponent.CleanUp();
                _processComponent = null;

                _scriptComponent.CleanUp();
                _scriptComponent = null;

                _controlComponent.CleanUp();
                _controlComponent = null;

                _viewComponent.CleanUp();
                _viewComponent = null;

                tableLayoutPanel1.Controls.Remove(_webView2Control);
                _webView2Control.Dispose();
                _webView2Control = null;
            }
        }
Esempio n. 6
0
        public void stRemoteTest1()
        {
            var target = new FileComponent();

            try {
                target.parse("[File remote]");
                Assert.Fail("1");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(IncorrectNodeException), ex.GetType().ToString()); }

            try {
                target.parse("[File remote.download]");
                Assert.Fail("2");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(IncorrectNodeException), ex.GetType().ToString()); }

            try {
                target.parse("[File remote.notRealNode]");
                Assert.Fail("3");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(IncorrectNodeException), ex.GetType().ToString()); }

            try {
                target.parse("[File remote.download(\"addr\", \"file\").notRealNode]");
                Assert.Fail("4");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(NotSupportedOperationException), ex.GetType().ToString()); }
        }
Esempio n. 7
0
		public void Download(FileComponent comp)
		{
			Debug.Assert(comp != null);

			Entity entity = new Entity();
			EntityIdleComponent idle = new EntityIdleComponent();
			entity.Add(idle);

			EntityStoreComponent store = new EntityStoreComponent(comp.Owner);
			entity.Add(store);

			FileComponent file = new FileComponent(comp);
			entity.Add(file);

			TransferComponent transfer = new TransferComponent();
			entity.Add(transfer);

			DownloadMachineComponent machine = new DownloadMachineComponent();
			entity.Add<MachineComponent>(machine);
#if DEBUG
			LogComponent log = new LogComponent(LogController);
			entity.Add(log);
#endif
			Add(entity);
		}
Esempio n. 8
0
        private void _webView2Control_BrowserCreated(object sender, EventArgs e)
        {
            _settingsComponent = new SettingsComponent(_environment, _webView2Control);
            _fileComponent     = new FileComponent(this, _webView2Control);
            _processComponent  = new ProcessComponent(this, _webView2Control);
            _scriptComponent   = new ScriptComponent(this, _webView2Control);
            _controlComponent  = new ControlComponent(this, navigationToolBar, _webView2Control);
            _viewComponent     = new ViewComponent(this, _webView2Control);

            if (_onWebViewFirstInitialized != null)
            {
                _onWebViewFirstInitialized.Invoke();
                _onWebViewFirstInitialized = null;
            }

            if (!string.IsNullOrEmpty(_initialUrl))
            {
                _webView2Control.Navigate(_initialUrl);
            }

            if (_newWindowRequestedEventArgs != null)
            {
                _newWindowRequestedEventArgs.NewWindow = _webView2Control.InnerWebView2WebView;
                _newWindowRequestedEventArgs.Handled   = true;
                _newWindowDeferral.Complete();
                _newWindowRequestedEventArgs = null;
                _newWindowDeferral           = null;
            }
        }
Esempio n. 9
0
        public void stCopyDirectoryTest1()
        {
            var target = new FileComponent();

            try {
                target.parse("[File copy.directory()]");
                Assert.Fail("1");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(ArgumentPMException), ex.GetType().ToString()); }

            try {
                target.parse("[File copy.directory(false)]");
                Assert.Fail("2");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(ArgumentPMException), ex.GetType().ToString()); }

            try {
                target.parse("[File copy.directory(\" \", \"dest\", false)]");
                Assert.Fail("3");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(InvalidArgumentException), ex.GetType().ToString()); }

            try {
                target.parse("[File copy.directory(\"src\", \" \", false)]");
                Assert.Fail("4");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(InvalidArgumentException), ex.GetType().ToString()); }
        }
Esempio n. 10
0
        public void stDeleteFilesTest1()
        {
            var target = new FileComponent();

            try {
                target.parse("[File delete.files(\"file\")]");
                Assert.Fail("1");
            }
            catch (Exception ex) {
                Assert.IsTrue(ex.GetType() == typeof(ArgumentPMException));
            }

            try {
                target.parse("[File delete.files({\"file\", false})]");
                Assert.Fail("2");
            }
            catch (Exception ex) {
                Assert.IsTrue(ex.GetType() == typeof(InvalidArgumentException));
            }

            try {
                target.parse("[File delete.files({\"file\"}, {true})]");
                Assert.Fail("3");
            }
            catch (Exception ex) {
                Assert.IsTrue(ex.GetType() == typeof(InvalidArgumentException));
            }
        }
Esempio n. 11
0
        public void StWriteParseTest5()
        {
            var target = new FileComponent(new Soba(), "");

            Assert.Throws <PMLevelException>(() =>
                                             target.Eval("[File write(\"file\", true):data]")
                                             );

            Assert.Throws <PMLevelException>(() =>
                                             target.Eval("[File write(\"file\", true, true):data]")
                                             );

            Assert.Throws <PMLevelException>(() =>
                                             target.Eval("[File write(\"file\", \"true\", \"true\", \"utf-8\"):data]")
                                             );

            Assert.Throws <PMLevelException>(() =>
                                             target.Eval("[File append(\"file\", true, true, \"utf-8\"):data]")
                                             );

            Assert.Throws <PMLevelException>(() =>
                                             target.Eval("[File appendLine(\"file\", true, true, \"utf-8\"):data]")
                                             );

            Assert.Throws <PMLevelException>(() =>
                                             target.Eval("[File writeLine(\"file\", true, true, \"utf-8\"):data]")
                                             );
        }
Esempio n. 12
0
        private void FileTreeView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            TreeListItem item = WpfUtil.GetTreeListItem(e.OriginalSource);

            if (item == null)
            {
                return;
            }

            FileComponent file = FileController.SelectedItem;

            if (file != null)
            {
                if (file.File)
                {
                    file.Open();
                }
                else
                {
                    TreeNode node = FileTreeView.SelectedNode;
                    if (node != null)
                    {
                        FileTreeView.SetIsExpanded(node, !node.IsExpanded);
                    }
                }
            }

            FileTreeView.UnselectAll();
        }
Esempio n. 13
0
        public void Add(ClientComponent client, ServerComponent server, GroupComponent group)
        {
            Entity entity = new Entity();

            entity.Add(client);

            ClientOptionsComponent options = new ClientOptionsComponent();

            entity.Add(options);

            entity.Add(server);

            entity.Add(group);

            FolderListComponent folderList = new FolderListComponent();

            entity.Add(folderList);

            FileMapComponent fileMap = new FileMapComponent();

            entity.Add(fileMap);

            FolderMapComponent folderMap = new FolderMapComponent();

            entity.Add(folderMap);

            ClientMachineComponent machine = new ClientMachineComponent();

            entity.Add <MachineComponent>(machine);

            SessionComponent session = new SessionComponent();

            entity.Add(session);

            FileComponent file = new FileComponent();

            entity.Add(file);

            SearchListComponent search = new SearchListComponent(SearchController.Dispatcher);

            entity.Add(search);

            BrowseComponent browse = new BrowseComponent();

            entity.Add(browse);

            DownloadListComponent download = new DownloadListComponent(DownloadController.Dispatcher);

            entity.Add(download);

            UploadListComponent upload = new UploadListComponent(UploadController.Dispatcher);

            entity.Add(upload);
#if DEBUG
            LogComponent log = new LogComponent(LogController);
            entity.Add(log);
#endif
            Add(entity);
        }
Esempio n. 14
0
        public void StGetParseTest1()
        {
            var target = new FileComponent(new Soba(), "");

            Assert.Throws <PMLevelException>(() =>
                                             target.Eval("[File get(file)]")
                                             );
        }
Esempio n. 15
0
        public HttpCode Execute(string jsonId, FileComponent file, string clientId = null)
        {
            Clear();

            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonChunk jsonChunk = new JsonChunk()
            {
                Size = file.Size
            };
            JsonClient jsonClient = (clientId != null) ? new JsonClient(clientId) : null;
            JsonDownloadRequestMessage jsonRequestMessage = new JsonDownloadRequestMessage(jsonId)
            {
                Chunk = jsonChunk, Client = jsonClient
            };

            JsonFile jsonFile = (JsonFile)file;
            JsonDownloadRequestData jsonRequestData = new JsonDownloadRequestData()
            {
                File = jsonFile
            };
            JsonPacket jsonRequest = new JsonPacket(jsonRequestMessage, Group.Encrypt(jsonRequestData));

            HttpRequest httpRequest = new HttpRequest(Session.Id)
            {
                Data = Session.Encrypt(jsonRequest)
            };

            channel.Send(httpRequest);

            // Response
            HttpResponse httpResponse;

            channel.Receive(out httpResponse);
            Code = httpResponse.Code;

            if (httpResponse.Ok)
            {
                JsonPacket jsonResponse = JsonPacket.Parse(Session.Decrypt(httpResponse.Data));
                JsonDownloadResponseMessage jsonResponseMessage = JsonDownloadResponseMessage.Parse(jsonResponse.Message);
                Chunk = jsonResponseMessage.Chunk;
                Id    = jsonResponseMessage.Id;

                JsonDownloadResponseData jsonResponseData = JsonDownloadResponseData.Parse(Group.Decrypt(jsonResponse.Data));
                if (jsonResponseData != null)
                {
                    Data = jsonResponseData.Data;
                }
#if DEBUG
                jsonResponse.Data = null;
                Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
            }

            return(httpResponse.Code);
        }
 /// <summary>
 /// Performs complete analysis of files stored under specified directory. Depends on <seealso cref="CollectorStrategy"/>.
 /// Catches all exceptions caught during program runtime.
 /// </summary>
 /// <param name="path">Root directory for analysis</param>
 /// <returns>Result of directory analysis. Can be either error message or a summary.</returns>
 public AnalysisResult RunAnalysis(string path)
 {
     try {
         FileComponent files = fileCollector.GetFilesFromDirectory(path);
         return(this.presenter.RunAnalysis(files));
     } catch (Exception e) {
         return(this.presenter.CreateExceptionMessage(e));
     }
 }
Esempio n. 17
0
 public void CompareCopiedFiles(FileComponent left, FileComponent right)
 {
     Assert.NotEqual(left.Id, right.Id);
     Assert.Equal(left.Type, right.Type);
     Assert.Equal($"Copy of {left.Name}", right.Name);
     // Assert.Equal(left.ParentId, right.ParentId);
     Assert.Equal(left.Size, right.Size);
     Assert.Equal(left.Src, right.Src);
 }
Esempio n. 18
0
        public ServiceResult <byte[]> Download(Guid id)
        {
            var resultData = new ServiceResult <byte[]>();

            try
            {
                if (!ModelState.IsValid)
                {
                    resultData.Code = MISSING_REQUIRED_FIELDS;
                    foreach (string error in ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage)))
                    {
                        resultData.Message += error + Environment.NewLine;
                    }

                    return(resultData);
                }

                var file = new FileComponent().GetById(id);

                if (file != null)
                {
                    var storageFolder = ConfigurationManager.AppSettings.Get("StorageFolder");
                    var fullPath      = System.IO.Path.Combine(storageFolder, file.FilePath);

                    if (System.IO.File.Exists(fullPath))
                    {
                        byte[] bytes;
                        using (var stream = System.IO.File.Open(fullPath, System.IO.FileMode.Open))
                        {
                            bytes = new byte[stream.Length];
                            stream.Read(bytes, 0, bytes.Length);
                            stream.Close();
                        }

                        resultData.Data = bytes;

                        resultData.Success();
                    }
                    else
                    {
                        resultData.Failer(10001, "File is not found");
                    }
                }
                else
                {
                    resultData.Failer(10001, "File is not found");
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                resultData.SystemError(ex);
            }

            return(resultData);
        }
Esempio n. 19
0
        public void Log(Action <LogBuilder> action)
        {
            StringBuilder stringBuilder = new StringBuilder();

            action(new LogBuilder(stringBuilder));
            lock (IDENT_CRITICAL_SECTION)
            {
                FileComponent.SaveContent(FILE_PATH, stringBuilder.ToString());
            }
        }
Esempio n. 20
0
 public void WalkFile(FileComponent file, ProjectItem item)
 {
     if (item.FileCodeModel.CodeElements != null &&
         item.FileCodeModel.CodeElements.Count > 0)
     {
         foreach (CodeElement ce in item.FileCodeModel.CodeElements)
         {
             WalkElements(ce, file);
         }
     }
 }
Esempio n. 21
0
 protected void VisitProject(ProjectComponent project, ProjectItem item)
 {
     if (item.SubProject == null)
     {
         FileComponent file = VisitFile(item);
         if (file != null)
         {
             project.Visit(file);
         }
     }
 }
Esempio n. 22
0
        private void SearchListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            FileComponent file = SearchController.SelectedItem;

            if (file == null)
            {
                return;
            }

            DownloadController.Download(file);
        }
Esempio n. 23
0
        private void DownloadListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DemonSaw.Entity.Entity entity = DownloadController.SelectedItem;
            if (entity == null)
            {
                return;
            }

            FileComponent file = entity.Get <FileComponent>();

            FileUtil.Execute(file.Path);
        }
Esempio n. 24
0
        public void ParseTest1()
        {
            var target = new FileComponent(new Soba(), "");

            Assert.Throws <IncorrectSyntaxException>(() =>
                                                     target.Eval("#[File get(\"file\")]")
                                                     );

            Assert.Throws <IncorrectSyntaxException>(() =>
                                                     target.Eval("File get(\"file\")")
                                                     );
        }
Esempio n. 25
0
        public void StRemoteTest2()
        {
            var target = new FileComponent(new Soba(), "");

            Assert.Throws <PMLevelException>(() =>
                                             target.Eval("[File remote.download()]")
                                             );

            Assert.Throws <PMLevelException>(() =>
                                             target.Eval("[File remote.download(\"addr\")]")
                                             );

            Assert.Throws <PMLevelException>(() =>
                                             target.Eval("[File remote.download(\"addr\", \"file\", \"user\")]")
                                             );
        }
Esempio n. 26
0
        public void StDeleteFilesTest1()
        {
            var target = new FileComponent(new Soba(), "");

            Assert.Throws <PMLevelException>(() =>
                                             target.Eval("[File delete.files(\"file\")]")
                                             );

            Assert.Throws <PMArgException>(() =>
                                           target.Eval("[File delete.files({\"file\", false})]")
                                           );

            Assert.Throws <PMArgException>(() =>
                                           target.Eval("[File delete.files({\"file\"}, {true})]")
                                           );
        }
Esempio n. 27
0
        protected FileComponent VisitFile(ProjectItem item)
        {
            FileComponent file = null;

            if (Filter(item))
            {
                m_app.StatusBar.Text = "building stats for " + item.Name;

                file = new FileComponent(item.get_FileNames(0), item.Name);

                Walker walker = new Walker();
                walker.WalkFile(file, item);
            }

            return(file);
        }
Esempio n. 28
0
        public void stCallParseTest1()
        {
            var target = new FileComponent();

            try {
                target.parse("[File call(file)]");
                Assert.Fail("1");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(ArgumentPMException), ex.GetType().ToString()); }

            try {
                target.parse("[File out(file)]");
                Assert.Fail("2");
            }
            catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(ArgumentPMException), ex.GetType().ToString()); }
        }
Esempio n. 29
0
        private void FileOpenCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (FileController.SelectedItems.Count == 1)
            {
                FileComponent file = FileController.SelectedItem;

                if (file.File)
                {
                    file.Open();
                    FileTreeView.UnselectAll();
                    return;
                }
            }

            FileController.Open(FileController.SelectedItems);
            FileTreeView.UnselectAll();
        }
Esempio n. 30
0
        public List <FileComponent> Execute(HttpRequest httpRequest, JsonPacket jsonRequest)
        {
            Clear();

            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Response
            JsonSearchResponseMessage jsonResponseMessage = new JsonSearchResponseMessage();
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage);

            HttpResponse httpResponse = new HttpResponse()
            {
                Data = Session.Encrypt(jsonResponse)
            };

            channel.Send(httpResponse);
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
            // Request
            JsonSearchResponseMessage jsonRequestMessage = JsonSearchResponseMessage.Parse(jsonRequest.Message);
            string jsonId = jsonRequestMessage.Id;
            if (SearchList.Id != jsonId)
            {
                return(null);
            }

            JsonSearchResponseData jsonRequestData = JsonSearchResponseData.Parse(Group.Decrypt(jsonRequest.Data));
            List <JsonFile>        jsonFiles       = jsonRequestData.Files;
            List <FileComponent>   list            = new List <FileComponent>();

            // Data
            foreach (JsonFile jsonFile in jsonFiles)
            {
                FileComponent file = new FileComponent(jsonFile.Id, jsonFile.Name, jsonFile.Size)
                {
                    Owner = Entity
                };
                list.Add(file);
            }

            return(list);
        }
 public void AddFileForVerification(string filePath, HashCollection verificationHashCollection)
 {
     FileComponent component = new FileComponent(filePath, verificationHashCollection);
     this._verificationComponents.Add(component);
 }