Exemplo n.º 1
0
        public void Process(JObject command, Context context)
        {
            var entity  = command["#cds-update-data"] ?? command["entity"];
            var source  = command["source"];
            var map     = command["map"];
            var idfield = command["id-field"];

            if (entity == null)
            {
                return;
            }
            if (source == null)
            {
                return;
            }
            if (idfield == null)
            {
                return;
            }

            CDSConnection cdsConnection = CDSConnection.FromCommand(command, context);

            if (cdsConnection == null)
            {
                return;
            }

            JArray set = (JArray)context.Fetch(source.ToString());

            var entities = CDSConnection.ConvertToCDSEntities(entity.ToString(), set, (JArray)map, cdsConnection);

            this.UpdateRecords(entities, idfield.ToString(), cdsConnection);
        }
Exemplo n.º 2
0
        public void Process(JObject command, Context context)
        {
            var entity = command["#cds-import-data"];

            if (entity == null)
            {
                entity = command["entity"].ToString();
            }
            string source = command["source"].ToString();
            JArray map    = (JArray)command["map"];

            CDSConnection cdsConnection = CDSConnection.FromCommand(command, context);

            if (cdsConnection == null)
            {
                return;
            }

            JArray set = (JArray)context.Fetch(source);
            //this._context = context;

            var entities = CDSConnection.ConvertToCDSEntities(entity.ToString(), set, map, cdsConnection);

            this.CreateRecords(entities, cdsConnection);
        }
Exemplo n.º 3
0
        public void Process(JObject command, Context context)
        {
            this._cdsConnection = CDSConnection.FromCommand(command, context);
            if (this._cdsConnection == null)
            {
                return;
            }

            this.CreateField(command);
        }
Exemplo n.º 4
0
        public void Process(JObject command, Context context)
        {
            var entity = JSONUtil.GetToken(command, "#cds-retrieve-data");

            if (entity == null)
            {
                entity = JSONUtil.GetToken(command, "entity");
            }
            if (entity == null)
            {
                return;
            }

            //string optionset = null;
            //if (entity.Length == 0) { optionset = CommandEngine.GetCommandArgument(command, "Option Set"); }
            string into = CommandEngine.GetCommandArgument(command, "into");
            //string env = CommandEngine.GetCommandArgument(command, "env");

            CDSConnection cdsConnection = CDSConnection.FromCommand(command, context);

            if (cdsConnection == null)
            {
                return;
            }

            ColumnSet columns = new ColumnSet(true);

            if (command["fields"] != null)
            {
                string fieldlist = command["fields"].ToString();
                if (fieldlist.Length > 0)
                {
                    List <string> fields = fieldlist.Split(',').Select(p => p.Trim()).ToList();
                    columns = new ColumnSet(fields.ToArray());
                }
            }

            //var cdsConnection = (CDSConnection)context.GetConnection(env);

            //if (optionset == null)
            //{
            Console.WriteLine("Loading CDS Entity Data {0} into {1}", entity, into);

            var sub = cdsConnection.RetrieveEntityData(entity.ToString(), columns);

            context.Store(into, sub);
            //}
            //else
            //{
            //Console.WriteLine("Loading CDS OptionSet {0} into {1}", entity, into);

            //    var sub = cdsConnection.RetrieveOptionSet(entity, optionset);
            //    context.Store(into, sub);
            //}
        }
Exemplo n.º 5
0
        public static CDSConnection FromCommand(JToken command, Context context)
        {
            var config        = command["env"];
            var cdsConnection = new CDSConnection(config);

            if (cdsConnection == null)
            {
                Console.WriteLine("No environment configuration information available. Aborting operation."); return(null);
            }
            return(cdsConnection);
        }
        private void Import(string solutionPath, CDSConnection cdsConnection, Context context)
        {
            byte[] fileBytes = File.ReadAllBytes(solutionPath);

            ImportSolutionRequest impSolReqWithMonitoring = new ImportSolutionRequest()
            {
                CustomizationFile = fileBytes,
                ImportJobId       = Guid.NewGuid()
            };

            Console.WriteLine($"Importing {solutionPath}");

            cdsConnection.Execute(impSolReqWithMonitoring);

            var job = cdsConnection.Retrieve("importjob",
                                             impSolReqWithMonitoring.ImportJobId, new ColumnSet(new System.String[] { "data", "solutionname" }));

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.LoadXml(job["data"].ToString()); // check

            String ImportedSolutionName =
                doc.SelectSingleNode("//solutionManifest/UniqueName").InnerText;

            String SolutionImportResult =
                doc.SelectSingleNode("//solutionManifest/result/@result").Value;

            Console.WriteLine("Report from the ImportJob data");
            Console.WriteLine("Solution Unique name: {0}", ImportedSolutionName);
            Console.WriteLine("Solution Import Result: {0}", SolutionImportResult);
            Console.WriteLine("");

            System.Xml.XmlNodeList optionSets = doc.SelectNodes("//optionSets/optionSet");

            foreach (System.Xml.XmlNode node in optionSets)
            {
                string OptionSetName = node.Attributes["LocalizedName"].Value;
                string result        = node.FirstChild.Attributes["result"].Value;

                if (result == "success")
                {
                    Console.WriteLine("{0} result: {1}", OptionSetName, result);
                }
                else
                {
                    string errorCode = node.FirstChild.Attributes["errorcode"].Value;
                    string errorText = node.FirstChild.Attributes["errortext"].Value;

                    Console.WriteLine("{0} result: {1} Code: {2} Description: {3}", OptionSetName,
                                      result, errorCode, errorText);
                }
            }
        }
Exemplo n.º 7
0
        public void CreateRecords(List <Entity> cdsEntities, CDSConnection cdsConnection)
        {
            var num = cdsEntities.Count;
            var i   = 0;

            foreach (var item in cdsEntities)
            {
                //Entity cdsEntity = new Entity(item.LogicalName);
                i++;

                Console.Write($"Adding record {i} of {num}...");
                cdsConnection.Create(item);
                Console.WriteLine("Added." + JSONUtil.SingleLine(JArray.FromObject(item.Attributes)));
            }
        }
Exemplo n.º 8
0
        public void Process(JObject command, Context context)
        {
            string    entityName = command["entity"].ToString();
            string    id         = command["id"].ToString();
            Guid      recordId   = Guid.Parse(id);
            ColumnSet columnSet  = new ColumnSet(true);
            string    into       = command["into"].ToString();
            string    env        = Connections.JSONUtil.GetText(command, "env");

            var cdsConnection = new CDSConnection(env);

            var entity = cdsConnection.Retrieve(entityName, recordId, columnSet);

            var jtEntity = JToken.FromObject(entity);

            context.Store(into, jtEntity);
        }
Exemplo n.º 9
0
        public void Process(JObject command, Context context)
        {
            var config = command["config"];

            if (config == null)
            {
                return;
            }
            var joConfig = context.FindItemByName(config.ToString());

            this._cdsConnection = new CDSConnection(joConfig);
            if (this._cdsConnection == null)
            {
                return;
            }

            this.CreateFields(command, context);
        }
Exemplo n.º 10
0
        public void UpdateRecords(List <Entity> cdsEntities, string idfield, CDSConnection cdsConnection)
        {
            foreach (var item in cdsEntities)
            {
                //Entity cdsEntity = new Entity(item.LogicalName);

                if (item.Contains(idfield) == false)
                {
                    continue;
                }

                var id = item[idfield].ToString();
                item.Id = Guid.Parse(id);

                Console.Write("Updating record...");
                cdsConnection.Update(item);
                Console.WriteLine("Updated.");
            }
        }
        public void Process(JObject command, Context context)
        {
            var source = command["#cds-import-solution"];

            if (source == null)
            {
                source = command["source"];
            }

            //source = context.ReplaceVariables(source);

            CDSConnection cdsConnection = CDSConnection.FromCommand(command, context);

            if (cdsConnection == null)
            {
                return;
            }

            this.Import(source.ToString(), cdsConnection, context);
        }
Exemplo n.º 12
0
 public void SetConnection(CDSConnection cdsConnection)
 {
     this._cdsConnection = cdsConnection;
 }
Exemplo n.º 13
0
        public static List <Entity> ConvertToCDSEntities(string entityName, JArray data, JArray map, CDSConnection cdsConnection)
        {
            var result = new List <Entity>();

            var em = cdsConnection.GetEntityMetadata(entityName);

            if (em == null)
            {
                Console.WriteLine("Unable to load entity metadata for " + entityName + " - skipping.");
                return(null);
            }

            foreach (var item in data)
            {
                Entity cdsEntity = new Entity(entityName);
                var    record    = (JObject)item;

                foreach (var field in record)
                {
                    string targetName = DetermineTargetName(field.Key, map, record);
                    if (targetName == null)
                    {
                        continue;
                    }

                    var atr = em.Attributes.FirstOrDefault(a => a.LogicalName == targetName);
                    if (atr == null)
                    {
                        continue;
                    }

                    var atrVal = ConvertToAttribute(atr, record[field.Key]);
                    if (atrVal == null)
                    {
                        continue;
                    }
                    cdsEntity.Attributes.Add(targetName, atrVal);
                }

                result.Add(cdsEntity);
            }

            return(result);
        }