Esempio n. 1
0
        public TResult <string> CreateComosDeviceByWebUID(CWriteValueCollection values, string projectname, string workinglayer, string language, string owner, string cdev, string user, string desc)
        {
            m_ComosSession.SetCurrentUser(user);
            m_ComosSession.SetCurrentProjectAndWorkingOverlay(projectname, workinglayer, language);

            string newuid  = m_ComosSession.CreateComosDeviceByWebUID(owner, cdev, desc);
            bool   created = false;

            foreach (var att in values.Values)
            {
                att.WebSystemUID = newuid;
            }

            if (newuid != "")
            {
                var result = m_ComosSession.WriteComosValues(values);
                created = true;
            }

            return(new TResult <string>
            {
                data = newuid,
                Status = created
            });
        }
Esempio n. 2
0
        public async Task <bool> WriteComosValues(CWriteValueCollection collection, string servername, string user, string project, string workinglayer, string language)
        {
            using (var client = new HttpClient())
            {
                try
                {
                    client.BaseAddress = new Uri($"{servername}/v1/WriteComosValues/{user}/{WebUtility.UrlEncode(project)}/{WebUtility.UrlEncode(workinglayer)}/{language}");

                    // We want the response to be JSON.
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    // Build up the data to POST.
                    var json = JsonConvert.SerializeObject(collection);

                    var response = await client.PostAsync(client.BaseAddress.AbsoluteUri,
                                                          new StringContent(json, Encoding.UTF8, "application/json")).ConfigureAwait(true);

                    if (!response.IsSuccessStatusCode)
                    {
                        throw new Exception($"Error al actualizar los valores. Code [{response.StatusCode}]");
                    }

                    var result = await response.Content.ReadAsStringAsync()
                                 .ContinueWith(task => JsonConvert.DeserializeObject <TResult <CWriteValueResult[]> >(task.Result));

                    return(result.Status);
                }
                catch (Exception ex)
                {
                    throw new Exception("Error al guardar modificacion en Comos: " + ex.Message);
                }
            }
        }
Esempio n. 3
0
        public TResult <string> CreateComosDeviceByWebUID(CWriteValueCollection values, string projectname, string workinglayer, string language, string owner, string cdev, string user, string desc)
        {
            try
            {
                //object comosobject = System.Web.HttpContext.Current.ApplicationInstance.Application["ComosAPI"];
                //IBRServiceContracts.IServiceContract m_ComosAPIService = (IBRServiceContracts.IServiceContract)comosobject;
                IServiceContract m_ComosAPIService = GetComosAPI();
                if (string.IsNullOrEmpty(workinglayer))
                {
                    LogHandler.WriteLog("Service.cs: WriteComosValues: Bad request workinglayer argument is empty", EventLogEntryType.Error);
                    return(new TResult <string>()
                    {
                        data = null,
                        Message = "Working Layer is empty",
                        Status = false,
                    });
                }

                return(m_ComosAPIService.CreateComosDeviceByWebUID(values, projectname, workinglayer, language, owner, cdev, user, desc));
            }
            catch (Exception ex)
            {
                LogHandler.WriteLog("Service.cs: CreateComosDeviceByWebUID.  " + ex.Message, EventLogEntryType.Error);
                return(new TResult <string>()
                {
                    Status = false,
                    data = null,
                    Message = ex.Message,
                });
            }
        }
Esempio n. 4
0
 public TResult <CWriteValueResult[]> WriteComosValuesTest2(CWriteValueCollection values, string user, string projectname, string workinglayer, string language)
 {
     return(new TResult <CWriteValueResult[]>()
     {
         Status = false,
         data = null,
         Message = "Test:" + user + " " + projectname + " " + workinglayer + " " + language,
     });
 }
Esempio n. 5
0
 public TResult <CWriteValueResult[]> WriteComosValues(CWriteValueCollection values, string user, string projectname, string workinglayer, string language)
 {
     try
     {
         Log.WriteLog("WriteComosValues: Set Current User = {0}", user);
         if (!m_ComosSession.SetCurrentUser(user))
         {
             Log.WriteLog("WriteComosValues: Can not set user.", System.Diagnostics.EventLogEntryType.Warning);
             return(new TResult <CWriteValueResult[]>()
             {
                 Status = false,
                 data = null,
                 Message = "Failed settings current user",
             });
         }
         Log.WriteLog("WriteComosValues: SetCurrentProjectAndWorkingOverlay = {0} - {1} - {2}", projectname, workinglayer, language);
         if (!m_ComosSession.SetCurrentProjectAndWorkingOverlay(projectname, workinglayer, language))
         {
             Log.WriteLog("WriteComosValues: Can not set project and working layer.", System.Diagnostics.EventLogEntryType.Warning);
             return(new TResult <CWriteValueResult[]>()
             {
                 Status = false,
                 data = null,
                 Message = "Failed settings working layer",
             });
         }
         Log.WriteLog("WriteComosValues: WriteComosValues");
         Log.WriteLog(string.Format("\tUser = {0}, projectname = {1}, workinglayer={2}, language={3}", user, projectname, workinglayer, language), System.Diagnostics.EventLogEntryType.Information);
         foreach (var att in values.Values)
         {
             Log.WriteLog(string.Format("\t\tSystemUID = {0}, NestedName = {1}, New={2}, Old={3}",
                                        att.WebSystemUID, att.NestedName, att.NewValue, att.OldValue), System.Diagnostics.EventLogEntryType.Information);
         }
         var result = m_ComosSession.WriteComosValues(values);
         return(new TResult <CWriteValueResult[]>()
         {
             Status = true,
             data = result.ToArray(),
         });
     }
     catch (Exception ex)
     {
         Log.WriteLog("WriteComosValues: Exception = {0}, Stack = {1}", ex.Message, ex.StackTrace);
         return(new TResult <CWriteValueResult[]>()
         {
             Status = false,
             data = null,
             Message = ex.Message,
         });
     }
 }
Esempio n. 6
0
        public TResult <CWriteValueResult[]> WriteComosValues(CWriteValueCollection values, string user, string projectname, string workinglayer, string language)
        {
            try
            {
                //object comosobject = System.Web.HttpContext.Current.ApplicationInstance.Application["ComosAPI"];
                //IBRServiceContracts.IServiceContract m_ComosAPIService = (IBRServiceContracts.IServiceContract)comosobject;
                IServiceContract m_ComosAPIService = GetComosAPI();
                if (string.IsNullOrEmpty(workinglayer))
                {
                    LogHandler.WriteLog("Service.cs: WriteComosValues: Bad request workinglayer argument is empty", EventLogEntryType.Error);
                    return(new TResult <CWriteValueResult[]>()
                    {
                        data = null,
                        Message = "Working Layer is empty",
                        Status = false,
                    });
                }

                LogHandler.WriteLog("Service.cs: WriteComosValues:", EventLogEntryType.Information);
                LogHandler.WriteLog(string.Format("\tUser = {0}, projectname = {1}, workinglayer={2}, language={3}", user, projectname, workinglayer, language), EventLogEntryType.Information);
                foreach (var att in values.Values)
                {
                    LogHandler.WriteLog(string.Format("\t\tSystemUID = {0}, NestedName = {1}, New={2}, Old={3}",
                                                      att.WebSystemUID, att.NestedName, att.NewValue, att.OldValue), EventLogEntryType.Information);
                }
                var result = m_ComosAPIService.WriteComosValues(values, user, projectname, workinglayer, language);
                return(result);
            }
            catch (Exception ex)
            {
                LogHandler.WriteLog("Service.cs: WriteComosValues.  " + ex.Message, EventLogEntryType.Error);
                return(new TResult <CWriteValueResult[]>()
                {
                    Status = false,
                    data = null,
                    Message = ex.Message,
                });
            }
        }