Esempio n. 1
0
        public static T CallMethod <T>(string service, string method, params object[] parameters)
        {
            var methodInputs = new MethodInput
            {
                MethodName  = method,
                ServiceName = service,
                Parameters  = parameters,
                Token       = ServiceConfigs.Token
            };

            var result      = CallService(methodInputs);
            var resultModel = JsonConvert.DeserializeObject <MethodOutput>(result);

            if (string.IsNullOrEmpty(resultModel.Error))
            {
                if (resultModel.Result == null)
                {
                    return(default(T));
                }
                if (resultModel.Result.GetType() == typeof(JObject))
                {
                    return((T)((JObject)resultModel.Result).ToObject(typeof(T)));
                }
                if (resultModel.Result.GetType() == typeof(JArray))
                {
                    return((T)((JArray)resultModel.Result).ToObject(typeof(T)));
                }

                var outParamType = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T);
                return((T)Convert.ChangeType(resultModel.Result, outParamType));
            }
            throw new Exception(resultModel.Error);
        }
Esempio n. 2
0
        public MethodOutput Post([FromBody] MethodInput value)
        {
            try
            {
                var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(ServiceConfigs.Username + ":" + ServiceConfigs.Password));
                var parameters  = JsonConvert.SerializeObject(value);

                using (var wc = new WebClient())
                {
                    wc.Encoding = Encoding.UTF8;
                    wc.Headers["ApiVersion"] = "1.0";
                    wc.Headers[HttpRequestHeader.ContentType]   = "application/JSON";
                    wc.Headers[HttpRequestHeader.CacheControl]  = "no-cache";
                    wc.Headers[HttpRequestHeader.Authorization] = $"Basic {credentials}";
                    var jsonResult = wc.UploadString(ServiceConfigs.ServiceUrl, "POST", parameters);
                    return(JsonConvert.DeserializeObject <MethodOutput>(jsonResult));
                }
            }
            catch (Exception e)
            {
                return(new MethodOutput
                {
                    Error = $"External service error: {e.Message}"
                });
            }
        }
Esempio n. 3
0
 public MutationResultMethodTestResult(MethodInput input, object originalResult, object mutatedResult, Exception originalException, Exception mutatedException)
 {
     MethodInput       = input;
     OriginalResult    = originalResult;
     MutatedResult     = mutatedResult;
     OriginalException = originalException;
     MutatedException  = mutatedException;
 }
Esempio n. 4
0
 public MethodResult ExecuteMethod(MethodInput input)
 {
     if (input.Name == QueryAction.Create.ToString())
     {
         return(executeCreate(input.Input));
     }
     throw new NotImplementedException();
 }
        public void TestCreateEvent_ViaConnector()
        {
            var         evtObjec = JsonDataFileHelper.GetObjectFromDisk <Core.ConnectorApi.DataEntity>("Event_OperationInput_.json");
            MethodInput input    = new MethodInput();

            input.Name         = "Create";
            input.IsTestMethod = false;
            input.Input        = evtObjec;
            Connector.ExecuteMethod((MethodInput)input);
        }
        /// <summary>
        /// This method creates an object used to
        /// track changes for future replications.
        /// In this case, a delete trigger is added to a specified table.
        /// Note: If the data-source already has a process for tracking changes, this
        ///       method will only need to return a positive success in the method result
        /// </summary>
        /// <param name="methodInput">Method input used for the replication object.
        /// This is the name of the table that we need to extract.
        /// methodInput.Input.properties["ObjectName"]
        /// </param>
        /// <returns></returns>
        public MethodResult InitReplicationObject(MethodInput methodInput)
        {
            MethodResult methodResult = null;

            // Use LogMethodExecution to add entry and exit tracing to a method.
            // When wrapped in a using statement, the exit point
            // is written during garbage collection.
            using (new LogMethodExecution(
                       Globals.ConnectorName, "InitReplication"))
            {
                //First ensure the change history table exists
                MethodResult initReplicationResult = InitReplication();

                //If the replication table already exist then
                //our work here is done and no other action is required
                if (initReplicationResult.Success)
                {
                    string tableName =
                        GetPropertyValueName("EntityName", methodInput.Input.Properties);
                    string triggerName =
                        string.Format("{0}_Deleted_TRG", tableName);

                    if (CheckForTrigger(triggerName, tableName) == false)
                    {
                        //Use the ConnectorApi provided local data storage to retrieve
                        //and read the sql scripts contents
                        LocalDataStorage localDataStorage    = new LocalDataStorage();
                        string           deleteTriggerString =
                            localDataStorage.ReadData(TriggerFileName);

                        if (string.IsNullOrWhiteSpace(deleteTriggerString))
                        {
                            throw new InvalidExecuteOperationException(string.Format("Unable to locate file: {0}", TriggerFileName));
                        }

                        string query = string.Format(deleteTriggerString, tableName);
                        //Execute the query to create the change history table.
                        _dataAccess.ExecuteNonQuery(query);
                    }

                    //If there were no errors in processing then
                    //just set the Success for the method result to true.
                    methodResult = new MethodResult {
                        Success = true
                    };
                }
                else
                {
                    methodResult = SetErrorMethodResult(ErrorCodes.InitReplication.Number,
                                                        ErrorCodes.InitReplication.Description);
                }
            }

            return(methodResult);
        }
Esempio n. 7
0
        public void InitReplicationValidTest()
        {
            //create a new method input
            MethodInput methodInput = new MethodInput {
                Name = "InitReplication"
            };
            //execute the selected method
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            //check that the result is a success
            Assert.IsTrue(methodResult.Success);
        }
Esempio n. 8
0
 public void GetChangeHistoryDataInValidDateTest()
 {
     //create a new method input
     MethodInput methodInput = new MethodInput { Name = "GetChangeHistoryData" };
     //set the method input properties
     methodInput.Input.Properties.Add("ObjectName", "Addresses");
     //note: the invalid date
     methodInput.Input.Properties.Add("LastSyncDate", InvalidPropertyValue);
     //execute the selected method
     MethodResult result = _rsSourceConnector.ExecuteMethod(methodInput);
     Assert.IsFalse(result.Success);
     Assert.IsNotNull(result.ErrorInfo);
 }
Esempio n. 9
0
        public void InitReplicationObjectValidTest()
        {
            //create a new method input
            MethodInput methodInput = new MethodInput {
                Name = "InitReplicationObject"
            };

            methodInput.Input.Properties.Add("EntityName", "Addresses");
            //execute the selected method
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            //check that the result is a success
            Assert.IsTrue(methodResult.Success);
        }
Esempio n. 10
0
        public void GetObjectDefinitionListValidTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput {
                Name = "GetObjectDefinitionList"
            };

            //execute the selected method and set the method result
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            //since we are requesting a list of Table definitions we want to ensure that everything
            //went as planned by check that the properties have been returned
            Assert.AreNotSame(methodResult.Return.Properties.Count, 0);
        }
Esempio n. 11
0
        public void InitReplicationObjectInValidObjectNameTest()
        {
            //create a new method input
            MethodInput methodInput = new MethodInput {
                Name = "InitReplicationObject"
            };

            //note the invalid entity name
            methodInput.Input.Properties.Add("EntityName", InvalidPropertyValue);
            //execute the selected method
            MethodResult result = _rsSourceConnector.ExecuteMethod(methodInput);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.ErrorInfo);
        }
Esempio n. 12
0
        public void GetChangeHistoryDataInValidObjectNamePropertyTest()
        {
            //create a new method input
            MethodInput methodInput = new MethodInput {
                Name = "GetChangeHistoryData"
            };

            //set the method input properties
            //note: the object name property is missing
            methodInput.Input.Properties.Add("LastSyncDate", DateTime.Now.AddDays(-1));
            //execute the selected method
            MethodResult result = _rsSourceConnector.ExecuteMethod(methodInput);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.ErrorInfo);
        }
Esempio n. 13
0
        public void GetChangeHistoryDataValidTest()
        {
            //create a new method input
            MethodInput methodInput = new MethodInput {
                Name = "GetChangeHistoryData"
            };

            //set the method input properties
            methodInput.Input.Properties.Add("ObjectName", "Addresses");
            methodInput.Input.Properties.Add("LastSyncDate", DateTime.Now.AddDays(-10));
            //execute the selected method
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            //verify the method was a success
            Assert.IsTrue(methodResult.Success);
        }
Esempio n. 14
0
        private static string CallService(MethodInput inputs)
        {
            var myParameters = JsonConvert.SerializeObject(inputs);
            var credentials  = Convert.ToBase64String(Encoding.ASCII.GetBytes(ServiceConfigs.Username + ":" + ServiceConfigs.Password));

            using (var wc = new WebClient())
            {
                wc.Encoding = Encoding.UTF8;
                wc.Headers["ApiVersion"] = "1.0";
                wc.Headers[HttpRequestHeader.ContentType]   = "application/json";
                wc.Headers[HttpRequestHeader.CacheControl]  = "no-cache";
                wc.Headers[HttpRequestHeader.Authorization] = $"Basic {credentials}";
                ServicePointManager.SecurityProtocol        = SecurityProtocolType.Tls12;
                return(wc.UploadString(ServiceConfigs.ServiceUri, myParameters));
            }
        }
Esempio n. 15
0
        public void GetObjectDefinitionInValidPropertyNameTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput {
                Name = "GetObjectDefinition"
            };

            //Note: the 'ObjectName' property has not been set

            //execute the selected method
            MethodResult result = _rsSourceConnector.ExecuteMethod(methodInput);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.ErrorInfo);
        }
Esempio n. 16
0
        /// <summary>
        /// This method defines the process for tracking changes to data.
        /// This particular example shows one way how this operation may work.
        /// Note: A seperate method will create triggers for each table that will fill this table with deletions.
        /// Note: If the data-source already has a process for tracking changes, this
        ///       method will only need to return a positive success in the method result
        /// </summary>
        /// <returns></returns>
        public MethodResult InitReplication()
        {
            MethodResult methodResult = null;

            // Use LogMethodExecution to add entry and exit tracing to a method.
            // When wrapped in a using statement, the exit point
            // is written during garbage collection.
            using (new LogMethodExecution(
                       Globals.ConnectorName, "InitReplication"))
            {
                //First retrieve the object definition of the
                //default table that is used for replication.
                MethodInput objectDefinitionInput = new MethodInput();
                objectDefinitionInput.Input.Properties.Add(
                    "ObjectName", "ScribeChangeHistory");
                MethodResult objectDefinitionResult =
                    GetObjectDefinition(objectDefinitionInput);

                //If the replication table already exist then our work
                //here is done. No other action is required.
                if (objectDefinitionResult.Success == false)
                {
                    //Use the Sribe-provided local data storage
                    //to retrieve and read the sql scripts contents.
                    LocalDataStorage localDataStorage = new LocalDataStorage();
                    string           query            =
                        localDataStorage.ReadData(ChangeHistoryFileName);

                    //Throw an error message if the file was not found
                    if (string.IsNullOrWhiteSpace(query))
                    {
                        throw new InvalidExecuteOperationException(string.Format("Unable to locate file: {0}", ChangeHistoryFileName));
                    }

                    //Execute the query to create the change history table.
                    _dataAccess.ExecuteNonQuery(query);
                }

                //If there were no errors in processing, then
                //set the Success for the method result to true.
                methodResult = new MethodResult {
                    Success = true
                };
            }

            return(methodResult);
        }
Esempio n. 17
0
        private static void TestSubtractMethod()
        {
            MethodInfo originalSubtractMethodInfo = typeof(MathClass).GetTypeInfo().GetMethod(nameof(MathClass.Subtract));

            MethodInput[] inputs = new MethodInput[]
            {
                new MethodInput(null, 0m, 0m),
                new MethodInput(null, 0m, 1m),
                new MethodInput(null, 1m, 0m),
                new MethodInput(null, 1m, 1m),
                new MethodInput(null, 2m, 0m),
                new MethodInput(null, 2m, 1m),
                new MethodInput(null, 2m, 2m),
                new MethodInput(null, 2m, 3m)
            };
            TestAnyMethod(originalSubtractMethodInfo, inputs, Mutate(FilePath, Mutatations.Subract, Mutatations.Add));
        }
Esempio n. 18
0
        public void GetChangeHistoryDataInValidDateTest()
        {
            //create a new method input
            MethodInput methodInput = new MethodInput {
                Name = "GetChangeHistoryData"
            };

            //set the method input properties
            methodInput.Input.Properties.Add("ObjectName", "Addresses");
            //note: the invalid date
            methodInput.Input.Properties.Add("LastSyncDate", InvalidPropertyValue);
            //execute the selected method
            MethodResult result = _rsSourceConnector.ExecuteMethod(methodInput);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.ErrorInfo);
        }
Esempio n. 19
0
 void ComposerWindow_Loaded(StartFocus focus)
 {
     if (focus == StartFocus.Method)
     {
         MethodInput.Focus();
     }
     else
     {
         if (TextEditorInput.Visibility == System.Windows.Visibility.Visible)
         {
             TextEditorInput.SetFocus();
         }
         else if (TextWithFilesEditorInput.Visibility == System.Windows.Visibility.Visible)
         {
             TextWithFilesEditorInput.SetFocus();
         }
     }
 }
Esempio n. 20
0
        public static void CallMethod(string service, string method, params object[] parameters)
        {
            var methodInputs = new MethodInput
            {
                MethodName  = method,
                ServiceName = service,
                Parameters  = parameters,
                Token       = ServiceConfigs.Token
            };

            var result      = CallService(methodInputs);
            var resultModel = JsonConvert.DeserializeObject <MethodOutput>(result);

            if (!string.IsNullOrEmpty(resultModel.Error))
            {
                throw new Exception(resultModel.Error);
            }
        }
Esempio n. 21
0
        public void GetLastReplicationSyncDateInvalidModifiedColumnTest()
        {
            //create hte method input and set the name of the method to execute
            MethodInput methodInput = new MethodInput {
                Name = "GetLastReplicationSyncDate"
            };

            //set the name of the table to to check by adding it to the input properties
            methodInput.Input.Properties.Add("ObjectName", "Addresses");
            //set the name of the column that the Modification Date is stored in
            //note: the invalid property name
            methodInput.Input.Properties.Add(InvalidPropertyValue, "ModifiedOn");
            //execute the method
            MethodResult result = _rsTargetConnector.ExecuteMethod(methodInput);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.ErrorInfo);
        }
Esempio n. 22
0
        public void GetChangeHistoryDataInValidObjectTest()
        {
            //create a new method input
            MethodInput methodInput = new MethodInput {
                Name = "GetChangeHistoryData"
            };

            //set the method input properties
            //note: the invalid object name
            methodInput.Input.Properties.Add("ObjectName", InvalidPropertyValue);
            methodInput.Input.Properties.Add("LastSyncDate", DateTime.Now.AddDays(-1));
            //execute the selected method
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            //verify the method was a success
            Assert.IsTrue(methodResult.Success);
            //verify that data was not returned
            Assert.IsNotNull(methodResult.Return);
        }
Esempio n. 23
0
        public void GetReplicationDataValidTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput {
                Name = "GetReplicationData"
            };

            //set the object name by adding the property to the input
            methodInput.Input.Properties.Add("ObjectName", "SalesOrders");

            //set the Last date of syncronization by adding the property to the input
            methodInput.Input.Properties.Add("LastSyncDate", DateTime.Now.AddYears(-5));

            //execute the selected method and set the method result
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            Assert.IsTrue(methodResult.Success);
        }
Esempio n. 24
0
        public void GetLastReplicationSyncDateValidTest()
        {
            //create hte method input and set the name of the method to execute
            MethodInput methodInput = new MethodInput {
                Name = "GetLastReplicationSyncDate"
            };

            //set the name of the table to to check by adding it to the input properties
            methodInput.Input.Properties.Add("ObjectName", "Addresses");
            //set the name of the column that the Modification Date is stored in
            methodInput.Input.Properties.Add("ModificationDateFullName", "ModifiedOn");
            //execute the method
            MethodResult result = _rsTargetConnector.ExecuteMethod(methodInput);

            //verify a success
            Assert.IsTrue(result.Success);
            //verify the method yielded a result
            Assert.IsNotNull(result.Return);
        }
Esempio n. 25
0
        public void GetObjectDefinitionInValidObjectNameTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput {
                Name = "GetObjectDefinition"
            };

            //Add an input property for the 'ObjectName' that is being requested
            methodInput.Input.Properties.Add("ObjectName", InvalidPropertyValue);

            //execute the selected method and set the method result
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            //since this is not an error that throws an exception success will be
            //false and the error information will be propery filled out
            Assert.IsFalse(methodResult.Success);
            Assert.IsNotNull(methodResult.ErrorInfo.Number);
        }
Esempio n. 26
0
        public void GetReplicationDataMissingObjectNamePropertyTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput {
                Name = "GetReplicationData"
            };

            //note: the object name input property has not been set

            //set the Last date of syncronization by adding the property to the input
            methodInput.Input.Properties.Add("LastSyncDate", DateTime.Now.AddYears(-5));


            //execute the selected method and set the method result
            MethodResult result = _rsSourceConnector.ExecuteMethod(methodInput);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.ErrorInfo);
        }
Esempio n. 27
0
        public void GetLastReplicationSyncDateInvalidTableTest()
        {
            //create the method input and set the name of the method to execute
            MethodInput methodInput = new MethodInput {
                Name = "GetLastReplicationSyncDate"
            };

            //set the name of the table to to check by adding it to the input properties
            //note: the invalid table name
            methodInput.Input.Properties.Add("ObjectName", InvalidPropertyValue);
            //set the name of the column that the Modification Date is stored in
            methodInput.Input.Properties.Add("ModificationDateFullName", "ModifiedOn");
            //execute the method
            MethodResult result = _rsTargetConnector.ExecuteMethod(methodInput);

            //verify not a success
            Assert.IsFalse(result.Success);
            //verify that the error info is filled out
            Assert.IsNotNull(result.ErrorInfo);
        }
Esempio n. 28
0
        public void GetReplicationDataDateOutOfRangeInvalidTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput {
                Name = "GetReplicationData"
            };

            //set the object name by adding the property to the input
            methodInput.Input.Properties.Add("ObjectName", "SalesOrders");

            //set the Last date of syncronization by adding the property to the input
            methodInput.Input.Properties.Add("LastSyncDate", DateTime.MinValue);

            //execute the selected method
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            //check that the result is not a success
            Assert.IsFalse(methodResult.Success);
        }
Esempio n. 29
0
        public void GetReplicationDataMissingDatePropertyTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput {
                Name = "GetReplicationData"
            };

            //set the object name by adding the property to the input
            methodInput.Input.Properties.Add("ObjectName", "SalesOrders");

            //note: the LastSyncDate input property is not set


            //execute the selected method and set the method result
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            //when the last sync date is missing the result should still be a success
            Assert.IsTrue(methodResult.Success);
        }
Esempio n. 30
0
    public bool CheckInput(PlayerInput player, ControllerInput input, MethodInput method)
    {
        bool result = false;

        switch (method)
        {
        case MethodInput.Down:
            result = Input.GetButtonDown(input.ToString() + "_" + player);
            break;

        case MethodInput.Up:
            result = Input.GetButtonUp(input.ToString() + "_" + player);
            break;

        case MethodInput.Hold:
            result = Input.GetButton(input.ToString() + "_" + player);
            break;
        }

        return(result);
    }
Esempio n. 31
0
        public void GetReplicationDataInvalidDateTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput {
                Name = "GetReplicationData"
            };

            //set the object name by adding the property to the input
            methodInput.Input.Properties.Add("ObjectName", "SalesOrders");

            //set the Last date of syncronization by adding the property to the input
            methodInput.Input.Properties.Add("LastSyncDate", InvalidPropertyValue);


            //execute the selected method
            MethodResult result = _rsSourceConnector.ExecuteMethod(methodInput);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.ErrorInfo);
        }
Esempio n. 32
0
        public void CreateOrUpdateObjectForReplicationColumnAddedTest()
        {
            MethodInput methodInput = new MethodInput { Name = "CreateOrUpdateObjectForReplication" };

            DataEntity tableEntity = new DataEntity { ObjectDefinitionFullName = "Parameters" };

            EntityProperties properties = new EntityProperties { { "Name", "Products" } };

            EntityChildren columns = new EntityChildren();

            List<DataEntity> columnList = new List<DataEntity>();

            DataEntity column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "RecordId");
            column.Properties.Add("DataType", typeof(Guid));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "ProductNumber");
            column.Properties.Add("DataType", typeof(string));
            column.Properties.Add("InPrimaryKey", true);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "ProductName");
            column.Properties.Add("DataType", typeof(string));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            //this is the new column
            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "NewPrice");
            column.Properties.Add("DataType", typeof(decimal));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "Type");
            column.Properties.Add("DataType", typeof(string));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "Type");
            column.Properties.Add("DataType", typeof(string));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "UoMSchedule");
            column.Properties.Add("DataType", typeof(string));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "Cost");
            column.Properties.Add("DataType", typeof(decimal));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "StandardCost");
            column.Properties.Add("DataType", typeof(decimal));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "QuantityInStock");
            column.Properties.Add("DataType", typeof(Int32));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "QuantityOnOrder");
            column.Properties.Add("DataType", typeof(Int32));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "Discontinued");
            column.Properties.Add("DataType", typeof(Int16));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "CreatedOn");
            column.Properties.Add("DataType", typeof(DateTime));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "CreatedBy");
            column.Properties.Add("DataType", typeof(string));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "ModifiedOn");
            column.Properties.Add("DataType", typeof(DateTime));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            column = new DataEntity("DataPropertyDefinition");
            column.Properties.Add("Name", "ModifiedBy");
            column.Properties.Add("DataType", typeof(string));
            column.Properties.Add("InPrimaryKey", false);
            columnList.Add(column);

            columns.Add("RSPropertyDefinitions", columnList);

            tableEntity.Children = columns;
            tableEntity.Properties = properties;

            methodInput.Input = tableEntity;

            MethodResult result = _rsTargetConnector.ExecuteMethod(methodInput);

            Assert.IsTrue(result.Success);
        }
Esempio n. 33
0
 public void InitReplicationValidTest()
 {
     //create a new method input
     MethodInput methodInput = new MethodInput { Name = "InitReplication" };
     //execute the selected method
     MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);
     //check that the result is a success
     Assert.IsTrue(methodResult.Success);
 }
Esempio n. 34
0
        public void InitReplicationObjectValidTest()
        {
            //create a new method input
            MethodInput methodInput = new MethodInput { Name = "InitReplicationObject" };

            methodInput.Input.Properties.Add("EntityName","Addresses");
            //execute the selected method
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);
            //check that the result is a success
            Assert.IsTrue(methodResult.Success);
        }
Esempio n. 35
0
 public void InitReplicationObjectInValidObjectNameTest()
 {
     //create a new method input
     MethodInput methodInput = new MethodInput { Name = "InitReplicationObject" };
     //note the invalid entity name
     methodInput.Input.Properties.Add("EntityName", InvalidPropertyValue);
     //execute the selected method
     MethodResult result =  _rsSourceConnector.ExecuteMethod(methodInput);
     Assert.IsFalse(result.Success);
     Assert.IsNotNull(result.ErrorInfo);
 }
Esempio n. 36
0
        public void GetReplicationDataValidTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput { Name = "GetReplicationData" };

            //set the object name by adding the property to the input
            methodInput.Input.Properties.Add("ObjectName", "SalesOrders");

            //set the Last date of syncronization by adding the property to the input
            methodInput.Input.Properties.Add("LastSyncDate", DateTime.Now.AddYears(-5));

            //execute the selected method and set the method result
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            Assert.IsTrue(methodResult.Success);
        }
Esempio n. 37
0
        /// <summary>
        /// Get a specific Object's definition, this includes any attributes and
        /// supporting object properties.
        /// In this case retrieve the table definition along with any columns and
        /// the definition of each.
        /// </summary>
        /// <param name="methodInput">Method Input which includes an 'ObjectName' 
        /// property to determine the object to retrieve the definition.</param>
        /// <returns>Method Result, which will either include error information or the 
        /// Object Definition of the 'ObjectName' specified in the 
        /// MethodInput properties.</returns>
        public MethodResult GetObjectDefinition(MethodInput methodInput)
        {
            //Create a new instance of the method result to fill with
            //meta data information
            MethodResult result = null;

            //Create a new instance of the metadata access class and pass the
            //data access instance along with it
            OleDbMetadataAccess metadataAccess = new OleDbMetadataAccess(_dataAccess);

            // Use LogMethodExecution to add entry and exit tracing to a method.
            // When wrapped in a using statement, the exit point
            // is written during garbage collection.
            using (new LogMethodExecution(
                Globals.ConnectorName, "GetObjectDefinition"))
            {
                //Get the name of the object in the input properties.
                string objectName =
                    GetPropertyValueName("ObjectName", methodInput.Input.Properties);

                //Use the metadata access to get the
                //definitions for each of the columns in the table.
                DataTable tableColumnDefinitions =
                    metadataAccess.GetColumnDefinitions(objectName);

                //Using the meta data access get the definition for the
                //table indexes (primary and foreign keys)
                DataTable tableIndexDefinition =
                    metadataAccess.GetTableIndexInformation(objectName);

                //Check that both sets of data have been returned
                //from the meta data access layer
                if ((tableColumnDefinitions != null
                    && tableColumnDefinitions.Rows.Count != 0) &&
                    (tableIndexDefinition != null
                    && tableIndexDefinition.Rows.Count != 0))
                {
                    //Create a new replication service object
                    RSObjectDefinition rsObjectDefinition = new RSObjectDefinition()
                    {
                        Name = objectName,
                        RSPropertyDefinitions = new List<RSPropertyDefinition>()
                    };

                    //If this is the change history table set the hidden attribute.
                    //Note: this is how to prevent an object from being replicated.
                    rsObjectDefinition.Hidden = objectName == Globals.ChangeHistoryTableName;

                    List<string> tablePrimaryKeys =
                        GetTablePrimaryKeys(rsObjectDefinition.Name, metadataAccess);

                    //Parse each column returned from the column definitions.
                    //For each column, add a new replication service property definition
                    //to the newly created replication service object definition.
                    foreach (DataRow columnDefinition in tableColumnDefinitions.Rows)
                    {
                        //Process the column definition and set it to the
                        //resplication service property definition.
                        RSPropertyDefinition rsPropertyDefinition =
                            ProcessColumnDefinition(columnDefinition);

                        //Check if this is the default last modified column and
                        //set the object property.
                        if (rsPropertyDefinition.Name == LastModifiedFieldName)
                        {
                            rsObjectDefinition.ModificationDateFullName =
                                rsPropertyDefinition.Name;
                        }

                        //Check if the property is a primary key value.
                        rsPropertyDefinition.InPrimaryKey =
                            tablePrimaryKeys.Contains(rsPropertyDefinition.Name);

                        //Add the property definition to the object definition.
                        rsObjectDefinition.RSPropertyDefinitions.Add(rsPropertyDefinition);
                    }

                    //Convert the replication service object definition to a Data Entity.
                    //Set the result return value to the
                    //replication service object definition.
                    //Set the result Success to true.
                    result = new MethodResult
                    { Success = true, Return = rsObjectDefinition.ToDataEntity() };
                }
                else
                {
                    //Set the proper error information in the method result in the
                    //event of a null table or column definitions.
                    result = SetErrorMethodResult(
                        ErrorCodes.NoObjectsFound.Number,
                        ErrorCodes.NoObjectsFound.Description);
                }

            }

            //Return the method result.
            return result;
        }
Esempio n. 38
0
        /// <summary>
        /// Retrieve all IDs for entities that have changed since last syncronization.
        /// </summary>
        /// <param name="methodInput"></param>
        /// <returns></returns>
        public MethodResult GetChangeHistoryData(MethodInput methodInput)
        {
            MethodResult result = null;

            using (new LogMethodExecution(Globals.ConnectorName, "GetChangeHistory"))
            {
                //Check for the last sync date property
                if (methodInput.Input.Properties.ContainsKey("LastSyncDate") == false)
                {
                    throw new ArgumentNullException("LastSyncDate", InputPropertyNotFound);
                }

                //Retrieve the last date of syncronization from the method input.
                DateTime lastSyncDate = GetLastSyncDate(methodInput.Input.Properties);

                //Retrieve the name of the table from the method input.
                string tableName = GetPropertyValueName(
                    "ObjectName", methodInput.Input.Properties);

                string query = string.Format(
                "SELECT Id FROM ScribeChangeHistory WHERE ModifiedOn > convert(datetime,'{0}') AND TableName ='{1}'",
                lastSyncDate.ToString("s"), tableName);

                //Execute the query.
                DataTable records = _dataAccess.Execute(query);

                result = new MethodResult();

                if (records != null && records.Rows.Count > 0)
                {
                    List<DataEntity> entityList = new List<DataEntity>();

                    //Parse each row and add the records to the entity properties.
                    foreach (DataRow row in records.Rows)
                    {
                        //Create a new entity for each ID returned.
                        DataEntity entity = new DataEntity {ObjectDefinitionFullName = tableName};
                        //This the key name MUST be 'ChangeHistoryId'.
                        //The value MUST be the primary key value of the row that has been deleted
                        entity.Properties.Add("ChangeHistoryId", row["Id"]);
                        //Add the entity to the list.
                        entityList.Add(entity);
                    }

                    //Set the result return the the created data entity.
                    result.Return = new DataEntity("ChangeHistoryData");
                    result.Return.Properties.Add("EntityData", entityList);
                }
                else
                {
                    //Even if no data is being returned
                    //make sure that the return has a value.
                    result.Return = new DataEntity();
                    result.Return.Properties.Add("EntityData", null);
                }

                result.Success = true;
            }

            return result;
        }
Esempio n. 39
0
        /// <summary>
        /// This method will execute a Method returning a result. 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public MethodResult ExecuteMethod(MethodInput input)
        {
            MethodResult methodResult;

            // Use LogMethodExecution to add entry and exit tracing to a method.
            // When wrapped in a using statement, the exit point is written during garbage collection.
            using (new LogMethodExecution(Globals.ConnectorName, "Execute Method"))
            {
                //Construct a new instance of the method handler
                //passing along the current instance of the data access object
                MethodHandler methodHandler = new MethodHandler(_dataAccess);

                try
                {
                    //Use the name stored in the method
                    //input to determine the correct method to execute
                    switch (input.Name.ToLower())
                    {
                        case "getobjectdefinition":
                            methodResult = methodHandler.GetObjectDefinition(input);
                            break;
                        case "createorupdateobjectforreplication":
                            methodResult = methodHandler.CreateOrUpdateObjectForReplication(input);
                            break;
                        case "getlastreplicationsyncdate":
                            methodResult = methodHandler.GetLastReplicationSyncDate(input);
                            break;
                        default:
                            string message = string.Format(ErrorCodes.UnknownMethod.Description, input.Name);
                            throw new InvalidExecuteMethodException(ErrorCodes.UnknownMethod.Number, message);
                    }

                    LogMethodResult(methodResult);
                }
                //Here we throw the Fatal Error Exception which is used to notify upper layers that
                //an error has occured in the Connector and will be unable to recover from it
                catch (FatalErrorException)
                {
                    throw;
                }
                catch (Exception exception)
                {
                    //Log any other exceptions that occur during method execution
                    //and store them in the MethodResult.ErrorInfo
                    methodResult = new MethodResult {Success = false};

                    //Create the error info using the exception message
                    methodResult.ErrorInfo = new ErrorResult
                    {
                        Description = exception.Message,
                        Detail = exception.StackTrace,
                        Number = ErrorCodes.MethodError.Number
                    };

                    LogMethodResult(methodResult);
                }

            }
            return methodResult;
        }
Esempio n. 40
0
        public void GetObjectDefinitionValidTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput { Name = "GetObjectDefinition" };

            //Add an input property for the 'ObjectName' that is being requested
            methodInput.Input.Properties.Add("ObjectName", "Addresses");

            //execute the selected method and set the method result
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            //since we are requesting a list of Table definitions we want to ensure that everything
            //went as planned by check that the properties have been returned
            Assert.AreNotSame(methodResult.Return.Properties.Count, 0);
        }
Esempio n. 41
0
        /// <summary>
        /// This method defines the process for tracking changes to data.
        /// This particular example shows one way how this operation may work. 
        /// Note: A seperate method will create triggers for each table that will fill this table with deletions.
        /// Note: If the data-source already has a process for tracking changes, this 
        ///       method will only need to return a positive success in the method result
        /// </summary>
        /// <returns></returns>
        public MethodResult InitReplication()
        {
            MethodResult methodResult = null;

            // Use LogMethodExecution to add entry and exit tracing to a method.
            // When wrapped in a using statement, the exit point
            // is written during garbage collection.
            using (new LogMethodExecution(
                Globals.ConnectorName, "InitReplication"))
            {
                //First retrieve the object definition of the
                //default table that is used for replication.
                MethodInput objectDefinitionInput = new MethodInput();
                objectDefinitionInput.Input.Properties.Add(
                    "ObjectName", "ScribeChangeHistory");
                MethodResult objectDefinitionResult =
                    GetObjectDefinition(objectDefinitionInput);

                //If the replication table already exist then our work
                //here is done. No other action is required.
                if (objectDefinitionResult.Success == false)
                {
                    //Use the Sribe-provided local data storage
                    //to retrieve and read the sql scripts contents.
                    LocalDataStorage localDataStorage = new LocalDataStorage();
                    string query =
                        localDataStorage.ReadData(ChangeHistoryFileName);

                    //Throw an error message if the file was not found
                    if (string.IsNullOrWhiteSpace(query))
                    {
                        throw new InvalidExecuteOperationException(string.Format("Unable to locate file: {0}", ChangeHistoryFileName));
                    }

                    //Execute the query to create the change history table.
                    _dataAccess.ExecuteNonQuery(query);
                }

                //If there were no errors in processing, then
                //set the Success for the method result to true.
                methodResult = new MethodResult { Success = true };
            }

            return methodResult;
        }
Esempio n. 42
0
        public void GetObjectDefinitionInValidPropertyNameTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput { Name = "GetObjectDefinition" };

            //Note: the 'ObjectName' property has not been set

            //execute the selected method
            MethodResult result = _rsSourceConnector.ExecuteMethod(methodInput);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.ErrorInfo);
        }
Esempio n. 43
0
        public void GetObjectDefinitionInValidObjectNameTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput { Name = "GetObjectDefinition" };

            //Add an input property for the 'ObjectName' that is being requested
            methodInput.Input.Properties.Add("ObjectName", InvalidPropertyValue);

            //execute the selected method and set the method result
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            //since this is not an error that throws an exception success will be
            //false and the error information will be propery filled out
            Assert.IsFalse(methodResult.Success);
            Assert.IsNotNull(methodResult.ErrorInfo.Number);
        }
Esempio n. 44
0
 public void GetChangeHistoryDataValidTest()
 {
     //create a new method input
     MethodInput methodInput = new MethodInput {Name = "GetChangeHistoryData"};
     //set the method input properties
     methodInput.Input.Properties.Add("ObjectName", "Addresses");
     methodInput.Input.Properties.Add("LastSyncDate", DateTime.Now.AddDays(-10));
     //execute the selected method
     MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);
     //verify the method was a success
     Assert.IsTrue(methodResult.Success);
 }
Esempio n. 45
0
 public void GetChangeHistoryDataInValidObjectNamePropertyTest()
 {
     //create a new method input
     MethodInput methodInput = new MethodInput { Name = "GetChangeHistoryData" };
     //set the method input properties
     //note: the object name property is missing
     methodInput.Input.Properties.Add("LastSyncDate", DateTime.Now.AddDays(-1));
     //execute the selected method
     MethodResult result = _rsSourceConnector.ExecuteMethod(methodInput);
     Assert.IsFalse(result.Success);
     Assert.IsNotNull(result.ErrorInfo);
 }
Esempio n. 46
0
        public void GetReplicationDataMissingDatePropertyTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput { Name = "GetReplicationData" };

            //set the object name by adding the property to the input
            methodInput.Input.Properties.Add("ObjectName", "SalesOrders");

            //note: the LastSyncDate input property is not set

            //execute the selected method and set the method result
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            //when the last sync date is missing the result should still be a success
            Assert.IsTrue(methodResult.Success);
        }
Esempio n. 47
0
 public MethodResult ExecuteMethod(MethodInput input)
 {
     if (input.Name == QueryAction.Create.ToString())
         return executeCreate(input.Input);
     throw new NotImplementedException();
 }
Esempio n. 48
0
        public void GetReplicationDataMissingObjectNamePropertyTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput { Name = "GetReplicationData" };

            //note: the object name input property has not been set

            //set the Last date of syncronization by adding the property to the input
            methodInput.Input.Properties.Add("LastSyncDate", DateTime.Now.AddYears(-5));

            //execute the selected method and set the method result
            MethodResult result = _rsSourceConnector.ExecuteMethod(methodInput);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.ErrorInfo);
        }
Esempio n. 49
0
        /// <summary>
        /// This is the method to get data for replication 
        /// for an individual object. Rows will be returned as they are read.
        /// </summary>
        /// <param name="methodInput"></param>
        /// <returns></returns>
        public MethodResult GetReplicationData(MethodInput methodInput)
        {
            MethodResult result = null;

            using (new LogMethodExecution(
                Globals.ConnectorName, "GetReplicationData"))
            {
                //Get the name of the object in the input properties.
                string objectName = GetPropertyValueName(
                    "ObjectName",methodInput.Input.Properties);

                //Get the last sychronization date from the input properties
                DateTime lastSyncDate = GetLastSyncDate(methodInput.Input.Properties);

                OleDbMetadataAccess metadataAccess = new OleDbMetadataAccess(_dataAccess);
                bool hasLastModified = CheckForLastModifiedColumnName(objectName, metadataAccess);

                try
                {
                    //Passes control of the lower level method in the data access layer
                    //to the calling method.This passes the IEnumerable object
                    //(filled with data rows) out to the calling methodin conjunction
                    //with the yield statement at the lower level, is looking for the
                    //foreach loop else control is passed out to the calling method.
                    //Here, the attempt to get an entity is performed (by calling the
                    //empty foreach loop) in order to check for errors - else the top
                    //level has control and exceptions get passed directly up.  Here we assume
                    //that no error on retrieving row 1 means we are safe to pass control
                    //back to the calling method and skip the error checking
                    //that is forced on the first entity.

                    IEnumerable<DataEntity> replicationData =
                        _dataAccess.GetReplicationDataRetrieve(
                        objectName, lastSyncDate, hasLastModified);

                    //Force a check for errors. The previous method call
                    //will not be performed until it is requested for use here.
                    foreach (var dataEntity in replicationData)
                    {
                        break;
                    }

                    //Create a new method result
                    result = new MethodResult();
                    //Indicate that the result is a success
                    result.Success = true;
                    //Set the result return to a new data entity
                    //which MUST be named "ReplicationQueryData"
                    result.Return = new DataEntity("ReplicationQueryData");

                    //Add the yielded replication data to the return properties in the result
                    //Note: the property name MUST be labeled as 'EntityData'
                    result.Return.Properties.Add("EntityData", replicationData);
                }
                catch (Exception exception)
                {
                    //Be sure to log any errors and add them to the
                    //error information for the method result
                    Logger.Write(
                        Logger.Severity.Error, Globals.ConnectorName, exception.Message);
                    result = SetErrorMethodResult(
                        ErrorCodes.GetData.Number, ErrorCodes.GetData.Description);
                }

            }
            //Return the method result containing the replication data
            return result;
        }
Esempio n. 50
0
        /// <summary>
        /// Get a specific Object's definition, this includes any attributes and supporting object properties.
        /// In this case retrieve the table definition along with any columns and the definition of each.
        /// </summary>
        /// <param name="methodInput">Method Input which includes an 'ObjectName' 
        /// property to determine the object to retrieve the definition for.</param>
        /// <returns>Method Result which will either include error information or the 
        /// Object Definition of the 'ObjectName' specified in the MethodInput properties</returns>
        public MethodResult GetObjectDefinition(MethodInput methodInput)
        {
            //Create a new instance of the method result to
            //fill with meta data information
            MethodResult result = new MethodResult();

            //create a new instance of the metadata access class and
            //pass the data access instance allong with it
            OleDbMetadataAccess metadataAccess = new OleDbMetadataAccess(_dataAccess);

            // Use LogMethodExecution to add entry and exit tracing to a method.
            // When wrapped in a using statement, the exit point
            //is written during garbage collection.
            using (new LogMethodExecution(
                Globals.ConnectorName, "GetObjectDefinitionMethod"))
            {
                //get the name of the object in the input properties
                string objectName = GetPropertyValue(
                    "ObjectName", methodInput.Input.Properties);

                //using the meta data access get the definitions
                //for each of the columns in the table
                DataTable tableColumnDefinitions =
                    metadataAccess.GetColumnDefinitions(objectName);

                //using the meta data access get the definition for
                //the table indexes (primary and foreign keys)
                DataTable tableIndexDefinition =
                    metadataAccess.GetTableIndexInformation(objectName);

                //check that both sets of data have been
                //returned from the meta data access layer
                if ((tableColumnDefinitions != null
                    && tableColumnDefinitions.Rows.Count != 0)
                    && (tableIndexDefinition != null
                    && tableIndexDefinition.Rows.Count != 0))
                {
                    //create a new replication service object
                    RSObjectDefinition rsObjectDefinition = new RSObjectDefinition()
                    {
                        Name = objectName,
                        RSPropertyDefinitions = new List<RSPropertyDefinition>()
                    };

                    List<string> tablePrimaryKeys =
                        GetTablePrimaryKeys(rsObjectDefinition.Name, metadataAccess);

                    //parse through each column return from the column definitions and
                    //add a new replication service property definition to the newly created
                    //replication service object definition for each column in the table
                    foreach (DataRow columnDefinition in tableColumnDefinitions.Rows)
                    {
                        //process the column definition and set it
                        //to the resplication service property definition
                        RSPropertyDefinition rsPropertyDefinition =
                            ProcessColumnDefinition(columnDefinition);

                        //check if this is the default last
                        //modified column and set the object property
                        if (rsPropertyDefinition.Name == LastModifiedFieldName)
                        {
                            rsObjectDefinition.ModificationDateFullName =
                                rsPropertyDefinition.Name;
                        }

                        //check if the property is a primary key value
                        rsPropertyDefinition.InPrimaryKey =
                            tablePrimaryKeys.Contains(rsPropertyDefinition.Name);

                        //add the property definition to the object definition
                        rsObjectDefinition.RSPropertyDefinitions.Add(rsPropertyDefinition);
                    }

                    //Convert the replication service object definition to a Data Entity
                    //set the result return value to the replication service object defintion
                    //set the result success to true
                    result = new MethodResult { Success = true, Return = rsObjectDefinition.ToDataEntity() };
                }
                else
                {
                    result = new MethodResult { Success = false, ErrorInfo = new ErrorResult { Description = ErrorCodes.ObjectNotFound.Description, Number = ErrorCodes.ObjectNotFound.Number } };
                }
            }

            //return the method result
            return result;
        }
Esempio n. 51
0
        /// <summary>
        /// This method creates an object used to 
        /// track changes for future replications.
        /// In this case, a delete trigger is added to a specified table. 
        /// Note: If the data-source already has a process for tracking changes, this 
        ///       method will only need to return a positive success in the method result
        /// </summary>
        /// <param name="methodInput">Method input used for the replication object.
        /// This is the name of the table that we need to extract.
        /// methodInput.Input.properties["ObjectName"]
        /// </param>
        /// <returns></returns>
        public MethodResult InitReplicationObject(MethodInput methodInput)
        {
            MethodResult methodResult = null;

            // Use LogMethodExecution to add entry and exit tracing to a method.
            // When wrapped in a using statement, the exit point
            // is written during garbage collection.
            using (new LogMethodExecution(
                Globals.ConnectorName, "InitReplication"))
            {
                //First ensure the change history table exists
                MethodResult initReplicationResult = InitReplication();

                //If the replication table already exist then
                //our work here is done and no other action is required
                if (initReplicationResult.Success)
                {
                    string tableName =
                         GetPropertyValueName("EntityName", methodInput.Input.Properties);
                    string triggerName =
                        string.Format("{0}_Deleted_TRG", tableName);

                    if (CheckForTrigger(triggerName, tableName) == false)
                    {
                        //Use the ConnectorApi provided local data storage to retrieve
                        //and read the sql scripts contents
                        LocalDataStorage localDataStorage = new LocalDataStorage();
                        string deleteTriggerString =
                            localDataStorage.ReadData(TriggerFileName);

                        if (string.IsNullOrWhiteSpace(deleteTriggerString))
                        {
                            throw new InvalidExecuteOperationException(string.Format("Unable to locate file: {0}", TriggerFileName));
                        }

                        string query = string.Format(deleteTriggerString, tableName);
                        //Execute the query to create the change history table.
                        _dataAccess.ExecuteNonQuery(query);
                    }

                    //If there were no errors in processing then
                    //just set the Success for the method result to true.
                    methodResult = new MethodResult { Success = true };
                }
                else
                {
                    methodResult = SetErrorMethodResult(ErrorCodes.InitReplication.Number,
                                                        ErrorCodes.InitReplication.Description);
                }
            }

            return methodResult;
        }
Esempio n. 52
0
        public void GetReplicationDataInvalidDateTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput { Name = "GetReplicationData" };

            //set the object name by adding the property to the input
            methodInput.Input.Properties.Add("ObjectName", "SalesOrders");

            //set the Last date of syncronization by adding the property to the input
            methodInput.Input.Properties.Add("LastSyncDate", InvalidPropertyValue);

            //execute the selected method
            MethodResult result = _rsSourceConnector.ExecuteMethod(methodInput);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.ErrorInfo);
        }
Esempio n. 53
0
        public void GetReplicationDataDateOutOfRangeInvalidTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput { Name = "GetReplicationData" };

            //set the object name by adding the property to the input
            methodInput.Input.Properties.Add("ObjectName", "SalesOrders");

            //set the Last date of syncronization by adding the property to the input
            methodInput.Input.Properties.Add("LastSyncDate", DateTime.MinValue);

            //execute the selected method
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            //check that the result is not a success
            Assert.IsFalse(methodResult.Success);
        }
Esempio n. 54
0
        public void GetReplicationDataInvalidObjectTest()
        {
            //create a new instance of the method input class found in ConnectorApi.Actions
            //Assign the MethodInput name to the Name of the method to be executed
            MethodInput methodInput = new MethodInput { Name = "GetReplicationData" };

            //set the object name by adding the property to the input
            methodInput.Input.Properties.Add("ObjectName", InvalidPropertyValue);

            //set the Last date of syncronization by adding the property to the input
            methodInput.Input.Properties.Add("LastSyncDate", DateTime.Now.AddYears(-5));

            //execute the selected method
            MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);

            //Note: this will show it was not a success and set the error info rather than throwing an exception
            Assert.IsFalse(methodResult.Success);
            Assert.IsNotNull(methodResult.ErrorInfo);
        }
Esempio n. 55
0
        /// <summary>
        /// Retrieve the last date the specified table was syncronized
        /// MethodInput.Input.Property.Keys 
        /// "ObjectName": Name of the table
        /// "ModificationDateFullName": Name of the column that stored the last date of syncronization
        /// </summary>
        /// <param name="methodInput">Container for the methods input properties</param>
        /// <returns>MethodResult</returns>
        public MethodResult GetLastReplicationSyncDate(MethodInput methodInput)
        {
            MethodResult methodResult = new MethodResult();

            // Use LogMethodExecution to add entry and exit tracing to a method.
            // When wrapped in a using statement, the exit point is written during garbage collection.
            using (new LogMethodExecution(
                Globals.ConnectorName, "GetLastReplicationSyncDate"))
            {
                //get the name of the table from the method input
                string tableName = GetPropertyValue(
                    "ObjectName", methodInput.Input.Properties);

                string modifiedOnColumn = GetPropertyValue(
                    "ModificationDateFullName",
                    methodInput.Input.Properties);

                DateTime lastSyncDate;

                try
                {
                    //verify that the column name for the lasty sync date is specified
                    if (string.IsNullOrWhiteSpace(modifiedOnColumn) == false)
                    {
                        string query = string.Format(
                            "SELECT TOP 1 [{0}] FROM [{1}] ORDER BY [{0}] DESC", modifiedOnColumn, tableName);
                        //execute the query
                        DataTable lastSyncDateTable = _dataAccess.Execute(query);
                        if (lastSyncDateTable.Rows.Count != 0)
                        {
                            lastSyncDate = Convert.ToDateTime(
                                lastSyncDateTable.Rows[0][modifiedOnColumn]);
                        }
                        //If no records are found in the table then set the last sync date to the min value
                        else
                        {
                            lastSyncDate = DateTime.MinValue;
                        }
                    }
                    //If no last sync date column is specified set the last sync date to the min value
                    else
                    {
                        lastSyncDate = DateTime.MinValue;
                    }
                    //create a new method result
                    methodResult = new MethodResult { Success = true, Return = new DataEntity("ReturnValue") };
                    //add the LastSyncDate to the return properties
                    methodResult.Return.Properties.Add("LastSyncDate", lastSyncDate);
                    //put the last sync date in the debug log
                    Logger.Write(Logger.Severity.Debug, Globals.ConnectorName,
                        "LastSyncDate: " + lastSyncDate + Environment.NewLine);
                }
                //catch an errors comming from the database
                //All other erros will be caught on a higher level and thrown
                //As an InvalidExecuteMethodException from the connector interface
                catch (OleDbException oleDbException)
                {
                    //in the event of a database error create a
                    //new method result and set the succes to false
                    methodResult = new MethodResult { Success = false };
                    //create the new error info and set the number
                    //to the code from the connection
                    methodResult.ErrorInfo = new ErrorResult { Number = oleDbException.ErrorCode };
                    //create the description for the error
                    methodResult.ErrorInfo.Description =
                        oleDbException.Message;
                    methodResult.ErrorInfo.Detail =
                        oleDbException.ToString();
                }
            }

            return methodResult;
        }
Esempio n. 56
0
 public void GetLastReplicationSyncDateValidTest()
 {
     //create hte method input and set the name of the method to execute
     MethodInput methodInput = new MethodInput { Name = "GetLastReplicationSyncDate" };
     //set the name of the table to to check by adding it to the input properties
     methodInput.Input.Properties.Add("ObjectName", "Addresses");
     //set the name of the column that the Modification Date is stored in
     methodInput.Input.Properties.Add("ModificationDateFullName", "ModifiedOn");
     //execute the method
     MethodResult result = _rsTargetConnector.ExecuteMethod(methodInput);
     //verify a success
     Assert.IsTrue(result.Success);
     //verify the method yielded a result
     Assert.IsNotNull(result.Return);
 }
Esempio n. 57
0
        /// <summary>
        /// This method determines whether or not an object from the source has changed.
        /// If the object does not exist it will be created.
        /// If the object has changed it will be deleted and the new one will be created.
        /// If no changes are detected then it will be noted and no further action is needed.
        /// </summary>
        /// <param name="methodInput"></param>
        /// <returns></returns>
        public MethodResult CreateOrUpdateObjectForReplication(MethodInput methodInput)
        {
            MethodResult methodResult = new MethodResult();

            // Use LogMethodExecution to add entry and exit tracing to a method.
            // When wrapped in a using statement, the exit point
            //is written during garbage collection.
            using (new LogMethodExecution(
                Globals.ConnectorName, "CreateOrUpdateObjectForReplication"))
            {
                string tableName = GetPropertyValue("Name", methodInput.Input.Properties);
                //get the list of the columns to be created
                List<DataEntity> newColumns =
                    methodInput.Input.Children["RSPropertyDefinitions"];

                //add the default columns to the new ones from the input
                newColumns.AddRange(CreateDefaultColumns());

                //get the definition of the existing table
                MethodResult currentTableDefinition =
                    GetObjectDefinition(new MethodInput
                                            {
                                                Input =
                                                    {
                                                        Properties = new EntityProperties
                                                                             {
                                                                                 {"ObjectName", tableName}
                                                                             }
                                                    }
                                            });

                bool changeDetected = true;

                //check if the table was returned from GetObjectDefinition method
                if (currentTableDefinition != null && currentTableDefinition.Success)
                {
                    //look for any changes in the table schema by
                    //comparing the properties
                    //of the existing object against the those
                    //found in the method input
                    changeDetected = CheckForSchemaChanges(newColumns,
                                                           currentTableDefinition.Return.Children[
                                                               "RSPropertyDefinitions"]);

                    //if a change is decteded drop the table
                    if (changeDetected)
                    {
                        string query = string.Format("DROP TABLE [{0}]", tableName);
                        _dataAccess.ExecuteNonQuery(query);
                    }
                }

                //Ff a change is detected create the table
                if (changeDetected)
                {
                    _dataAccess.CreateTable(tableName, newColumns);
                }

                //Set the method result object
                methodResult = new MethodResult { Success = true, Return = new DataEntity() };

                //add a property called 'SchemaChanged' to the return properties
                //this is how ScribeOnline will determine whether or not a replication
                //is required when this method has completed
                //Note: this MUST be labeled 'SchemaChanged'
                methodResult.Return.Properties.Add("SchemaChanged", changeDetected);
            }

            return methodResult;
        }
Esempio n. 58
0
 public void GetChangeHistoryDataInValidObjectTest()
 {
     //create a new method input
     MethodInput methodInput = new MethodInput { Name = "GetChangeHistoryData" };
     //set the method input properties
     //note: the invalid object name
     methodInput.Input.Properties.Add("ObjectName", InvalidPropertyValue);
     methodInput.Input.Properties.Add("LastSyncDate", DateTime.Now.AddDays(-1));
     //execute the selected method
     MethodResult methodResult = _rsSourceConnector.ExecuteMethod(methodInput);
     //verify the method was a success
     Assert.IsTrue(methodResult.Success);
     //verify that data was not returned
     Assert.IsNotNull(methodResult.Return);
 }
Esempio n. 59
0
 //-----------------------------------------------------------------------------------------------------
 public MethodResult ExecuteMethod(MethodInput input)
 {
     throw new NotImplementedException();
 }
Esempio n. 60
0
 public void GetLastReplicationSyncDateInvalidTableTest()
 {
     //create the method input and set the name of the method to execute
     MethodInput methodInput = new MethodInput { Name = "GetLastReplicationSyncDate" };
     //set the name of the table to to check by adding it to the input properties
     //note: the invalid table name
     methodInput.Input.Properties.Add("ObjectName", InvalidPropertyValue);
     //set the name of the column that the Modification Date is stored in
     methodInput.Input.Properties.Add("ModificationDateFullName", "ModifiedOn");
     //execute the method
     MethodResult result = _rsTargetConnector.ExecuteMethod(methodInput);
     //verify not a success
     Assert.IsFalse(result.Success);
     //verify that the error info is filled out
     Assert.IsNotNull(result.ErrorInfo);
 }