Пример #1
0
        /// <summary>
        /// Updates the SalesOrderLine Entities in the External System.
        /// </summary>
        public void UpdateSalesOrderLineItems()
        {
            DataRow row = null;

            // Loop through and call Updater on each changed SalesOrderLine
            IEnumerator enumerator = changedSalesLineRows.GetEnumerator();

            while (enumerator.MoveNext())
            {
                row = (DataRow)enumerator.Current;

                // BCS OM adds a column with name BdcIdentity when
                // it returns the DataTable
                object[] ids = EntityInstanceIdEncoder.
                               DecodeEntityInstanceId(row["BdcIdentity"].ToString());

                Identity salesOrderLineIdentity = new Identity(ids);

                // Get the specific SalesOrderLine using FindSpecific
                IEntityInstance salesOrderLineinstance =
                    entitySalesOrderLine.FindSpecific(
                        salesOrderLineIdentity,
                        SalesOrderLineSpecificFinderName,
                        lobInstance,
                        OperationMode.Online);

                salesOrderLineinstance["UnitPriceDiscount"] =
                    row["UnitPriceDiscount"];

                salesOrderLineinstance.Update();
            }

            return;
        }
Пример #2
0
 public static void SetExternalFieldValue(this SPListItem item, string fieldInternalName, string newValue)
 {
     if (item.Fields[fieldInternalName].TypeAsString == "BusinessData")
     {
         SPField     field   = item.Fields[fieldInternalName];
         XmlDocument xmlData = new XmlDocument();
         xmlData.LoadXml(field.SchemaXml);
         //Get teh internal name of the SPBusinessDataField's identity column.
         String entityName = xmlData.FirstChild.Attributes["RelatedFieldWssStaticName"].Value;
         //Set the value of the identity column.
         item[entityName]        = EntityInstanceIdEncoder.EncodeEntityInstanceId(new object[] { newValue });
         item[fieldInternalName] = newValue;
     }
     else
     {
         throw new InvalidOperationException(fieldInternalName + " is not of type BusinessData");
     }
 }
Пример #3
0
        private static IEntityInstance GetEntityInstance(SPBusinessDataField dataField, string entityId, SPSite site, SPListItem item, string finderMethodName)
        {
            IEntityInstance entInstance = null;

            try
            {
                IEntity            entity            = GetEntity(site, dataField);
                ILobSystemInstance lobSystemInstance = entity.GetLobSystem().GetLobSystemInstances()[0].Value;

                // Get methods collection
                foreach (KeyValuePair <string, IMethod> method in entity.GetMethods())
                {
                    // Get current method's instance
                    IMethodInstance methodInstance = method.Value.GetMethodInstances()[method.Key];
                    // Execute specific finder method
                    if (methodInstance.MethodInstanceType == MethodInstanceType.SpecificFinder && methodInstance.Name == finderMethodName)
                    {
                        Identity id = null;

                        if (EntityInstanceIdEncoder.IsEncodedIdentifier(entityId))
                        {
                            object[] oIDList = EntityInstanceIdEncoder.DecodeEntityInstanceId(entityId);
                            id = new Identity(oIDList[0]);

                            // Execute specific finder method and get the entity instance
                            entInstance = entity.FindSpecific(id, methodInstance.Name, entity.GetLobSystem().GetLobSystemInstances()[0].Value);
                            item[dataField.RelatedField] = entityId.ToString();
                        }
                        else
                        {
                            object oID = GetTypedIDValue(entityId, entity);
                            id = new Identity(oID);
                            string encodedIdentifier = EntityInstanceIdEncoder.EncodeEntityInstanceId(new object[] { oID });
                            // Execute specific finder method and get the entity instance
                            entInstance = entity.FindSpecific(id, methodInstance.Name, entity.GetLobSystem().GetLobSystemInstances()[0].Value);
                            item[dataField.RelatedField] = encodedIdentifier;
                        }
                    }
                }
            }
            catch (ObjectNotFoundException notFoundException)
            {
                LogError("GetEntityInstance errored with message " + notFoundException.Message + ". Adding item to Guidewire.");
                Console.WriteLine("GetEntityInstance errored with message " + notFoundException.Message + ". Adding item to Guidewire.");
                bool   addDocumentToGuidewire = CallGuidewire(item, GuidewireOperationType.New);
                string outMessage             = "";
                if (addDocumentToGuidewire)
                {
                    outMessage = string.Format("Item with ID {0} added to Guidewire", item.ID);
                }
                else
                {
                    outMessage = string.Format("Item with ID {0} could not be added to Guidewire", item.ID);
                    if (Settings.Default.DeleteFailures)
                    {
                        try
                        {
                            // Recycle the item if it can't be added to guidewire and it's older than 30 days
                            if (DateTime.Now.AddDays(-30) > (DateTime)item[SPBuiltInFieldId.Modified])
                            {
                                item.Recycle();
                            }
                        }
                        catch
                        {
                            // Swallow this error. The item doesn't exist in Guidewire and can't be deleted in SharePoint. It has problems
                        }
                    }
                    LogError(outMessage);
                }
                Console.WriteLine(outMessage);
            }
            catch (Exception ex)
            {
                // Swallow this error
                LogError("GetEntityInstance errored with message " + ex.Message);
                Console.WriteLine("GetEntityInstance errored with message " + ex.Message);
            }
            return(entInstance);
        }
Пример #4
0
 public string GetEntityInstanceId()
 {
     return(EntityInstanceIdEncoder.EncodeEntityInstanceId(this.IdentifierValues));
 }