Exemplo n.º 1
0
 /// <summary>
 /// Iports the invoice from XML.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="url">The URL.</param>
 /// <param name="listIndex">Index of the list.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="progressChanged">The progress changed.</param>
 public static void IportInvoiceFromXml(Stream stream, string url, int listIndex, string fileName, ProgressChangedEventHandler progressChanged)
 {
     try
     {
         using (Entities edc = new Entities(url))
         {
             String message = String.Format("Import of the invoice message {0} starting.", fileName);
             ActivityLogCT.WriteEntry(edc, m_Title, message);
             InvoiceXml document = InvoiceXml.ImportDocument(stream);
             InvoiceLib entry    = Element.GetAtIndex <InvoiceLib>(edc.InvoiceLibrary, listIndex);
             GetXmlContent(document, edc, entry);
             ActivityLogCT.WriteEntry(edc, m_Title, String.Format("Import of the invoice message {0} finished", fileName));
         }
     }
     catch (CAS.SmartFactory.IPR.WebsiteModel.InputDataValidationException _iove)
     {
         _iove.ReportActionResult(url, fileName);
         ActivityLogCT.WriteEntry(m_Title, "Import of the invoice message failed", url);
     }
     catch (Exception ex)
     {
         ActivityLogCT.WriteEntry("Aborted Invoice message import because of the error", ex.Message, url);
         ActivityLogCT.WriteEntry(m_Title, "Import of the invoice message failed", url);
     }
 }
 private static void DeleteWebParts(Entities edc, SPWeb root)
 {
     ActivityLogCT.WriteEntry(edc, m_SourceClass + m_SourceDeleteWebParts, "Delete Web Parts starting");
     try
     {
         SPList        _wpl           = root.GetCatalog(SPListTemplateType.WebPartCatalog);
         List <SPFile> _filesToDelete = new List <SPFile>();
         // figure out which Web Part template files need to be deleted
         ActivityLogCT.WriteEntry
         (
             edc, m_SourceClass + m_SourceDeleteWebParts,
             String.Format("Processing of the WebPartCatalog containing {0} items starting ", _wpl.ItemCount)
         );
         foreach (SPListItem _li in _wpl.Items)
         {
             bool _delete = _li.File.Name.StartsWith("IPRDashboards");
             if (_delete)
             {
                 _filesToDelete.Add(_li.File);
             }
             string _mess = String.Format("Title: {0}, Name: {1}, File name: {2}, deleted: {3}", _li.Title, _li.Name, _li.File.Name, _delete);
             ActivityLogCT.WriteEntry(edc, "Processing Web Part", _mess);
         }
         // delete Web Part template files
         foreach (SPFile file in _filesToDelete)
         {
             file.Delete();
         }
     }
     catch (Exception ex)
     {
         ActivityLogCT.WriteEntry(edc, m_SourceClass + m_SourceDeleteWebParts, "Delete Web Parts finished with exception: " + ex.Message);
     }
     ActivityLogCT.WriteEntry(edc, m_SourceClass + m_SourceDeleteWebParts, "Delete Web Parts finished");
 }
Exemplo n.º 3
0
        protected override void ShowActionResult(ActionResult _rslt)
        {
            switch (_rslt.LastActionResult)
            {
            case ActionResult.Result.Success:
            case ActionResult.Result.NotValidated:
                break;

            case ActionResult.Result.Exception:
                ActivityLogCT.WriteEntry(_rslt.ActionException.Source, _rslt.ActionException.Message);
                break;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// An item was added.
        /// </summary>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            string At = "SKU Library";

            try
            {
                if (!properties.ListTitle.Contains("SKU Library"))
                {
                    //TODO  [pr4-3435] Item add event - selective handling mechanism. http://itrserver/Bugs/BugDetail.aspx?bid=3435
                    base.ItemAdded(properties);
                    return;
                }
                this.EventFiringEnabled = false;
                if (properties.ListItem.File == null)
                {
                    throw new System.ArgumentException("Import of SKU xml message failed because the file is empty.", "File");
                }
                At = "using";
                using (Stream _strm = properties.ListItem.File.OpenBinaryStream())
                    using (Entities edc = new Entities(properties.WebUrl))
                    {
                        String message = String.Format("Import of the SKU message {0} starting.", properties.ListItem.File.Name);
                        ActivityLogCT.WriteEntry(edc, m_Title, message);
                        At = "ImportDocument";
                        SKUXml xml = SKUXml.ImportDocument(_strm);
                        At = "GetAtIndex";
                        Document entry = Element.GetAtIndex <Document>(edc.SKULibrary, properties.ListItem.ID);
                        At = "GetXmlContent";
                        SKUGetFromXML.GetXmlContent(xml, edc, entry, (object obj, ProgressChangedEventArgs progres) => { At = (string)progres.UserState; });
                        ActivityLogCT.WriteEntry(edc, m_Title, String.Format("Import of the sku message {0} finished", properties.ListItem.File.Name));
                    }
            }
            catch (InputDataValidationException _ioex)
            {
                _ioex.ReportActionResult(properties.WebUrl, properties.ListItem.File.Name);
                string _fileName = GetFileName(properties);
                ActivityLogCT.WriteEntry(m_Title, String.Format("SKU message {0} import has been stoped because of errors.", _fileName), properties.WebUrl);
            }
            catch (Exception ex)
            {
                string _pattern  = @"SKU message {2} import has been stoped because of an unexpected fatal error <b>{0}</b> at: <b>{1}</b>";
                string _fileName = GetFileName(properties);
                ActivityLogCT.WriteEntry(m_Title, String.Format(_pattern, ex.Message, At, _fileName), properties.WebUrl);
            }
            finally
            {
                this.EventFiringEnabled = true;
            }
            base.ItemAdded(properties);
        }
Exemplo n.º 5
0
        private static void GetXmlContent
            (MaterialXml[] material, Entities edc, Document parent, CreateMaterialXml creator, ProgressChangedEventHandler progressChanged)
        {
            List <SKUCommonPart> entities = new List <SKUCommonPart>();
            List <string>        warnings = new List <string>();
            int _entries    = 0;
            int _newEntries = 0;

            foreach (MaterialXml item in material)
            {
                try
                {
                    _entries++;
                    progressChanged(null, new ProgressChangedEventArgs(1, "Processing: " + item.GetMaterial()));
                    SKUCommonPart entity = SKUCommonPart.Find(edc, item.GetMaterial());
                    if (entity != null)
                    {
                        continue;
                    }
                    SKUCommonPart sku = creator(item, parent, edc, warnings);
                    if (sku != null)
                    {
                        _newEntries++;
                        entities.Add(sku);
                    }
                }
                catch (Exception ex)
                {
                    string message = String.Format("Cannot create: {0}:{1} because of the error: {2}", item.GetMaterial(), item.GetMaterialDescription(), ex.Message);
                    ActivityLogCT.WriteEntry(edc, "SKU entry error", message);
                }
            }
            if (entities.Count > 0)
            {
                edc.SKU.InsertAllOnSubmit(entities);
                progressChanged(null, new ProgressChangedEventArgs(1, "Submiting Changes"));
                edc.SubmitChanges();
            }
            if (warnings.Count > 0)
            {
                throw new InputDataValidationException("SKU message import errors.", "XML import", new ErrorsList(warnings, true));
            }
            string _pattern = "Finished content analysis, there are {0} entries, {1} new entries, {2} erroneous entries";

            ActivityLogCT.WriteEntry("SKU Message Import", String.Format(_pattern, _entries, _newEntries, warnings.Count), edc.Web);
        }
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite _site = properties.Feature.Parent as SPSite;

            if (_site == null)
            {
                throw new ApplicationException("FeatureDeactivating cannot get access to the Web");
            }
            using (Entities _edc = new Entities(_site.RootWeb.Url))
            {
                ActivityLogCT.WriteEntry(_edc, "FeatureDeactivating", "Feature Deactivation starting.");
                ActivityLogCT.WriteEntry(_edc, "FeatureDeactivating", "Removing pages.");
                WebPartPagesCW.ProjectElementManagement.RemovePages(_edc, _site.RootWeb);
                ActivityLogCT.WriteEntry(_edc, "FeatureDeactivating", "Removing Navigation Entries.");
                RemoveNavigationEntries(_site.RootWeb);
                ActivityLogCT.WriteEntry(_edc, "FeatureDeactivating", "Feature Deactivation finished.");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Imports the batch from XML.
        /// </summary>
        /// <param name="edc">The _edc.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="progressChanged">The progress changed delegate <see cref="ProgressChangedEventHandler" />.</param>
        /// <returns></returns>
        /// <exception cref="CAS.SmartFactory.IPR.WebsiteModel.InputDataValidationException">Batch XML message validation failed;XML sysntax validation</exception>
        /// <exception cref="IPRDataConsistencyException"></exception>
        public static BatchXml ImportBatchFromXml(Entities edc, Stream stream, string fileName, ProgressChangedEventHandler progressChanged)
        {
            progressChanged(null, new ProgressChangedEventArgs(1, "ImportBatchFromXml.starting"));
            string _Message = String.Format(m_Message, fileName);

            ActivityLogCT.WriteEntry(edc, m_Title, _Message);
            BatchXml _xml = BatchXml.ImportDocument(stream);

            progressChanged(null, new ProgressChangedEventArgs(1, "ImportBatchFromXml.Validate"));
            List <string> _validationErrors = new List <string>();

            _xml.Validate(Settings.GetParameter(edc, SettingsEntry.BatchNumberPattern), _validationErrors);
            if (_validationErrors.Count > 0)
            {
                ErrorsList _el = new ErrorsList(_validationErrors, true);
                throw new InputDataValidationException("Batch XML message validation failed", "XML sysntax validation", _el);
            }
            return(_xml);
        }
        /// <summary>
        /// Occurs after a Feature is activated.
        /// </summary>
        /// <param name="properties">An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties" /> object that represents the properties of the event.</param>
        /// <exception cref="System.ApplicationException">
        /// In FeatureActivated the Site is null
        /// or
        /// </exception>
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            string _cp = "Starting";

            try
            {
                SPSite site = (SPSite)properties.Feature.Parent;
                if (site == null)
                {
                    throw new ApplicationException("In FeatureActivated the Site is null");
                }
                using (Entities _edc = new Entities(site.RootWeb.Url))
                {
                    ActivityLogCT.WriteEntry(_edc, m_SourceClass + m_SourceFeatureActivated, "FeatureActivated strating");
                    _cp = "ReplaceMasterMage";
                    ReplaceMasterPage(site);
                    ActivityLogCT.WriteEntry(_edc, m_SourceClass + m_SourceFeatureActivated, "Navigation setup starting");
                    _cp = "SPNavigationNodeCollection";
                    SPNavigationNodeCollection _topNav = site.RootWeb.Navigation.TopNavigationBar;
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuIPRBookTitle, ProjectElementManagement.URLIPRBookDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuIPRClosedBookTitle, ProjectElementManagement.URLIPRBookClosedDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuIPRBookCustomsOfficeTitle, ProjectElementManagement.URLIPRBookCustomsOfficeDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuIPRClosedBookCustomsOfficeTitle, ProjectElementManagement.URLIPRBookClosedCustomsOfficeDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuClearanceTitle, ProjectElementManagement.URLClearenceDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuClearanceViewTitle, ProjectElementManagement.URLClearenceViewDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuExportTitle, ProjectElementManagement.URLExportDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuBatchTitle, ProjectElementManagement.URLBatchDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuStocksTitle, ProjectElementManagement.URLStocksDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuReportsTitle, ProjectElementManagement.URLReportsDashboard));
                    foreach (SPNavigationNode item in _topNav)
                    {
                        item.Update();
                    }
                    //WebPartPages.ProjectElementManagement.SetupConnections(_edc, _root);
                    _cp = "Entities.Anons";
                    ActivityLogCT.WriteEntry(_edc, m_SourceClass + m_SourceFeatureActivated, "FeatureActivated finished");
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(String.Format("FeatureActivated exception at {0}: {1}", _cp, ex.Message));
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Iports the stock from XML.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="url">The URL.</param>
        /// <param name="listIndex">Index of the list.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="progressChanged">The progress changed.</param>
        public static void IportStockFromXML(Stream stream, string url, int listIndex, string fileName, ProgressChangedEventHandler progressChanged)
        {
            try
            {
                using (Entities _edc = new Entities(url))
                {
                    String _message = String.Format("Import of the stock message {0} starting.", fileName);
                    ActivityLogCT.WriteEntry(_edc, m_Source, _message);
                    StockXml document = StockXml.ImportDocument(stream);
                    StockLib _entry   = Element.GetAtIndex <StockLib>(_edc.StockLibrary, listIndex);
                    _entry.Stock2JSOXLibraryIndex = null;
                    ErrorsList _warnings = new ErrorsList();
                    IportXml(document, _edc, _entry, _warnings, progressChanged);
                    InputDataValidationException _exc = new InputDataValidationException("there are errors in the stockm XML message.", "GetBatchLookup", _warnings);
                    switch (_exc.Valid)
                    {
                    case InputDataValidationException.Result.Success:
                        break;

                    case InputDataValidationException.Result.Warnings:
                        _exc.ReportActionResult(url, fileName);
                        break;

                    case InputDataValidationException.Result.FatalErrors:
                        throw _exc;
                    }
                    progressChanged(null, new ProgressChangedEventArgs(1, "Submitting Changes - Warnings"));
                    _edc.SubmitChanges();
                }
            }
            catch (WebsiteModel.InputDataValidationException _iove)
            {
                _iove.ReportActionResult(url, fileName);
                ActivityLogCT.WriteEntry(m_Source, String.Format("Import of the stock message {0} failed.", fileName), url);
            }
            catch (Exception ex)
            {
                ActivityLogCT.WriteEntry("Stock XML message import fatal error", ex.Message, url);
            }
            ActivityLogCT.WriteEntry(m_Source, String.Format("Import of the stock message {0} finished.", fileName), url);
        }
Exemplo n.º 10
0
 internal static void RemovePages(Entities _edc, SPWeb _root)
 {
     ActivityLogCT.WriteEntry(_edc, m_SourceClass + m_SourceRemovePages, "Remove Pages starting");
     try
     {
         SPFolder WebPartPagesFolder = _root.GetFolder(ProjectElementManagement.WebPartPagesFolder);
         if (WebPartPagesFolder.Exists)
         {
             WebPartPagesFolder.Delete();
         }
         else
         {
             ActivityLogCT.WriteEntry(_edc, m_SourceClass + m_SourceRemovePages, "Failed, the folder " + WebPartPagesFolder + "dies not exist.");
         }
     }
     catch (Exception ex)
     {
         ActivityLogCT.WriteEntry(_edc, m_SourceClass + m_SourceRemovePages, "Remove pages failed with exception: " + ex.Message);
     }
     ActivityLogCT.WriteEntry(_edc, m_SourceClass + m_SourceRemovePages, "Remove Pages finished");
 }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            string _cp = "Starting";

            try
            {
                SPSite site = (SPSite)properties.Feature.Parent;
                if (site == null)
                {
                    throw new ApplicationException("In FeatureActivated the Site is null");
                }
                using (Entities _edc = new Entities(site.RootWeb.Url))
                {
                    ActivityLogCT.WriteEntry(_edc, m_SourceClass + m_SourceFeatureActivated, "FeatureActivated strating");
                    ActivityLogCT.WriteEntry(_edc, m_SourceClass + m_SourceFeatureActivated, "Navigation setup starting");
                    _cp = "SPNavigationNodeCollection";
                    SPNavigationNodeCollection _topNav = site.RootWeb.Navigation.TopNavigationBar;
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuCWBookTitle, ProjectElementManagement.URLCWBookDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuCWBookClosedTitle, ProjectElementManagement.URLCWBookClosedDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuCWBookCustomsOfficeTitle, ProjectElementManagement.URLCWBookCustomsOfficeDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuCWBookClosedCustomsOfficeTitle, ProjectElementManagement.URLCWBookClosedCustomsOfficeDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuCheckListExitSheetTitle, ProjectElementManagement.URLCheckListExitSheetDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuSupplementCWBookTitle, ProjectElementManagement.URLSupplementCWBookDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuSupplementWZNoTitle, ProjectElementManagement.URLSupplementWZNoDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuDisposalRequestTitle, ProjectElementManagement.URLDisposalRequestDashboard));
                    _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuDisposalsViewTitle, ProjectElementManagement.URLDisposalsViewDashboard));
                    foreach (SPNavigationNode item in _topNav)
                    {
                        item.Update();
                    }
                    //WebPartPages.ProjectElementManagement.SetupConnections(_edc, _root);
                    _cp = "Entities.Anons";
                    ActivityLogCT.WriteEntry(_edc, m_SourceClass + m_SourceFeatureActivated, "FeatureActivated finished");
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(String.Format("FeatureActivated exception at {0}: {1}", _cp, ex.Message));
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// An item was added.
 /// </summary>
 public override void ItemAdded(SPItemEventProperties properties)
 {
     if (!properties.ListTitle.Contains("Stock Library"))
     {
         //TODO  [pr4-3435] Item add event - selective handling mechanism. http://itrserver/Bugs/BugDetail.aspx?bid=3435
         base.ItemAdded(properties);
         return;
     }
     this.EventFiringEnabled = false;
     try
     {
         properties.List.Update();
         //if (properties.ListItem.File == null)
         //{
         //  Anons.WriteEntry(edc, m_Title, "Import of a stock xml message failed because the file is empty.");
         //  edc.SubmitChanges();
         //  return;
         //}
         using (Stream _str = properties.ListItem.File.OpenBinaryStream())
             IportStockFromXML
             (
                 _str,
                 properties.WebUrl,
                 properties.ListItem.ID,
                 properties.ListItem.File.Name,
                 (object obj, ProgressChangedEventArgs progres) => { return; }
             );
         properties.List.Update();
         properties.Cancel = true;
         properties.Status = SPEventReceiverStatus.CancelNoError;
     }
     catch (Exception ex)
     {
         ActivityLogCT.WriteEntry("Stock xml message SPItemEventReceiver fatal error.", ex.Message, properties.WebUrl);
     }
     this.EventFiringEnabled = true;
     base.ItemAdded(properties);
 }
 /// <summary>
 /// Add the log entry with exception description.
 /// </summary>
 /// <param name="edc">The edc.</param>
 public void Add2Log(Entities edc)
 {
     ActivityLogCT.WriteEntry(edc, this.Source, this.Message);
 }
Exemplo n.º 14
0
 /// <summary>
 /// An item was added.
 /// </summary>
 /// <param name="properties">Contains properties for asynchronous list item event handlers.</param>
 public override void ItemAdded(SPItemEventProperties properties)
 {
     TraceEvent("Entering BatchEventReceiver.ItemAdded", 43, TraceSeverity.Monitorable);
     base.ItemAdded(properties);
     try
     {
         if (!properties.ListTitle.Contains("Batch Library"))
         {
             //TODO  [pr4-3435] Item add event - selective handling mechanism. http://itrserver/Bugs/BugDetail.aspx?bid=3435
             TraceEvent("BatchEventReceiver.ItemAdded ", 50, TraceSeverity.Verbose);
             TraceEvent(String.Format("Exiting BatchEventReceiver.ItemAdded - event called for wrong list, list name {0}.", properties.ListTitle), 51, TraceSeverity.Monitorable);
             base.ItemAdded(properties);
             return;
             //throw new IPRDataConsistencyException(m_Title, "Wrong library name", null, "Wrong library name");
         }
         this.EventFiringEnabled = false;
         using (Entities _edc = new Entities(properties.WebUrl))
         {
             BatchLib _entry = _entry = Element.GetAtIndex <BatchLib>(_edc.BatchLibrary, properties.ListItemId);
             At = "ImportBatchFromXml";
             BatchXml _xml = default(BatchXml);
             using (Stream _stream = properties.ListItem.File.OpenBinaryStream())
                 _xml = ImportBatchFromXml(_edc, _stream, properties.ListItem.File.Name, ProgressChange);
             At = "Getting Data";
             GetXmlContent(_xml, _edc, _entry, ProgressChange);
             At = "ListItem assign";
             _entry.BatchLibraryOK       = true;
             _entry.BatchLibraryComments = "Batch message import succeeded.";
             At = "SubmitChanges";
             TraceEvent("BatchEventReceiver.ItemAdded at SubmitChanges", 70, TraceSeverity.Verbose);
             _edc.SubmitChanges();
             foreach (Warnning _wrnngx in m_Warnings)
             {
                 ActivityLogCT.WriteEntry(_edc, m_Title, String.Format("Import of the batch warning: {0}", _wrnngx.Message));
             }
             ActivityLogCT.WriteEntry(_edc, m_Title, String.Format("Import of the batch {0} message finished", properties.ListItem.File.Name));
         }
     }
     catch (InputDataValidationException _idve)
     {
         _idve.ReportActionResult(properties.WebUrl, properties.ListItem.File.Name);
     }
     catch (IPRDataConsistencyException _ex)
     {
         _ex.Source += " at " + At;
         using (Entities _edc = new Entities(properties.WebUrl))
         {
             _ex.Add2Log(_edc);
             BatchLib _entry = _entry = Element.GetAtIndex <BatchLib>(_edc.BatchLibrary, properties.ListItemId);
             _entry.BatchLibraryOK       = false;
             _entry.BatchLibraryComments = _ex.Comments;
             _edc.SubmitChanges();
         }
     }
     catch (Exception _ex)
     {
         using (Entities _edc = new Entities(properties.WebUrl))
         {
             ActivityLogCT.WriteEntry(_edc, "BatchEventReceiver.ItemAdded" + " at " + At, _ex.Message);
             BatchLib _entry = _entry = Element.GetAtIndex <BatchLib>(_edc.BatchLibrary, properties.ListItemId);
             _entry.BatchLibraryComments = "Batch message import error";
             _entry.BatchLibraryOK       = false;
             _edc.SubmitChanges();
         }
     }
     finally
     {
         this.EventFiringEnabled = true;
     }
     TraceEvent("Finishing BatchEventReceiver.ItemAdded", 107, TraceSeverity.Verbose);
 }
Exemplo n.º 15
0
 /// <summary>
 /// An item was added
 /// </summary>
 /// <param name="properties">An object of <see cref="SPItemEventProperties"/></param>
 public override void ItemAdded(SPItemEventProperties properties)
 {
     try
     {
         if (!properties.ListTitle.Contains("Disposal Request Library"))
         {
             //TODO  [pr4-3435] Item add event - selective handling mechanism. http://itrserver/Bugs/BugDetail.aspx?bid=3435
             base.ItemAdded(properties);
             return;
         }
         this.EventFiringEnabled = false;
         using (Entities _edc = new Entities(properties.WebUrl))
         {
             ActivityLogCT.WriteEntry(_edc, m_Title, String.Format("Import of the Disposal Request {0} XML message started", properties.ListItem.File.Name));
             At = "ImportDocument";
             DisposalRequestXml _xml = default(DisposalRequestXml);
             using (Stream _stream = properties.ListItem.File.OpenBinaryStream())
                 _xml = DisposalRequestXml.ImportDocument(_stream);
             At = "GetAtIndex - DisposalRequestLib";
             DisposalRequestLib _entry = Element.GetAtIndex <DisposalRequestLib>(_edc.DisposalRequestLibrary, properties.ListItemId);
             _entry.Archival           = true;
             _entry.ClearenceProcedure = Covert2ClearenceProcedure(_xml.ClearenceProcedure);
             At = "GetXmlContent";
             GetXmlContent(_edc, _xml, _entry, ProgressChange);
             At = "SubmitChanges";
             _edc.SubmitChanges();
             foreach (CAS.SmartFactory.Customs.Warnning _wrnngx in m_Warnings)
             {
                 ActivityLogCT.WriteEntry(_edc, m_Title, String.Format("Import warnning: {0}", _wrnngx.Message));
             }
             ActivityLogCT.WriteEntry(_edc, m_Title, String.Format("Import of the Disposal Request {0} XML message message finished - document imported", properties.ListItem.File.Name));
         }
     }
     //catch (InputDataValidationException _idve)
     //{
     //  _idve.ReportActionResult(_properties.WebUrl, _properties.ListItem.File.Name);
     //}
     //catch (IPRDataConsistencyException _ex)
     //{
     //  _ex.Source += " at " + At;
     //  using (Entities _edc = new Entities(_properties.WebUrl))
     //  {
     //    _ex.Add2Log(_edc);
     //    BatchLib _entry = _entry = Element.GetAtIndex<BatchLib>(_edc.BatchLibrary, _properties.ListItemId);
     //    _entry.BatchLibraryOK = false;
     //    _entry.BatchLibraryComments = _ex.Comments;
     //    _edc.SubmitChanges();
     //  }
     //}
     catch (Exception _ex)
     {
         using (Entities _edc = new Entities(properties.WebUrl))
         {
             ActivityLogCT.WriteEntry(_edc, "BatchEventReceiver.ItemAdded" + " at " + At, _ex.Message);
             DisposalRequestLib _entry = Element.GetAtIndex <DisposalRequestLib>(_edc.DisposalRequestLibrary, properties.ListItemId);
             _entry.ClearenceProcedure = new Nullable <ClearenceProcedure>();
             _edc.SubmitChanges();
         }
     }
     finally
     {
         this.EventFiringEnabled = true;
     }
     base.ItemAdded(properties);
 }
Exemplo n.º 16
0
        /// <summary>
        /// An item was added
        /// </summary>
        /// <param name="properties"> Contains properties for asynchronous list item event handlers, and serves as a base class for
        /// event handlers.
        /// </param>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            TraceEvent("Entering SADImportXML ItemAdded", 46, TraceSeverity.Monitorable);
            ErrorsList m_Warnings = new ErrorsList();
            string     _at        = "beginning";

            if (!properties.ListTitle.Contains(CommonDefinition.SADDocumentLibrary))
            {
                //TODO  [pr4-3435] Item add event - selective handling mechanism. http://itrserver/Bugs/BugDetail.aspx?bid=3435
                TraceEvent(String.Format("Exiting SADImportXML.ItemAdded - event called for wrong lis list name {0}.", properties.ListTitle), 52, TraceSeverity.Monitorable);
                base.ItemAdded(properties);
                return;
            }
            bool   _entrySADDocumentLibraryOK       = false;
            string _entrySADDocumentLibraryComments = "Item adding error";

            try
            {
                this.EventFiringEnabled = false;
                if (properties.ListItem.File == null)
                {
                    TraceEvent("Exiting SADImportXML.ItemAdded - file is empty", 63, TraceSeverity.High);
                    base.ItemAdded(properties);
                    return;
                    //TODO  [pr4-3435] Item add event - selective handling mechanism. http://itrserver/Bugs/BugDetail.aspx?bid=3435
                    //throw new IPRDataConsistencyException("ItemAdded", "Import of a SAD declaration message failed because the file is empty.", null, "There is no file");
                }
                try
                {
                    ActivityLogCT.WriteEntry(m_Title, String.Format("Import of the SAD declaration {0} starting.", properties.ListItem.File.Name), properties.WebUrl);
                    CustomsDocument _message = null;
                    using (Stream _str = properties.ListItem.File.OpenBinaryStream())
                        _message = CustomsDocument.ImportDocument(_str);
                    int _sadIDValue;
                    using (Entities edc = new Entities(properties.WebUrl))
                    {
                        _at = "GetAtIndex<SADDocumentLib>";
                        SADDocumentLib _SADLibEntry = Element.GetAtIndex <SADDocumentLib>(edc.SADDocumentLibrary, properties.ListItem.ID);
                        _at = "GetSADDocument";
                        SADDocumentType _SADEntity = GetSADDocument(_message, edc, _SADLibEntry);
                        _at = "SubmitChanges";
                        edc.SubmitChanges();
                        _sadIDValue = _SADEntity.Id.Value;
                    }
                    _at = "DeclarationProcessing";
                    _entrySADDocumentLibraryComments = "OK";
                    ClearenceHelpers.DeclarationProcessing(properties.WebUrl, _sadIDValue, _message.MessageRootName(), ref _entrySADDocumentLibraryComments, m_Warnings, TraceEvent);
                }
                catch (InputDataValidationException _ie)
                {
                    TraceEvent(String.Format("Exception {0} at SADImportXML.ItemAdded file={1}", _ie.GetType().Name, properties.ListItem.File.Name), 92, TraceSeverity.High);
                    _ie.ReportActionResult(properties.WebUrl, properties.ListItem.File.Name);
                }
                catch (Exception _ex)
                {
                    string _pattern = "XML import error at {0}.";
                    if (_ex is CustomsDataException)
                    {
                        _pattern = "XML import error at {0}.";
                        _at      = ((CustomsDataException)_ex).Source;
                    }
                    else if (_ex is IPRDataConsistencyException)
                    {
                        IPRDataConsistencyException _iprex = _ex as IPRDataConsistencyException;
                        _pattern = "SAD analyses error at {0}.";
                        _at      = _iprex.Source;
                    }
                    else if (_ex is GenericStateMachineEngine.ActionResult)
                    {
                        GenericStateMachineEngine.ActionResult _ar = _ex as GenericStateMachineEngine.ActionResult;
                        if (_ar.LastActionResult == GenericStateMachineEngine.ActionResult.Result.NotValidated)
                        {
                            _pattern = "SAD content validation error at {0}.";
                        }
                        else
                        {
                            _pattern = "SAD analyses internal error at {0}.";
                        }
                        _at = _ar.Source;
                    }
                    else
                    {
                        _pattern = "ItemAdded error at {0}.";
                    }
                    string _innerMsg = String.Empty;
                    if (_ex.InnerException != null)
                    {
                        _innerMsg = String.Format(" as the result of {0}.", _ex.InnerException.Message);
                    }
                    string _msg   = String.Format("Message= {0}; Inner: {1}", _ex.Message, _innerMsg);
                    string _where = String.Format(_pattern, _at);
                    ActivityLogCT.WriteEntry(_where, _msg, properties.WebUrl);
                    TraceEvent(String.Format("Exception {0} at SADImportXML.ItemAdded/{1}, Stack: {2}", _ex.GetType().Name, _where, _ex.StackTrace), 126, TraceSeverity.High);
                }
                try
                {
                    using (Entities edc = new Entities(properties.WebUrl))
                    {
                        SADDocumentLib _entry = Element.GetAtIndex <SADDocumentLib>(edc.SADDocumentLibrary, properties.ListItem.ID);
                        _entry.SADDocumentLibraryOK       = _entrySADDocumentLibraryOK;
                        _entry.SADDocumentLibraryComments = _entrySADDocumentLibraryComments;
                        _entrySADDocumentLibraryOK        = true;
                        _at = "m_Warnings";
                        foreach (Warnning _wrnngx in m_Warnings)
                        {
                            ActivityLogCT.WriteEntry(edc, m_Title, String.Format("Import of the SAD declaration wanning: {0}", _wrnngx.Message));
                        }
                        if (m_Warnings.Count == 0)
                        {
                            ActivityLogCT.WriteEntry(edc, m_Title, String.Format("Import of the SAD declaration {0} finished.", properties.ListItem.File.Name));
                        }
                        else
                        {
                            ActivityLogCT.WriteEntry(edc, m_Title, String.Format("Import of the SAD declaration {0} finished. {1} warnings have been reported.", properties.ListItem.File.Name, m_Warnings.Count));
                        }
                        _at = "SubmitChanges";
                        TraceEvent("SADImportXMLItemAdded SubmitChanges", 144, TraceSeverity.Verbose);
                        edc.SubmitChanges();
                    }
                }
                catch (Exception _ex)
                {
                    string _pattern = "Unexpected SADDocumentLib SubmitChanges error: {0}.";
                    ActivityLogCT.WriteEntry(m_Title, String.Format(_pattern, _ex.Message), properties.WebUrl);
                    TraceEvent(String.Format("Exception {0} at SADImportXML.ItemAdded/{1}, Stack: {2}", _ex.GetType().Name, _at, _ex.StackTrace), 152, TraceSeverity.High);
                }
            }
            finally
            {
                this.EventFiringEnabled = true;
            }
            base.ItemAdded(properties);
            TraceEvent("Finished SADImportXML ItemAdded", 160, TraceSeverity.Verbose);
        }