public IQueryable <T> GetQuery <T>()
        {
            var type = typeof(T);

            if (this.queryCache.ContainsKey(type))
            {
                return((IQueryable <T>) this.queryCache[type]);
            }

            if (this.orgService == null)
            {
                this.orgService = this.orgServiceFactory.CreateOrganizationService(this.userId);
            }

            if (this.uow == null)
            {
                var uowTypeCache = Kipon.Fake.Xrm.Reflection.TypeCache.ForUow(false);
                var pms          = new object[1];
                pms[0]   = this.orgService;
                this.uow = uowTypeCache.Constructor.Invoke(pms);
            }

            var queryType      = typeof(IQueryable <>).GetGenericTypeDefinition().MakeGenericType(typeof(T));
            var queryTypeCache = Kipon.Fake.Xrm.Reflection.TypeCache.ForQuery(queryType);

            var repo   = queryTypeCache.RepositoryProperty.GetValue(this.uow);
            var method = queryTypeCache.QueryMethod;

            this.queryCache[type] = method.Invoke(repo, new object[0]);


            var r = (IQueryable <T>) this.queryCache[type];

            return(r);
        }
 public void OnPreUpdate(
     Entities.Account target,
     Microsoft.Xrm.Sdk.IOrganizationService orgService,
     Kipon.Solid.Plugin.Entities.IAdminUnitOfWork aUow,
     Kipon.Solid.Plugin.ServiceAPI.IAccountService accountService,
     Kipon.Solid.Plugin.Entities.Account.IAccountNameChanged account)
 {
 }
        public void ConnectionChanged(IConnection connection)
        {
            ConfigurationContent.Content = new LoadingControl();

            this.orgServiceInstance = connection.GetConnection() as Microsoft.Xrm.Sdk.IOrganizationService;

            BackgroundWorker bgwConnectionChanged = new BackgroundWorker();

            bgwConnectionChanged.DoWork             += bgwConnectionChanged_DoWork;
            bgwConnectionChanged.RunWorkerCompleted += bgwConnectionChanged_RunWorkerCompleted;
            bgwConnectionChanged.RunWorkerAsync();
        }
Esempio n. 4
0
 public void Commit(Microsoft.Xrm.Sdk.IOrganizationService orgService)
 {
     if (trans.Requests != null && trans.Requests.Count > 0)
     {
         orgService.Execute(trans);
         this.trans = new Microsoft.Xrm.Sdk.Messages.ExecuteTransactionRequest
         {
             Requests        = new Microsoft.Xrm.Sdk.OrganizationRequestCollection(),
             ReturnResponses = false
         };
     }
 }
        public static string RetrieveAll(Microsoft.Xrm.Sdk.IOrganizationService serviceOrgnization, string entityName, string columnSet, string filter, int retrievedNumberOfRecords, string orderBy, bool isDisplayAllRecords, out Microsoft.Xrm.Sdk.EntityCollection _EntityCollection)
        {
            int    page   = 1;
            string retVal = "";

            int recordCounter          = 0;
            var entityCollectionResult = RetrieveAll(serviceOrgnization, entityName, columnSet, filter, retrievedNumberOfRecords, orderBy, page, null);

            _EntityCollection = entityCollectionResult;

            bool isFirstTime = true;

            //List<string> header = Entity.RetrieveAllFacade.GetColumnSet(entityName,columnSet).ToList<string>();
            //header.Insert(0, "#");


            do
            {
                if ((isDisplayAllRecords || isFirstTime))
                {
                    if (entityCollectionResult.MoreRecords)
                    {
                        if (!isFirstTime)
                        {
                            entityCollectionResult = RetrieveAll(serviceOrgnization, entityName, columnSet, filter, retrievedNumberOfRecords, orderBy, page, entityCollectionResult.PagingCookie);

                            _EntityCollection.Entities.AddRange(entityCollectionResult.Entities);
                        }
                        recordCounter = page * retrievedNumberOfRecords;
                        ++page;
                    }
                }
                else
                {
                    break;
                }
                isFirstTime = false;
            } while (entityCollectionResult.MoreRecords);



            return(retVal);
        }
Esempio n. 6
0
        public ConfigurationContent(WriteToDynamicsCrmN2NConfiguration configuration, Microsoft.Xrm.Sdk.IOrganizationService organizationService, EntityMetadata entity1Metadata, IDatastore dataObject)
        {
            InitializeComponent();

            this.entity1Metadata     = entity1Metadata;
            this.organizationService = organizationService;
            this.dataObject          = dataObject;
            this.configuration       = configuration;

            InitializeMappingControl(entity1MappingControl, entity1Metadata, configuration.Entity1Mapping);
            InitializeEntity2Dropdown();
            if (!String.IsNullOrEmpty(configuration.Entity2Name))
            {
                foreach (var item in ddEntity2.Items)
                {
                    if (((ComboBoxItem)item).Tag.ToString() == configuration.Entity2Name)
                    {
                        ddEntity2.SelectedItem = item;
                    }
                }
            }
        }
Esempio n. 7
0
 public CrmContext(Microsoft.Xrm.Sdk.IOrganizationService service) :
     base(service)
 {
 }
Esempio n. 8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public XrmSvc(Microsoft.Xrm.Sdk.IOrganizationService service) :
     base(service)
 {
 }
Esempio n. 9
0
        public static object GetAttributeValueFromString(Microsoft.Xrm.Sdk.IOrganizationService service, string entityName, string attribute, string value)

        {
            object retVal = null;



            var attributeRequest = new Microsoft.Xrm.Sdk.Messages.RetrieveAttributeRequest

            {
                EntityLogicalName = entityName,

                LogicalName = attribute,

                RetrieveAsIfPublished = true
            };

            Microsoft.Xrm.Sdk.Messages.RetrieveAttributeResponse attributeResponse = (Microsoft.Xrm.Sdk.Messages.RetrieveAttributeResponse)service.Execute(attributeRequest);

            Microsoft.Xrm.Sdk.Metadata.AttributeMetadata attrMetadata = (Microsoft.Xrm.Sdk.Metadata.AttributeMetadata)attributeResponse.AttributeMetadata;



            switch (attrMetadata.AttributeType.ToString())

            {
            case "Status":     //Status



                //Microsoft.Xrm.Sdk.Metadata.StatusAttributeMetadata tmp = new Microsoft.Xrm.Sdk.Metadata.StatusAttributeMetadata();

                //tmp.DefaultFormValue = int.Parse(value);

                //retVal = tmp;

                retVal = int.Parse(value);

                break;

            case "Picklist":     //Picklist



                retVal = int.Parse(value);

                break;

            case "State":     //State



                retVal = int.Parse(value);

                break;

            case "Decimal":     //Decimal



                retVal = decimal.Parse(value);

                break;

            case "Enum":     //Enum



                retVal = int.Parse(value);

                break;

            case "Memo":     //Memo

                retVal = value;

                break;

            case "Money":     //Money



                retVal = decimal.Parse(value);

                break;

            case "Lookup":

            {
                //    attrMetadata

                string[] strs = value.Split('\\');

                //Microsoft.Xrm.Sdk.EntityReference er = new Microsoft.Xrm.Sdk.EntityReference();

                //    er.LogicalName = ((Microsoft.Xrm.Sdk.Metadata.LookupAttributeMetadata) attrMetadata).Targets[0];
                //    er.Id = Guid.Parse(strs[0]);

                if (strs.Length > 1)
                {
                    retVal = Guid.Parse(strs[1]);
                }
                else if (strs.Length == 1)
                {
                    retVal = Guid.Parse(strs[0]);
                }
            }

            break;

            case "Integer":



                retVal = int.Parse(value);

                break;

            case "Owner":

            {
                string[] strs = value.Split('\\');

                Microsoft.Xrm.Sdk.EntityReference er = new Microsoft.Xrm.Sdk.EntityReference();

                er.LogicalName = strs[0];

                er.Id = Guid.Parse(strs[1]);

                retVal = er;
            }

            break;

            case "DateTime":     //DateTime



                retVal = DateTime.Parse(value);

                break;

            case "Boolean":     //Boolean

                retVal = bool.Parse(value);

                break;

            case "String":     //String

                retVal = value;

                break;

            case "Double":     //Double

                retVal = Double.Parse(value);

                break;

            case "EntityName":     //Entity Name

                retVal = value;

                break;

            case "Image":     //Image, it will return image name.

                retVal = value;

                break;

            case "BigInt":

                break;

            case "ManagedProperty":

                break;

            case "Uniqueidentifier":

                retVal = Guid.Parse(value);

                break;

            case "Virtual":

                break;

            default:

                //TODO: Write Err Exception

                break;
            }

            return(retVal);
        }
Esempio n. 10
0
        public static string GetAttributeLabel(Microsoft.Xrm.Sdk.IOrganizationService service, Microsoft.Xrm.Sdk.Entity entity, string attribute)

        {
            string strLabel = String.Empty;

            Microsoft.Xrm.Sdk.OptionSetValue option = null;



            var attributeRequest = new Microsoft.Xrm.Sdk.Messages.RetrieveAttributeRequest

            {
                EntityLogicalName = entity.LogicalName,

                LogicalName = attribute,

                RetrieveAsIfPublished = true
            };



            Microsoft.Xrm.Sdk.Messages.RetrieveAttributeResponse attributeResponse = (Microsoft.Xrm.Sdk.Messages.RetrieveAttributeResponse)service.Execute(attributeRequest);

            Microsoft.Xrm.Sdk.Metadata.AttributeMetadata attrMetadata = (Microsoft.Xrm.Sdk.Metadata.AttributeMetadata)attributeResponse.AttributeMetadata;

            Microsoft.Xrm.Sdk.Metadata.OptionMetadataCollection optionMeta = null;



            //Console.Write("\tDebug attributeType : " + attrMetadata.AttributeType.ToString() + "\t");



            #region Switch

            switch (attrMetadata.AttributeType.ToString())

            {
            case "Status":     //Status

                optionMeta = ((Microsoft.Xrm.Sdk.Metadata.StatusAttributeMetadata)attrMetadata).OptionSet.Options;

                break;

            case "Picklist":     //Picklist

                optionMeta = ((Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata)attrMetadata).OptionSet.Options;

                break;

            case "State":     //State

                optionMeta = ((Microsoft.Xrm.Sdk.Metadata.StateAttributeMetadata)attrMetadata).OptionSet.Options;

                break;

            case "Decimal":     //Decimal

                break;

            case "Enum":     //Enum

                break;

            case "Memo":     //Memo

                break;

            case "Money":     //Money

                break;

            case "Lookup":

                break;

            case "Integer":

                break;

            case "Owner":

                strLabel = ((Microsoft.Xrm.Sdk.EntityReference)entity.Attributes[attribute]).Name;

                break;

            case "DateTime":     //DateTime

                strLabel = Convert.ToDateTime(entity.Attributes[attribute].ToString()).ToString();

                break;

            case "Boolean":     //Boolean

                break;

            case "String":     //String

                strLabel = entity[attribute].ToString();

                break;

            case "Double":     //Double

                break;

            case "EntityName":     //Entity Name

                break;

            case "Image":     //Image, it will return image name.

                break;

            case "BigInt":

                break;

            case "ManagedProperty":

                break;

            case "Uniqueidentifier":

                break;

            case "Virtual":

                break;

            default:

                //TODO: Write Err Exception

                break;
            }

            #endregion Switch

            //If this attr is OptionSet, Find Label
            if (optionMeta != null)
            {
                option = ((Microsoft.Xrm.Sdk.OptionSetValue)entity.Attributes[attribute]);

                foreach (Microsoft.Xrm.Sdk.Metadata.OptionMetadata metadata in optionMeta)

                {
                    if (metadata.Value == option.Value)

                    {
                        strLabel = metadata.Label.UserLocalizedLabel.Label;
                    }
                }
            }



            return(strLabel);
        }
 public ScantegraServiceContext(Microsoft.Xrm.Sdk.IOrganizationService service) :
     base(service)
 {
 }
        //    public static Dictionary<string, Microsoft.Xrm.Sdk.EntityCollection> EntityCollectionCached = new Dictionary<string, Microsoft.Xrm.Sdk.EntityCollection>();



        //https://msdn.microsoft.com/en-us/library/mt269606.aspx
        public static Microsoft.Xrm.Sdk.EntityCollection RetrieveAll(Microsoft.Xrm.Sdk.IOrganizationService serviceOrgnization, string entityName
                                                                     , string columnSet = "", string filter = "", int retrievedNumberOfRecords = 50, string orderBy = "", int pageNumber = 1, string pagingCookie = null)
        {
            Microsoft.Xrm.Sdk.EntityCollection retVal = null;

            string uniqueRecordString = $"{entityName} '{columnSet}' '{filter}' {retrievedNumberOfRecords} '{orderBy}' {pageNumber}  ";

            /*
             * if (EntityCollectionCached.ContainsKey(uniqueRecordString))
             * {
             *  return EntityCollectionCached[uniqueRecordString];
             * }*/
            // Query using the paging cookie.
            // Define the paging attributes.
            // The number of records per page to retrieve.
            int queryCount = retrievedNumberOfRecords;

            // Create the query expression and add condition.
            Microsoft.Xrm.Sdk.Query.QueryExpression pagequery = new Microsoft.Xrm.Sdk.Query.QueryExpression();
            pagequery.EntityName = entityName;

            filter = filter.ToLower();
            if (!string.IsNullOrEmpty(filter) && !string.IsNullOrWhiteSpace(filter) && filter != "null")
            {
                string[] conditionsStr = filter.Split(new string[] { "&" }, StringSplitOptions.None);

                foreach (string conditionStr in conditionsStr)
                {
                    string[] conditionStrs          = conditionStr.Split('=');
                    string   conditionAttributeName = conditionStrs[0];

                    bool isNot = false;

                    if (conditionAttributeName.EndsWith("!"))
                    {
                        isNot = true;
                        conditionAttributeName = conditionAttributeName.Replace("!", "");
                    }

                    string conditionAttributeValue = conditionStrs[1];

                    // Define the condition expression for retrieving records.
                    Microsoft.Xrm.Sdk.Query.ConditionExpression pagecondition = new Microsoft.Xrm.Sdk.Query.ConditionExpression();
                    pagecondition.AttributeName = conditionAttributeName;



                    if (conditionAttributeValue.StartsWith("(") && conditionAttributeValue.EndsWith(")"))
                    {
                        conditionAttributeValue = conditionAttributeValue.Replace("(", "").Replace(")", "");

                        pagecondition.Operator = isNot ? Microsoft.Xrm.Sdk.Query.ConditionOperator.NotIn : Microsoft.Xrm.Sdk.Query.ConditionOperator.In;

                        foreach (var val in conditionAttributeValue.Split(','))
                        {
                            pagecondition.Values.Add(val);
                        }
                    }
                    else if (conditionAttributeValue.StartsWith("%") && conditionAttributeValue.EndsWith("%"))
                    {
                        pagecondition.Operator = isNot ? Microsoft.Xrm.Sdk.Query.ConditionOperator.NotLike : Microsoft.Xrm.Sdk.Query.ConditionOperator.Like;
                        pagecondition.Values.Add(conditionAttributeValue);
                    }
                    else if (conditionAttributeValue.StartsWith(">"))
                    {
                        object objConditionAttributeValue = AttributeManager.GetAttributeValueFromString(serviceOrgnization, entityName, conditionAttributeName, conditionAttributeValue.Replace("<", "").Replace(">", ""));
                        pagecondition.Operator = Microsoft.Xrm.Sdk.Query.ConditionOperator.GreaterEqual;
                        pagecondition.Values.Add(objConditionAttributeValue);
                    }
                    else if (conditionAttributeValue.StartsWith("<"))
                    {
                        object objConditionAttributeValue = AttributeManager.GetAttributeValueFromString(serviceOrgnization, entityName, conditionAttributeName, conditionAttributeValue.Replace("<", "").Replace(">", ""));
                        pagecondition.Operator = Microsoft.Xrm.Sdk.Query.ConditionOperator.LessEqual;
                        pagecondition.Values.Add(objConditionAttributeValue);
                    }
                    else
                    {
                        object objConditionAttributeValue = AttributeManager.GetAttributeValueFromString(serviceOrgnization, entityName, conditionAttributeName, conditionAttributeValue);
                        pagecondition.Operator = isNot ? Microsoft.Xrm.Sdk.Query.ConditionOperator.NotEqual : Microsoft.Xrm.Sdk.Query.ConditionOperator.Equal;
                        pagecondition.Values.Add(objConditionAttributeValue);
                    }

                    pagequery.Criteria.AddCondition(pagecondition);
                }
            }

            // Define the order expression to retrieve the records.
            if (!string.IsNullOrEmpty(orderBy))
            {
                orderBy = orderBy.ToLower();
                string[] orderByStrs = orderBy.Split(' ');

                string orderAttributeName = orderByStrs[0];


                string orderType = "desc";

                if (orderByStrs.Length > 1)
                {
                    orderType = (string.IsNullOrEmpty(orderByStrs[1]) || orderByStrs[1] != "asc") ? "desc" : "asc";
                }

                Microsoft.Xrm.Sdk.Query.OrderExpression order = new Microsoft.Xrm.Sdk.Query.OrderExpression();
                order.AttributeName = orderAttributeName;

                order.OrderType = (orderType == "desc") ? Microsoft.Xrm.Sdk.Query.OrderType.Ascending : Microsoft.Xrm.Sdk.Query.OrderType.Descending;

                pagequery.Orders.Add(order);
            }

            // pagequery.ColumnSet.AddColumns("name", "emailaddress1");
            //By Rasheed
            string[] columns = GetColumnSet(entityName, columnSet);
            pagequery.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(columns);
            // end by rasheed

            // Assign the pageinfo properties to the query expression.
            pagequery.PageInfo            = new Microsoft.Xrm.Sdk.Query.PagingInfo();
            pagequery.PageInfo.Count      = queryCount;
            pagequery.PageInfo.PageNumber = pageNumber;

            // The current paging cookie. When retrieving the first page,
            // pagingCookie should be null.
            pagequery.PageInfo.PagingCookie = pagingCookie;


            // Retrieve the page.
            retVal = serviceOrgnization.RetrieveMultiple(pagequery);


            //EntityCollectionCached.Add(uniqueRecordString, retVal);
            return(retVal);
        }
 public void OnPreCreate(
     Entities.IAccountTarget account,
     [Kipon.Xrm.Attributes.Admin] Microsoft.Xrm.Sdk.IOrganizationService adminOrgService,
     Microsoft.Xrm.Sdk.IOrganizationService orgService)
 {
 }
 public WastePermitsCrmServiceContext(Microsoft.Xrm.Sdk.IOrganizationService service) :
     base(service)
 {
 }