private LoadAppResult convertEntityToApplicationObject(EntityCollection annotationList)
        {
            LoadAppResult appObject = null;

            if (annotationList.Entities.Count > 0)
            {
                // get Template File
                appObject = new LoadAppResult();
                var filteredList = annotationList.Entities.Where(item => item.Attributes["filename"].ToString().Contains("Template")).ToList();
                if (filteredList != null && filteredList.Count > 0)
                {
                    appObject.xlstemplate  = Convert.FromBase64String(filteredList[0].Attributes["documentbody"].ToString());
                    appObject.templateName = filteredList[0].Attributes["filename"].ToString();
                }

                // get config File
                filteredList = annotationList.Entities.Where(item => item.Attributes["filename"].ToString().Contains("AppDefinition")).ToList();
                if (filteredList != null && filteredList.Count > 0)
                {
                    appObject.config = Convert.FromBase64String(filteredList[0].Attributes["documentbody"].ToString());
                }

                // get schema File
                filteredList = annotationList.Entities.Where(item => item.Attributes["filename"].ToString().Contains("ExternalSchema")).ToList();
                if (filteredList != null && filteredList.Count > 0)
                {
                    appObject.schema = Convert.FromBase64String(filteredList[0].Attributes["documentbody"].ToString());
                }
            }
            return(appObject);
        }
        public ApplicationObject LoadApplication(Guid uniqueId, Guid appId)
        {
            ApplicationObject App = null;

            MSCRMAdapterController CRMAdapter    = new MSCRMAdapterController();
            LoadAppResult          loadAppResult = CRMAdapter.LoadApplication(uniqueId, appId);

            if (loadAppResult != null)
            {
                App              = new ApplicationObject();
                App.Config       = loadAppResult.config;
                App.Schema       = loadAppResult.schema;
                App.Template     = loadAppResult.xlstemplate;
                App.TemplateName = loadAppResult.templateName;
            }

            return(App);
        }
        public LoadAppResult LoadApplication(Guid uniqueId, Guid appId)
        {
            LoadAppResult appObject = null;

            if (appId == Guid.Empty)
            {
                appId = getAppIdbyAppUniqueId(uniqueId);
            }

            if (appId != Guid.Empty)
            {
                IOrganizationService service = CRMHelper.ConnectToMSCRM();
                QueryExpression      query   = new QueryExpression("annotation");
                query.ColumnSet = new ColumnSet(new string[] { "filename", "documentbody" });
                query.Criteria.AddCondition("objectid", ConditionOperator.Equal, appId);
                appObject = convertEntityToApplicationObject(service.RetrieveMultiple(query));
            }
            return(appObject);
        }