Beispiel #1
0
 public TextTO update(String jsonDictionaryFieldsAndValues, String recordId, String file)
 {
     try
     {
         Dictionary <String, String> deserializedDict = JsonUtils.Deserialize <Dictionary <String, String> >(jsonDictionaryFieldsAndValues);
         VistaFieldTO[] fieldArray = new VistaFieldTO[deserializedDict.Count];
         int            counter    = 0;
         foreach (String key in deserializedDict.Keys)
         {
             VistaFieldTO current = new VistaFieldTO()
             {
                 number = key, value = deserializedDict[key]
             };
             fieldArray[counter] = current;
         }
         VistaRecordTO record = new VistaRecordTO()
         {
             fields = fieldArray, file = new VistaFileTO()
             {
                 number = file
             }, iens = recordId
         };
         return(create(record));
     }
     catch (Exception exc)
     {
         return(new TextTO()
         {
             fault = new FaultTO(exc)
         });
     }
 }
Beispiel #2
0
        public TextTO update(String siteId, String vistaFile, String iens, Dictionary <String, String> fieldsAndValues)
        {
            VistaRecordTO recordToUpdate = new VistaRecordTO()
            {
                file = new VistaFileTO()
                {
                    number = vistaFile
                },
                iens   = iens,
                siteId = siteId,
                fields = new VistaFieldTO[fieldsAndValues.Count]
            };

            IList <VistaFieldTO> fieldsToSet = new List <VistaFieldTO>();

            foreach (String key in fieldsAndValues.Keys)
            {
                fieldsToSet.Add(new VistaFieldTO()
                {
                    number = key, value = fieldsAndValues[key]
                });
            }

            fieldsToSet.CopyTo(recordToUpdate.fields, 0);

            return(JsonUtils.Deserialize <TextTO>(_client.postOrPut(HttpRequestType.PUT, JsonUtils.Serialize <VistaRecordTO>(recordToUpdate))));
        }
Beispiel #3
0
        public void testGetSubfile()
        {
            VistaRecordTO result = _dao.read("901", "8994.51", "1,13,");

            Assert.IsNull(result.fault);
            Assert.IsNotNull(result.fields);
            foreach (VistaFieldTO field in result.fields)
            {
                System.Console.WriteLine(field.number + " - " + field.value);
            }
        }
Beispiel #4
0
        public TextTO update(VistaRecordTO record)
        {
            TextTO result = new TextTO();

            if (record == null || record.fields == null || record.fields.Length < 1)
            {
                result.fault = new FaultTO("The record must have at least 1 field");
            }
            if (record.file == null || String.IsNullOrEmpty(record.file.number))
            {
                result.fault = new FaultTO("You must specify the file number in which this record should be created");
            }
            foreach (VistaFieldTO field in record.fields)
            {
                if (field == null || String.IsNullOrEmpty(field.number) || String.IsNullOrEmpty(field.value))
                {
                    result.fault = new FaultTO("All fields must have a number and value");
                    break;
                }
            }
            if (String.IsNullOrEmpty(record.iens))
            {
                result.fault = new FaultTO("You must supply the IENS string for the record being updated");
            }

            if (result.fault != null)
            {
                return(result);
            }

            try
            {
                Dictionary <String, String> keysAndValues = new Dictionary <string, string>();
                foreach (VistaFieldTO field in record.fields)
                {
                    keysAndValues.Add(field.number, field.value);
                }
                CrudOperation co = new ToolsApi().update(mySession.ConnectionSet.BaseConnection, keysAndValues, record.iens, record.file.number);
                //result.rpc = new RpcTO(co.RPC);
                result.text = "OK";
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }
            return(result);
        }
Beispiel #5
0
        public VistaRecordTO read(String recordId, String fields, String file)
        {
            VistaRecordTO result = new VistaRecordTO();

            if (String.IsNullOrEmpty(fields))
            {
                result.fault = new FaultTO("Missing fields");
            }
            else if (String.IsNullOrEmpty(file))
            {
                result.fault = new FaultTO("Missing file");
            }

            if (result.fault != null)
            {
                return(result);
            }

            try
            {
                CrudOperation co = new ToolsApi().read(mySession.ConnectionSet.BaseConnection, recordId, fields, file);
                Dictionary <String, String> fieldsAndValues = (Dictionary <String, String>)co.Result;
                //result.rpc = new RpcTO(co.RPC);
                result.file = new VistaFileTO()
                {
                    number = file
                };
                result.ien    = recordId;
                result.siteId = mySession.ConnectionSet.BaseConnection.DataSource.SiteId.Id;
                result.fields = new VistaFieldTO[fieldsAndValues.Count];
                String[] allKeys = new String[fieldsAndValues.Count];
                fieldsAndValues.Keys.CopyTo(allKeys, 0);
                for (int i = 0; i < allKeys.Length; i++)
                {
                    result.fields[i] = new VistaFieldTO()
                    {
                        number = allKeys[i], value = fieldsAndValues[allKeys[i]]
                    };
                }
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }
            return(result);
        }
Beispiel #6
0
        public Stream create(System.IO.Stream postBody, String siteId, String pwd)
        {
            if (!String.Equals(pwd, _mySession.MdwsConfiguration.AllConfigs["CRUD"]["Password"]))
            {
                return(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(JsonUtils.Serialize <TextTO>(new TextTO()
                {
                    fault = new FaultTO("Incorrect password")
                }))));
            }
            if (!String.Equals("true", _mySession.MdwsConfiguration.AllConfigs["CRUD"]["EnableCreate"], StringComparison.CurrentCultureIgnoreCase))
            {
                return(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(JsonUtils.Serialize <TextTO>(new TextTO()
                {
                    fault = new FaultTO("Create not enabled")
                }))));
            }

            MySession     newSession       = new MySession();
            VistaRecordTO deserializedBody = null;

            try
            {
                String body = "";
                using (StreamReader sr = new StreamReader(postBody))
                {
                    body = sr.ReadToEnd();
                }
                deserializedBody = JsonUtils.Deserialize <VistaRecordTO>(body);
            }
            catch (Exception exc)
            {
                TextTO fault = new TextTO()
                {
                    fault = new FaultTO(exc)
                };
                return(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(JsonUtils.Serialize <TextTO>(fault))));
            }

            TextTO result = (TextTO)QueryTemplate.getQuery(QueryType.STATELESS, siteId)
                            .execute(newSession, new Func <VistaRecordTO, TextTO>(new ToolsLib(newSession).create),
                                     new object[] { deserializedBody });

            return(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(JsonUtils.Serialize <TextTO>(result))));
        }
Beispiel #7
0
        public Stream read(String siteId, String file, String recordId, String fields, String pwd)
        {
            if (!String.Equals(pwd, _mySession.MdwsConfiguration.AllConfigs["CRUD"]["Password"]))
            {
                return(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(JsonUtils.Serialize <VistaRecordTO>(new VistaRecordTO()
                {
                    fault = new FaultTO("Incorrect password")
                }))));
            }
            if (!String.Equals("true", _mySession.MdwsConfiguration.AllConfigs["CRUD"]["EnableRead"], StringComparison.CurrentCultureIgnoreCase))
            {
                return(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(JsonUtils.Serialize <VistaRecordTO>(new VistaRecordTO()
                {
                    fault = new FaultTO("Read not enabled")
                }))));
            }

            MySession     newSession = new MySession();
            VistaRecordTO result     = (VistaRecordTO)QueryTemplate.getQuery(QueryType.STATELESS, siteId)
                                       .execute(newSession, new Func <String, String, String, VistaRecordTO>(new ToolsLib(newSession).read),
                                                new object[] { recordId, fields, file });

            return(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(JsonUtils.Serialize <VistaRecordTO>(result))));
        }