Exemplo n.º 1
0
        /// <summary>
        /// Upload a file to the file server
        /// </summary>
        public void AddFile(FileRequest fileRequest)
        {
            Task.Factory.StartNew(
                   delegate
                   {
                        if (fileRequest == null)
                            throw new ArgumentNullException("fileRequest");

                        //Find the activity and attach the resource
                        ActivityStore.Activities[fileRequest.Resouce.ActivityId].Resources.Add(fileRequest.Resouce);

                        //Add the file to the fileserver
                        _fileServer.AddFile(fileRequest.Resouce,
                                            JsonConvert.DeserializeObject<byte[]>(fileRequest.Bytes),
                                            FileSource.ActivityManager);
                    });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a file to a given activity
        /// </summary>
        /// <param name="fileInfo">The fileinfo describing the file</param>
        /// <param name="activityId">The id of activity</param>
        public void AddResource(FileInfo fileInfo,Guid activityId)
        {
            //Create a new resource from the file
            var resource = new Resource((int)fileInfo.Length, fileInfo.Name)
            {
                ActivityId = activityId,
                CreationTime = DateTime.Now.ToString("u"),
                LastWriteTime = DateTime.Now.ToString("u")  
            };
            var req = new FileRequest
                          {
                              Resouce = resource,
                              Bytes = JsonConvert.SerializeObject(File.ReadAllBytes(fileInfo.FullName))
                          };

            Task.Factory.StartNew(
                delegate
                {
                        Rest.Post(ServiceAddress + Url.Files, req);
                        Log.Out("ActivityClient", string.Format("Received Request to upload {0}", resource.Name),
                                LogCode.Log);
                    });

        }