コード例 #1
0
ファイル: AudiosViewModel.cs プロジェクト: fnktastic/MuseeMe
        public async Task SelectAudio(Audio audio)
        {
            string fileName = Path.GetFileName(audio.FileName);

            string folderName = Path.GetDirectoryName(audio.FileName);

            IFolder folder = await FileSystem.Current.GetFolderFromPathAsync(folderName);

            bool exist = await fileName.IsFileExistAsync(folder);

            if (exist == true)
            {
                IFile file = await folder.GetFileAsync(fileName);

                await CrossMediaManager.Current.Play(audio.FileName);
            }

            if (exist == false)
            {
                var audioFile = await FilesService.GetItemAsync(audio.Id);

                folder = FileSystem.Current.LocalStorage;
                IFile file = await folder.CreateFileAsync(audio.Id.ToString(), CreationCollisionOption.ReplaceExisting);

                var stream = await file.OpenAsync(FileAccess.ReadAndWrite);

                await stream.WriteAsync(audioFile.FileData, 0, audioFile.FileData.Length);

                stream.Dispose();
            }

            await AudiosRepository.UpdateItemAsync(audio);
        }
コード例 #2
0
ファイル: AudiosViewModel.cs プロジェクト: fnktastic/MuseeMe
        public AudiosViewModel()
        {
            Title             = "Audios";
            Audios            = new ObservableCollection <Audio>();
            LoadAudiosCommand = new Command(async() => await ExecuteLoadAudiosCommand());

            MessagingCenter.Subscribe <NewAudioPage>(this, "AddAudio", async(obj) =>
            {
                try
                {
                    IsBusy    = true;
                    var audio = AudioTagHelper.Read(obj.PickedFile.FilePath, obj.PickedFile.DataArray);

                    var isAudioAdded = await AudiosRepository.AddItemAsync(audio);

                    if (isAudioAdded)
                    {
                        Audios.Add(audio);

                        var audioFile = new AudioFile(audio.Id, obj.PickedFile.DataArray);

                        var isFileAdded = await FilesService.AddItemAsync(audioFile);
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    IsBusy = false;
                }
            });
        }
コード例 #3
0
        public async Task <ActionResult <ActionResult <List <string> > > > AddFile(IFormFile[] file)
        {
            try
            {
                List <string> urls = null;
                if (file[0] == null)
                {
                    return(NotFound(("Bad Request")));
                }
                else
                {
                    foreach (var item in file)
                    {
                        if (urls == null)
                        {
                            urls = new List <string>();
                        }
                        FilesService service = new FilesService();
                        string       url     = await service.UploadFile(item);

                        urls.Add(url);
                    }
                    return(Ok(urls));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message.ToString()));
            }
        }
コード例 #4
0
 public ProjectsController(ProjectsService projectsService, FilesService filesService, UsersService usersService, UserManager <ApplicationUser> userManager)
 {
     _userManager     = userManager;
     _projectsService = projectsService;
     _filesService    = filesService;
     _usersService    = usersService;
 }
コード例 #5
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            var fileName = FilesService.getFullFilePath("request", "request");

            using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
            {
                Byte[] address = new UTF8Encoding(true).GetBytes(JsonConvert.SerializeObject(request.RequestUri));
                await fs.WriteAsync(address, 0, address.Length, cancellationToken);

                byte[] newline = Encoding.ASCII.GetBytes(Environment.NewLine);
                fs.Write(newline, 0, newline.Length);
                fs.Write(newline, 0, newline.Length);

                foreach (var httpRequestHeader in request.Headers)
                {
                    Byte[] headers = new UTF8Encoding(true).GetBytes(JsonConvert.SerializeObject(httpRequestHeader));
                    await fs.WriteAsync(headers, 0, headers.Length, cancellationToken);

                    fs.Write(newline, 0, newline.Length);
                }

                fs.Write(newline, 0, newline.Length);
                fs.Write(newline, 0, newline.Length);

                Byte[] content = await request.Content.ReadAsByteArrayAsync();

                await fs.WriteAsync(content, 0, content.Length, cancellationToken);
            }

            return(await base.SendAsync(request, cancellationToken));
        }
コード例 #6
0
        public ActionResult Create(string id, string nid)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(Content("<script>alert(\"参数错误\");location.href=\"/\"</script>", "text/html"));
            }
            Class ml = new Class();

            if (CheckRoleService.instance().CheckRole_ClassID(new Guid(id), UserDateTicket.UID))
            {
                ml = ClassService.instance().GetEnumByID(new Guid(id)).FirstOrDefault();
            }
            else
            {
                return(Content("<script>alert(\"没有权限\")</script>", "text/html"));
            }
            News m = new News();

            if (string.IsNullOrEmpty(nid))
            {
                m = new News();
            }
            else
            {
                m = NewsService.instance().GetEnumByID(new Guid(nid)).FirstOrDefault();
                Files file = FilesService.instance().Single(new Guid(nid));
                ViewBag.filepath = file == null ? "" : file.FilePath;
            }
            ViewBag.ClassID = id;
            return(View(m));
        }
コード例 #7
0
 public AuthenticationController(SignInManager <BlogUserIdentity> signInManager, UserManager <BlogUserIdentity> userManager, MyContext myContext, FilesService fileservice)
 {
     _signInManager = signInManager;
     _userManager   = userManager;
     _appContext    = myContext;
     _filesService  = fileservice;
 }
コード例 #8
0
        public FilesControllerTests()
        {
            //TODO NInject or some other resolvers.
            var fileServices          = new EnvironmentBuilder("FileServicesClient:Username", "FileServicesClient:Password", "FileServicesClient:Url");
            var lookupServices        = new EnvironmentBuilder("LookupServicesClient:Username", "LookupServicesClient:Password", "LookupServicesClient:Url");
            var locationServices      = new EnvironmentBuilder("LocationServicesClient:Username", "LocationServicesClient:Password", "LocationServicesClient:Url");
            var lookupServiceClient   = new LookupCodeServicesClient(lookupServices.HttpClient);
            var locationServiceClient = new LocationServicesClient(locationServices.HttpClient);
            var fileServicesClient    = new FileServicesClient(fileServices.HttpClient);

            _fileServicesClient = fileServicesClient;
            var lookupService   = new LookupService(lookupServices.Configuration, lookupServiceClient, new CachingService());
            var locationService = new LocationService(locationServices.Configuration, locationServiceClient, new CachingService());

            _agencyIdentifierId = fileServices.Configuration.GetNonEmptyValue("Request:AgencyIdentifierId");
            _partId             = fileServices.Configuration.GetNonEmptyValue("Request:PartId");
            var claims = new[] {
                new Claim(CustomClaimTypes.JcParticipantId, _partId),
                new Claim(CustomClaimTypes.JcAgencyCode, _agencyIdentifierId),
            };
            var identity  = new ClaimsIdentity(claims, "Cookies");
            var principal = new ClaimsPrincipal(identity);

            var filesService = new FilesService(fileServices.Configuration, fileServicesClient, new Mapper(), lookupService, locationService, new CachingService(), principal);

            //TODO fake this.
            var vcCivilFileAccessHandler = new VcCivilFileAccessHandler(new ScvDbContext());

            _controller = new FilesController(fileServices.Configuration, fileServices.LogFactory.CreateLogger <FilesController>(), filesService, vcCivilFileAccessHandler);
            _controller.ControllerContext = HttpResponseTest.SetupMockControllerContext(fileServices.Configuration);
        }
コード例 #9
0
 public ChatService(
     IChatDataProvider chatDataProvider,
     IUsersRepository usersRepository,
     IUsersConversationsRepository usersConversationsRepository,
     IConversationRepository conversationRepository,
     ILastMessagesRepository lastMessagesRepository,
     IDhPublicKeysRepository dh,
     IChatRolesRepository rolesRepository,
     FilesService filesService,
     UnitOfWork unitOfWork,
     BansService bansService,
     MessagesService messagesService,
     IComparer <Shared.DTO.Conversations.Chat> chatComparer,
     IRolesRepository staticRolesRepo)
 {
     this.chatDataProvider             = chatDataProvider;
     this.usersRepository              = usersRepository;
     this.usersConversationsRepository = usersConversationsRepository;
     this.conversationRepository       = conversationRepository;
     this.lastMessagesRepository       = lastMessagesRepository;
     publicKeys           = dh;
     this.rolesRepository = rolesRepository;
     this.filesService    = filesService;
     this.unitOfWork      = unitOfWork;
     this.bansService     = bansService;
     this.messagesService = messagesService;
     this.chatComparer    = chatComparer;
     this.staticRolesRepo = staticRolesRepo;
 }
コード例 #10
0
 public MediaObjectInfo NewMediaObject(String blogId, String userName, String password, MediaObject mediaObject)
 {
     using (var db = new DataService())
     {
         if (!db.PublisherAccessAllowed(userName, password))
         {
             return(new MediaObjectInfo());
         }
         // Try to upload this file
         Uri uri = FilesService.Upload(mediaObject.Name, mediaObject.Bits);
         // Error
         if (uri == null)
         {
             return(new MediaObjectInfo());
         }
         // Else return informations
         return(new MediaObjectInfo()
         {
             Id = mediaObject.Name,
             Name = mediaObject.Name,
             Type = mediaObject.Type,
             Url = uri.ToString()
         });
     }
 }
コード例 #11
0
 public override void Context()
 {
     XmlService.ResetCalls();
     FileSystem.ResetCalls();
     HashProvider.ResetCalls();
     Service = new FilesService(XmlService.Object, FileSystem.Object, HashProvider.Object);
 }
コード例 #12
0
 public InstructionsController(ApplicationDbContext context, UserManager <ApplicationUser> userManager, FilesService files, InformationService info)
 {
     _context     = context;
     _userManager = userManager;
     _files       = files;
     _info        = info;
 }
コード例 #13
0
 public UserController(SignInManager <BlogUserIdentity> signinmanager, UserManager <BlogUserIdentity> usermanager, MyContext context, FilesService fileservice)
 {
     _signInManager = signinmanager;
     _userManager   = usermanager;
     _appContext    = context;
     _filesService  = fileservice;
 }
コード例 #14
0
        public int Validate([FromUri] NewWebhookValidate hub)
        {
            //hub.verify_token =
            //03a5cde6-5717-4ec1-910e-ac5f15bbf068

            FilesService.CreateFile("web_hook_validate", JsonConvert.SerializeObject(hub), "json");
            return(hub.challenge);
        }
コード例 #15
0
 public FilesController(IConfiguration configuration, ILogger <FilesController> logger, FilesService filesService)
 {
     _configuration        = configuration;
     _logger               = logger;
     _filesService         = filesService;
     _civilFilesService    = filesService.Civil;
     _criminalFilesService = filesService.Criminal;
 }
コード例 #16
0
 public CourseController(CourseService courseService, ApplicationDbContext context, AccessService access, FilesService files, UserManager <ApplicationUser> userManager)
 {
     _context       = context;
     _courseService = courseService;
     _access        = access;
     _files         = files;
     _userManager   = userManager;
 }
コード例 #17
0
        public ActionResult Product(string id)
        {
            Product p = ProductService.instance().Single(new Guid(id));

            ViewBag.files    = FilesService.instance().GetFilesByRelationID(p.ID);
            ViewBag.cate_ids = ClassService.instance().Single(p.ClassID).cate_id;
            return(View(p));
        }
コード例 #18
0
ファイル: FilesServiceTests.cs プロジェクト: ramgp/softedule
        public void FilesTest()
        {
            FilesService fs = new FilesService(@"x:\softedule");

            int count = fs.ResourceFiles().Count();

            Assert.AreEqual(1, count);
        }
コード例 #19
0
ファイル: FilesController.cs プロジェクト: cysun/MyNotes
 public FilesController(FilesService filesService, IAuthorizationService authorizationService,
                        IMapper mapper, ILogger <FilesController> logger)
 {
     _filesService         = filesService;
     _authorizationService = authorizationService;
     _mapper = mapper;
     _logger = logger;
 }
コード例 #20
0
 public AlgoController(ProjectsRepository projectsRepository, ActivityRepository activityRepository, AlgoExecutionService algoExecutionService, FilesService filesService, IHttpContextAccessor accessor)
 {
     _projectsRepository   = projectsRepository;
     _activityRepository   = activityRepository;
     _algoExecutionService = algoExecutionService;
     _filesService         = filesService;
     _accessor             = accessor;
 }
コード例 #21
0
 public FilesController(IConfiguration configuration, ILogger <FilesController> logger, FilesService filesService, VcCivilFileAccessHandler vcCivilFileAccessHandler)
 {
     _configuration            = configuration;
     _logger                   = logger;
     _filesService             = filesService;
     _civilFilesService        = filesService.Civil;
     _criminalFilesService     = filesService.Criminal;
     _vcCivilFileAccessHandler = vcCivilFileAccessHandler;
 }
コード例 #22
0
 public HomeController(NotesService notesService, FilesService filesService, TagsService tagsService,
                       IAuthorizationService authorizationService, ILogger <HomeController> logger)
 {
     _notesService         = notesService;
     _filesService         = filesService;
     _tagsService          = tagsService;
     _authorizationService = authorizationService;
     _logger = logger;
 }
コード例 #23
0
        public JsonResult GetPicPage(int pageIndex, int pageSize, string wheres, string sortorder, string sortname)
        {
            int totalcount = 0;
            IEnumerable <Files> datalist = FilesService.instance().GetPageByDynamic(pageIndex, pageSize, out totalcount, sortname, sortorder, wheres);
            ResultBase_Page     page     = new ResultBase_Page(pageIndex, pageSize, totalcount);

            page.content = datalist.ToList();
            return(Json(page, JsonRequestBehavior.AllowGet));
        }
コード例 #24
0
ファイル: program.cs プロジェクト: bruennijs/file-storage
 public static void Main(string[] args) {
     
     //log4net.
     
     string var1 = "sugaaaar";
     var fs = new FilesService();
     fs.Create(var1);
     Console.WriteLine($"Can you give me {var1}");
 }   
コード例 #25
0
 public SalesController()
 {
     db = new DbContext();
     customersService = new CustomersService(db);
     filesService     = new FilesService(db);
     reportsService   = new ReportService(db);
     salesmansService = new SalesmansService(db);
     salesService     = new SalesService(db);
 }
コード例 #26
0
 public StorageService(
     OSSApiService ossApiService,
     AppsContainer appsContainer,
     FilesService filesService)
 {
     _ossApiService = ossApiService;
     _appsContainer = appsContainer;
     _filesService  = filesService;
 }
コード例 #27
0
        /// <summary>
        /// 获取RelationID的文件信息
        /// </summary>
        /// <param name="RelationID">关联ID</param>
        /// <returns></returns>
        public HttpResponseMessage GetRelationFiles(string RelationID)
        {
            Guid ID;

            if (Guid.TryParse(RelationID, out ID))
            {
                return(Util.Utils.ConvertToJson(FilesService.instance().GetFilesByRelationID(ID)));
            }
            return(null);
        }
コード例 #28
0
ファイル: FilesController.cs プロジェクト: zhibek-7/dordoi
        public FilesController(
            FilesService filesService,
            IHubContext <FilesHub> hubContext)
        {
            this._filesService = filesService;
            this._hubContext   = hubContext;

            this._filesService.FileParsingFailed += OnFileParsingFailedAsync;
            ur = new UserRepository(Settings.GetStringDB());
        }
コード例 #29
0
        public ResourceFileViewModel(FilesService filesService)
        {
            this.filesService = filesService;
            files             = new ObservableCollection <ResourceFile>(filesService.ResourceFiles());

            if (files.Count > 0)
            {
                selectedFile = files.First();
            }
        }
コード例 #30
0
        /// <summary>
        /// 根据ID获取详细信息
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns></returns>
        public HttpResponseMessage Get(string id)
        {
            Guid ID;

            if (Guid.TryParse(id, out ID))
            {
                return(Util.Utils.ConvertToJson(FilesService.instance().Single(ID)));
            }
            return(null);
        }
コード例 #31
0
        public async Task <IActionResult> CheckFileInfo(string id, [FromQuery] string access_token)
        {
            try
            {
                Config.logger.LogDebug("CheckFileInfo: id=" + id);
                if (string.IsNullOrEmpty(access_token))
                {
                    Config.logger.LogError("status:500 accessToken is null");
                    return(StatusCode(500));
                }
                Dictionary <string, Object> token    = AccessTokenVerifier.DecodeJWT(access_token);
                Dictionary <string, string> user     = (Dictionary <string, string>)token["user"];
                Dictionary <string, string> metadata = (Dictionary <string, string>)token["metadata"];

                if (!AccessTokenVerifier.VerifyAccessToken(id, (string)metadata["id"], (string)token["created"]))
                {
                    Config.logger.LogError("status:500 accessToken is illegal");
                    return(StatusCode(500)); //access token is illegal
                }
                var     sessionContext = Request.Headers["X-WOPI-SessionContext"];
                string  idToDownload   = id;
                string  fileName       = Config.Folder + "/" + metadata["id"] + "." + metadata["type"];
                Session editSession    = Session.GetSessionFromRedis(id);
                if (editSession == null)
                {
                    FilesService.DownloadFileFromDrive(idToDownload, fileName, user["authorization"]);
                    editSession = new Session(id, fileName);
                    editSession.SaveToRedis();
                    editSession.AddSessionToSetInRedis();
                    Config.logger.LogDebug("New session added to Redis for id=" + id);
                }
                if (!editSession.UserIsInSession(user["id"]))
                {
                    Config.logger.LogDebug("add new user to session");
                    editSession.AddUser(user["id"], user["authorization"], user["permission"], user["name"]);
                    editSession.SaveToRedis();
                    Config.logger.LogDebug("Added user {0} to session {1}", user["id"], id);
                }
                CheckFileInfo checkFileInfo = editSession.GetCheckFileInfo(user["id"], user["name"], metadata["name"]);
                return(Ok(checkFileInfo));
            }
            catch (Exception ex)
            {
                if (ex is DriveFileNotFoundException)
                {
                    Config.logger.LogError("status:404 CheckFileInfo Drive Error" + ex.Message);
                    return(StatusCode(404));
                }
                else
                {
                    Config.logger.LogError("status:500, CheckFileInfo Error:" + ex.Message);
                    return(StatusCode(500));
                }
            }
        }
 public override void TestInit()
 {
     this.user = new TestUser();
     this.FilesService = new FilesService();
 }
コード例 #33
0
 public FilesController(IIdentityService identityService, FilesService fileService)
 {
   Console.WriteLine("filesController ctor");
   this.identityService = identityService;
   this.filesService = fileService;  
 }