예제 #1
0
        internal static void LoadMappingProfilesFromXml()
        {
            MappingProfiles = new List <MappingProfile>();
            try
            {
                if (GlobalVars.SETTINGS.metadata_MappingProfiles == null)
                {
                    XmlDocument doc = new XmlDocument();
                    doc.AppendChild(doc.CreateElement("root"));
                    GlobalVars.SETTINGS.metadata_MappingProfiles = doc;
                }

                foreach (XmlElement xNode in GlobalVars.SETTINGS.metadata_MappingProfiles.DocumentElement.ChildNodes)
                {
                    string         name = xNode.Attributes["ProfileName"].InnerText;
                    string         targetContentTypeName = xNode.Attributes["TargetContentTypeName"].InnerText;
                    MappingProfile mp = new MappingProfile(name, targetContentTypeName);
                    mp.MappingItems = new List <MappingItem>();
                    foreach (XmlElement x2 in xNode.ChildNodes)
                    {
                        MappingItem mi = new MappingItem(x2.Attributes["SourceColumn"].InnerText, x2.Attributes["DestColumn"].InnerText);
                        mp.MappingItems.Add(mi);
                    }
                    mp.MappingItems.Sort();
                    MappingProfiles.Add(mp);
                }
            }
            catch (Exception ex)
            {
                Eh.GlobalErrorHandler(ex);
            }
        }
        public static void ShowBuildMappingForm(SPDocumentLibrary docLib, MappingProfile mp)
        {
            if (docLib == null)
            {
                return;
            }
            frmBuildMapping f = new frmBuildMapping();

            //--populate cboTargetContentType
            List <string> inelligableContentTypes = new List <string>();

            //inelligableContentTypes.Add("Document");
            inelligableContentTypes.Add("Folder");
            foreach (SPContentType ct in docLib.ContentTypes)
            {
                if (!inelligableContentTypes.Contains(ct.Name))
                {
                    f.cboTargetContentType.Items.Add(ct.Name);
                }
            }

            //--
            f.lblTargetDocLib.Text = "Target Document Library: " + docLib.Title;
            f.m_targetDocLib       = docLib;
            if (mp == null) //--create a new Mapping Profile
            {
                f.m_mpWorking = new MappingProfile("new profile", "");
                f.m_mpWorking.MappingItems = new List <MappingItem>();
                f.txtProfileName.Text      = "(New Mapping Profile)";
                f.Text = "New Mapping Profile";
                f.lnkDeleteProfile.Enabled = false;
                if (f.cboTargetContentType.Items.Count == 1)
                {
                    f.cboTargetContentType.SelectedIndex = 0;
                }
            }
            else //--edit existing Mapping Profile
            {
                f.m_editingMPindex = ActionMetaDataUtil.MappingProfiles.IndexOf(mp);
                MappingProfile ret = (MappingProfile)Util.DeepCopy(mp);
                if (ret == null)
                {
                    return;
                }
                f.m_mpWorking         = ret;
                f.txtProfileName.Text = mp.ProfileName;
                f.cboTargetContentType.SelectedIndex = f.cboTargetContentType.FindStringExact(mp.TargetContentTypeName);
                f.Text = "Edit Mapping Profile";
                if (f.m_mpWorking.MappingItems == null)
                {
                    f.m_mpWorking.MappingItems = new List <MappingItem>();
                }
            }

            f.displayMappingProfileInRtb(null, null);
            f.Location = new Point(MainForm.DefInstance.Left + 10, MainForm.DefInstance.Top + 10);

            //--
            f.ShowDialog();
        }
예제 #3
0
        private bool findColoumRefFromInternalName(MappingProfile mp, SPList list)
        {
            int countFound = 0;

            foreach (MappingItem mi in mp.MappingItems)
            {
                mi.sourceID = new Guid();
                mi.destID   = new Guid();
                foreach (SPField field in list.Fields)
                {
                    if (field.InternalName == mi.SourceColumn)
                    {
                        mi.sourceID           = field.Id;
                        mi.sourceTypeAsString = field.TypeAsString;
                        break;
                    }
                }
                foreach (SPField field in list.Fields)
                {
                    if (field.InternalName == mi.DestColumn)
                    {
                        mi.destID           = field.Id;
                        mi.destTypeAsString = field.TypeAsString;
                        break;
                    }
                }

                if (mi.sourceID == new Guid())
                {
                    AddToRtbLocal("source column " + mi.SourceColumn + " not found\r\n", StyleType.bodyRed);
                }
                else
                {
                    AddToRtbLocal("source column " + mi.SourceColumn + " found\r\n", StyleType.bodySeaGreen);
                    countFound++;
                }
                if (mi.destID == new Guid())
                {
                    AddToRtbLocal("  ->destination column " + mi.DestColumn + " not found\r\n", StyleType.bodyRed);
                }
                else
                {
                    AddToRtbLocal("  ->destination column " + mi.DestColumn + " found\r\n", StyleType.bodySeaGreen);
                    countFound++;
                }
            }
            if (countFound != mp.MappingItems.Count * 2)
            {
                return(false);
            }

            return(true);
        }
예제 #4
0
        private void lnkCopyProfile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            MappingProfile mp     = (MappingProfile)cboMappingProfile.SelectedItem;
            MappingProfile mpCopy = (MappingProfile)Util.DeepCopy(mp);

            if (mpCopy == null)
            {
                return;
            }
            ActionMetaDataUtil.MappingProfiles.Add(mpCopy);
            mpCopy.ProfileName = "Copy of " + mpCopy.ProfileName;
            cboMappingProfile.Items.Add(mpCopy);
            cboMappingProfile.SelectedItem = mpCopy;
            ActionMetaDataUtil.SaveMappingProfileToXml();
        }
예제 #5
0
        private void lnkEditProfiles_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                MainForm.DefInstance.Cursor = Cursors.WaitCursor;
                SPDocumentLibrary docLib = (SPList)cboDocLibs.SelectedItem as SPDocumentLibrary;

                MappingProfile mp = (MappingProfile)cboMappingProfile.SelectedItem;
                frmBuildMapping.ShowBuildMappingForm(docLib, mp);
            }
            finally
            {
                MainForm.DefInstance.Cursor = Cursors.Default;
            }
        }
예제 #6
0
        private void lnkDeleteSourceColumns_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            rtbDisplay.Clear();
            //TODO: redo to just display a form with checkboxes to delete columns, listing all content types besides target content type and folder content type.

            if (cboMappingProfile.SelectedItem == null)
            {
                return;
            }

            SPList         list = (SPList)cboDocLibs.SelectedItem;
            MappingProfile mp   = (MappingProfile)cboMappingProfile.SelectedItem;

            //--
            AddToRtbLocal("Deleting source columns from document library\r\n", StyleType.titleSeagreen);

            if (!findColoumRefFromInternalName(mp, list))
            {
                return;
            }

            DialogResult ret = MessageBox.Show(this, "Are you sure you want to delete these " + mp.MappingItems.Count + " columns?", "SUSHI", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (ret == DialogResult.Yes)
            {
                foreach (MappingItem mi in mp.MappingItems)
                {
                    SPField field = list.Fields[mi.sourceID];
                    if (field.CanBeDeleted == false)
                    {
                        SmartStepUtil.AddToRTB(rtbDisplay, "can't delete source column " + mi.SourceColumn + ", because it is an undeletable column\r\n");
                    }
                    else
                    {
                        SmartStepUtil.AddToRTB(rtbDisplay, "deleting source column " + mi.SourceColumn);
                        field.Delete();
                        SmartStepUtil.AddToRTB(rtbDisplay, " done. \r\n", StyleType.bodyBlackBold);
                    }
                }
            }
        }
예제 #7
0
        private void MapData(bool onlyValidate)
        {
            int counter     = 0;
            int countErrors = 0;

            try
            {
                //--validate
                if (cboMappingProfile.SelectedItem == null)
                {
                    return;
                }

                //--
                FrmCancelRunning.ToggleEnabled(true); //toggleEnabled(true);

                //--
                rtbDisplay.Clear();
                if (onlyValidate)
                {
                    AddToRtbLocal("Validating Mapping for target Document Library\r\n", StyleType.titleSeagreen);
                }
                else
                {
                    AddToRtbLocal("Mapping metadata for target Document Library\r\n", StyleType.titleSeagreen);
                }

                //--
                SPList         list = (SPList)cboDocLibs.SelectedItem;
                MappingProfile mp   = (MappingProfile)cboMappingProfile.SelectedItem;

                //--Find column ref and validate mapping profile for document library
                if (!findColoumRefFromInternalName(mp, list))
                {
                    return;
                }

                //--
                foreach (SPListItem listitem in list.Items)
                {
                    AddToRtbLocal(listitem.File.Name + "\r\n", StyleType.bodyBlackBold);
                    counter++;
                    foreach (MappingItem mi in mp.MappingItems)
                    {
                        if (onlyValidate)
                        {
                            AddToRtbLocal("   " + mi.DestColumn + " will be updated to \"" + Util.ToStr(listitem[mi.sourceID] + "\"\r\n"), StyleType.bodyBlack);
                        }
                        else
                        {
                            AddToRtbLocal("   " + mi.DestColumn + " updated to \"" + Util.ToStr(listitem[mi.sourceID] + "\"\r\n"), StyleType.bodyBlack);
                            //--for Lookup fields, need to validate format before updating
                            if (mi.DestColumn != "LookupMulti" || validateFormatOfLookup(listitem[mi.sourceID]))
                            {
                                listitem[mi.destID] = listitem[mi.sourceID];
                            }
                            //setLookupValueForPRTMproduct(listitem, mi);
                        }
                    }
                    try
                    {
                        if (!onlyValidate)
                        {
                            listitem.Update();
                        }
                    }
                    catch (Exception ex)
                    {
                        countErrors++;
                        AddToRtbLocal("Error while updating: " + ex.Message + ", continuing to next item..\r\n", StyleType.bodyRed);
                    }

                    //--
                    if (GlobalVars.CancelRunning)
                    {
                        throw new Eh.CancelException();
                    }
                    SmartStepUtil.ScrollToBottom(rtbDisplay);
                    Application.DoEvents();
                }
            }
            catch (Eh.CancelException)
            {
                SmartStepUtil.AddToRTB(rtbDisplay, "Canceled by user\r\n", Color.Black, 10, true);
            }
            catch (Exception ex)
            {
                AddToRtbLocal("error: " + ex.Message + "\r\nMessageType:" + ex.GetType().ToString() + "\r\n", StyleType.bodyRed);
            }
            finally
            {
                FrmCancelRunning.ToggleEnabled(false); //toggleEnabled(false);
            }
            string u = onlyValidate ? "validated" : "updated";

            AddToRtbLocal("\r\nNumber of documents " + u + ":" + counter + ", errors:" + countErrors + "\r\n", StyleType.bodyDarkGray);
            SmartStepUtil.ScrollToBottom(rtbDisplay);
        }