public void UploadFile(ISiteSetting siteSetting, UploadItem uploadItem, IConnectorExplorer connectorExplorer, bool canUpdateItemInGrid, bool saveAsWord, UploadEventHandler UploadSucceeded, UploadEventHandler UploadFailed)
        {
            IServiceManager serviceManager          = ServiceManagerFactory.GetServiceManager(siteSetting.SiteSettingType);
            bool            isListItemAndAttachment = ConfigurationManager.GetInstance().GetListItemAndAttachmentOption();
            IItem           item      = null;
            bool            isSuccess = serviceManager.UploadFile(siteSetting, uploadItem, isListItemAndAttachment, out item);
            UploadEventArgs e         = new UploadEventArgs();

            e.UploadItem          = uploadItem;
            e.UploadedItem        = item;
            e.CanUpdateItemInGrid = canUpdateItemInGrid;
            e.ConnectorExplorer   = connectorExplorer;



            if (isSuccess == true)
            {
                UploadSucceeded(null, e);
            }
            else
            {
                e.ErrorMessage = Languages.Translate("Upload failed");
                UploadFailed(null, e);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Loads the settings.
        /// </summary>
        /// <returns></returns>
        public AppConfiguration LoadAdministrativeConfiguration()
        {
            string settingFilePath = GetAdministrativeConfigurationFilePath();

            if (File.Exists(settingFilePath) == false)
            {
                return new AppConfiguration()
                       {
                           Exist = false
                       }
            }
            ;

            AppConfiguration configuration = SerializationManager.ReadSettings <AppConfiguration>(settingFilePath);

            configuration.Exist = true;
            DocumentTemplateManager.GetInstance().UpdateTemplateImages(configuration.DocumentTemplates);

            foreach (ExplorerLocation explorerLocation in configuration.ExplorerConfiguration.ExplorerLocations)
            {
                if (explorerLocation.Folder == null && explorerLocation.BasicFolderDefinition != null)
                {
                    SiteSetting     siteSetting    = configuration.SiteSettings[explorerLocation.BasicFolderDefinition.SiteSettingID];
                    IServiceManager serviceManager = ServiceManagerFactory.GetServiceManager(siteSetting.SiteSettingType);
                    explorerLocation.Folder = serviceManager.GetFolderByBasicFolderDefinition(siteSetting, explorerLocation.BasicFolderDefinition, true);
                }
            }

            return(configuration);
        }
Beispiel #3
0
        void LoadAdministrative_Callback(object item, DateTime dateTime)
        {
            object[] args = (object[])item;
            ExternalAdministrationConfiguration config = (ExternalAdministrationConfiguration)args[0];
            Action callback = (Action)args[1];

            ServiceManagerFactory.GetServiceManager(config.SiteSetting.SiteSettingType).DownloadAdministrativeConfiguration(config.SiteSetting, config.Url, GetAdministrativeConfigurationFilePath());
            LoadAdministrativeConfiguration();
            callback();
        }
Beispiel #4
0
 public Folder GetDefaultAttachmentSaveFolder()
 {
     if (this.AdministrativeConfiguration.OutlookConfigurations.DefaultAttachmentSaveFolder != null && string.IsNullOrEmpty(this.AdministrativeConfiguration.OutlookConfigurations.DefaultAttachmentSaveFolder.FolderUrl) == false)
     {
         SiteSetting siteSetting = this.GetSiteSetting(this.AdministrativeConfiguration.OutlookConfigurations.DefaultAttachmentSaveFolder.SiteSettingID);
         return(ServiceManagerFactory.GetServiceManager(siteSetting.SiteSettingType).GetFolder(siteSetting, this.AdministrativeConfiguration.OutlookConfigurations.DefaultAttachmentSaveFolder));
     }
     else if (this.Configuration.OutlookConfigurations.DefaultAttachmentSaveFolder != null && string.IsNullOrEmpty(this.Configuration.OutlookConfigurations.DefaultAttachmentSaveFolder.FolderUrl) == false)
     {
         SiteSetting siteSetting = this.GetSiteSetting(this.Configuration.OutlookConfigurations.DefaultAttachmentSaveFolder.SiteSettingID);
         return(ServiceManagerFactory.GetServiceManager(siteSetting.SiteSettingType).GetFolder(siteSetting, this.Configuration.OutlookConfigurations.DefaultAttachmentSaveFolder));
     }
     else
     {
         return(null);
     }
 }
        public List <UploadItem> GetUploadItems(string webURL, ISiteSetting siteSetting, Folder destinationFolder, string[] fileNames)
        {
            try
            {
                IServiceManager serviceManager = ServiceManagerFactory.GetServiceManager(siteSetting.SiteSettingType);
                //List<Field> fieldCollection = serviceManager.GetFields(destinationFolder).GetEditableFields();
                List <ContentType> contentTypes = serviceManager.GetContentTypes(siteSetting, destinationFolder, false);

                // Files are dragged from outside Outlook
                List <UploadItem> uploadItems = new List <UploadItem>();
                // 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.FieldInformations = new System.Collections.Generic.Dictionary <object, object>();
                    uploadItem.FilePath          = fileName;
                    uploadItem.Folder            = destinationFolder;
                    uploadItems.Add(uploadItem);
                }
                return(uploadItems);
            }
            catch (Exception ex)
            {
                //Trace.WriteLine("Error in DragDrop function: " + ex.Message);
                // don't use MessageBox here - Outlook or Explorer is waiting !
            }

            return(null);
        }
        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);
        }