internal static void ImportTags(Product product, List<string> tagsList, UploadConfig config)
        {
            TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
            CatalogManager catalogManager = CatalogManager.GetManager();

            FlatTaxonomy tagsTaxonomy = taxonomyManager.GetTaxonomies<FlatTaxonomy>().Where(t => t.Name == "Tags").SingleOrDefault();

            foreach (var tagString in tagsList)
            {
                try
                {
                    Taxon tag = GetTagIfItExsistsOrCreateOneIfItDoesnt(tagString, tagsTaxonomy, taxonomyManager);

                    SetTagProperties(tag, tagString);

                    taxonomyManager.SaveChanges();

                    if (product.Organizer.TaxonExists("Tags", tag.Id) == true)
                    {
                        continue;        // Product already linked to Tag
                    }

                    product.Organizer.AddTaxa("Tags", tag.Id);

                    catalogManager.SaveChanges();
                }
                catch
                {
                    //catching so even if one fails rest goes on
                }
            }
        }
        internal static CsvData ParseFileAndGetCsvData(string filePath, UploadConfig config)
        {
            CsvConfiguration configuration = new CsvConfiguration();
            configuration.HasHeaderRecord = true;

            CsvReader csvReader = new CsvReader(new StreamReader(filePath), configuration);

            string[] header = default(string[]);

            List<string[]> rows = new List<string[]>();
            string[] row;
            while (csvReader.Read())
            {
                header = csvReader.FieldHeaders;

                row = new string[header.Length];
                for (int j = 0; j < header.Length; j++)
                {
                    row[j] = csvReader.GetField(j);
                }

                rows.Add(row);
            }

            return new CsvData { Header = header, Rows = rows };
        }
        internal static void ImportDepartments(Product product, List<string> departmentList, UploadConfig config)
        {
            TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
            CatalogManager catalogManager = CatalogManager.GetManager();

            HierarchicalTaxonomy departmentTaxonomy = taxonomyManager.GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Name == "Departments").SingleOrDefault();

            foreach (var departmentString in departmentList)
            {
                try
                {
                    Taxon department = GetDepartmentIfItExsistsOrCreateOneIfItDoesnt(departmentString, departmentTaxonomy, taxonomyManager);

                    SetDepartmentProperties(department, departmentString);

                    taxonomyManager.SaveChanges();

                    if (product.Organizer.TaxonExists("Department", department.Id) == true)
                    {
                        continue;        // Product already linked to department
                    }

                    product.Organizer.AddTaxa("Department", department.Id);

                    catalogManager.SaveChanges();
                }
                catch
                {
                    //catching so even if one department fails rest goes on
                }

            }
        }
        internal static List<ProductDocumentFileInfo> ImportDocuments(List<string> documentsAndFilesPath, UploadConfig config)
        {
            List<ProductDocumentFileInfo> productDocumentFileInfos = new List<ProductDocumentFileInfo>();

            LibrariesManager librariesManager = LibrariesManager.GetManager();

            Library libraryToUploadDocumentsTo = librariesManager.GetDocumentLibrary(config.UploadToLibraryId);

            foreach (var documentPath in documentsAndFilesPath)
            {
                try
                {
                    FileInfo fileInfo = new FileInfo(documentPath);
                    if (fileInfo == null)
                    {
                        continue;
                    }

                    //To create an image you have to be logged in as an admin.
                    Document document = librariesManager.CreateDocument();

                    var extension = fileInfo.Extension;
                    var documentTitle = fileInfo.Name;
                    if (extension.Length > 0)
                    {
                        documentTitle = documentTitle.Substring(0, documentTitle.Length - extension.Length);
                    }
                    document.Parent = libraryToUploadDocumentsTo;
                    document.Title = documentTitle;
                    document.UrlName = documentTitle.ToLower().Replace(' ', '-');
                    librariesManager.RecompileItemUrls<Document>(document);
                    using (var fileStream = fileInfo.OpenRead())
                    {
                        librariesManager.Upload(document, fileStream, fileInfo.Extension);
                    }
                    librariesManager.SaveChanges();

                    Document liveDocument = librariesManager.Lifecycle.Publish(document) as Document;

                    ProductDocumentFileInfo documentFileInfo = new ProductDocumentFileInfo
                    {
                        FileInfo = fileInfo,
                        Library = libraryToUploadDocumentsTo,
                        Document = liveDocument,
                    };

                    productDocumentFileInfos.Add(documentFileInfo);
                }
                catch
                {
                    //catching so even if one document fails rest succeeds
                }
            }

            librariesManager.SaveChanges();

            return productDocumentFileInfos;
        }
        internal static List<ProductImageInfo> ImportImages(List<string> imagesPath, UploadConfig config)
        {
            List<ProductImageInfo> productImageInfos = new List<ProductImageInfo>();

            LibrariesManager librariesManager = LibrariesManager.GetManager();

            Album albumToUploadImagesTo = librariesManager.GetAlbum(config.UploadToAlbumId);

            foreach (var imagePath in imagesPath)
            {
                try
                {
                    FileInfo fileInfo = new FileInfo(imagePath);
                    if (fileInfo == null)
                    {
                        continue;
                    }

                    //To create an image you have to be logged in as an admin.
                    Telerik.Sitefinity.Libraries.Model.Image image = librariesManager.CreateImage();
                    image.AlternativeText = "Some alt text";

                    var extension = fileInfo.Extension;
                    var imageTitle = fileInfo.Name;
                    if (extension.Length > 0)
                    {
                        imageTitle = imageTitle.Substring(0, imageTitle.Length - extension.Length);
                    }
                    image.Parent = albumToUploadImagesTo;
                    image.Title = imageTitle;
                    image.UrlName = imageTitle.ToLower().Replace(' ', '-');
                    librariesManager.RecompileItemUrls<Telerik.Sitefinity.Libraries.Model.Image>(image);
                    using (var fileStream = fileInfo.OpenRead())
                    {
                        librariesManager.Upload(image, fileStream, fileInfo.Extension);
                    }
                    librariesManager.Lifecycle.Publish(image);

                    ProductImageInfo imageInfo = new ProductImageInfo
                    {
                        ImageInfo = fileInfo,
                        Album = albumToUploadImagesTo,
                        Image = image,
                    };

                    productImageInfos.Add(imageInfo);
                }
                catch
                {
                    //catching so even if one image fails the rest goes on
                }
            }

            librariesManager.SaveChanges();

            return productImageInfos;
        }
        internal static List<ProductVariationImportModel> ConvertCsvDataToProductVariationImportModel(CsvData csvData, UploadConfig config)
        {
            List<ProductVariationImportModel> dataToInsertInDatabase = new List<ProductVariationImportModel>();
            foreach (var dataRow in csvData.Rows)
            {
                ProductVariationImportModel rowToInsert = new ProductVariationImportModel();
                rowToInsert.ProductNameSku = dataRow[0];
                rowToInsert.AttributeName = dataRow[1];
                rowToInsert.ValueName = dataRow[2];
                rowToInsert.Sku = dataRow[3];
                rowToInsert.AdditionalPrice = Convert.ToDecimal(dataRow[4]);
                rowToInsert.TrackInventory = GetTrackInventory(dataRow[5]);
                rowToInsert.InventoryAmount = GetSafeInt(dataRow[6]);
                rowToInsert.OutOfStockOption = GetOutOfStockOption(dataRow[7]);
                rowToInsert.IsActive = Convert.ToBoolean(dataRow[8]);

                rowToInsert.CorrespondingRowData = dataRow;

                dataToInsertInDatabase.Add(rowToInsert);
            }
            return dataToInsertInDatabase;
        }
        internal static List<ProductImportModel> ConvertCsvDataToProductImportModel(CsvData csvData, UploadConfig config)
        {
            List<ProductImportModel> dataToInsertInDatabase = new List<ProductImportModel>();
            foreach (var dataRow in csvData.Rows)
            {
                ProductImportModel rowToInsert = new ProductImportModel();
                rowToInsert.Title = dataRow[0];
                rowToInsert.ProductTypeTitle = dataRow[1];
                rowToInsert.Description = dataRow[2];
                rowToInsert.Url = dataRow[3];
                rowToInsert.Price = Convert.ToDecimal(dataRow[4]);
                rowToInsert.Weight = Convert.ToDecimal(dataRow[5]);
                rowToInsert.Sku = dataRow[6];

                rowToInsert.ImagesPath = dataRow[7].Split(config.MultipleItemsSeparator).ToList();
                rowToInsert.DocumentsAndFilesPath = dataRow[8].Split(config.MultipleItemsSeparator).ToList();
                rowToInsert.Departments = dataRow[9].Split(config.MultipleItemsSeparator).ToList();
                rowToInsert.Tags = dataRow[10].Split(config.MultipleItemsSeparator).ToList();

                rowToInsert.TrackInventory = GetTrackInventory(dataRow[11]);
                rowToInsert.InventoryAmount = GetSafeInt(dataRow[12]);
                rowToInsert.OutOfStockOption = GetOutOfStockOption(dataRow[13]);

                rowToInsert.IsActive = Convert.ToBoolean(dataRow[14]);

                rowToInsert.CustomFieldData = new List<CustomFieldData>();

                for (int i = 12; i < config.NumberOfColumns; i++)
                {
                    CustomFieldData customFieldData = new CustomFieldData { PropertyName = csvData.Header[i], PropertyValue = dataRow[i] };
                    rowToInsert.CustomFieldData.Add(customFieldData);
                }

                rowToInsert.CorrespondingRowData = dataRow;

                dataToInsertInDatabase.Add(rowToInsert);
            }
            return dataToInsertInDatabase;
        }
        internal static List<ProductImage> ImportImagesAndGetProductImages(ProductImportModel productImportModel, UploadConfig config)
        {
            List<ProductImageInfo> importedImages = ImagesImporter.ImportImages(productImportModel.ImagesPath, config);

            List<ProductImage> productImages = ImagesImporter.GetProductImages(importedImages);

            return productImages;
        }
示例#9
0
 public UploadHandler(HttpContext context, UploadConfig config)
     : base(context)
 {
     this.UploadConfig = config;
     this.Result = new UploadResult() { State = UploadState.Unknown };
 }
        /// <summary>
        /// Imports list of <see cref="ProductImportModel"/> to database
        /// </summary>
        /// <param name="dataToInsertInDatabase"></param>
        /// <returns></returns>
        internal static ImportStatistic SaveProducts(List<ProductImportModel> data, UploadConfig config)
        {
            CatalogManager catalogManager = CatalogManager.GetManager();

            List<ImportError> importErrors = new List<ImportError>();

            int numberOfRecordsProcessed = 0;
            int numberOfSuccessfulRecords = 0;
            int numberOfFailedRecords = 0;

            foreach (ProductImportModel productImportModel in data)
            {

                bool isFailedSet = false;
                try
                {
                    numberOfRecordsProcessed++;

                    ProductType productType = catalogManager.GetProductTypes().Where(pt => pt.Title == productImportModel.ProductTypeTitle).FirstOrDefault();
                    if (productType != null)
                    {
                        Product product = catalogManager.CreateProduct(productType.ClrType);

                        product.ApplicationName = "/Catalog";
                        product.Title = productImportModel.Title;
                        if (string.IsNullOrWhiteSpace(productImportModel.Url))
                        {
                            product.UrlName = Regex.Replace(productImportModel.Title.ToLower(), @"\s+", "-");
                        }
                        else
                        {
                            product.UrlName = productImportModel.Url;
                        }

                        product.Description = productImportModel.Description;
                        product.Price = productImportModel.Price;
                        product.Weight = Convert.ToDouble(productImportModel.Weight);
                        product.Sku = productImportModel.Sku;
                        product.TrackInventory = productImportModel.TrackInventory;
                        if (productImportModel.TrackInventory == TrackInventory.Track)
                        {
                            product.Inventory = productImportModel.InventoryAmount;
                            product.OutOfStockOption = productImportModel.OutOfStockOption;
                        }
                        product.ClrType = productType.ClrType;

                        catalogManager.RecompileItemUrls<Product>(product);
                        catalogManager.SaveChanges();

                        var props = TypeDescriptor.GetProperties(product);
                        foreach (var singleProp in props)
                        {
                            if (singleProp.GetType() == typeof(MetafieldPropertyDescriptor))
                            {
                                MetafieldPropertyDescriptor customField = singleProp as MetafieldPropertyDescriptor;
                                if (customField != null)
                                {
                                    foreach (var customFieldData in productImportModel.CustomFieldData)
                                    {
                                        if (customField.Name == customFieldData.PropertyName)
                                        {
                                            customField.SetValue(product, customFieldData.PropertyValue);
                                        }
                                    }
                                }
                            }
                        }
                        catalogManager.SaveChanges();

                        ImportImages(config, catalogManager, importErrors, ref numberOfFailedRecords, productImportModel, ref isFailedSet, product);

                        ImportFiles(config, catalogManager, importErrors, ref numberOfFailedRecords, productImportModel, ref isFailedSet, product);

                        ImportDepartments(config, importErrors, ref numberOfFailedRecords, productImportModel, ref isFailedSet, product);

                        ImportTags(config, importErrors, ref numberOfFailedRecords, productImportModel, ref isFailedSet, product);

                        var contextBag = new Dictionary<string, string>();
                        contextBag.Add("ContentType", product.GetType().FullName);

                        string workflowOperation = "Publish";

                        WorkflowManager.MessageWorkflow(
                                                        product.Id,
                                                        product.GetType(),
                                                        DefaultProvider,
                                                        workflowOperation,
                                                        false,
                                                        contextBag);

                        numberOfSuccessfulRecords++;
                    }
                    else
                    {
                        throw new ArgumentException("Cannot find product type " + productImportModel.ProductTypeTitle);
                    }

                }
                catch (Exception ex)
                {
                    if (!isFailedSet)
                    {
                        numberOfFailedRecords++;

                        importErrors.Add(new ImportError { ErrorMessage = ex.Message, ErrorRow = productImportModel.CorrespondingRowData });
                    }

                    continue;
                }

            }
            ImportStatistic statisticsOfImport = new ImportStatistic
                                                        {
                                                            TotalNumberOfRecordsProcessed = numberOfRecordsProcessed,
                                                            NumberOfSuccessfulRecords = numberOfSuccessfulRecords,
                                                            NumberOfFailedRecords = numberOfFailedRecords,
                                                            Errors = importErrors
                                                        };
            return statisticsOfImport;
        }
 private static void ImportTags(UploadConfig config, List<ImportError> importErrors, ref int numberOfFailedRecords, ProductImportModel productImportModel, ref bool isFailedSet, Product product)
 {
     try
     {
         TagsImporter.ImportTags(product, productImportModel.Tags, config);
     }
     catch (Exception tagsEx)
     {
         if (!isFailedSet)
         {
             isFailedSet = true;
             numberOfFailedRecords++;
             importErrors.Add(new ImportError { ErrorMessage = tagsEx.Message, ErrorRow = productImportModel.CorrespondingRowData });
         }
     }
 }
        private static void ImportImages(UploadConfig config, CatalogManager catalogManager, List<ImportError> importErrors, ref int numberOfFailedRecords, ProductImportModel productImportModel, ref bool isFailedSet, Product product)
        {
            try
            {
                List<ProductImage> productImages = ImagesImporter.ImportImagesAndGetProductImages(productImportModel, config);
                product.Images.AddRange(productImages);

                catalogManager.SaveChanges();

                ContentLinkGenerator.GenerateContentLinksForProductImages(product);
            }
            catch (Exception imageEx)
            {
                if (!isFailedSet)
                {
                    isFailedSet = true;
                    numberOfFailedRecords++;
                    importErrors.Add(new ImportError { ErrorMessage = imageEx.Message, ErrorRow = productImportModel.CorrespondingRowData });
                }
            }
        }
        private static void ImportFiles(UploadConfig config, CatalogManager catalogManager, List<ImportError> importErrors, ref int numberOfFailedRecords, ProductImportModel productImportModel, ref bool isFailedSet, Product product)
        {
            try
            {
                List<ProductFile> productFiles = DocumentsAndFilesImporter.ImportDocumentsAndGetProductDocuments(productImportModel, config);
                product.DocumentsAndFiles.AddRange(productFiles);

                catalogManager.SaveChanges();

                ProductSynchronizer.UpdateProductDocumentsAndFilesLinks(product, DefaultProvider);
            }
            catch (Exception filesEx)
            {
                if (!isFailedSet)
                {
                    isFailedSet = true;
                    numberOfFailedRecords++;
                    importErrors.Add(new ImportError { ErrorMessage = filesEx.Message, ErrorRow = productImportModel.CorrespondingRowData });
                }
            }
        }
        internal static ImportStatistic SaveProductVariations(List<ProductVariationImportModel> data, UploadConfig config)
        {
            CatalogManager catalogManager = CatalogManager.GetManager();

            List<ImportError> importErrors = new List<ImportError>();

            int numberOfRecordsProcessed = 0;
            int numberOfSuccessfulRecords = 0;
            int numberOfFailedRecords = 0;

            foreach (ProductVariationImportModel productVariationImportModel in data)
            {

                try
                {
                    numberOfRecordsProcessed++;

                    Product parentProduct = catalogManager.GetProducts().Where(p => p.Status == ContentLifecycleStatus.Master && p.Sku == productVariationImportModel.ProductNameSku).FirstOrDefault();

                    if (parentProduct != null)
                    {
                        ProductAttribute productAttribute = catalogManager.GetProductAttributeByName(productVariationImportModel.AttributeName);
                        if (productAttribute != null)
                        {
                            ProductAttributeValue attributeValue = catalogManager.GetProductAttributeValues().Where(pav => pav.Title == productVariationImportModel.ValueName).FirstOrDefault();
                            if (attributeValue != null)
                            {
                                ProductVariation productVariation = catalogManager.CreateProductVariation();

                                //Set the properties
                                productVariation.AdditionalPrice = productVariationImportModel.AdditionalPrice;
                                productVariation.Parent = parentProduct;
                                productVariation.Sku = productVariationImportModel.Sku;
                                productVariation.TrackInventory = productVariationImportModel.TrackInventory;
                                if (productVariationImportModel.TrackInventory == TrackInventory.Track || productVariationImportModel.TrackInventory == TrackInventory.TrackByVariations)
                                {
                                    productVariation.Inventory = productVariationImportModel.InventoryAmount;
                                    productVariation.OutOfStockOption = productVariationImportModel.OutOfStockOption;
                                }
                                productVariation.IsActive = productVariationImportModel.IsActive;

                                //Set the Variant property
                                List<AttributeValuePair> attributeValuePairs = new List<AttributeValuePair>();
                                AttributeValuePair attributeValuePair = new AttributeValuePair();
                                attributeValuePair.AttributeValueId = attributeValue.Id;
                                attributeValuePair.AttributeId = attributeValue.Parent.Id;
                                attributeValuePairs.Add(attributeValuePair);

                                JavaScriptSerializer serializer = new JavaScriptSerializer();
                                string attributeValuePairsJson = serializer.Serialize(attributeValuePairs);

                                productVariation.Variant = attributeValuePairsJson;

                                //Create the product variation detail
                                ProductVariationDetail detail = catalogManager.CreateProductVariationDetail();
                                detail.ProductAttributeParent = attributeValue.Parent;
                                detail.ProductAttributeValueParent = attributeValue;
                                detail.ProductVariationParent = productVariation;
                                detail.ProductVariationDetailParentId = Guid.Empty;
                                detail.Parent = parentProduct;

                                parentProduct.ProductVariations.Add(productVariation);

                                catalogManager.SaveChanges();

                                numberOfSuccessfulRecords++;
                            }
                            else
                            {
                                throw new ArgumentException("Cannot find attribute value with title  " + productVariationImportModel.ValueName);
                            }
                        }
                        else
                        {
                            throw new ArgumentException("Cannot find attribute with title  " + productVariationImportModel.AttributeName);
                        }

                    }
                    else
                    {
                        throw new ArgumentException("Cannot find product with Sku " + productVariationImportModel.ProductNameSku);
                    }

                }
                catch (Exception ex)
                {
                    numberOfFailedRecords++;

                    importErrors.Add(new ImportError { ErrorMessage = ex.Message, ErrorRow = productVariationImportModel.CorrespondingRowData });

                    continue;
                }

            }
            ImportStatistic statisticsOfImport = new ImportStatistic
            {
                TotalNumberOfRecordsProcessed = numberOfRecordsProcessed,
                NumberOfSuccessfulRecords = numberOfSuccessfulRecords,
                NumberOfFailedRecords = numberOfFailedRecords,
                Errors = importErrors
            };
            return statisticsOfImport;
        }
        internal static List<ProductFile> ImportDocumentsAndGetProductDocuments(ProductImportModel productImportModel, UploadConfig config)
        {
            List<ProductDocumentFileInfo> importedDocuments = DocumentsAndFilesImporter.ImportDocuments(productImportModel.DocumentsAndFilesPath, config);

            List<ProductFile> productDocumentsAndFiles = DocumentsAndFilesImporter.GetProductDocumentsAndFiles(importedDocuments);

            return productDocumentsAndFiles;
        }
示例#16
0
        public Uri UploadImage(BitmapSource bitmapSource, UploadConfig config)
        {
            string url = config.Url;
            string userName = config.UserName;
            string password = config.Password;

            HttpClient http = new HttpClient();
            http.Request.Accept = HttpContentTypes.ApplicationJson;

            string apiUrl = url + "/api.php";

            // at first, request action=login (to get token)
            var paramsLogin1 = new Dictionary<string, string>()
                {
                    {"action", "login"},
                    {"format", "json"},
                    {"lgname", userName},
                    {"lgpassword", password}
                };

            var respLogin1 = http.Post(apiUrl, paramsLogin1, HttpContentTypes.ApplicationXWwwFormUrlEncoded);
            var treeLogin1 = respLogin1.DynamicBody;

            string resultLogin1 = treeLogin1.login.result;
            if (resultLogin1 != "NeedToken")
            {
                throw new UploadFailedException(
                    String.Format("Failed to login (first). You may be using older MediaWiki. (result: {0})", resultLogin1));
            }

            string token = treeLogin1.login.token;
            string cookieprefix = treeLogin1.login.cookieprefix;
            Cookie cookieSession = respLogin1.Cookies[cookieprefix + "_session"];

            // next, request login really.
            var paramsLogin2 = new Dictionary<string, string>()
                {
                    {"action", "login"},
                    {"format", "json"},
                    {"lgname", userName},
                    {"lgpassword", password},
                    {"lgtoken", token}
                };
            http.Request.Cookies = respLogin1.Cookies;
            var respLogin2 = http.Post(apiUrl, paramsLogin2, HttpContentTypes.ApplicationXWwwFormUrlEncoded);
            var treeLogin2 = respLogin2.DynamicBody;

            string resultLogin2 = treeLogin2.login.result;
            if (resultLogin2 != "Success")
            {
                throw new UploadFailedException(
                    String.Format("Failed to login. Check username and password. (result: {0})", resultLogin2));
            }

            string userId = treeLogin2.login.lguserid.ToString();
            string lgtoken = treeLogin2.login.lgtoken;

            // get edittoken
            http.Request.Cookies.Add(new Cookie(cookieprefix + "UserName", userName, "/", cookieSession.Value));
            http.Request.Cookies.Add(new Cookie(cookieprefix + "UserId", userId, "/", cookieSession.Value));
            http.Request.Cookies.Add(new Cookie(cookieprefix + "Token", lgtoken, "/", cookieSession.Value));
            var paramsQuery = new Dictionary<string, string>()
                {
                    {"action", "query"},
                    {"format", "json"},
                    {"prop", "info"},
                    {"intoken", "edit"},
                    {"titles", "NonExistPageToGetEditToken"}
                };

            var respQuery = http.Post(apiUrl, paramsQuery, HttpContentTypes.ApplicationXWwwFormUrlEncoded);
            var treeQuery = respQuery.DynamicBody;

            var pages = treeQuery.query.pages;
            // "pages" has "-1" key... since to call "-1" is difficult. this is dirty way.
            var page = (dynamic) ((IDictionary<string, object>)pages)["-1"];
            string edittoken = page.edittoken;

            if (edittoken.Length < 3) {
                throw new UploadFailedException(
                    String.Format("Failed to get edittoken (edittoken: {0})", edittoken));
            }

            string filename = ScreenToWikiUtil.GetFileName(".png");
            string descriptionUrl = null;
            ScreenToWikiUtil.UseTempDir((tempDir) =>
            {
                string path = System.IO.Path.Combine(tempDir, filename);

                ScreenToWikiUtil.SavePngFile(bitmapSource, path);

                var fileData = new FileData();
                fileData.ContentType = "image/png";
                fileData.ContentTransferEncoding = HttpContentEncoding.Binary;
                fileData.FieldName = "file";
                fileData.Filename = path;

                var paramsUpload = new Dictionary<string, object>()
                    {
                        {"action", "upload"},
                        {"format", "json"},
                        {"filename", filename},
                        {"token", edittoken}
                    };
                var respUpload = http.Post(apiUrl, paramsUpload, new List<FileData>() {fileData});
                var respTree = respUpload.DynamicBody;

                string result = respTree.upload.result;

                if (result != "Success")
                {
                    throw new UploadFailedException(String.Format("Uploading failed (result: {0})", result));
                }

                descriptionUrl = respTree.upload.imageinfo.descriptionurl;
            });

            return new Uri(descriptionUrl);
        }