Exemplo n.º 1
0
        public void CopyFolder(IMailFolder folder, Folder sqlEntity, bool update, string password)
        {
            try
            {
                folder.Open(FolderAccess.ReadOnly);
            }
            catch (Exception)
            {
                return;
            }

            Random           rng   = AzusaContext.GetInstance().RandomNumberGenerator;
            IList <UniqueId> uuids = folder.Search(FolderService.GetSearchQuery(sqlEntity));

            foreach (UniqueId uuid in uuids)
            {
                if (MessageService.TestForMessage((int)uuid.Id))
                {
                    continue;
                }

                var message = folder.GetMessage(uuid);

                byte[] saltBuffer = new byte[16];
                rng.NextBytes(saltBuffer);
                Array.Copy(azusaString, 0, saltBuffer, 0, azusaString.Length);
                int iterations = rng.Next(1000, short.MaxValue);
                Rfc2898DeriveBytes deriveBytes = new Rfc2898DeriveBytes(password, saltBuffer, iterations);
                Aes aes = Aes.Create();
                aes.Key = deriveBytes.GetBytes(32);
                aes.IV  = deriveBytes.GetBytes(16);
                MemoryStream ms           = new MemoryStream();
                CryptoStream cryptoStream = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write);
                message.WriteTo(cryptoStream);
                cryptoStream.Flush();

                Mail child = new Mail();
                child.Uid          = (int)uuid.Id;
                child.MessageUtime = message.Date.DateTime.ToUnixTime();
                child.Folder       = sqlEntity.id;
                child.From         = message.From[0].ToString();
                if (message.To.Count > 0)
                {
                    child.To = message.To[0].ToString();
                }
                else
                {
                    child.To = null;
                }
                child.Subject    = message.Subject;
                child.Salt       = saltBuffer;
                child.Iterations = (short)iterations;
                child.Data       = new byte[ms.Position];
                Array.Copy(ms.GetBuffer(), 0, child.Data, 0, ms.Position);

                MessageService.StoreMessage(child);
            }

            folder.Close(false);
        }
Exemplo n.º 2
0
        private SelectableAction[] GetActions(string path)
        {
            var actions = new List <SelectableAction>
            {
                new SelectableAction("Open", () => FolderService.OpenLocation(path)),
                new SelectableAction("Terminal", () => TerminalService.OpenTerminal(path)),
            };

            var hasGit = GitService.TryGetRemoteGitLocation(path, out string uri);

            if (hasGit)
            {
                actions.Add(new SelectableAction("Web", () => StartProgramService.StartProgram(uri)));
            }

            foreach (var type in m_programTypesToStart)
            {
                actions.Add(new SelectableAction(type, () => StartProgramService.StartProgramOfType(type, path, true)));
            }

            foreach (var type in m_programTypesTopFolderToStart)
            {
                actions.Add(new SelectableAction(type, () => StartProgramService.StartProgramOfType(type, path, true)));
            }

            return(actions.ToArray());
        }
Exemplo n.º 3
0
        internal static void HandleInitialData(string url, OpcInitialData initialData)
        {
            log.Debug("HandleInitialData entered");
            OPCServerFolderBehaviorData folderExt = EntityCache <OPCServerFolderBehaviorData> .GetCache().AllEntities.FirstOrDefault(s => s.Url == url);

            Folder f = folderExt?.GetEntity() as Folder;

            if (f == null)
            {
                throw new Exception("No OPC server found with this URL");
            }

            if (initialData.Nodes != null)
            {
                UpdateTagsInFolder(f.FolderID + ".tagdata", f.FolderID, url, initialData.Nodes);
            }

            string[] eventIds = FolderService.GetFolderEntities <OPCEvent>(f.FolderID).Select(e => e.Id).ToArray();

            foreach (BaseTagValue value in initialData.Values)
            {
                // Record the value separately for each event, because they might update at different rates:
                foreach (string eventId in eventIds)
                {
                    string key = eventId + "|" + value.Path;
                    OPCEngine.mostRecentValues[key] = value;
                }
            }

            log.Debug("HandleInitialData complete");
        }
Exemplo n.º 4
0
        private FolderService CreateFolderService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new FolderService(userId);

            return(service);
        }
Exemplo n.º 5
0
        private void deletefolder_Click(object sender, EventArgs e)
        {
            FolderService myfolderservice = new FolderService();

            myfolderservice.delete(cname);
            MessageBox.Show("删除文件夹成功!");
        }
Exemplo n.º 6
0
 public AcceleratorPackage(
     AssortmentService assortmentService,
     FieldTemplateService fieldTemplateService,
     StructureInfoService structureInfoService,
     MarketService marketService,
     ChannelService channelService,
     CurrencyService currencyService,
     WebsiteService websiteService,
     InventoryService inventoryService,
     PriceListService priceListService,
     DomainNameService domainNameService,
     GroupService groupService,
     FolderService folderService,
     PersonService personService,
     LanguageService languageService,
     SlugifyService slugifyService)
 {
     _assortmentService    = assortmentService;
     _fieldTemplateService = fieldTemplateService;
     _structureInfoService = structureInfoService;
     _marketService        = marketService;
     _channelService       = channelService;
     _currencyService      = currencyService;
     _websiteService       = websiteService;
     _inventoryService     = inventoryService;
     _priceListService     = priceListService;
     _domainNameService    = domainNameService;
     _groupService         = groupService;
     _folderService        = folderService;
     _personService        = personService;
     _languageService      = languageService;
     _slugifyService       = slugifyService;
 }
Exemplo n.º 7
0
        public Task <ConcurrentBag <SelectableItem> > GetItems()
        {
            var folders = FolderService.GetFolders(m_path);
            var items   = folders.Select(f => new SelectableItem(m_prefix + FileService.GetFileName(f), () => GetActions(f))).ToList();

            return(Task.FromResult(new ConcurrentBag <SelectableItem>(items)));
        }
        public async void DisableDebugMode()
#endif
        {
            _isDebugMode = false;
            SettingsService.SaveSetting(SettingsResources.DebugModeIsEnabled, false);
            LogService.SetLogLevel(MLogLevel.LOG_LEVEL_DEBUG);

#if WINDOWS_PHONE_80
            FileService.DeleteFile(AppService.GetFileLogPath());
            if (App.SavedForOfflineViewModel != null)
            {
                App.SavedForOfflineViewModel.SavedForOffline.Refresh();
            }
#elif WINDOWS_PHONE_81
            // Need force to false to show the options dialog
            App.AppInformation.PickerOrAsyncDialogIsOpen = false;
            await DialogService.ShowOptionsDialog(AppMessages.AM_SaveLogFile_Title, AppMessages.AM_SaveLogFile,
                                                  new[]
            {
                new DialogButton(UiResources.Yes, () =>
                {
                    // Ask the user a save location
                    FolderService.SelectFolder("SelectLogFileSaveLocation");
                }),
                new DialogButton(UiResources.No, () =>
                {
                    FileService.DeleteFile(AppService.GetFileLogPath());
                    if (App.SavedForOfflineViewModel != null)
                    {
                        App.SavedForOfflineViewModel.SavedForOffline.Refresh();
                    }
                })
            });
#endif
        }
Exemplo n.º 9
0
        public void Search_WithResults()
        {
            string criteria = "unit_test";
            string expected = $"file_test1 : 1 occurrences {System.Environment.NewLine}";

            expected += $"file_test3 : 1 occurrences {System.Environment.NewLine}";
            FolderService folderService = new FolderService(
                host.Services.GetRequiredService <ILogger <FolderService> >());

            folderService.Folder = new Folder()
            {
                Name  = "folder_test",
                Files = new System.Collections.Generic.List <File>()
            };
            folderService.Folder.Files.Add(new File()
            {
                Name = "file_test1", Content = "0000000unit_test0000000000000000000000000000000000000000000000000"
            });
            folderService.Folder.Files.Add(new File()
            {
                Name = "file_test2", Content = "00000000000000000000000000000000000000000000000000000000"
            });
            folderService.Folder.Files.Add(new File()
            {
                Name = "file_test3", Content = "0000000000000000000000000000000000000unit_test0000000000000000000"
            });


            folderService.Search(criteria);
            var actual = folderService.Message;



            Assert.AreEqual(expected, actual, "Wrong result.");
        }
Exemplo n.º 10
0
        public async Task RemoveForOffline(AutoResetEvent waitEventRequest = null)
        {
            String parentNodePath = ((new DirectoryInfo(this.NodePath)).Parent).FullName;

            String sfoRootPath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                              AppResources.DownloadsDirectory.Replace("\\", ""));

            if (this.IsFolder)
            {
                await RecursiveRemoveForOffline(parentNodePath, this.Name);

                FolderService.DeleteFolder(this.NodePath, true);
            }
            else
            {
                // Search if the file has a pending transfer for offline and cancel it on this case
                TransfersService.CancelPendingNodeOfflineTransfers(this.NodePath, this.IsFolder);

                FileService.DeleteFile(this.NodePath);
            }

            SavedForOffline.DeleteNodeByLocalPath(this.NodePath);

            if (this.ParentCollection != null)
            {
                this.ParentCollection.Remove((IOfflineNode)this);
            }

            if (waitEventRequest != null)
            {
                waitEventRequest.Set();
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Remove the node from the offline section.
        /// </summary>
        /// <returns>TRUE if the node was successfully removed or FALSE in other case.</returns>
        public bool RemoveFromOffline()
        {
            var nodePath       = OfflineService.GetOfflineNodePath(this.OriginalMNode);
            var parentNodePath = OfflineService.GetOfflineParentNodePath(this.OriginalMNode);

            // Search if the file has a pending transfer for offline and cancel it on this case
            TransferService.CancelPendingNodeOfflineTransfers(this);

            bool result = true;

            if (this.IsFolder)
            {
                result &= OfflineService.RemoveFolderFromOfflineDB(nodePath);
                result &= FolderService.DeleteFolder(nodePath, true);
            }
            else
            {
                result &= SavedForOfflineDB.DeleteNodeByLocalPath(nodePath);
                result &= FileService.DeleteFile(nodePath);
            }

            result &= OfflineService.CleanOfflineFolderNodePath(parentNodePath);
            this.IsSavedForOffline = !result;

            return(result);
        }
        public async Task TestAddFolderTaskAsync_validParentFolder()
        {
            // Arrange
            var dbContext = AppDBContextMocker.GetAppDbContext(nameof(TestAddFolderTaskAsync_validParentFolder));
            var fService  = new FolderService(new FolderRepository(dbContext), new UnitOfWork(dbContext), null);


            //auto mapper configuration
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new ResourceToModelProfile());
                cfg.AddProfile(new ModelToResourceProfile());
            });

            var folderModel = new SaveFolderResource()
            {
                Name           = "validParentFolder",
                ParentFolderId = 104,
            };
            // Act
            var controller = new FoldersController(fService, mockMapper.CreateMapper(), null);
            var response   = await controller.AddFolderAsync(folderModel) as ObjectResult;

            dbContext.Dispose();

            // Assert
            Assert.NotNull(response);
            var folderResponce = response.Value as FolderResource;

            Assert.NotNull(folderResponce);
            Assert.NotNull(folderResponce.FolderID);
            Assert.Equal(folderResponce.Name, folderModel.Name);
            Assert.Null(folderModel.ParentFolderId);
        }
Exemplo n.º 13
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (!NetworkService.IsNetworkAvailable())
            {
                UpdateGUI(false);
                return;
            }

            if (PhoneApplicationService.Current.StartupMode == StartupMode.Activate)
            {
                // Needed on every UI interaction
                SdkService.MegaSdk.retryPendingConnections();

                #if WINDOWS_PHONE_81
                // Check to see if any folder has been picked
                var app = Application.Current as App;
                if (app != null && app.FolderPickerContinuationArgs != null)
                {
                    FolderService.ContinueFolderOpenPicker(app.FolderPickerContinuationArgs,
                                                           this._sharedItemsViewModel.ActiveSharedFolderView);
                }
                #endif
            }
        }
Exemplo n.º 14
0
        private void CheckAndUpdateOffline(MNode megaNode)
        {
            var offlineNodePath = OfflineService.GetOfflineNodePath(megaNode);

            if ((megaNode.getType() == MNodeType.TYPE_FILE && FileService.FileExists(offlineNodePath)) ||
                (megaNode.getType() == MNodeType.TYPE_FOLDER && FolderService.FolderExists(offlineNodePath)) ||
                TransferService.ExistPendingNodeOfflineTransfer(this))
            {
                if (SavedForOfflineDB.ExistsNodeByLocalPath(offlineNodePath))
                {
                    SavedForOfflineDB.UpdateNode(megaNode);
                }
                else
                {
                    SavedForOfflineDB.InsertNode(megaNode);
                }

                this.IsSavedForOffline = true;
                return;
            }

            if (SavedForOfflineDB.ExistsNodeByLocalPath(offlineNodePath))
            {
                SavedForOfflineDB.DeleteNodeByLocalPath(offlineNodePath);
            }

            this.IsSavedForOffline = false;
        }
Exemplo n.º 15
0
        private async void RemoveItem(object obj)
        {
            if (await FocusedNode.RemoveAsync(false) != NodeActionResult.Cancelled)
            {
                String parentNodePath = ((new DirectoryInfo(FocusedNode.NodePath)).Parent).FullName;

                String sfoRootPath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                                  AppResources.DownloadsDirectory.Replace("\\", ""));

                // Check if the previous folders of the path are empty and
                // remove from the offline and the DB on this case
                while (String.Compare(parentNodePath, sfoRootPath) != 0)
                {
                    var folderPathToRemove = parentNodePath;
                    parentNodePath = ((new DirectoryInfo(parentNodePath)).Parent).FullName;

                    if (FolderService.IsEmptyFolder(folderPathToRemove))
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() => GoFolderUp());
                        FolderService.DeleteFolder(folderPathToRemove);
                        SavedForOffline.DeleteNodeByLocalPath(folderPathToRemove);
                    }
                }

                Refresh();
            }
        }
Exemplo n.º 16
0
 public DeploymentViewModelBuilder(ChannelService channelService, FolderService folderService, IPackage package, AuthorizationService authorizationService)
 {
     _channelService       = channelService;
     _folderService        = folderService;
     _package              = package;
     _authorizationService = authorizationService;
 }
Exemplo n.º 17
0
 public FolderParser(FolderService folderService, IEnumerable <IParser> childParsers)
 {
     ChildrenParsers = new List <IParser>();
     ChildrenParsers.AddRange(childParsers);
     ChildrenParsers.ForEach(p => p.Parent = this);
     this.folderService = folderService;
 }
Exemplo n.º 18
0
        /// <summary>
        /// Main entry point. Creates a bunch of services, and then kicks off
        /// the webserver, which is a blocking call (since it's the dispatcher
        /// thread) until the app exits.
        /// </summary>
        /// <param name="listeningPort"></param>
        /// <param name="args"></param>
        private static void StartWebServer(int listeningPort, string[] args)
        {
            try
            {
                Logging.Log("Starting Damselfly Services");

                // Instantiate all of our services
                var status    = new StatusService();
                var thumbs    = new ThumbnailService();
                var indexing  = new IndexingService();
                var downloads = new DownloadService();
                var basket    = new BasketService();
                var folder    = new FolderService();
                var search    = new SearchService();
                var tasks     = new TaskService();
                var config    = new ConfigService();
                var meta      = new MetaDataService();
                var wp        = new WordpressService();
                var proc      = new ImageProcessService();
                var select    = new SelectionService();

                Logging.Log("Starting Damselfly Webserver");

                BuildWebHost(listeningPort, args).Run();

                Logging.Log("Damselfly Webserver stopped. Exiting");
            }
            catch (Exception ex)
            {
                Logging.Log("Damselfly Webserver terminated with exception: {0}", ex.Message);
            }
        }
Exemplo n.º 19
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (App.AppInformation.IsStartupModeActivate)
            {
                // Needed on every UI interaction
                SdkService.MegaSdk.retryPendingConnections();

                if (!App.AppInformation.HasPinLockIntroduced && SettingsService.LoadSetting <bool>(SettingsResources.UserPinLockIsEnabled))
                {
                    NavigateService.NavigateTo(typeof(PasswordPage), NavigationParameter.Normal, this.GetType());
                    return;
                }

                App.AppInformation.IsStartupModeActivate = false;

                #if WINDOWS_PHONE_81
                // Check to see if any files have been picked
                var app = Application.Current as App;
                if (app != null && app.FolderPickerContinuationArgs != null)
                {
                    FolderService.ContinueFolderOpenPicker(app.FolderPickerContinuationArgs,
                                                           this._folderViewModel);
                }
                return;
                #endif
            }

            base.OnNavigatedTo(e);
        }
        public MainPresenter(IMainView view, ITagView tagger, ITagService service, ICSVView csv, ISearchService searcher, FolderService folder, IStatisticsService dataset, ITaggedStatisticsService corpus, IConcordanceService concordancer, INGramService ngrammer)
        {
            this._tagger       = tagger;
            this._service      = service;
            this._main         = view;
            this._csv          = csv;
            this._searcher     = searcher;
            this._folder       = folder;
            this._dataset      = dataset;
            this._corpus       = corpus;
            this._concordancer = concordancer;
            this._ngrammer     = ngrammer;

            _main.FindClick         += _view_FindClick;
            _main.OpenIndexedCorpus += _view_OpenIndexedCorpus;
            _main.ConcordanceClick  += _main_ConcordanceClick;
            _main.NGramClick        += _main_NGramClick;
            _main.KeywordClick      += _main_KeywordClick;
            _main.LoadStatistics    += _main_LoadStatistics;
            _main.ExtractInfoClick  += _main_ExtractInfoClick;
            _main.BuildIndexClick   += _main_BuildIndexClick;
            _main.CheckNgramState   += _main_CheckNgramState;
            _main.LoadMore          += _main_LoadMore;
            _folder.CheckFolder();
        }
Exemplo n.º 21
0
        public void Initialize()
        {
            var MockDb = new MockDatabase();


            var P1 = new Project
            {
                ID   = 4,
                Name = "Project1"
            };

            MockDb.Projects.Add(P1);
            var P2 = new Project
            {
                ID   = 2,
                Name = "Project2"
            };

            MockDb.Projects.Add(P2);

            var F1 = new Folder
            {
                ID               = 1,
                Name             = "1Root",
                FolderStructure  = null,
                ProjectStructure = P1
            };

            MockDb.Folders.Add(F1);
            var F2 = new Folder
            {
                ID               = 2,
                Name             = "11Child",
                FolderStructure  = F1,
                ProjectStructure = P1
            };

            MockDb.Folders.Add(F2);
            var F3 = new Folder
            {
                ID              = 3,
                Name            = "12Child",
                FolderStructure = F1,
                //ProjectStructure = P1
            };

            MockDb.Folders.Add(F3);
            var F4 = new Folder
            {
                ID              = 4,
                Name            = "111Grandchild",
                FolderStructure = F2,
                //ProjectStructure = P1
            };

            MockDb.Folders.Add(F4);

            service = new FolderService(MockDb);
        }
Exemplo n.º 22
0
        public async Task <bool> SaveForOffline()
        {
            // User must be online to perform this operation
            if (!IsUserOnline())
            {
                return(false);
            }

            MNode parentNode = SdkService.MegaSdk.getParentNode(this.OriginalMNode);

            String sfoRootPath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                              AppResources.DownloadsDirectory.Replace("\\", ""));

            String parentNodePath;

            if (ParentContainerType != ContainerType.PublicLink)
            {
                parentNodePath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                              AppResources.DownloadsDirectory.Replace("\\", ""),
                                              (SdkService.MegaSdk.getNodePath(parentNode)).Remove(0, 1).Replace("/", "\\"));
            }
            else
            {
                // If is a public node (link) the destination folder is the SFO root
                parentNodePath = sfoRootPath;
            }

            if (!FolderService.FolderExists(parentNodePath))
            {
                FolderService.CreateFolder(parentNodePath);
            }

            if (this.IsFolder)
            {
                await RecursiveSaveForOffline(parentNodePath, this);
            }
            else
            {
                await SaveFileForOffline(parentNodePath, this);
            }

            this.IsAvailableOffline = this.IsSelectedForOffline = true;

            // Check and add to the DB if necessary the previous folders of the path
            while (String.Compare(parentNodePath, sfoRootPath) != 0)
            {
                var folderPathToAdd = parentNodePath;
                parentNodePath = ((new DirectoryInfo(parentNodePath)).Parent).FullName;

                if (!SavedForOffline.ExistsNodeByLocalPath(folderPathToAdd))
                {
                    SavedForOffline.Insert(parentNode);
                }

                parentNode = SdkService.MegaSdk.getParentNode(parentNode);
            }

            return(true);
        }
Exemplo n.º 23
0
 private void SelectDownloadLocation(object obj)
 {
     if (App.FileOpenOrFolderPickerOpenend)
     {
         return;
     }
     FolderService.SelectFolder("SelectDefaultDownloadFolder");
 }
Exemplo n.º 24
0
        public ViewModelLocator()
        {
            //ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
            IFolderService folderService = new FolderService();
            string         org           = "test";

            this.MainVM = new MainVM(folderService, org);
        }
Exemplo n.º 25
0
        public ViewModelLocator()
        {
            //ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
             IFolderService folderService = new FolderService();
             string org = "test";

             this.MainVM = new MainVM(folderService, org);
        }
Exemplo n.º 26
0
        public async Task RenameFolder_FolderRenamed()
        {
            var db      = CreateAndSeedDb();
            var service = new FolderService(db);

            await service.RenameFolderAsync("895973FB-F8E1-4FD6-89C4-DC13CED4780E", 1, "New Folder");

            Assert.Contains(db.Folders, folder => folder.Id == 1 && folder.Name == "New Folder");
        }
Exemplo n.º 27
0
        public async Task DeleteFolder_FolderDeleted()
        {
            var db      = CreateAndSeedDb();
            var service = new FolderService(db);

            await service.DeleteFolderAsync("895973FB-F8E1-4FD6-89C4-DC13CED4780E", 1);

            Assert.DoesNotContain(db.Folders, folder => folder.Id == 1);
        }
Exemplo n.º 28
0
        protected override async Task OnInitializedAsync()
        {
            _folders = await FolderService.GetFoldersAsync(ModuleState.SiteId);

            if (PageState.QueryString.ContainsKey("id"))
            {
                _folderId = int.Parse(PageState.QueryString["id"]);
            }
        }
Exemplo n.º 29
0
        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            folderdisplay.Items.Clear();
            FolderService myFolderservice = new FolderService();

            for (int i = 0; i < myFolderservice.find().Count; i++)
            {
                folderdisplay.Items.Add(myFolderservice.find()[i].Foldername, 1);
            }
        }
Exemplo n.º 30
0
        public async Task DeleteFolder_UserHasNoRights_ExceptionThrown()
        {
            var db      = CreateAndSeedDb();
            var service = new FolderService(db);

            await Assert.ThrowsAsync <AccessDeniedException>(async() =>
            {
                await service.DeleteFolderAsync("895973FB-F8E1-4FD6-89C4-DC13CED4780E", 2);
            });
        }
Exemplo n.º 31
0
        public async Task DeleteFolder_FolderDoesNotExist_ExceptionThrown()
        {
            var db      = CreateAndSeedDb();
            var service = new FolderService(db);

            await Assert.ThrowsAsync <ResourceNotFoundException>(async() =>
            {
                await service.DeleteFolderAsync("895973FB-F8E1-4FD6-89C4-DC13CED4780E", 4);
            });
        }
 public FolderServiceFacts()
 {
     Database = new Db();
         Database.SetupDatabase();
         FolderService = new FolderService(Database.ConnectionFactory);
 }