Beispiel #1
0
        /// <summary>
        ///
        /// Extract all filewrappers from some data.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"></param>
        /// <returns></returns>

        public static Dictionary <string, Property <FileWrapper> > ExtractFileWrappers(object data)
        {
            return(ExtractObjects <FileWrapper>(data, (X) => FileWrapper.isFileWrapper(X), (Y) =>
            {
                return FileWrapper.FromObject((object)Y);
            }));
        }
Beispiel #2
0
 public static Boolean isFileWrapper(Object obj)
 {
     // If the object is already of type FileWrapper return true
     if (obj.ToString() == "Stratumn.Sdk.FilePathWrapper")
     {
         return(true);
     }
     if (obj.ToString() == "Stratumn.Sdk.FileBlobWrapper")
     {
         return(true);
     }
     if (obj.ToString() == "Stratumn.Sdk.BrowserFileWrapper")
     {
         return(true);
     }
     if (obj == null)
     {
         return(false);
     }
     // For strings, assume it's a JSON string
     if (obj is String)
     {
         string json        = (string)obj;
         Object fileWrapper = null;
         // attempt to generate FileWrapper from json.
         try
         {
             if (json.ToUpper().Contains("PATH"))
             {
                 fileWrapper = JsonHelper.FromJson <FilePathWrapper>(json);
             }
             else if (json.ToUpper().Contains("FILEINFO"))
             {
                 fileWrapper = JsonHelper.FromJson <FileBlobWrapper>(json);
             }
             else if (json.ToUpper().Contains("FILE"))
             {
                 fileWrapper = JsonHelper.FromJson <BrowserFileWrapper>(json);
             }
         }
         catch (Exception)
         { // obj can not be converted
         }
         return(fileWrapper != null);
     }
     // Otherwise, try to coerce from json
     try
     {
         FileWrapper fileWrapper = FromObject(obj);
         return(fileWrapper.Info() != null);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #3
0
        private async Task <List <Property <FileWrapper> > > DownloadFiles(Dictionary <string, Property <FileRecord> > fileRecordMap)
        {
            List <Property <FileWrapper> > fileWrapperList = new List <Property <FileWrapper> >();

            if (fileRecordMap.Count == 0)
            {
                return(fileWrapperList);
            }

            foreach (var fileRecordProp in fileRecordMap)
            {
                FileRecord   fileRecord = fileRecordProp.Value.Value;
                MemoryStream file       = await client.DownloadFile(fileRecord);

                fileWrapperList.Add(
                    fileRecordProp.Value.Transform((T) => FileWrapper.FromFileBlob(file, fileRecord.GetFileInfo())));
            }
            return(fileWrapperList);
        }