public override void Execute(List <DataCompareItem> addItems, List <DataCompareItem> updateItems, List <DataCompareItem> deleteItems, IDataSourceReader reader, IDataSynchronizationStatus status)
        {
            DataSourceReader = reader as PipedriveDatasourceReader;

            if (DataSourceReader != null)
            {
                Mapping = new DataSchemaMapping(SchemaMap, DataCompare);

                WebRequestHelper = DataSourceReader.GetWebRequestHelper();
                DatasourceInfo   = DataSourceReader.GetDatasourceInfo();
                DataSchema       = DatasourceInfo.GetPipedriveDataSchema(WebRequestHelper);

                //Process the Changed Items
                if (addItems != null && status.ContinueProcessing)
                {
                    AddItems(addItems, status);
                }
                if (updateItems != null && status.ContinueProcessing)
                {
                    UpdateItems(updateItems, status);
                }
                if (deleteItems != null && status.ContinueProcessing)
                {
                    DeleteItems(deleteItems, status);
                }
            }
        }
        public ReportInfo(ReportDocument reportDocument)
        {
            ReportName = reportDocument.Name;
            FileName   = reportDocument.FileName;

            Connections = new ConnectionInfo[reportDocument.DataSourceConnections.Count];
            for (var i = 0; i < reportDocument.DataSourceConnections.Count; i++)
            {
                var conn = reportDocument.DataSourceConnections[i];
                Connections[i] = new ConnectionInfo();
                Connections[i].DatabaseName           = conn.DatabaseName;
                Connections[i].UsesIntegratedSecurity = conn.IntegratedSecurity;
                Connections[i].ServerName             = conn.ServerName;
                Connections[i].Username = conn.UserID;
                Connections[i].Password = conn.Password;
            }

            Datasources = new DatasourceInfo[reportDocument.Database.Tables.Count];
            for (var i = 0; i < reportDocument.Database.Tables.Count; i++)
            {
                var table = reportDocument.Database.Tables[i];
                Datasources[i]          = new DatasourceInfo();
                Datasources[i].Name     = table.Name;
                Datasources[i].Location = table.Location;
            }
        }
        public override void DeleteItems(List <DataCompareItem> items, IDataSynchronizationStatus status)
        {
            if (items != null && items.Count > 0)
            {
                int currentItem = 0;

                foreach (var item in items)
                {
                    if (!status.ContinueProcessing)
                    {
                        break;
                    }

                    var itemInvariant = new DataCompareItemInvariant(item);

                    //Example: Get the item ID from the Target Identifier Store
                    var item_id = itemInvariant.GetTargetIdentifier <int>();

                    try
                    {
                        //Call the Automation BeforeDeleteItem (Optional only required if your supporting Automation Item Events)
                        Automation?.BeforeDeleteItem(this, itemInvariant, item_id);

                        if (itemInvariant.Sync)
                        {
                            #region Delete Item

                            var result = WebRequestHelper.DeleteRequestAsJson(null, DatasourceInfo.GetPipedriveItemEndpointUrl(item_id));

                            #endregion

                            //Call the Automation AfterDeleteItem
                            Automation?.AfterDeleteItem(this, itemInvariant, item_id);
                        }

                        ClearSyncStatus(item); //Clear the Sync Flag on Processed Rows
                    }
                    catch (WebException e)
                    {
                        Automation?.ErrorItem(this, itemInvariant, item_id, e);
                        HandleError(status, e);
                    }
                    catch (SystemException e)
                    {
                        Automation?.ErrorItem(this, itemInvariant, item_id, e);
                        HandleError(status, e);
                    }
                    finally
                    {
                        status.Progress(items.Count, ++currentItem); //Update the Sync Progress
                    }
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Copy constructor. Does a deep copy.
 /// </summary>
 /// <param name="src">Initialize with the values in this object.</param>
 public DatasourceInfo(DatasourceInfo src)
 {
     type             = src.type;
     name             = src.name;
     filename         = src.filename;
     schemaFilename   = src.schemaFilename;
     sqlDriverInfo    = src.sqlDriverInfo;
     connectionString = src.connectionString;
     username         = src.username;
     password         = src.password;
     securitytoken    = src.securitytoken;
     podFilename      = src.podFilename;
     encoding         = src.encoding;
     restful          = src.restful;
 }
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (DatasourceInfo == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "DatasourceInfo");
     }
     if (DatasourceInfo != null)
     {
         DatasourceInfo.Validate();
     }
     if (DatasourceSetInfo != null)
     {
         DatasourceSetInfo.Validate();
     }
 }
 /// <summary>
 /// 拷贝的构造函数。
 /// </summary>
 /// <param name="dataSourceInfo">DataSourceInfo对象实例。</param>
 /// <exception cref="ArgumentNullException">参数 dataSourceInfo 为空时抛出异常。</exception>
 public DatasourceInfo(DatasourceInfo dataSourceInfo)
 {
     if (dataSourceInfo == null)
     {
         throw new ArgumentNullException("dataSourceInfo");
     }
     this.CoordUnit = dataSourceInfo.CoordUnit;
     this.Description = dataSourceInfo.Description;
     this.DistanceUnit = dataSourceInfo.DistanceUnit;
     this.EngineType = dataSourceInfo.EngineType;
     this.Name = dataSourceInfo.Name;
     if (dataSourceInfo.PrjCoordSys != null)
     {
         this.PrjCoordSys = new PrjCoordSys(dataSourceInfo.PrjCoordSys);
     }
 }
Esempio n. 7
0
        public IDatasource Build(DatasourceInfo dsInfo)
        {
            IDatasource retVal;

            switch (dsInfo.TypeId)
            {
            case "Superplacar3DaysDatasource":
                retVal = new Superplacar3DaysDatasource();
                break;

            default:
                retVal = new DummyDatasource();
                break;
            }

            retVal.Configure(dsInfo.Config);
            return(retVal);
        }
        public override void UpdateItems(List <DataCompareItem> items, IDataSynchronizationStatus status)
        {
            if (items != null && items.Count > 0)
            {
                int currentItem = 0;

                foreach (var item in items)
                {
                    if (!status.ContinueProcessing)
                    {
                        break;
                    }

                    var itemInvariant = new DataCompareItemInvariant(item);

                    //Example: Get the item ID from the Target Identifier Store
                    var item_id = itemInvariant.GetTargetIdentifier <int>();

                    try
                    {
                        //Call the Automation BeforeUpdateItem
                        Automation?.BeforeUpdateItem(this, itemInvariant, item_id);

                        if (itemInvariant.Sync)
                        {
                            #region Update Item

                            //Get the Target Item Data
                            var targetItem       = UpdateItemToDictionary(Mapping, itemInvariant);
                            var targetItemToSend = new Dictionary <string, object>();

                            foreach (var k in targetItem.Keys)
                            {
                                var val = targetItem[k];

                                var pdsi = DataSchema[k];
                                targetItemToSend[pdsi.Key] = pdsi.Parser.ConvertValue(val);
                            }

                            if (targetItemToSend.Any())
                            {
                                var json   = JsonConvert.SerializeObject(targetItemToSend, Formatting.None);
                                var result = WebRequestHelper.PutRequestAsJson(json, DatasourceInfo.GetPipedriveItemEndpointUrl(item_id));

                                //Call the Automation AfterUpdateItem
                                Automation?.AfterUpdateItem(this, itemInvariant, item_id);
                            }

                            #endregion
                        }

                        ClearSyncStatus(item); //Clear the Sync Flag on Processed Rows
                    }
                    catch (WebException e)
                    {
                        Automation?.ErrorItem(this, itemInvariant, item_id, e);
                        HandleError(status, e);
                    }
                    catch (SystemException e)
                    {
                        Automation?.ErrorItem(this, itemInvariant, item_id, e);
                        HandleError(status, e);
                    }
                    finally
                    {
                        status.Progress(items.Count, ++currentItem); //Update the Sync Progress
                    }
                }
            }
        }
        public void Output(string outputFormat, string outputPath)
        {
            // Generate the output
            var outBuffer = new StringBuilder();

            switch ((outputFormat ?? "print").ToUpper())
            {
            case "TAB":
                outBuffer.AppendFormat("{0}\t", ReportName);
                outBuffer.AppendFormat("{0}\t", FileName);

                for (var i = 0; i < MaxConnections; i++)
                {
                    ConnectionInfo conn = null;
                    if (i < Connections.Length)
                    {
                        conn = Connections[i];
                    }
                    outBuffer.AppendFormat("{0}\t", conn?.ServerName);
                    outBuffer.AppendFormat("{0}\t", conn?.DatabaseName);
                    outBuffer.AppendFormat("{0}\t", conn == null ? "" : (conn.UsesIntegratedSecurity ? "Yes" : "No"));
                    outBuffer.AppendFormat("{0}\t", conn?.Username);
                    outBuffer.AppendFormat("{0}\t", conn?.Password);
                }


                for (var i = 0; i < MaxDatasources; i++)
                {
                    DatasourceInfo datasource = null;
                    if (i < Datasources.Length)
                    {
                        datasource = Datasources[i];
                    }
                    outBuffer.AppendFormat("{0}\t", datasource?.Name);
                    outBuffer.AppendFormat("{0}\t", datasource?.Location);
                }

                // Remove the trailing \t and add an endline
                outBuffer.Length -= 1;
                outBuffer.AppendLine();
                break;

            default:
                outBuffer.AppendFormat("Report Name: {0}\n", ReportName);
                outBuffer.AppendFormat("File Name: {0}\n", FileName);

                if (Connections.Length > 0)
                {
                    for (var i = 0; i < Connections.Length; i++)
                    {
                        outBuffer.AppendFormat("Connection #{0}:\n", i + 1);
                        var conn = Connections[i];
                        outBuffer.AppendFormat("  Server Name: {0}\n", conn.ServerName);
                        outBuffer.AppendFormat("  Database Name: {0}\n", conn.DatabaseName);
                        outBuffer.AppendFormat("  Integrated Security: {0}\n", conn.UsesIntegratedSecurity ? "Yes" : "No");
                        outBuffer.AppendFormat("  Username: {0}\n", conn.Username);
                        outBuffer.AppendFormat("  Password: {0}\n", conn.Password);
                    }
                }
                else
                {
                    outBuffer.AppendFormat("No connections found\n");
                }

                if (Datasources.Length > 0)
                {
                    for (var i = 0; i < Datasources.Length; i++)
                    {
                        outBuffer.AppendFormat("Datasource #{0}:\n", i + 1);
                        var datasource = Datasources[i];
                        outBuffer.AppendFormat("  Name: {0}\n", datasource.Name);
                        outBuffer.AppendFormat("  Location: {0}\n", datasource.Location);
                    }
                }
                else
                {
                    outBuffer.AppendFormat("No datasources found\n");
                }

                break;
            }

            // Output the, uh, output
            if (string.IsNullOrEmpty(outputPath))
            {
                Console.Write(outBuffer.ToString());
            }
            else
            {
                if (!File.Exists(outputPath))
                {
                    File.WriteAllText(outputPath, GetHeader(outputFormat));
                }

                using (var strm = File.AppendText(outputPath))
                {
                    strm.Write(outBuffer.ToString());
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Create a CommandLine object from the command line passed to the program.
        /// </summary>
        /// <param name="args">The arguments passed to the program.</param>
        /// <returns>A CommandLine object populated from the args.</returns>
        public static CommandLine Factory(IList <string> args)
        {
            CommandLine rtn = new CommandLine(args[0], args[1]);

            string username = null, password = null, podFilename = null, encoding = null;

            for (int ind = 2; ind < args.Count; ind++)
            {
                string[] sa   = args[ind].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                string   cmd  = sa[0].Trim();
                string   name = sa.Length < 2 ? "" : sa[1].Trim();

                if (cmd == "-performance")
                {
                    rtn.NumReports = int.Parse(name);
                    continue;
                }

                if (cmd == "-threads")
                {
                    rtn.NumThreads = int.Parse(name);
                    continue;
                }

                if (cmd == "-verify")
                {
                    rtn.VerifyFlag = int.Parse(name);
                    continue;
                }

                if (cmd == "-launch")
                {
                    rtn.Launch = true;
                    continue;
                }

                if (cmd == "-basedir")
                {
                    rtn.BaseDirectory = args[++ind];
                    continue;
                }

                if (cmd == "-rest")
                {
                    if (rtn.Datasources.Count > 0)
                    {
                        rtn.Datasources[rtn.Datasources.Count - 1].restful = true;
                    }
                    continue;
                }

                if ((cmd == "-xml") || (cmd == "-xpath"))
                {
                    string filename       = args[++ind];
                    string schemaFilename = null;
                    int    split          = filename.IndexOf("=schema:");
                    if (split == -1)
                    {
                        schemaFilename = null;
                    }
                    else
                    {
                        schemaFilename = filename.Substring(split + 8).Trim();
                        filename       = filename.Substring(0, split).Trim();
                    }
                    DatasourceInfo.TYPE type = (cmd == "-rest" ? DatasourceInfo.TYPE.REST
                                                : (cmd == "-xpath" ? DatasourceInfo.TYPE.XPATH_1 : DatasourceInfo.TYPE.XML));
                    DatasourceInfo datasourceOn = new DatasourceInfo(name, filename, schemaFilename, username, password, podFilename, type);
                    rtn.Datasources.Add(datasourceOn);
                    username = password = podFilename = null;
                    continue;
                }

                if (cmd == "-odata")
                {
                    string         url          = args[++ind];
                    DatasourceInfo datasourceOn = new DatasourceInfo(name, url, null, username, password, podFilename, DatasourceInfo.TYPE.ODATA);
                    rtn.Datasources.Add(datasourceOn);
                    username = password = podFilename = null;
                    continue;
                }

                if (cmd == "-json")
                {
                    string         url          = args[++ind];
                    DatasourceInfo datasourceOn = new DatasourceInfo(name, url, null, encoding, DatasourceInfo.TYPE.JSON);
                    rtn.Datasources.Add(datasourceOn);
                    username = password = podFilename = null;
                    continue;
                }

                if (cmd == "-dataset")
                {
                    string         dataSetStr = args[++ind];
                    DatasourceInfo dsInfo     = new DatasourceInfo(name, dataSetStr, null, null, DatasourceInfo.TYPE.DATA_SET);
                    rtn.Datasources.Add(dsInfo);
                    username = password = podFilename = null;
                    continue;
                }


                bool isDb = false;

                if (cmd == "-sforce")
                {
                    string         url          = "https://login.salesforce.com";
                    DatasourceInfo datasourceOn = new DatasourceInfo(name, url, null, username, password, podFilename, DatasourceInfo.TYPE.SFORCE);
                    rtn.Datasources.Add(datasourceOn);
                    isDb     = true;
                    username = password = podFilename = null;
                }
                foreach (AdoDriverInfo di in AdoDriverInfo.AdoConnectors)
                {
                    if (cmd == "-" + di.Name)
                    {
                        if (((di.Name == "odbc") || (di.Name == "oledb")) && (IntPtr.Size != 4))
                        {
                            Console.Out.WriteLine("Warning - some ODBC & OleDB connectors only work in 32-bit mode.");
                        }

                        DatasourceInfo datasourceOn = new DatasourceInfo(name, di, args[++ind], username, password, podFilename, DatasourceInfo.TYPE.SQL);
                        rtn.Datasources.Add(datasourceOn);
                        isDb     = true;
                        username = password = podFilename = null;
                        break;
                    }
                }
                if (isDb)
                {
                    continue;
                }

                // assume this is a key=value
                string[] keyValue = args[ind].Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                if (keyValue.Length != 2)
                {
                    if (keyValue.Length == 1 && args[ind].EndsWith("="))
                    {
                        // We have a variable with the empty value.
                        keyValue = new string[2] {
                            keyValue[0], ""
                        };
                    }
                    else if (keyValue.Length < 2)
                    {
                        throw new ArgumentException(string.Format("Unknown option {0}", args[ind]));
                    }
                    else
                    {
                        // put the rest together.
                        string val = "";
                        for (int i = 1; i < keyValue.Length; i++)
                        {
                            val += keyValue[i];
                            if (i < keyValue.Length - 1)
                            {
                                val += '=';
                            }
                        }
                        keyValue = new string[2] {
                            keyValue[0], val
                        };
                    }
                }

                switch (keyValue[0])
                {
                case "locale":
                    rtn.Locale = keyValue[1];
                    break;

                case "version":
                    rtn.TemplateVersion = int.Parse(keyValue[1]);
                    break;

                case "username":
                    username = keyValue[1];
                    break;

                case "password":
                    password = keyValue[1];
                    break;

                case "pod":
                    podFilename = keyValue[1];
                    break;

                case "encoding":
                    encoding = keyValue[1];
                    break;

                default:
                    object value;
                    // may be a list
                    if (keyValue[1].IndexOf(',') != -1)
                    {
                        string[] tok   = keyValue[1].Split(new char[] { ',' });
                        IList    items = new ArrayList();
                        foreach (string elem in tok)
                        {
                            items.Add(ConvertValue(elem, rtn.Locale));
                        }
                        value = items;
                    }
                    else
                    {
                        value = ConvertValue(keyValue[1], rtn.Locale);
                    }
                    rtn.Parameters.Add(keyValue[0], value);
                    break;
                }
            }

            return(rtn);
        }
Esempio n. 11
0
        public bool UpdateDatasourceInfo(string datasourceName, DatasourceInfo newDatasourceInfo)
        {
#if NET40
            if (string.IsNullOrWhiteSpace(datasourceName))
            {
                throw new ArgumentNullException("datasourceName", Resources.ArgumentIsNotNull);
            }
#else
            if(string.IsNullOrEmpty(datasourceName))
            {
                throw new ArgumentNullException("datasourceName", Resources.ArgumentIsNotNull);
            }
#endif
            if (newDatasourceInfo == null)
            {
                throw new ArgumentNullException("newDataSourceInfo", Resources.ArgumentIsNotNull);
            }
            string baseUri = string.Format("{0}/data/datasources/{1}.json?",
                this._serviceUrl, HttpUtility.UrlEncode(datasourceName));
            string result = SynchHttpRequest.GetRequestString(baseUri, HttpRequestMethod.PUT, JsonConvert.SerializeObject(newDatasourceInfo));
            Succeed succeed = JsonConvert.DeserializeObject<Succeed>(result);
            return succeed.succeed;
        }
Esempio n. 12
0
 /// <summary>
 /// 用新的数据源信息更新原来的数据源信息。
 /// </summary>
 /// <param name="datasourceName">数据源名称,必设参数。</param>
 /// <param name="newDatasourceInfo">新的数据源信息。</param>
 /// <returns>数据源信息更新是否成功。</returns>
 /// <exception cref="ArgumentNullException">参数 datasourceName 为空时抛出异常。</exception>
 /// <exception cref="SuperMap.Connector.Utility.ServiceException">服务端处理错误时抛出异常。</exception>
 /// <remarks>
 /// 只能对数据源信息中的 CoordUnit、Description、DistanceUnit" 进行更新。
 /// </remarks>
 public bool UpdateDatasourceInfo(string datasourceName, DatasourceInfo newDatasourceInfo)
 {
     return _dataProvider.UpdateDatasourceInfo(datasourceName, newDatasourceInfo);
 }