public EditItemPropertiesControl(string webURL, List <ApplicationItemProperty> properties, List <ContentType> contentTypes, FolderSettings folderSettings, FolderSetting defaultFolderSetting, ISiteSetting siteSetting, string rootFolder, Dictionary <string, string> defaultValues, bool displayFileName) { InitializeComponent(); _contentTypes = contentTypes; _properties = properties; _folderSettings = folderSettings; _defaultFolderSetting = defaultFolderSetting; _siteSetting = siteSetting; _rootFolder = rootFolder; _defaultValues = defaultValues; _webURL = webURL; _displayFileName = displayFileName; CheckInAfter.IsChecked = siteSetting.CheckInAfterEditProperties; isFolder = GetProperty(defaultValues, "ows_FSObjType", true, false) == "1"; foreach (ContentType contentType in _contentTypes) { ContentTypeComboBox.Items.Add(new { Name = contentType.Name, ID = contentType }); } if (_contentTypes.Count > 0) { ContentTypeComboBox.SelectedIndex = 0; } displayGenericField(defaultValues); }
private void EditItem(ItemPropertyMapping itemPropertyMapping, FolderSetting folderSetting) { ContentType selectedContentType = null; if (folderSetting.Folder != null) { //SiteSetting siteSetting = this.SiteSettings[folderSetting.Folder.SiteSettingID];//JD ISiteSetting siteSetting = ConfigurationManager.GetInstance().GetSiteSetting(folderSetting.Folder.SiteSettingID); IServiceManager serviceManager = ServiceManagerFactory.GetServiceManager(siteSetting.SiteSettingType); List <ContentType> contentTypes = serviceManager.GetContentTypes(siteSetting, folderSetting.Folder, false); selectedContentType = contentTypes.Single(t => t.ID.Equals(itemPropertyMapping.ContentTypeID)); } ItemPropertyMappingForm itemPropertyMappingForm = new ItemPropertyMappingForm(); itemPropertyMappingForm.Initialize(ApplicationContext.Current.GetApplicationFields(null), selectedContentType, itemPropertyMapping.ApplicationPropertyName, itemPropertyMapping.ServicePropertyName); if (itemPropertyMappingForm.ShowDialog(this.ParentWindow, Languages.Translate("Add Mapping"), 200, 300) == true) { itemPropertyMapping.ApplicationPropertyName = itemPropertyMappingForm.SelectedApplicationPropertyID; itemPropertyMapping.ServicePropertyName = itemPropertyMappingForm.SelectedServicePropertyID; this.RefreshMappingListView(); } }
private void AddButton_Click(object sender, RoutedEventArgs e) { ContentType selectedContentType; if (GeneralLocationTypeRadioButton.IsChecked == true) { selectedContentType = null; } else { selectedContentType = ContentTypeComboBox.SelectedValue as ContentType; if (selectedContentType == null) { MessageBox.Show(Languages.Translate("Please select a content type or use general location instead of specific")); } } ItemPropertyMappingForm itemPropertyMapping = new ItemPropertyMappingForm(); itemPropertyMapping.Initialize(ConfigurationManager.GetInstance().GetApplicationItemProperties(this.SelectedApplicationType), selectedContentType); if (itemPropertyMapping.ShowDialog(this.ParentWindow, Languages.Translate("Add Mapping"), 300, 350) == true) { ItemPropertyMapping newItemPropertyMapping = new ItemPropertyMapping(); newItemPropertyMapping.ID = Guid.NewGuid(); if (selectedContentType != null) { newItemPropertyMapping.ContentTypeID = selectedContentType.ID; } newItemPropertyMapping.ApplicationPropertyName = itemPropertyMapping.SelectedApplicationPropertyID; newItemPropertyMapping.ServicePropertyName = itemPropertyMapping.SelectedServicePropertyID; FolderSetting folderSetting; if (this.SelectedFolder == null) { folderSetting = this.FolderSettings.GetDefaultFolderSetting(this.SelectedApplicationType); folderSetting.ItemPropertyMappings.Add(newItemPropertyMapping); } else { folderSetting = this.FolderSettings.GetFolderSetting(this.SelectedApplicationType, this.SelectedFolder); if (folderSetting != null) { folderSetting.ItemPropertyMappings.Add(newItemPropertyMapping); } else { folderSetting = new FolderSetting(); folderSetting.ApplicationType = this.SelectedApplicationType; folderSetting.BasicFolderDefinition = this.SelectedFolder.GetBasicFolderDefinition(); folderSetting.Folder = this.SelectedFolder; folderSetting.ItemPropertyMappings.Add(newItemPropertyMapping); this.FolderSettings.Add(folderSetting); } } this.RefreshMappingListView(); } }
public void Start() { var taskArray = new Task[_folderSettings.Count]; for (int i = 0; i < taskArray.Length; i++) { FolderSetting folderSetting = _folderSettings[i]; taskArray[i] = Task.Run(() => DoTask(folderSetting)); } _log.Info("Waiting for tasks to finish."); Task.WaitAll(taskArray); _log.Info("Tasks have finished."); }
public void SetFolderSetting(ApplicationTypes applicationType, FolderSetting folderSetting) { FolderSettings folderSettings = this.Configuration.FolderSettings.GetFolderSettings(applicationType); if (folderSettings[folderSetting.Folder.GetUrl()] != null) { folderSettings[folderSetting.Folder.GetUrl()] = folderSetting; } else { this.Configuration.FolderSettings.Add(folderSetting); } }
public FoldersToWatchViewModel() { var deserializeResult = FolderSetting .Deserialize(Settings.Default.Folders) .DistinctBy(x => x.Path) .Where(x => Directory.Exists(x.Path)) .Select(x => new FolderViewModel(x.Path) { IsEnabled = x.IsEnabled }); Folders = new ObservableCollection <FolderViewModel>(deserializeResult); }
public string GetMappedServicePropertyName(ApplicationTypes applicationType, string url, string applicationPropertyName, string contentTypeID) { FolderSetting folderSetting = GetFolderSettings(applicationType)[url]; if (folderSetting == null) { return(String.Empty); } ItemPropertyMapping itemPropertyMapping = folderSetting.ItemPropertyMappings.SingleOrDefault(em => em.ContentTypeID.Equals(contentTypeID, StringComparison.InvariantCultureIgnoreCase) && em.ApplicationPropertyName.Equals(applicationPropertyName, StringComparison.InvariantCultureIgnoreCase) && string.IsNullOrEmpty(em.ServicePropertyName) == false); if (itemPropertyMapping != null) { return(itemPropertyMapping.ServicePropertyName); } return(String.Empty); }
private async Task <List <Displayable> > GetVirtualFolderAsync(string path) { // var splitList = path.Split('\\'); //var virtualFolderName = path.Substring(0, path.LastIndexOf('\\')); //path = path.Substring(path.LastIndexOf('\\')); var directoryName = Path.GetDirectoryName(path); var virtualFolderName = path.Substring(path.LastIndexOf('\\') + 1); if (directoryName == null) { throw new FileNotFoundException(); } StorageFolder folder; folder = await StorageFolder.GetFolderFromPathAsync(directoryName); FolderSetting folderSetting = await FolderSetting.GetInstance(folder); VirtualFolder virtualFolder = folderSetting.VirtualFolders.Find(x => x.Name == virtualFolderName); if (virtualFolder == null) { throw new FileNotFoundException(); } var displayFileFolderItems = new List <Displayable> { new DisplayableSpecial( "..", directoryName, Type.Folder, await IconServer.GetFolderIcon(ThumbnailMode.ListView, 32) ) }; foreach (var virtualFilderItem in virtualFolder.Includes) { displayFileFolderItems.AddRange( await GetRegularFilesAsync(virtualFilderItem, false) ); } return(displayFileFolderItems); }
private void TemplatesGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e) { DocumentTemplate documentTemplate = (DocumentTemplate)TemplatesGrid.SelectedItem; List <DocumentTemplateMapping> mappings = ConfigurationManager.GetInstance().GetDocumentTemplateMappings(documentTemplate.ID); DocumentTemplateMapping selectedDocumentTemplateMapping = null; Folder selectedTargetFolder = null; SiteSetting siteSetting = null; ContentType contentType = null; IServiceManager serviceManager = null; if (mappings.Count == 0) { MessageBox.Show(Languages.Translate("This template does not have any mapping for location")); return; } else if (mappings.Count == 1) { selectedDocumentTemplateMapping = mappings[0]; siteSetting = ConfigurationManager.GetInstance().GetSiteSetting(selectedDocumentTemplateMapping.Folder.SiteSettingID); serviceManager = ServiceManagerFactory.GetServiceManager(siteSetting.SiteSettingType); selectedTargetFolder = serviceManager.GetFolder(siteSetting, selectedDocumentTemplateMapping.Folder); contentType = serviceManager.GetContentType(siteSetting, selectedTargetFolder, selectedDocumentTemplateMapping.ContentTypeID, false); } else { DocumentTemplateLocationSelectionForm documentTemplateLocationSelectionForm = new DocumentTemplateLocationSelectionForm(); documentTemplateLocationSelectionForm.Initialize(mappings); if (documentTemplateLocationSelectionForm.ShowDialog(null, Languages.Translate("Select a location")) == true) { selectedDocumentTemplateMapping = documentTemplateLocationSelectionForm.SelectedDocumentTemplateMapping; selectedTargetFolder = documentTemplateLocationSelectionForm.SelectedFolder; siteSetting = ConfigurationManager.GetInstance().GetSiteSetting(selectedDocumentTemplateMapping.Folder.SiteSettingID); serviceManager = ServiceManagerFactory.GetServiceManager(siteSetting.SiteSettingType); contentType = serviceManager.GetContentType(siteSetting, selectedTargetFolder, selectedDocumentTemplateMapping.ContentTypeID, false); } else { return; } } List <ContentType> contentTypes = new List <ContentType>(); contentTypes.Add(contentType); FolderSettings folderSettings = ConfigurationManager.GetInstance().GetFolderSettings(ApplicationContext.Current.GetApplicationType()).GetRelatedFolderSettings(selectedTargetFolder.GetUrl()); FolderSetting defaultFolderSetting = ConfigurationManager.GetInstance().GetFolderSettings(ApplicationContext.Current.GetApplicationType()).GetDefaultFolderSetting(); EditItemPropertiesControl editItemPropertiesControl = new EditItemPropertiesControl(selectedTargetFolder.GetWebUrl(), null, contentTypes, folderSettings, defaultFolderSetting, siteSetting, selectedTargetFolder.GetUrl(), null, true); bool?dialogResult = editItemPropertiesControl.ShowDialog(null, Languages.Translate("Meta Data")); if (dialogResult == true) { LoadingWindow lw = new LoadingWindow(); lw.WindowStartupLocation = WindowStartupLocation.CenterScreen; lw.Show(); ContentType selectedContentType; Dictionary <object, object> values = editItemPropertiesControl.GetValues(out selectedContentType); string templateFilePath = documentTemplate.TemplatePath; FileInfo fi = new FileInfo(templateFilePath); string fileName = string.Empty; foreach (object key in values.Keys) { Field f = key as Field; if (f.Name.Equals("Title", StringComparison.InvariantCultureIgnoreCase) == true) { fileName = values[key] + fi.Extension; break; } } //string fileName = string.Format("w_{0}{1}", Guid.NewGuid().ToString().Replace("-", ""), fi.Extension); string actualFilePath = ConfigurationManager.GetInstance().GetTempFolder() + "\\" + fileName; ApplicationContext.Current.CreateNewFile(templateFilePath, actualFilePath); bool isListItemAndAttachment = ConfigurationManager.GetInstance().GetListItemAndAttachmentOption(); UploadItem uploadItem = new UploadItem(); uploadItem.FilePath = actualFilePath; uploadItem.Folder = selectedTargetFolder; uploadItem.ContentType = contentType; uploadItem.FieldInformations = values; Sobiens.Connectors.Common.ApplicationContext.Current.UploadFile(siteSetting, uploadItem, null, false, isListItemAndAttachment, Upload_Success, Upload_Failed); string documentURL = selectedTargetFolder.GetUrl() + "/" + fileName; object document = ApplicationContext.Current.OpenFile(siteSetting, documentURL); ApplicationContext.Current.RefreshControlsFromConfiguration(); lw.Close(); ApplicationContext.Current.ActivateDocument(document); } }
private Dictionary<object, object> getFieldMappings(string webURL, List<ApplicationItemProperty> properties, List<ContentType> contentTypes, FolderSettings folderSettings, FolderSetting defaultFolderSetting, ISiteSetting siteSetting, string rootFolder, out ContentType contentType,bool displayFileName) { Dictionary<object, object> mappings = new Dictionary<object, object>(); EditItemPropertiesControl editItemPropertiesControl = new EditItemPropertiesControl(webURL, properties, contentTypes, folderSettings, defaultFolderSetting, siteSetting, rootFolder, null,displayFileName); bool? dialogResult = editItemPropertiesControl.ShowDialog(null, Languages.Translate("Mappings...")); if (dialogResult.HasValue == false || dialogResult.Value == false) { contentType = null; return null; } else { return editItemPropertiesControl.GetValues(out contentType); } }
public List <UploadItem> GetUploadItems(string webURL, ISiteSetting siteSetting, Folder destinationFolder, System.Windows.DragEventArgs e, GetFieldMappings getFieldMappings) { try { IServiceManager serviceManager = ServiceManagerFactory.GetServiceManager(siteSetting.SiteSettingType); //List<Field> fieldCollection = serviceManager.GetFields(destinationFolder).GetEditableFields(); List <ContentType> contentTypes = serviceManager.GetContentTypes(siteSetting, destinationFolder, false); if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop, false) == true) { // Files are dragged from outside Outlook List <UploadItem> uploadItems = new List <UploadItem>(); string[] fileNames = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop); // handle each file passed as needed foreach (string fileName in fileNames) { Dictionary <object, object> fileFields = new Dictionary <object, object>(); FileInfo info = new FileInfo(fileName); fileFields.Add("Name", info.Name); fileFields.Add("CreationTime", info.CreationTime.ToLongDateString()); //TODO: Date formatting may be optional fileFields.Add("CreationTimeUtc", info.CreationTimeUtc.ToLongDateString()); fileFields.Add("DirectoryName", info.DirectoryName); fileFields.Add("Extension", info.Extension); fileFields.Add("FullName", info.FullName); fileFields.Add("LastWriteTime", info.LastWriteTime.ToLongDateString()); fileFields.Add("LastWriteTimeUtc", info.LastWriteTimeUtc.ToLongDateString()); fileFields.Add("Length", info.Length.ToString()); UploadItem uploadItem = new UploadItem(); uploadItem.UniqueID = Guid.NewGuid(); //uploadItem.ContentType = user defined //SharePointManager.GetContentTypes(folder.SiteSetting, folder.WebUrl, folder.ListName); //uploadItem.FieldInformations = field -> value mapping uploadItem.FieldInformations = new System.Collections.Generic.Dictionary <object, object>(); // //uploadItem.FieldInformations.Add(fieldCollection[0], fileName); // //uploadItem.FieldInformations.Add(fieldCollection[1], fileName); uploadItem.FilePath = fileName; uploadItem.Folder = destinationFolder; //uploadItem.Fields = not needed //SharePointManager.GetFields(dragedSPFolder.SiteSetting, dragedSPFolder.WebUrl, dragedSPFolder.ListName); //uploadItem.UniqueID = Unique ID used in UI for delegate status update (uploading -> done) uploadItems.Add(uploadItem); } return(uploadItems); } else if (e.Data.GetDataPresent("FileGroupDescriptorW")) { string[] fileFieldsData = null; string[] fileFieldsKeys = null; bool isApplicationFileDrop = e.Data.GetDataPresent(typeof(string)); if (isApplicationFileDrop) { // Application files are dragged string[] separator = { "\r\n" }; fileFieldsData = ((string)e.Data.GetData(typeof(string))).Split(separator, StringSplitOptions.None); fileFieldsKeys = fileFieldsData[0].Split('\t'); } List <UploadItem> uploadItems = new List <UploadItem>(); string tempPath = Path.GetTempPath(); string[] filenames; MemoryStream[] filestreams; GetApplicationDragDropInformation(e.Data, out filenames, out filestreams); List <ApplicationItemProperty> generalProperties = GetApplicationFields(null); ContentType contentType; FolderSettings folderSettings = ConfigurationManager.GetInstance().GetFolderSettings(ApplicationContext.Current.GetApplicationType()).GetRelatedFolderSettings(destinationFolder.GetUrl()); FolderSetting defaultFolderSetting = ConfigurationManager.GetInstance().GetFolderSettings(ApplicationContext.Current.GetApplicationType()).GetDefaultFolderSetting(); Dictionary <object, object> fieldMappings; string initialFileName = tempPath + filenames[0]; if (Path.GetExtension(initialFileName) == ".msg")//this is a mail { fieldMappings = getFieldMappings(destinationFolder.GetWebUrl(), generalProperties, contentTypes, folderSettings, defaultFolderSetting, siteSetting, destinationFolder.GetUrl(), out contentType, false); } else//this an attachement { fieldMappings = getFieldMappings(destinationFolder.GetWebUrl(), null, contentTypes, folderSettings, defaultFolderSetting, siteSetting, destinationFolder.GetUrl(), out contentType, true); } if (fieldMappings == null || fieldMappings.Count == 0) { return(null); } for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++) { //use the fileindex to get the name and data stream string filename = tempPath + filenames[fileIndex]; MemoryStream filestream = filestreams[fileIndex]; //save the file stream using its name to the application path FileStream outputStream = File.Create(filename); filestream.WriteTo(outputStream); outputStream.Close(); FileInfo tempFile = new FileInfo(filename); // always good to make sure we actually created the file if (tempFile.Exists == true) { Hashtable fileFields = new Hashtable(); if (isApplicationFileDrop) { // Application files are dragged string[] fileFieldsValues = fileFieldsData[fileIndex + 1].Split('\t'); for (int i = 0; i < fileFieldsKeys.Count() - 1; i++) { fileFields.Add(fileFieldsKeys[i], fileFieldsValues[i]); } } else { //Application attachments are dragged fileFields.Add("Name", filenames[fileIndex]); } UploadItem uploadItem = new UploadItem(); uploadItem.UniqueID = Guid.NewGuid(); uploadItem.FieldInformations = new System.Collections.Generic.Dictionary <object, object>(); if (Path.GetExtension(filename) == ".msg") {//for message mapping needed List <ApplicationItemProperty> properties = GetApplicationFields(filename); foreach (Field field in fieldMappings.Keys) { object obj = fieldMappings[field]; object value = string.Empty; if (obj is ApplicationItemProperty) { value = properties.FirstOrDefault(p => p.Name == ((ApplicationItemProperty)obj).Name).Value; } else { value = obj; } uploadItem.FieldInformations.Add(field, value); } } else {//for single attachement file uploadItem.FieldInformations = fieldMappings; } uploadItem.Folder = destinationFolder; uploadItem.ContentType = contentType; List <UploadItem> additionalItems = SetUploadItemFilePath(tempPath, filename, uploadItem); //uploadItem.Fields = not needed //SharePointManager.GetFields(dragedSPFolder.SiteSetting, dragedSPFolder.WebUrl, dragedSPFolder.ListName); //uploadItem.UniqueID = Unique ID used in UI for delegate status update (uploading -> done) uploadItems.Add(uploadItem); if (additionalItems != null) { foreach (UploadItem item in additionalItems) { uploadItems.Add(item); } } //tempFile.Delete(); TODO: cannot delete so soon, delete later } else { //Trace.WriteLine("File was not created!"); } } return(uploadItems); } } catch (Exception ex) { int y = 3; //Trace.WriteLine("Error in DragDrop function: " + ex.Message); // don't use MessageBox here - Outlook or Explorer is waiting ! } return(null); }
/// <summary> /// 获得普通文件夹中的文件 /// </summary> /// <param name="path"></param> /// <param name="withParent"></param> /// <returns></returns> private async Task <List <Displayable> > GetRegularFilesAsync(string path, bool withParent = true) { StorageFolder folder = null; try { folder = await StorageFolder.GetFolderFromPathAsync(path); } catch (System.UnauthorizedAccessException) { throw; } catch (Exception e) { Debug.WriteLine(e.Message + " " + path + " try to get Virtual Folder"); try { return(await GetVirtualFolderAsync(path)); } catch (Exception) { Debug.WriteLine(e.Message); throw; } } // 打开文件夹 var displayFileFolderItems = new List <Displayable>(); if (withParent) { displayFileFolderItems.Add(await DisplayableFolder.GetParentAsync(folder)); } // 读取配置文件 FolderSetting folderSetting = await FolderSetting.GetInstance(folder); foreach (var virtualFolder in folderSetting.VirtualFolders) { displayFileFolderItems.Add(new DisplayableSpecial( virtualFolder.Name, folder.Path + "\\" + virtualFolder.Name, Type.VirtualFolder, await IconServer.GetFolderIcon(ThumbnailMode.ListView, 32))); } IReadOnlyList <StorageFolder> folders = await folder.GetFoldersAsync(); IReadOnlyList <StorageFile> files = await folder.GetFilesAsync(); //displayFileFolderItems.AddRange(folders // .Select(async i => await DisplayFileFolderItem.GetInstance(i)) // .Select(i => i.Result) //); //displayFileFolderItems.AddRange(files // .Select(async i => await DisplayFileFolderItem.GetInstance(i)) // .Select(i => i.Result) //); try { foreach (var file in folders) { displayFileFolderItems.Add( await DisplayableFolder.GetInstanceAsync(file)); } foreach (var file in files) { displayFileFolderItems.Add( await DisplayableFile.GetInstanceAsync(file)); } } catch (Exception e) { Debug.WriteLine("Exception at appending dispalyFileFolder " + e.Message); } return(displayFileFolderItems); }
private void DoTask(FolderSetting folderSetting) { Thread.Sleep(500); _log.Info("Task finished."); }