예제 #1
0
        void BWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            foreach (ListViewItem item in ListViewDelegates.GetItems(lvFiles))
            {
                var fi        = (FileInfo)item.Tag;
                var extension = fi.Extension.Remove(0, 1).ToLower();

                var webR = new Entity("webresource");
                webR["displayname"]     = fi.Name;
                webR["webresourcetype"] = extension == "png"
                                              ? new OptionSetValue(5)
                                              : extension == "jpg" || extension == "jpeg"
                                                    ? new OptionSetValue(6)
                                                    : new OptionSetValue(7);

                webR["name"] = (txtPrefixToUse.Text + fi.Name).Replace(" ", "");

                var fs         = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read);
                var binaryData = new byte[fs.Length];
                fs.Read(binaryData, 0, (int)fs.Length);
                fs.Close();
                webR["content"] = Convert.ToBase64String(binaryData, 0, binaryData.Length);

                bool processed = false;
                if (CheckBoxDelegates.IsChecked(chkOverwriteExistingImages))
                {
                    var existingWr = _service.RetrieveMultiple(new QueryByAttribute
                    {
                        EntityName = "webresource",
                        Attributes = { "name" },
                        Values     = { webR["name"] }
                    }).Entities.ToList().FirstOrDefault();

                    if (existingWr != null)
                    {
                        webR.Id = existingWr.Id;
                        _service.Update(webR);
                        processed = true;
                    }
                }

                if (!processed)
                {
                    Guid wrId = _service.Create(webR);
                    webR.Id = wrId;
                }

                if (!CheckBoxDelegates.IsChecked(chkAddToDefaultSolution))
                {
                    var request = new AddSolutionComponentRequest
                    {
                        ComponentType      = 61,
                        SolutionUniqueName = cbbSolutions.SelectedItem.ToString(),
                        ComponentId        = webR.Id
                    };

                    _service.Execute(request);
                }

                WebResourcesCreated.Add(webR);
            }
        }