public void Revert_MustFailIfServiceNotDisconnectedWithinTimeout()
        {
            const int TIMEOUT = 50;

            var after  = default(DateTime);
            var before = default(DateTime);

            sut = new ServiceOperation(logger.Object, runtimeHost.Object, service.Object, sessionContext, TIMEOUT);

            service.Setup(s => s.Disconnect()).Returns(true);
            service
            .Setup(s => s.StopSession(It.IsAny <Guid>()))
            .Returns(new CommunicationResult(true))
            .Callback(() => runtimeHost.Raise(h => h.ServiceSessionStopped += null));

            PerformNormally();

            before = DateTime.Now;
            var result = sut.Revert();

            after = DateTime.Now;

            service.Verify(s => s.Disconnect(), Times.Once);

            Assert.AreEqual(OperationResult.Failed, result);
            Assert.IsTrue(after - before >= new TimeSpan(0, 0, 0, 0, TIMEOUT));
        }
Example #2
0
        public Expression <Action <ReactiveServiceConnectionEnvironment> > Bind(ServiceOperation operation)
        {
            if (operation == null)
            {
                throw new ArgumentNullException(nameof(operation));
            }

            var connectionProperty = s_getQcProperty;

            if ((operation.Kind == ServiceOperationKind.CreateSubscription || operation.Kind == ServiceOperationKind.DeleteSubscription) && _subscribeToQueryEvaluator)
            {
                connectionProperty = s_getQeProperty;
            }

            var binder      = new ServiceOperationBinder();
            var clientBound = binder.Visit(operation);

            return(Expression.Parameter(typeof(ReactiveServiceConnectionEnvironment), "env").Let(env =>
                                                                                                 Expression.Lambda <Action <ReactiveServiceConnectionEnvironment> >(
                                                                                                     Expression.Invoke(
                                                                                                         clientBound,
                                                                                                         Expression.MakeMemberAccess(
                                                                                                             env,
                                                                                                             connectionProperty
                                                                                                             )
                                                                                                         ),
                                                                                                     env
                                                                                                     )
                                                                                                 ).BetaReduce());
        }
Example #3
0
        /// <summary>
        /// Initializes a new <see cref="ServiceOperation"/> instance.
        /// </summary>
        /// <param name="name">name of the service operation.</param>
        /// <param name="resultKind">Kind of result expected from this operation.</param>
        /// <param name="resultType">Type of element of the method result.</param>
        /// <param name="resultSet">EntitySet of the result expected from this operation.</param>
        /// <param name="method">Protocol (for example HTTP) method the service operation responds to.</param>
        /// <param name="parameters">In-order parameters for this operation.</param>
        public ServiceOperation  AddServiceOperation(string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable <ServiceOperationParameter> parameters)
        {
            ServiceOperation so = new ServiceOperation(name, resultKind, resultType, resultSet, method, parameters);

            this.serviceOperationsByName.Add(name, so);
            return(so);
        }
Example #4
0
            private XmlNode CallService(ref string webURL, ServiceOperation serviceOperation)
            {
                try
                {
                    webURL = webURL.Substring(0, webURL.LastIndexOf("/"));

                    try
                    {
                        m_listService.Url = webURL + "/_vti_bin/Lists.asmx";

                        return(serviceOperation());
                    }

                    catch
                    {
                        return(CallService(ref webURL, serviceOperation));
                    }
                }

                catch
                {
                    webURL = null;

                    return(null);
                }
            }
        public Expression <Action <QueryEngineEnvironment> > Bind(ServiceOperation operation)
        {
            if (operation == null)
            {
                throw new ArgumentNullException(nameof(operation));
            }

            var reactiveProxyBinder = new ReactiveServiceOperationBinder();
            var bound = reactiveProxyBinder.Visit(operation);

            var envParam    = Expression.Parameter(typeof(QueryEngineEnvironment), "env");
            var contextExpr = operation.Kind is ServiceOperationKind.CreateSubscription or ServiceOperationKind.DeleteSubscription
                ? Expression.MakeMemberAccess(envParam, s_engineCtx)
                : Expression.MakeMemberAccess(envParam, s_metadataCtx);

            var ctxParam = Expression.Parameter(typeof(IReactive), "ctx");

            return(Expression.Lambda <Action <QueryEngineEnvironment> >(
                       Expression.Block(
                           new[] { ctxParam },
                           Expression.Assign(ctxParam, contextExpr),
                           Expression.Invoke(
                               bound,
                               ctxParam
                               )
                           ),
                       envParam
                       ));
        }
Example #6
0
        private void btnStartStop_Click(object sender, EventArgs e)
        {
            ServiceOperation    operation = (btnStartStop.Text == "Start") ? ServiceOperation.ServiceStart : ServiceOperation.ServiceStop;
            ServiceProgressForm progress  = new ServiceProgressForm(operation);

            progress.ShowDialog(this);
        }
        private static string GetPrepositionString(ServiceOperation settingsAction)
        {
            switch (settingsAction)
            {
            case ServiceOperation.Add:
                return("to");

            case ServiceOperation.Update:
                return("in");

            case ServiceOperation.AddOrUpdate:
                return("in");

            case ServiceOperation.Remove:
                return("from");

            case ServiceOperation.Load:
                return("from");

            case ServiceOperation.Reload:
                return("from");

            default:
                return("to");
            }
        }
        private static void CallMethodOnService(ServiceOperation operation,
                                                ServiceBase serviceBase)
        {
            Type serviceBaseType = serviceBase.GetType();

            object[] parameters = null;
            if (operation == ServiceOperation.Start)
            {
                parameters = new object[] { null }
            }
            ;

            string methodName = "On" + Enum.GetName(typeof(ServiceOperation), operation);

            try
            {
                serviceBaseType.InvokeMember(methodName,
                                             BindingFlags.Instance |
                                             BindingFlags.Public |
                                             BindingFlags.NonPublic |
                                             BindingFlags.InvokeMethod, null, serviceBase, parameters);
            }
            catch (Exception ex)
            {
                throw new Exception($"An exception was thrown while trying to call the {methodName} of the {serviceBase.ServiceName} service.  Examine the inner exception for more information.",
                                    ex.InnerException);
            }
        }
    }
Example #9
0
        /// <summary>
        /// Binds a service operation to the environment.
        /// </summary>
        /// <param name="operation">The operation to bind.</param>
        /// <returns>
        /// A lambda expression that can be evaluated with an environment
        /// instance returned from the `CreateEnvironment` method.
        /// </returns>
        public Expression <Action <IReactiveClientEnvironment> > Bind(ServiceOperation operation)
        {
            if (operation == null)
            {
                throw new ArgumentNullException(nameof(operation));
            }

            var binder      = new ReactiveProxyServiceOperationBinder();
            var clientBound = binder.Visit(operation);

            return(Expression.Parameter(typeof(IReactiveClientEnvironment), "env").Let(env =>
                                                                                       Expression.Lambda <Action <IReactiveClientEnvironment> >(
                                                                                           Expression.Call(
                                                                                               Expression.Invoke(
                                                                                                   clientBound,
                                                                                                   Expression.MakeMemberAccess(
                                                                                                       env,
                                                                                                       s_getContextProperty
                                                                                                       )
                                                                                                   ),
                                                                                               s_waitMethod
                                                                                               ),
                                                                                           env
                                                                                           )
                                                                                       ).BetaReduce());
        }
        public async Task <IActionResult> PutServiceOperation(long id, ServiceOperation serviceOperation)
        {
            if (id != serviceOperation.OperationId)
            {
                return(BadRequest());
            }

            _context.Entry(serviceOperation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ServiceOperationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #11
0
        public object InvokeServiceOperation(ServiceOperation serviceOperation, object[] parameters)
        {
            var method             = (MethodInfo)serviceOperation.CustomState;
            var currentDataContext = ((TypedDataSource)CurrentDataSource).DataContext;

            return(method.Invoke(currentDataContext, parameters));
        }
Example #12
0
        /// <summary>
        /// Event for when the "Delete" Button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            // Get currently selected record's ID.
            int mealIngredientID = int.Parse(lblID.Text);

            if (mealIngredientID != 0)
            {
                // Tell DB to delete it.
                CharityKitchenDataServiceSoapClient svc = new CharityKitchenDataServiceSoapClient();
                ServiceOperation operation = svc.DeleteMealIngredient(mealIngredientID);

                if (operation.Success)
                {
                    lblInfo.ForeColor = System.Drawing.Color.DarkGreen;
                    lblInfo.Text      = operation.Message;

                    // Refresh GridView if data was modified.
                    GetMealIngredients(svc);
                }
                else
                {
                    lblInfo.ForeColor = System.Drawing.Color.Red;
                    lblInfo.Text      = operation.Message + Environment.NewLine + operation.Exception;
                }
            }
        }
Example #13
0
        private void SendRequest(ServiceOperation operation, SuccessCallback success, FailureCallback failure, object cbObject, IDictionary data)
        {
            ServerCallback callback = BrainCloudClient.CreateServerCallback(success, failure, cbObject);
            ServerCall     sc       = new ServerCall(ServiceName.Group, operation, data, callback);

            _bcClient.SendRequest(sc);
        }
Example #14
0
 /// <summary>
 /// Lazy try get the service operation of specified
 /// name declared on the service type.
 /// </summary>
 public bool LazyTryGetServiceOperation(
     TContext adapter,
     string name,
     out ServiceOperation serviceOperation)
 {
     Initialize(adapter);
     return(serviceOperations.TryGetValue(name, out serviceOperation));
 }
 public bool TryResolveServiceOperation(
     string name,
     out ServiceOperation serviceOperation)
 {
     // No service operations are supported yet
     serviceOperation = null;
     return(false);
 }
 object IDataServiceQueryProvider.InvokeServiceOperation(ServiceOperation serviceOperation, object[] parameters)
 {
     return(ReflectionHelper.Invoke(
                service,
                serviceOperation.Name,
                null,
                parameters));
 }
Example #17
0
        /// <summary>Given the specified name, tries to find a service operation.</summary>
        /// <param name="name">Name of the service operation to resolve.</param>
        /// <param name="serviceOperation">Returns the resolved service operation, null if no service operation was found for the given name.</param>
        /// <returns>True if we found the service operation for the given name, false otherwise.</returns>
        public bool TryResolveServiceOperation(string name, out ServiceOperation serviceOperation)
        {
            DomainDataServiceMetadata.DomainDataServiceOperation op;
            bool result = this.metadata.ServiceOperations.TryGetValue(name, out op);

            serviceOperation = op;
            return(result);
        }
Example #18
0
        /// <summary>
        /// Event ffor when the Save Button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            // Some sanity checks for TextBox contents.
            if (txtUsername.Text == "")
            {
                lblInfo.ForeColor = System.Drawing.Color.Red;
                lblInfo.Text      = "Please enter a Username.";
                return;
            }

            if (!txtUsername.Text.IsAlphaNumeric())
            {
                lblInfo.ForeColor = System.Drawing.Color.Red;
                lblInfo.Text      = "Username is not allowed. Needs to be AlphaNumeric (Letters and numbers only). Please enter a valid Username.";
                return;
            }

            // Bundle data from page controls into object to send to DB.
            UserIDNameCombo userCombo = new UserIDNameCombo();

            try
            {
                userCombo.ID       = int.Parse(lblUserID.Text);
                userCombo.Username = txtUsername.Text;
            }
            catch (Exception ex)
            {
                lblInfo.ForeColor = System.Drawing.Color.Red;
                lblInfo.Text      = ex.Message;
                return;
            }

            if (userCombo.ID == 0)
            {
                lblInfo.ForeColor = System.Drawing.Color.Red;
                lblInfo.Text      = "ID for existing User is somehow 0. THIS SHOULD NOT BE HAPPENING. Saving Halted.";
                return;
            }

            // Send object to DB.
            CharityKitchenDataServiceSoapClient svc = new CharityKitchenDataServiceSoapClient();
            ServiceOperation operation = svc.UpdateUser(userCombo);

            if (operation.Success)
            {
                lblInfo.ForeColor = System.Drawing.Color.DarkGreen;
                lblInfo.Text      = operation.Message;

                // Refresh GridView if data was modified.
                gvUsers.DataSource = svc.GetUserIDNameCombos().Data;
                gvUsers.DataBind();
            }
            else
            {
                lblInfo.ForeColor = System.Drawing.Color.Red;
                lblInfo.Text      = operation.Message + Environment.NewLine + operation.Exception;
            }
        }
        public ServiceOperation GetUserIDNameCombos()
        {
            // Setup DB Connection and ServiceOperation object.
            ServiceOperation operation = new ServiceOperation();
            OleDbConnection  dbConn    = new OleDbConnection(CONNECTION_STRING);

            // Setup Query and send it to DB.
            string query = "SELECT UserID,Username FROM tblUsers";

            try
            {
                OleDbCommand dbCmd = new OleDbCommand(query, dbConn);
                dbConn.Open();

                OleDbDataReader reader = dbCmd.ExecuteReader();

                while (reader.Read())
                {
                    // Add retrieved data to ServiceOperation object.
                    operation.Data.Add(new UserIDNameCombo(reader));
                }
            }

            // If something fails, get Exception message and add it to ServiceOperation object.
            catch (FormatException ex)
            {
                operation.Success   = false;
                operation.Exception = ex.Message;
                operation.Message   = "Invalid data supplied";
            }

            catch (OleDbException ex)
            {
                operation.Success   = false;
                operation.Exception = ex.Message;
                operation.Message   = "Database error";
            }

            catch (Exception ex)
            {
                operation.Success   = false;
                operation.Exception = ex.Message;
                operation.Message   = "Unspecified error";
            }

            finally
            {
                if (dbConn.State == System.Data.ConnectionState.Open)
                {
                    // Close any DB connections when done.
                    dbConn.Close();
                }
            }

            // Return the finished ServiceOperation object.
            return(operation);
        }
 public ServiceOperationHelper(string itemType, Plurality plurality, ServiceOperation serviceOperation, string targetName, string itemIdentifier = "")
 {
     ItemType               = itemType;
     Plurality              = plurality;
     ServiceOperation       = serviceOperation;
     TargetName             = targetName;
     ServiceOperationResult = new ServiceOperationResult();
     ItemIdentifier         = itemIdentifier;
 }
        /// <summary>Invokes the specified service operation.</summary>
        /// <param name="serviceOperation">The service operation to invoke.</param>
        /// <param name="parameters">The parameters for the service operation. Their types will match the types of the declared parameters for the service operation.</param>
        /// <returns>The result of the service operation.
        /// If the service operation is declared to return void, this method should return null.
        /// Otherwise the method should return object of the type declared as the return type for the service operation.</returns>
        public object InvokeServiceOperation(ServiceOperation serviceOperation, object[] parameters)
        {
            if (invokeServiceOperationDel != null)
            {
                return(invokeServiceOperationDel(serviceOperation, parameters));
            }

            throw new NotSupportedException("No service operation handler has been registered.");
        }
        /// <summary>
        /// Method to Get all the OrderMeals for a specified Oredr from the DB and display in a GridView on the page.
        /// </summary>
        /// <param name="svc">The Instantiated service objedct to use.</param>
        private void GetOrderMeals(CharityKitchenDataServiceSoapClient svc)
        {
            // get OrderID of Order-to-edit stored in Session data by Orders page.
            int orderID = 0; //default

            try
            {
                orderID = (int)Session["OrderToEdit_ID"];
            }
            catch
            {
                Response.Redirect("~/Orders");
            }

            // If OrderID is an actual ID, continue, else kick user back to Orders page.
            if (orderID != 0)
            {
                // Get data from DB.
                ServiceOperation operation = svc.GetOrderMeals(orderID);

                if (operation.Success)
                {
                    // Display data on page.
                    gvOrderMeals.DataSource = operation.Data;
                    gvOrderMeals.DataBind();

                    lblOrderIDName.Text = orderID.ToString() + " - " + (string)Session["OrderToEdit_Name"];
                    // Prettyifying things, makes GridView display Order's name for user instead of ID.
                    if (operation.Data.Count > 0)
                    {
                        gvOrderMeals.HeaderRow.Cells[3].Text = "MealName";



                        for (int i = 0; i < gvOrderMeals.Rows.Count; i++)
                        {
                            foreach (ListItem ml in meals)
                            {
                                if (ml.Value == gvOrderMeals.Rows[i].Cells[3].Text)
                                {
                                    gvOrderMeals.Rows[i].Cells[3].Text = ml.Text;
                                }
                            }
                        }
                    }
                }
                else
                {
                    lblInfo.ForeColor = System.Drawing.Color.Red;
                    lblInfo.Text      = operation.Message + Environment.NewLine + operation.Exception;
                }
            }
            else
            {
                Response.Redirect("~/Orders");
            }
        }
Example #23
0
        /// <summary>
        /// Method to Get all the MealIngredients for a specified Meal from the DB and display in a GridView on the page.
        /// </summary>
        /// <param name="svc">The Instantiated service objedct to use.</param>
        private void GetMealIngredients(CharityKitchenDataServiceSoapClient svc)
        {
            // get MealID of Meal-to-edit stored in Session data by Meals page.
            int mealID = 0; //default

            try
            {
                mealID = (int)Session["MealToEdit_ID"];
            }
            catch
            {
                Response.Redirect("~/Meals");
            }

            // If MealID is an actual ID, continue, else kick user back to Meals page.
            if (mealID != 0)
            {
                // Get data from DB.
                ServiceOperation operation = svc.GetMealIngredients(mealID);

                if (operation.Success)
                {
                    // Display data on page.
                    lblMealName.Text = (string)Session["MealToEdit_Name"];

                    gvMealIngredients.DataSource = operation.Data;
                    gvMealIngredients.DataBind();

                    // Prettyifying things, makes GridView display Ingredient's name for user instead of ID.
                    if (operation.Data.Count > 0)
                    {
                        gvMealIngredients.HeaderRow.Cells[3].Text = "IngredientName";

                        for (int i = 0; i < gvMealIngredients.Rows.Count; i++)
                        {
                            foreach (ListItem ing in ingredients)
                            {
                                if (ing.Value == gvMealIngredients.Rows[i].Cells[3].Text)
                                {
                                    gvMealIngredients.Rows[i].Cells[3].Text = ing.Text;
                                }
                            }
                        }
                    }
                }
                else
                {
                    lblInfo.ForeColor = System.Drawing.Color.Red;
                    lblInfo.Text      = operation.Message + Environment.NewLine + operation.Exception;
                }
            }
            else
            {
                Response.Redirect("~/Meals");
            }
        }
        private ServiceOperation CheckIfExists(string table, string conditions)
        {
            // Setup DB Connection and ServiceOperation object.
            ServiceOperation operation = new ServiceOperation();
            OleDbConnection  dbConn    = new OleDbConnection(CONNECTION_STRING);

            // Setup Query and send it to DB.
            string query = String.Format("SELECT 1 FROM {0} WHERE {1}", table, conditions);

            try
            {
                OleDbCommand dbCmd = new OleDbCommand(query, dbConn);
                dbConn.Open();
                OleDbDataReader reader = dbCmd.ExecuteReader();

                while (reader.Read())
                {
                    // Add retrieved data to ServiceOperation object.
                    operation.Data.Add(reader[0]);
                }
            }

            // If something fails, get Exception message and add it to ServiceOperation object.
            catch (FormatException ex)
            {
                operation.Success   = false;
                operation.Exception = ex.Message;
                operation.Message   = "Invalid data supplied";
            }

            catch (OleDbException ex)
            {
                operation.Success   = false;
                operation.Exception = ex.Message;
                operation.Message   = "Database error";
            }

            catch (Exception ex)
            {
                operation.Success   = false;
                operation.Exception = ex.Message;
                operation.Message   = "Unspecified error";
            }

            finally
            {
                if (dbConn.State == System.Data.ConnectionState.Open)
                {
                    // Close any DB connections when done.
                    dbConn.Close();
                }
            }

            // Return the finished ServiceOperation object.
            return(operation);
        }
        public ServiceOperation UserLogin(string username, string password)
        {
            // Setup DB Connection and ServiceOperation object.
            ServiceOperation operation = new ServiceOperation();
            OleDbConnection  dbConn    = new OleDbConnection(CONNECTION_STRING);

            // Setup Query and send it to DB.
            string query = String.Format("SELECT * FROM tblUsers WHERE Username=\"{0}\" AND UserPass=\"{1}\"", username, password);

            try
            {
                OleDbCommand dbCmd = new OleDbCommand(query, dbConn);
                dbConn.Open();

                OleDbDataReader reader = dbCmd.ExecuteReader();

                while (reader.Read())
                {
                    // Add retrieved data to ServiceOperation object.
                    operation.Data.Add(new User(reader));
                }
            }

            // If something fails, get Exception message and add it to ServiceOperation object.
            catch (FormatException ex)
            {
                operation.Success   = false;
                operation.Exception = ex.Message;
                operation.Message   = "Invalid data supplied";
            }

            catch (OleDbException ex)
            {
                operation.Success   = false;
                operation.Exception = ex.Message;
                operation.Message   = "Database error";
            }

            catch (Exception ex)
            {
                operation.Success   = false;
                operation.Exception = ex.Message;
                operation.Message   = "Unspecified error";
            }

            finally
            {
                if (dbConn.State == System.Data.ConnectionState.Open)
                {
                    // Close any DB connections when done.
                    dbConn.Close();
                }
            }

            return(operation);
        }
Example #26
0
 /// <summary>Given the specified name, tries to find a service operation.</summary>
 /// <param name="name">Name of the service operation to resolve.</param>
 /// <param name="serviceOperation">Returns the resolved service operation, null if no service operation was found for the given name.</param>
 /// <returns>True if we found the service operation for the given name, false otherwise.</returns>
 public bool TryResolveServiceOperation(string name, out ServiceOperation serviceOperation)
 {
     Log.Trace(name);
     serviceOperation = serviceOperationProvider.ServiceOperations.SingleOrDefault(so => so.Name == name);
     if (serviceOperation != null)
     {
         serviceOperation.SetReadOnly();
     }
     return(serviceOperation != null);
 }
        internal ServiceOperationRights GetServiceOperationRights(ServiceOperation serviceOperation)
        {
            ServiceOperationRights rightsForUnspecifiedServiceOperation;

            if (!this.serviceOperationRights.TryGetValue(serviceOperation.Name, out rightsForUnspecifiedServiceOperation))
            {
                rightsForUnspecifiedServiceOperation = this.rightsForUnspecifiedServiceOperation;
            }
            return(rightsForUnspecifiedServiceOperation);
        }
        public static string LogServiceOperation(Type itemType, Plurality plurality, ServiceOperation serviceOperation, ServiceOperationStatus serviceOperationStatus, string targetName, string itemIdentifier = "", string exceptionMessage = "")
        {
            var logMessageType         = serviceOperationStatus == ServiceOperationStatus.Failed ? LogMessageType.Error : LogMessageType.Verbose;
            var exceptionMessageSuffix = serviceOperationStatus == ServiceOperationStatus.Failed ? $"Error message: {exceptionMessage}" : string.Empty;
            var identifier             = plurality == Plurality.Single ? $"{itemType.Name} \"{itemIdentifier}\"" : GetPluralIdentifier(itemType);
            var logMessage             = $"{GetActionString(serviceOperation, serviceOperationStatus)} {identifier} {GetPrepositionString(serviceOperation)} the {targetName}. {exceptionMessageSuffix}";

            AppInfo.BaseAppInfo.Log.QueueLogMessageAsync(logMessage, logMessageType);
            return(logMessage);
        }
        public void Dequeue(ServiceOperation operation, object parameter)
        {
            var targetCallbacks = _callbacks.Where(x => x.Item1.Equals(operation)).ToArray();

            targetCallbacks.All(x => _callbacks.Remove(x));
            foreach (var callback in targetCallbacks)
            {
                _callbacks.Remove(callback);
                callback.Item2.Invoke(parameter);
            }
        }
        // Private
        private void SendMessage(
            ServiceOperation operation,
            Dictionary <string, object> data,
            SuccessCallback success = null,
            FailureCallback failure = null,
            object cbObject         = null)
        {
            ServerCallback callback = BrainCloudClient.CreateServerCallback(success, failure, cbObject);

            _clientRef.SendRequest(new ServerCall(ServiceName.Mail, operation, data, callback));
        }
Example #31
0
 public static ServiceOperation ServiceOperation(String name, ResourceContainer container, ResourceType baseType, params ResourceType[] resourceTypes)
 {
     ServiceOperation serviceOp = new ServiceOperation(name, container, baseType, resourceTypes);
     return serviceOp;
 }
 public ServiceArgs(ServiceOperation operation, string usn, Service service)
 {
     this.operation = operation;
     this.usn = usn;
     this.service = service;
 }
 public ServiceArgs(ServiceOperation operation, Service service)
     : this(operation, service.Usn, service)
 {
 }
Example #34
0
        public virtual IQueryable ServiceOperationToQueryable(ServiceOperation serviceOp)
        {
            IQueryable containerQueryable = null;
            IQueryable serviceOperationResults = null;
            Expression queryExpression = null;
            switch (serviceOp.BackingType)
            {
                case ServiceOpBackingType.EntitySet:
                    containerQueryable = this.ResourceContainerToQueryable(serviceOp.Container);
                    queryExpression = containerQueryable.Expression;

                    if (serviceOp.HasQueryExpression)
                    {
                        Type[] typeArgs = new Type[] { containerQueryable.ElementType };

                        serviceOp.ClrTypeOfExpression = containerQueryable.ElementType;

                        if (containerQueryable.ElementType.Name != serviceOp.ExpectedTypeName
                            ||
                            serviceOp.Container.ResourceTypes.Count() > 1)
                        {
                            serviceOp.ClrTypeOfExpression = this.ServiceContainer.ResourceTypes.First(rt => rt.Name == serviceOp.ExpectedTypeName).ClrType;
                            typeArgs = new Type[] { serviceOp.ClrTypeOfExpression };
                            AstoriaTestLog.WriteLine("types dont match");
                            queryExpression = Expression.Call(typeof(Queryable), "OfType", typeArgs, queryExpression);
                            typeArgs = new Type[] { serviceOp.ClrTypeOfExpression };
                        }
                        var result = Expression.Call(typeof(Queryable), "Where", typeArgs, queryExpression, serviceOp.QueryExpression);
                        serviceOperationResults = containerQueryable.Provider.CreateQuery(result);
                    }
                    else
                    {
                        serviceOperationResults = containerQueryable;
                    }
                    break;

                case ServiceOpBackingType.PrimitiveType:
                    serviceOperationResults = (IQueryable)serviceOp.PrimitiveTypeData;
                    break;
                case ServiceOpBackingType.ComplexType:
                    containerQueryable = this.ResourceContainerToQueryable(serviceOp.Container);
                    queryExpression = containerQueryable.Expression;
                    if (serviceOp.HasQueryExpression)
                    {
                        serviceOp.ClrTypeOfExpression = this.ServiceContainer.ResourceTypes.First(rt => rt.Name == serviceOp.ExpectedTypeName).ClrType;
                        serviceOp.ClrComplexTypeOfExpression = serviceOp.ClrTypeOfExpression.GetProperties().FirstOrDefault(prop => prop.Name == serviceOp.ExpectedComplexPropertyName).PropertyType;
                        Expression serviceOpQueryExpression = serviceOp.QueryExpression;
                        serviceOpQueryExpression = Expression.Call(typeof(Queryable), "Select", new Type[] { serviceOp.ClrTypeOfExpression, serviceOp.ClrComplexTypeOfExpression },
                            queryExpression, serviceOpQueryExpression);
                        serviceOperationResults = containerQueryable.Provider.CreateQuery(serviceOpQueryExpression);
                    }
                    else
                    {
                        serviceOperationResults = (IQueryable)serviceOp.ComplexTypeData;
                    }
                    break;
            }
            return serviceOperationResults;
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="serviceOperationInfo"></param>
 /// <param name="serviceRegister"></param>
 protected MessageFormatter(ServiceOperation serviceOperationInfo, IServiceRegister serviceRegister)
     : this(serviceOperationInfo.Action, serviceOperationInfo.Parameters, serviceOperationInfo.ReturnType, serviceRegister)
 {
 }
Example #36
0
 public static ServiceOperation ServiceOperation(String name, ResourceContainer container, ResourceType baseType, List<KeyValuePair<string, Type>> InputParams, params ResourceType[] resourceTypes)
 {
     ServiceOperation serviceOp = new ServiceOperation(name, container, baseType, resourceTypes);
     serviceOp.InputParameters = InputParams;
     return serviceOp;
 }