Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ContactClient"/> class.
 ///   This parametrized constructore does accept a "ready to use" http-requester.
 ///   This way you can specify a requester with properties that differ from
 ///   default/config-file properties.
 /// </summary>
 /// <param name="preconfiguredHttpHelper">
 /// the preconfigured http-helper class
 /// </param>
 public ContactClient(HttpHelper preconfiguredHttpHelper)
 {
     this.xingRequester  = preconfiguredHttpHelper;
     this.vCardConverter = new VCardConverter {
         HttpRequester = this.xingRequester
     };
 }
Exemplo n.º 2
0
        public static void Initialize(VCardContext context, IFileProvider fileProvider)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.VCards.Any())
            {
                return;   // DB has been seeded
            }

            // Read from vCard file.
            var fileInfo = fileProvider.GetFileInfo("/DemoFiles/RFC2426.vcf");

            if (!fileInfo.Exists)
            {
                return;
            }

            using (var stream = fileInfo.CreateReadStream())
            {
                var vCards = VCardParser.ParseFromStream(new StreamReader(stream));
                vCards.Sort(VCardSorter);
                // Convert to Dto
                var vCardDtoes = VCardConverter.CollectionToDtoes(vCards);
                foreach (var vCardDto in vCardDtoes)
                {
                    context.VCards.Add(vCardDto);
                }
                context.SaveChanges();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "ContactClient" /> class.
        ///   The default constructor will create and configure a new http-requester by reading
        ///   the config file. Use the parametrized constructor to provide a "ready-to-use"
        ///   http-requester.
        /// </summary>
        public ContactClient()
        {
            var config = ConfigReader.GetConfig <XingConfiguration>();

            this.xingRequester = Factory.Invoke <IHttpHelper>(() => new HttpHelper(HttpUrlBaseAddress, true)
            {
                UseCache      = config.HttpConnection.ReadCache,
                SkipNotCached = config.HttpConnection.SkipNotCached,
                UseIeCookies  = config.HttpConnection.UseIeCookies
            });

            this.vCardConverter = new VCardConverter {
                HttpRequester = this.xingRequester
            };
        }
Exemplo n.º 4
0
        /// <summary>
        /// Overrides the method to write the full list of data.
        /// </summary>
        /// <param name="elements">
        /// The elements to be exported.
        /// </param>
        /// <param name="clientFolderName">
        /// the name of the folder that will get the vCard files while exporting data.
        /// </param>
        /// <param name="skipIfExisting">
        /// a value indicating whether existing entries should be added overwritten or skipped.
        /// </param>
        protected override void WriteFullList(List <StdElement> elements, string clientFolderName, bool skipIfExisting)
        {
            Tools.EnsurePathExist(clientFolderName);
            var use3Char = this.GetConfigValueBoolean("FileExtensionVCF");

            foreach (var element in elements.ToStdContacts())
            {
                if (element.Name == null)
                {
                    continue;
                }

                var fileName = Path.Combine(clientFolderName, SyncTools.NormalizeFileName(element.ToStringSimple()));
                File.WriteAllBytes(
                    fileName + (use3Char ? VCardFilenameExtension2 : VCardFilenameExtension),
                    VCardConverter.StdContactToVCard(element));
                if (this.savePictureExternal && !string.IsNullOrEmpty(element.PictureName))
                {
                    File.WriteAllBytes(fileName + "-" + element.PictureName, element.PictureData);
                }
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> UploadFiles(List <IFormFile> files, string fileEncoding, string propEncoding)
        {
            long size = files.Sum(f => f.Length);

            // full path to file in temp location
            var filePath = Path.GetTempFileName();

            foreach (var formFile in files)
            {
                if (formFile.Length > 0)
                {
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await formFile.CopyToAsync(stream);
                    }
                }
            }

            // process uploaded files
            // Don't rely on or trust the FileName property without validation.
            try
            {
                using (var reader = new StreamReader(filePath, Encoding.GetEncoding(fileEncoding)))
                {
                    BaseProperty.DefaultEncoding = Encoding.GetEncoding(propEncoding);

                    var vCards     = VCardParser.ParseFromStream(reader);
                    var vCardDtoes = VCardConverter.CollectionToDtoes(vCards);

                    return(View("Index", vCardDtoes));
                }
            }
            catch (Exception ex)
            {
                return(Ok(string.Format("Unable to parse file: {0}", ex.Message)));
            }
        }
Exemplo n.º 6
0
 private VCardDto ParseDto(VCardDto vCardDto)
 {
     return(VCardConverter.VCardToDto(VCardConverter.DtoToVCard(vCardDto), vCardDto));
 }