Beispiel #1
0
 public void StopReceiving()
 {
     _botclient.StopReceiving();
     _synchronizationContext.OperationCompleted();
 }
        /// <summary>
        /// Updates the destination fields.
        /// </summary>
        /// <param name="storedFields">The stored fields.</param>
        /// <param name="destinationFields">The destination fields.</param>
        /// <param name="syncContext">The synchronize context.</param>
        private static void UpdateDestinationFields(IList<IExpressionField> storedFields, IEnumerable<IExpressionField> destinationFields, SynchronizationContext syncContext)
        {
            var newDestinationFields = destinationFields.ToArray();

            foreach (var field in newDestinationFields)
            {
                var exField =
                    (from f in storedFields where ((DestinationField)f).SystemName == ((DestinationField)field).SystemName select f).FirstOrDefault();
                if (exField == null)
                {
                    storedFields.Add(field);
                }
                else
                {
                    //ensure that old script is updated
                    var exf = (DestinationField)exField;
                    var df = (DestinationField)field;
                    exf.SetName = df.SetName;
                    exf.Name = df.Name;
                    exf.InnerName = df.InnerName;
                    exf.SystemName = df.SystemName;
                    exf.DataType = df.DataType;
                    exf.SubfieldsRetriever = df.SubfieldsRetriever;
                    exf.IsKeyVisible = df.IsKeyVisible;
                    exf.IsKeyEnabled = df.IsKeyEnabled;
                    exf.IsKey = exf.IsKey && df.IsKeyEnabled;
                    exf.IsRequired = df.IsRequired;

                    exf.ConnectorIn.Name = df.ConnectorIn.Name;
                    exf.ConnectorIn.DataType = df.ConnectorIn.DataType;
                    exf.ConnectorIn.Validator = df.ConnectorIn.Validator != null ? df.ConnectorIn.Validator.Clone(exf.ConnectorIn) : null;
                    exf.ConnectorIn.IsNullable = df.ConnectorIn.IsNullable;

                    if (exField.Subfields.Count > 0 && field.SubfieldsRetriever != null)
                    {
                        syncContext.OperationStarted();
                        field.SubfieldsRetriever.BeginLoad(
                            exField,
                            (f, l) =>
                                {
                                    UpdateDestinationFields(exField.Subfields, l, syncContext);
                                    syncContext.OperationCompleted();
                                });
                    }
                    else
                    {
                        UpdateDestinationFields(exField.Subfields, field.Subfields, syncContext);
                    }
                }
            }

            for (var i = storedFields.Count - 1; i >= 0; --i)
            {
                var newField =
                    (from f in newDestinationFields where ((DestinationField)f).SystemName == ((DestinationField)storedFields[i]).SystemName select f)
                        .FirstOrDefault();

                if (newField == null)
                {
                    storedFields.RemoveAt(i);
                }
            }
        }